From: Nick Clifton Date: Mon, 30 Sep 2024 13:41:11 +0000 (+0100) Subject: Improve the placement of orphan note sections. X-Git-Tag: gdb-16-branchpoint~769 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ecf0250f7f0868f3b828ffadd47d0e5f2dbd875;p=thirdparty%2Fbinutils-gdb.git Improve the placement of orphan note sections. PR 32219 --- diff --git a/ld/ldelf.c b/ld/ldelf.c index 09691609fc0..2371af38b79 100644 --- a/ld/ldelf.c +++ b/ld/ldelf.c @@ -2118,7 +2118,7 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint) { ".bss", SEC_ALLOC, 0, 0, 0, 0 }, - { 0, + { NULL, SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_DATA, 0, 0, 0, 0 }, { ".interp", @@ -2328,7 +2328,18 @@ ldelf_place_orphan (asection *s, const char *secname, int constraint) && (elfinput ? sh_type == SHT_NOTE : startswith (secname, ".note"))) - place = &hold[orphan_interp]; + { + /* PR 32219: Check that the .interp section + exists before attaching orphans to it. */ + if (lang_output_section_find (hold[orphan_interp].name)) + place = &hold[orphan_interp]; + /* Next best place: after .rodata. */ + else if (lang_output_section_find (hold[orphan_rodata].name)) + place = &hold[orphan_rodata]; + /* Last attempt: the .text section. */ + else + place = &hold[orphan_text]; + } else if ((flags & (SEC_LOAD | SEC_HAS_CONTENTS | SEC_THREAD_LOCAL)) == 0) place = &hold[orphan_bss]; else if ((flags & SEC_SMALL_DATA) != 0) diff --git a/ld/ldlang.c b/ld/ldlang.c index 95d64fd05e2..7f9e3d2b119 100644 --- a/ld/ldlang.c +++ b/ld/ldlang.c @@ -9012,7 +9012,7 @@ lang_record_phdrs (void) continue; /* Don't add orphans to PT_INTERP header. */ - if (l->type == 3) + if (l->type == PT_INTERP) continue; if (last == NULL) diff --git a/ld/scripttempl/arclinux.sc b/ld/scripttempl/arclinux.sc index 36ba5a664d3..245e0208f0b 100644 --- a/ld/scripttempl/arclinux.sc +++ b/ld/scripttempl/arclinux.sc @@ -661,6 +661,7 @@ source_sh $srcdir/scripttempl/DWARF.sc cat <INSN} + .text ${RELOCATING+${TEXT_START_ADDR}} : { ${RELOCATING+${TEXT_START_SYMBOLS} @@ -175,7 +179,7 @@ SECTIONS EOF -source_sh $srcdir/scripttempl/misc-sections.sc +source_sh $srcdir/scripttempl/misc-sections.sc DATA source_sh $srcdir/scripttempl/DWARF.sc cat <