aboutsummaryrefslogtreecommitdiff
path: root/ld
diff options
context:
space:
mode:
authorNick Clifton <nickc@redhat.com>2024-09-30 14:41:11 +0100
committerNick Clifton <nickc@redhat.com>2024-09-30 14:41:11 +0100
commit7ecf0250f7f0868f3b828ffadd47d0e5f2dbd875 (patch)
tree14ea6e716632df8b904e1b8509ef949d97d8569f /ld
parent4339a3ffc39af599305bd992536dd379ac8390ca (diff)
downloadbinutils-7ecf0250f7f0868f3b828ffadd47d0e5f2dbd875.zip
binutils-7ecf0250f7f0868f3b828ffadd47d0e5f2dbd875.tar.gz
binutils-7ecf0250f7f0868f3b828ffadd47d0e5f2dbd875.tar.bz2
Improve the placement of orphan note sections.
PR 32219
Diffstat (limited to 'ld')
-rw-r--r--ld/ldelf.c15
-rw-r--r--ld/ldlang.c2
-rw-r--r--ld/scripttempl/arclinux.sc1
-rw-r--r--ld/scripttempl/elf32cr16.sc2
-rw-r--r--ld/scripttempl/elf32crx.sc2
-rw-r--r--ld/scripttempl/elfd10v.sc6
-rw-r--r--ld/scripttempl/elfxtensa.sc5
-rw-r--r--ld/scripttempl/mep.sc5
-rw-r--r--ld/scripttempl/misc-sections.sc28
-rw-r--r--ld/scripttempl/nds32elf.sc3
-rw-r--r--ld/scripttempl/v850.sc4
-rw-r--r--ld/scripttempl/v850_rh850.sc4
-rw-r--r--ld/testsuite/ld-elf/pr23658-1a.d4
-rw-r--r--ld/testsuite/ld-elf/pr23658-1e.d3
14 files changed, 71 insertions, 13 deletions
diff --git a/ld/ldelf.c b/ld/ldelf.c
index 0969160..2371af3 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 95d64fd..7f9e3d2 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 36ba5a6..245e020 100644
--- a/ld/scripttempl/arclinux.sc
+++ b/ld/scripttempl/arclinux.sc
@@ -661,6 +661,7 @@ source_sh $srcdir/scripttempl/DWARF.sc
cat <<EOF
${ATTRS_SECTIONS}
+ .ARC.attributes 0 : { KEEP (*(.ARC.attributes)) }
${OTHER_SECTIONS}
${RELOCATING+${OTHER_SYMBOLS}}
${RELOCATING+${DISCARDED}}
diff --git a/ld/scripttempl/elf32cr16.sc b/ld/scripttempl/elf32cr16.sc
index 3e7d92a..305f1f2 100644
--- a/ld/scripttempl/elf32cr16.sc
+++ b/ld/scripttempl/elf32cr16.sc
@@ -171,7 +171,7 @@ SECTIONS
EOF
-source_sh $srcdir/scripttempl/misc-sections.sc
+source_sh $srcdir/scripttempl/misc-sections.sc rom
source_sh $srcdir/scripttempl/DWARF.sc
cat <<EOF
diff --git a/ld/scripttempl/elf32crx.sc b/ld/scripttempl/elf32crx.sc
index 1b13166..0dcf6ad 100644
--- a/ld/scripttempl/elf32crx.sc
+++ b/ld/scripttempl/elf32crx.sc
@@ -169,7 +169,7 @@ SECTIONS
EOF
-source_sh $srcdir/scripttempl/misc-sections.sc
+source_sh $srcdir/scripttempl/misc-sections.sc rom
source_sh $srcdir/scripttempl/DWARF.sc
cat <<EOF
diff --git a/ld/scripttempl/elfd10v.sc b/ld/scripttempl/elfd10v.sc
index 1ecf4a1..8d139de 100644
--- a/ld/scripttempl/elfd10v.sc
+++ b/ld/scripttempl/elfd10v.sc
@@ -102,6 +102,10 @@ EOF
cat <<EOF
SECTIONS
{
+ /* PR 32100: GDB makes use of the fact that the .note.gnu.build-id
+ section is typically placed next to the ELF headers. */
+ .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) } ${RELOCATING+ >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 <<EOF
diff --git a/ld/scripttempl/elfxtensa.sc b/ld/scripttempl/elfxtensa.sc
index 231f53b..046e872 100644
--- a/ld/scripttempl/elfxtensa.sc
+++ b/ld/scripttempl/elfxtensa.sc
@@ -305,6 +305,10 @@ ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
SECTIONS
{
+ /* PR 32100: GDB makes use of the fact that the .note.gnu.build-id
+ section is typically placed next to the ELF headers. */
+ .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) }
+
/* Read-only sections, merged into text segment: */
${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
@@ -549,6 +553,7 @@ source_sh $srcdir/scripttempl/DWARF.sc
cat <<EOF
${ATTRS_SECTIONS}
+ .xtensa.info : { *(.xtensa.info) }
${OTHER_SECTIONS}
${RELOCATING+${OTHER_SYMBOLS}}
${RELOCATING+${DISCARDED}}
diff --git a/ld/scripttempl/mep.sc b/ld/scripttempl/mep.sc
index 39e4d64..2f085d7 100644
--- a/ld/scripttempl/mep.sc
+++ b/ld/scripttempl/mep.sc
@@ -230,6 +230,11 @@ SECTIONS
${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
+
+ /* PR 32100: GDB makes use of the fact that the .note.gnu.build-id
+ section is typically placed next to the ELF headers. */
+ .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) }
+
${CREATE_SHLIB-${INTERP}}
${INITIAL_READONLY_SECTIONS}
${TEXT_DYNAMIC+${DYNAMIC}}
diff --git a/ld/scripttempl/misc-sections.sc b/ld/scripttempl/misc-sections.sc
index 94ad715..71b1a6b 100644
--- a/ld/scripttempl/misc-sections.sc
+++ b/ld/scripttempl/misc-sections.sc
@@ -3,10 +3,23 @@
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
-#
+
+# This script fragment gathers together some of the more miscellaneous
+# sections that might appear in a linker's input. It can be invoked
+# with a single parameter which is the memory region into which loadable
+# sections should be placed. If the parameter is missing, no memory
+# section placement is used.
+
+if test "x$2" = "x" ;
+then
+ REGION=""
+else
+ REGION="> $2"
+fi
+
cat <<EOF
/* Stabs debugging sections. */
- .stab 0 : { *(.stab) }
+ .stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
@@ -17,4 +30,15 @@ cat <<EOF
.gnu.build.attributes : { *(.gnu.build.attributes${RELOCATING+ .gnu.build.attributes.*}) }
+ /* Various note sections. Placed here so that they do not get
+ treated as orphan sections. */
+ .note.build-id : { *(.note.build-id) } ${RELOCATING+${REGION}}
+ .note.GNU-stack : { *(.note.GNU-stack) } ${RELOCATING+${REGION}}
+ .note.gnu-property : { *(.note.gnu-property) } ${RELOCATING+${REGION}}
+ .note.ABI-tag : { *(.note.ABI-tag) } ${RELOCATING+${REGION}}
+ .note.package : { *(.note.package) } ${RELOCATING+${REGION}}
+ .note.dlopen : { *(.note.dlopen) } ${RELOCATING+${REGION}}
+ .note.netbsd.ident : { *(.note.netbsd.ident) } ${RELOCATING+${REGION}}
+ .note.openbsd.ident : { *(.note.openbsd.ident) } ${RELOCATING+${REGION}}
+
EOF
diff --git a/ld/scripttempl/nds32elf.sc b/ld/scripttempl/nds32elf.sc
index 0f8366d..ac7de72 100644
--- a/ld/scripttempl/nds32elf.sc
+++ b/ld/scripttempl/nds32elf.sc
@@ -597,6 +597,8 @@ SHLIB_LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${SHLIB_LARGE_DATA_A
${TINY_DATA_SECTION}
${TINY_BSS_SECTION}
${STACK_ADDR+${STACK}}
+
+ ${RELOCATING+${DISCARDED}}
EOF
test -z "${NON_ALLOC_DYN}" || emit_dyn
@@ -608,6 +610,5 @@ cat <<EOF
${ATTRS_SECTIONS}
${OTHER_SECTIONS}
${RELOCATING+${OTHER_SYMBOLS}}
- ${RELOCATING+${DISCARDED}}
}
EOF
diff --git a/ld/scripttempl/v850.sc b/ld/scripttempl/v850.sc
index 10d1da8..7daea32 100644
--- a/ld/scripttempl/v850.sc
+++ b/ld/scripttempl/v850.sc
@@ -19,6 +19,10 @@ SEARCH_DIR(.);
${RELOCATING+EXTERN(__ctbp __ep __gp)};
SECTIONS
{
+ /* PR 32100: GDB makes use of the fact that the .note.gnu.build-id
+ section is typically placed next to the ELF headers. */
+ .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) }
+
/* This saves a little space in the ELF file, since the zda starts
at a higher location that the ELF headers take up. */
diff --git a/ld/scripttempl/v850_rh850.sc b/ld/scripttempl/v850_rh850.sc
index e63e7db..dd9d832 100644
--- a/ld/scripttempl/v850_rh850.sc
+++ b/ld/scripttempl/v850_rh850.sc
@@ -19,6 +19,10 @@ SEARCH_DIR(.);
${RELOCATING+EXTERN(__ctbp __ep __gp)};
SECTIONS
{
+ /* PR 32100: GDB makes use of the fact that the .note.gnu.build-id
+ section is typically placed next to the ELF headers. */
+ .note.gnu.build-id ${RELOCATING-0}: { *(.note.gnu.build-id) }
+
/* This saves a little space in the ELF file, since the zda starts
at a higher location that the ELF headers take up. */
diff --git a/ld/testsuite/ld-elf/pr23658-1a.d b/ld/testsuite/ld-elf/pr23658-1a.d
index 388f7a4..21847f9 100644
--- a/ld/testsuite/ld-elf/pr23658-1a.d
+++ b/ld/testsuite/ld-elf/pr23658-1a.d
@@ -9,10 +9,8 @@
# SHT_NOTE sections aren't grouped nor sorted.
#xfail: [uses_genelf]
#xfail: m68hc12-*
-# The following targets don't support --build-id.
-#xfail: cr16-* crx-* visium-*
# The following targets place .note.gnu.build-id in unusual places.
-#xfail: pru-*
+#xfail: d10v-* pru-*
#...
+[0-9]+ +\.note\.4 \.note\.1 +
diff --git a/ld/testsuite/ld-elf/pr23658-1e.d b/ld/testsuite/ld-elf/pr23658-1e.d
index a281e48..992c748 100644
--- a/ld/testsuite/ld-elf/pr23658-1e.d
+++ b/ld/testsuite/ld-elf/pr23658-1e.d
@@ -14,10 +14,11 @@
# The following targets don't support --build-id.
#xfail: cr16-* crx-* visium-*
# The following targets place .note.gnu.build-id in unusual places.
-#xfail: pru-*
+#xfail: *-*-hpux* arc*-* avr-* microblaze-*-* nds32*-* spu-*-*
#...
+[0-9]+ +\.note.gnu.build-id +
+#...
+[0-9]+ +\.note\.4 \.note\.1 +
+[0-9]+ +\.note\.2 \.note\.3 +
#pass