From nobody Tue Apr 18 18:49:16 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Q1Cd83DLJz45Vmb; Tue, 18 Apr 2023 18:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Q1Cd82J28z3Kmw; Tue, 18 Apr 2023 18:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681843756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rXGOMESswaXlyct14vb76YY/WLM1x+k507i/ncR/FZk=; b=spJwGzoah8g1wDiK2TmO87njAAQoHawplOo9ZvnN02+C41MwNp5WD9aq1RR/golVWD29lm SPw7jDyCtq9Ppgx8oJjRavWOnEsJOIRxcPOot5mk4NaeuYZKrtkgKpsaEBh6A83OtJM7W/ PhuAMUyIuBtw1/5/UX4TZwx8C7mkEHo09qgD49qEpNSr9jGai1zbQ1pvuwYWLPoJxHOf/O LQhUyFG0zCoNyxIpQA5BeolN70FIBkFLX9QO2epOHeJ7CbmDc6j9dMRoFyYxQ3B3BcMVDn lMpNgVcrRSET3zt5FrQshGDRwB2ehQ04sRvvqOfz7edxJRluicG1pzYDnD8a6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681843756; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=rXGOMESswaXlyct14vb76YY/WLM1x+k507i/ncR/FZk=; b=ybIrY4sP+ZN38AtZbOcb/WaZJcRJl6J2Mhwjs43LGKJzCpRHJhm+IcaGYRActCUz0V7FJY bTbBzaZD5FoVWtXH6MIRuNBfLy9jsHBgH6oOVdRBPM5rIjOYhZ5JLv6eAGoSCrO2DNB9H6 Sv/C7ql7hobtCVJ8pcASHSnsXXog1QzR2GKoSUydJdC+x9qs3JVeCBfHhkcfmsI1RQM4iB QqJcv+qCJp2H0Q2dhjlh2rPYyek1TV+jzl4ekgzmvfdDG17uab2yoh7WXyu03ezpBhxYN1 7HewhG5jUPiFsy8f3wYztm2FKlLi2PSN3XdrKgVG7GY6UdtPK/k5K4hlTh4aBQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681843756; a=rsa-sha256; cv=none; b=nv5wUuX14flqmddR7VOHDL7lWu/JmgyWGi9QR3O9Y2OJVModjaooNRauPHxRBSTMksM2vk tq6Cxu4UNP6tuXWH5wBu+KiJY5KNI05hOOci81iSq12ApxTSOrAqkkTpRKJgU6m9cweETf 3W0Sz7mJo6Q0oeRHWlU6Mdjk/h9sKdd4osmumPT06RspFdVsx0gAbSSnH/jsE6iViA8nGV 2R70EQLMA5DHKmtuQ/WzNxrxHYsR7XUSfn9M71FkK42ymkGO0WYCfxFn4TUniMwCR7YjPk vSnSI2WltbZnjmXa7uTKzxqjic0iJWbC8MG7+XSsH1FdPB3flMUOehaNBOJiOA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Q1Cd81M0JzNm8; Tue, 18 Apr 2023 18:49:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 33IInG1R047329; Tue, 18 Apr 2023 18:49:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33IInGjI047328; Tue, 18 Apr 2023 18:49:16 GMT (envelope-from git) Date: Tue, 18 Apr 2023 18:49:16 GMT Message-Id: <202304181849.33IInGjI047328@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 21d56b796634 - main - loader.efi: Fix some arm64 PE metadata List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 21d56b796634bda628b149c717461bf88c23677d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=21d56b796634bda628b149c717461bf88c23677d commit 21d56b796634bda628b149c717461bf88c23677d Author: Mark Johnston AuthorDate: 2023-04-18 18:32:04 +0000 Commit: Mark Johnston CommitDate: 2023-04-18 18:36:24 +0000 loader.efi: Fix some arm64 PE metadata - Mark the file as an executable in the COFF header. - Provide separate .text and .data sections. - Provide sane file and section alignment values. These values are the defaults defined in the PE specification. - Set appropriate characteristics for each of .text and .data. This is required for the MS devkit to load our UEFI image. Obtained from: OpenBSD via allanjude MFC after: 1 month Differential Revision: https://reviews.freebsd.org/D37765 --- stand/efi/loader/arch/arm64/ldscript.arm64 | 5 +++- stand/efi/loader/arch/arm64/start.S | 46 ++++++++++++++++-------------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/stand/efi/loader/arch/arm64/ldscript.arm64 b/stand/efi/loader/arch/arm64/ldscript.arm64 index d0ed320a319c..c10448f4180e 100644 --- a/stand/efi/loader/arch/arm64/ldscript.arm64 +++ b/stand/efi/loader/arch/arm64/ldscript.arm64 @@ -16,7 +16,9 @@ SECTIONS *(.gnu.warning) *(.plt) } =0xD4200000 - . = ALIGN(16); + . = ALIGN(4096); + _etext = .; + __data_start = .; .data : { *(.rodata .rodata.* .gnu.linkonce.r.*) *(.rodata1) @@ -78,6 +80,7 @@ SECTIONS . = ALIGN(16); .dynsym : { *(.dynsym) } _edata = .; + __data_size = . - __data_start; /* Unused sections */ .interp : { *(.interp) } diff --git a/stand/efi/loader/arch/arm64/start.S b/stand/efi/loader/arch/arm64/start.S index 675d4e153f36..0b8537fed30e 100644 --- a/stand/efi/loader/arch/arm64/start.S +++ b/stand/efi/loader/arch/arm64/start.S @@ -34,11 +34,14 @@ #define IMAGE_FILE_MACHINE_ARM64 0xaa64 +#define IMAGE_FILE_EXECUTABLE 0x0002 + #define IMAGE_SCN_CNT_CODE 0x00000020 #define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040 #define IMAGE_SCN_MEM_DISCARDABLE 0x02000000 #define IMAGE_SCN_MEM_EXECUTE 0x20000000 #define IMAGE_SCN_MEM_READ 0x40000000 +#define IMAGE_SCN_MEM_WRITE 0x80000000 .section .peheader,"a" efi_start: @@ -60,22 +63,22 @@ coff_head: .long 0 /* No symbol table */ .long 0 /* No symbols */ .short section_table - optional_header /* Optional header size */ - .short 0 /* Characteristics TODO: Fill in */ + .short IMAGE_FILE_EXECUTABLE /* Characteristics */ optional_header: .short 0x020b /* PE32+ (64-bit addressing) */ .byte 0 /* Major linker version */ .byte 0 /* Minor linker version */ - .long _edata - _end_header /* Code size */ - .long 0 /* No initialized data */ + .long _etext - _end_header /* Code size */ + .long __data_size /* Initialized data size */ .long 0 /* No uninitialized data */ .long _start - efi_start /* Entry point */ .long _end_header - efi_start /* Start of code */ optional_windows_header: .quad 0 /* Image base */ - .long 32 /* Section Alignment */ - .long 8 /* File alignment */ + .long 4096 /* Section Alignment */ + .long 512 /* File alignment */ .short 0 /* Major OS version */ .short 0 /* Minor OS version */ .short 0 /* Major image version */ @@ -104,36 +107,37 @@ optional_windows_header: .quad 0 section_table: - /* We need a .reloc section for EFI */ - .ascii ".reloc" + .ascii ".text" + .byte 0 .byte 0 .byte 0 /* Pad to 8 bytes */ - .long 0 /* Virtual size */ - .long 0 /* Virtual address */ - .long 0 /* Size of raw data */ - .long 0 /* Pointer to raw data */ + .long _etext - _end_header /* Virtual size */ + .long _end_header - efi_start /* Virtual address */ + .long _etext - _end_header /* Size of raw data */ + .long _end_header - efi_start /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ - .long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \ - IMAGE_SCN_MEM_DISCARDABLE) /* Characteristics */ + .long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \ + IMAGE_SCN_MEM_READ) /* Characteristics */ - /* The contents of the loader */ - .ascii ".text" + .ascii ".data" .byte 0 .byte 0 .byte 0 /* Pad to 8 bytes */ - .long _edata - _end_header /* Virtual size */ - .long _end_header - efi_start /* Virtual address */ - .long _edata - _end_header /* Size of raw data */ - .long _end_header - efi_start /* Pointer to raw data */ + .long __data_size /* Virtual size */ + .long __data_start - efi_start /* Virtual address */ + .long __data_size /* Size of raw data */ + .long __data_start - efi_start /* Pointer to raw data */ .long 0 /* Pointer to relocations */ .long 0 /* Pointer to line numbers */ .short 0 /* Number of relocations */ .short 0 /* Number of line numbers */ - .long (IMAGE_SCN_CNT_CODE | IMAGE_SCN_MEM_EXECUTE | \ - IMAGE_SCN_MEM_READ) /* Characteristics */ + .long (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | \ + IMAGE_SCN_MEM_WRITE) /* Characteristics */ + + .align 12 _end_header: .text