]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Improve the placement of orphan note sections.
authorNick Clifton <nickc@redhat.com>
Mon, 30 Sep 2024 13:41:11 +0000 (14:41 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 30 Sep 2024 13:41:11 +0000 (14:41 +0100)
PR 32219

14 files changed:
ld/ldelf.c
ld/ldlang.c
ld/scripttempl/arclinux.sc
ld/scripttempl/elf32cr16.sc
ld/scripttempl/elf32crx.sc
ld/scripttempl/elfd10v.sc
ld/scripttempl/elfxtensa.sc
ld/scripttempl/mep.sc
ld/scripttempl/misc-sections.sc
ld/scripttempl/nds32elf.sc
ld/scripttempl/v850.sc
ld/scripttempl/v850_rh850.sc
ld/testsuite/ld-elf/pr23658-1a.d
ld/testsuite/ld-elf/pr23658-1e.d

index 09691609fc0e920eb53dabc7050c0aee046d2f0e..2371af38b79851267bd496bc42245143a2baac65 100644 (file)
@@ -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)
index 95d64fd05e2f251006d81250f924507a13bc976c..7f9e3d2b119b57015149dbbc15a7167ac6e36af1 100644 (file)
@@ -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)
index 36ba5a664d356d54ba521e34fff22750bd9998dc..245e0208f0b1fcd98b1e49bed01f73e8047762a5 100644 (file)
@@ -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}}
index 3e7d92a4f34fa60dd7280a5d72760f491bf024aa..305f1f27cd2635de7a632a4f2e82591a78db7d47 100644 (file)
@@ -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
index 1b1316676a76dd5f377f60ba3b04bd20a1ca11b7..0dcf6adad2328f4533e7e768d88cba6b5b769f8e 100644 (file)
@@ -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
index 1ecf4a19092056e1c984132a00a53502509290a8..8d139de8b51d60b421ae4d8a906f3937df09f094 100644 (file)
@@ -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
index 231f53b5f5b102f45ff5cf7ebf817007bc01a119..046e87244874e7ee4eddf0c0a0d284e62cb99651 100644 (file)
@@ -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}}
index 39e4d64857c12a2883b1fb94179e272d9ac4650e..2f085d75000feb6b8ccc5ef3fcef2dc9fc33313f 100644 (file)
@@ -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}}
index 94ad7157b883a0bcca64ca29259241a216638076..71b1a6ba643e71d684775fdf8ed1662b5f2947f0 100644 (file)
@@ -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
index 0f8366d91ac9e0a4c7bd125175c883f44d640832..ac7de72a32648b40b915f78e7a316319f47206c6 100644 (file)
@@ -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
index 10d1da8b5bb30e7d8c884b28725dc33c76fe30f1..7daea326d2f2e2b13f9c25b329b12d7e179faa4b 100644 (file)
@@ -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.  */
 
index e63e7db888453a7786110a7834f0582c73166794..dd9d832d5faceb9ac1ec816e99120747c3fde2f2 100644 (file)
@@ -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.  */
 
index 388f7a42fa759222bbf4b9c8e07a8c7e5f153de3..21847f9350c74aae9ef0b107d01991bce57c9955 100644 (file)
@@ -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 +
index a281e48d730ce2342d28e1de572351676221a539..992c7484ff7a54c61dbfe08fcb9f0f061a90ed46 100644 (file)
 # 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