From f2b42c83dd0086dce484eae47b87b4351426746e Mon Sep 17 00:00:00 2001 From: Ard Biesheuvel Date: Tue, 28 Jan 2025 10:34:01 +0100 Subject: BaseTools/Scripts/GccBase.lds: Use separate R-W and RW- ELF segments To prevent the ELF linkers from complaining about emitted ELF segments that require both writable and executable permissions, define two separate R-X and RW- ELF segments, and emit the output sections explicitly into those segments as appropriate. Note that this has no bearing on the PE image, and using a single RW- segment would probably be fine too. Signed-off-by: Ard Biesheuvel --- BaseTools/Scripts/GccBase.lds | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BaseTools/Scripts/GccBase.lds b/BaseTools/Scripts/GccBase.lds index 582d00ccba..8d6c29d7b6 100644 --- a/BaseTools/Scripts/GccBase.lds +++ b/BaseTools/Scripts/GccBase.lds @@ -10,6 +10,12 @@ **/ +PHDRS { + text PT_LOAD FLAGS(5); /* R_X */ + data PT_LOAD FLAGS(6); /* RW_ */ + dynamic PT_DYNAMIC FLAGS(4); /* R__ */ +} + SECTIONS { /* @@ -35,7 +41,7 @@ SECTIONS { * emitted GUIDs here. */ *:AutoGen.obj(.data.g*Guid) - } + } :text /* * The alignment of the .data section should be less than or equal to the @@ -46,19 +52,21 @@ SECTIONS { .data ALIGN(ALIGNOF(.text)) : ALIGN(CONSTANT(COMMONPAGESIZE)) { *(.data .data.* .gnu.linkonce.d.*) *(.bss .bss.*) - } + } :data .eh_frame ALIGN(CONSTANT(COMMONPAGESIZE)) : { KEEP (*(.eh_frame)) } + .dynamic : { *(.dynamic) } :data :dynamic + .rela (INFO) : { *(.rela .rela.*) } .hii : ALIGN(CONSTANT(COMMONPAGESIZE)) { KEEP (*(.hii)) - } + } :data .got : { *(.got) -- cgit