From nobody Mon May 29 13:13:55 2023 X-Original-To: dev-commits-src-all@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 4QVGFJ1Yz6z4XlWN; Mon, 29 May 2023 13:13:56 +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 4QVGFJ14jFz3FVD; Mon, 29 May 2023 13:13:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685366036; 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=X0AOl9x8Wfx3REa92qJHrxoJPXrOhhdu1mnWeLFoyQU=; b=yyjWP8462yq4isOo2lWg24P9VjELd9S3q2RonPnc2o6fPzFtQkX7rbS7iqSrVYe2T+V+wZ WRWEh1V+SUmpXZthn+o3Snf9USNklKDXzUNiSKZLfZN7qGzl36MmGEuzmrx2DZxDRvVlBL SSoPWP/lQSEenK53SDfxmywVseAS9sgfKMcG2FCMap+w6Lw5yUASZ1+luTRhYCy0epnzi+ 5jJKBSNAPlmJf1+hnl2rvoMJM4iGlHIULurHqzw2m177NwibkCZgk/dVMNNfhOEfRTN/r6 5dgB6Cj8FZg6gGCV1ea3XyNgJe4W5LXLJGmz95F/qzrM2lTEuXr+Pl121bEyQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685366036; 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=X0AOl9x8Wfx3REa92qJHrxoJPXrOhhdu1mnWeLFoyQU=; b=EeW7emanfG/dOWtRvDV1OiaAQX5Y+HUst2Ur1JQSm0UYuaSYNMwh+q3HLUMYES1RMqvd97 OVqTV2FEVskgWtntZzS+S7w67zVGViebJd1N7Tool9mPG9jNIMtl+5gIVEJnEYimqSRrS8 EYPKBeWywK145mypGBNu5s3sjVx6YaTz+u7Syc1pT7IwbU+Lc6jbCcqOtfqBStU1ZMoABd 9INphKQAgoSe3XzrV1BDfWK5b0n+lcAAm3NEFz1lYjN0tOsJ3N8Vw7qFhBDlfk+UyUKUKM kpRDJ9l4zoKMxxqTHoTf8XQt6v+mxPgpDSqbZ1WwHzGHH8t4lLn101RgRGKWYQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685366036; a=rsa-sha256; cv=none; b=vNNF9tmpcB8XUpxFmosXr43PiQhqzcvQJ2EYauwtZWcJr7Pj/rvc+EE67I+D9korENco99 qh+Oq+N3YlRfMt9hbgj6NhXiTyufaXmnNAsGfMgaIB1gWvK4JBzmKQc/xKKkvMJdLiTnBJ hPqzmZAVHfnGh4diENsWs18aTkYlAsUEvO0vh2FH9THsazCkTN/+b3zxXBrFnBXlChojHr pYFbt4AyD3Zgavrh0AerEOh+6Uc2Yapsn8/FHrX7twJydNyQbubnJyfND28qGuD8O1sIQ6 likU3RKAXapNqndDaz0RS/IlBobAKt/Gsdl5mcStkNLCmZJfsUkDvFcgKwLvkQ== 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 4QVGFJ0824z1CQP; Mon, 29 May 2023 13:13:56 +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 34TDDtUr057296; Mon, 29 May 2023 13:13:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34TDDtVr057295; Mon, 29 May 2023 13:13:55 GMT (envelope-from git) Date: Mon, 29 May 2023 13:13:55 GMT Message-Id: <202305291313.34TDDtVr057295@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 753f15c24fba - stable/13 - loader.efi: Fix some arm64 PE metadata List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 753f15c24fbac5f445477ea82d3b72b2a7a3d90d Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=753f15c24fbac5f445477ea82d3b72b2a7a3d90d commit 753f15c24fbac5f445477ea82d3b72b2a7a3d90d Author: Mark Johnston AuthorDate: 2023-04-18 18:32:04 +0000 Commit: Mark Johnston CommitDate: 2023-05-29 13:12:55 +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 (cherry picked from commit 21d56b796634bda628b149c717461bf88c23677d) --- 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