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 <ardb@kernel.org>
This commit is contained in:
Ard Biesheuvel 2025-01-28 10:34:01 +01:00 committed by mergify[bot]
parent e5d95c786b
commit f2b42c83dd

View File

@ -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 { SECTIONS {
/* /*
@ -35,7 +41,7 @@ SECTIONS {
* emitted GUIDs here. * emitted GUIDs here.
*/ */
*:AutoGen.obj(.data.g*Guid) *:AutoGen.obj(.data.g*Guid)
} } :text
/* /*
* The alignment of the .data section should be less than or equal to the * 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 ALIGN(ALIGNOF(.text)) : ALIGN(CONSTANT(COMMONPAGESIZE)) {
*(.data .data.* .gnu.linkonce.d.*) *(.data .data.* .gnu.linkonce.d.*)
*(.bss .bss.*) *(.bss .bss.*)
} } :data
.eh_frame ALIGN(CONSTANT(COMMONPAGESIZE)) : { .eh_frame ALIGN(CONSTANT(COMMONPAGESIZE)) : {
KEEP (*(.eh_frame)) KEEP (*(.eh_frame))
} }
.dynamic : { *(.dynamic) } :data :dynamic
.rela (INFO) : { .rela (INFO) : {
*(.rela .rela.*) *(.rela .rela.*)
} }
.hii : ALIGN(CONSTANT(COMMONPAGESIZE)) { .hii : ALIGN(CONSTANT(COMMONPAGESIZE)) {
KEEP (*(.hii)) KEEP (*(.hii))
} } :data
.got : { .got : {
*(.got) *(.got)