]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
hppa64: Re-enable -gc-section support on hppa*64*-*-hpux*
authorJohn David Anglin <danglin@gcc.gnu.org>
Thu, 7 May 2026 18:55:33 +0000 (14:55 -0400)
committerJohn David Anglin <danglin@gcc.gnu.org>
Thu, 7 May 2026 18:55:33 +0000 (14:55 -0400)
The previous change to elf_hppa_final_link_relocate didn't eliminate
relocatios with invalid offsets.  Here we take a different approach
to handle invalid offsets on hpux.  We allocate 16 bytes at the start
of the .data section for the linker.  If we encounter a relocation
with an invalid offset, we set the relocation's offset to the start
of the data section.  As a result, the HP dynamic linker is happy
and we can re-enable -gc-section support.

2026-05-07  John David Anglin  <danglin@gcc.gnu.org>

bfd/ChangeLog:

* elf64-hppa.c (elf_hppa_final_link_relocate): Rework
handling of relocations with invalid offsets on hpux.
(elf_backend_can_gc_sections): Set to one on hpux.

ld/ChangeLog:

* emulparams/elf64hppa.sh (DATA_START_SYMBOLS): Define.
* testsuite/ld-elf/group8a.d: Revert commit d6ce0aa3f877.
* testsuite/ld-elf/group8b.d: Likewise.
* testsuite/ld-elf/group9a.d: Likewise.
* testsuite/ld-elf/group9b.d: Likewise.
* testsuite/ld-elf/pr12851.d: Likewise.
* testsuite/ld-elf/pr22677.d: Likewise.

bfd/elf64-hppa.c
ld/emulparams/elf64hppa.sh
ld/testsuite/ld-elf/group8a.d
ld/testsuite/ld-elf/group8b.d
ld/testsuite/ld-elf/group9a.d
ld/testsuite/ld-elf/group9b.d
ld/testsuite/ld-elf/pr12851.d
ld/testsuite/ld-elf/pr22677.d

index 4f405c32f35e544ef559ddd36d2b09c68cd92134..8de91622465321b0fe111bad56e7a2168018f283 100644 (file)
@@ -4060,24 +4060,33 @@ elf_hppa_final_link_relocate (Elf_Internal_Rela *rel,
                                                 rel->r_offset);
              skip = out_off == (bfd_vma) -1 || out_off == (bfd_vma) -2;
 
-             /* If this triggers, we need to skip this relocation or
-                output a NULL relocation.  Skipping the relocation messes
-                up the relocation count as we can't detect this case in
-                elf64_hppa_late_size_sections().  The HP dynamic linker
-                doesn't like relocations with the R_PARISC_NONE type.
-                So, we are scuppered.  We need to avoid dynamic relocations
-                in linkonce sections that may be garbage collected.  */
-             BFD_ASSERT (!skip || output_bfd->xvec != &hppa_elf64_vec);
-
-             if (skip)
-               memset (&rela, 0, sizeof (rela));
-             else
+             /* The HP dynamic linker doesn't support relocations with
+                the R_PARISC_NONE type.  So, we can't just output a zero
+                relocation if we encounter an invalid offset.  We reserve
+                16 bytes at the start of the data section that aren't
+                used.  */
+             if (skip && output_bfd->xvec == &hppa_elf64_vec)
+               {
+                 /* Set the relocation offset to the start of the
+                    data section.  */
+                 skip = false;
+                 baseh = hppa_info->data_hash_entry;
+                 sec = baseh->root.u.def.section;
+                 rela.r_offset = (sec->output_offset
+                                  + sec->output_section->vma);
+               }
+             else if (!skip)
                {
                  /* This is the output relocation offset.  */
                  rela.r_offset = (out_off
                                   + input_section->output_offset
                                   + input_section->output_section->vma);
+               }
 
+             if (skip)
+               memset (&rela, 0, sizeof (rela));
+             else
+               {
                  /* Select base segment.  */
                  if (sym_sec->flags & SEC_READONLY)
                    baseh = hppa_info->text_hash_entry;
@@ -4582,7 +4591,7 @@ static const struct elf_size_info hppa64_elf_size_info =
 #define elf_backend_link_output_symbol_hook \
        elf64_hppa_link_output_symbol_hook
 
-#define elf_backend_can_gc_sections    0
+#define elf_backend_can_gc_sections    1
 #define elf_backend_want_got_plt       0
 #define elf_backend_plt_readonly       0
 #define elf_backend_want_plt_sym       0
@@ -4612,9 +4621,6 @@ static const struct elf_size_info hppa64_elf_size_info =
 #define elf_backend_special_sections   (elf64_hppa_special_sections + 1)
 #undef elf_backend_modify_segment_map
 #undef elf_backend_want_p_paddr_set_to_zero
-
-#undef elf_backend_can_gc_sections
-#define elf_backend_can_gc_sections    1
 #undef elf_backend_want_dynrelro
 #define elf_backend_want_dynrelro      1
 
index 9f185ee491f543c7da5fbf4ebe21483ca37cc79e..9708d172f48e57a4cde302a4dbdb52c650b53fef 100644 (file)
@@ -101,6 +101,11 @@ OTHER_GOT_RELOC_SECTIONS="
   .rela.dlt     ${RELOCATING-0} : { *(.rela.dlt) }
   .rela.opd     ${RELOCATING-0} : { *(.rela.opd) }"
 
+# We're not actually providing a symbol anymore (due to the inability to be
+# safe in regards to shared libraries). So we just allocate the hunk of space
+# unconditionally, but do not mess around with the symbol table.
+DATA_START_SYMBOLS='. += 16;'
+
 DATA_PLT=
 PLT_BEFORE_GOT=
 
index 34e17636778815a9c3f793e4b9a0b6e951c3ebf8..09320f6cdf911f5e8ad430c1add2f998415c90ad 100644 (file)
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry foo
 #readelf: -g --wide
 # generic linker targets don't support --gc-sections, nor do a bunch of others
-#xfail: [is_generic] hppa*64*-*-hpux* mep-*-* mn10200-*-*
+#xfail: [is_generic] mep-*-* mn10200-*-*
 
 COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains . sections:
    \[Index\]    Name
index acfbd68eb670f68db0649d064e332e0b2703133b..a3851d005297bed8dc5501a17579e34c2b48b33b 100644 (file)
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry bar
 #readelf: -g --wide
 # generic linker targets don't support --gc-sections, nor do a bunch of others
-#xfail: [is_generic] hppa*64*-*-hpux* mep-*-* mn10200-*-*
+#xfail: [is_generic] mep-*-* mn10200-*-*
 
 COMDAT group section \[[ 0-9]+\] `.group' \[bar\] contains . sections:
    \[Index\]    Name
index 4fb7021721ba858e54a09c316a16fcfc24d282c6..9b481637dd5c6a7d59c926c1e9ac96cb609cac61 100644 (file)
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry foo
 #readelf: -g --wide
 # generic linker targets don't support --gc-sections, nor do a bunch of others
-#xfail: [is_generic] hppa*64*-*-hpux* mep-*-* mn10200-*-*
+#xfail: [is_generic] mep-*-* mn10200-*-*
 
 COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains . sections:
    \[Index\]    Name
index 08bd6138653f06eae84b20fd5f7e2160dcf11ed1..09cdb1f27cf34467867e13f48441130486e93901 100644 (file)
@@ -2,7 +2,7 @@
 #ld: -r --gc-sections --entry bar
 #readelf: -g --wide
 # generic linker targets don't support --gc-sections, nor do a bunch of others
-#xfail: [is_generic] hppa*64*-*-hpux* mep-*-* mn10200-*-*
+#xfail: [is_generic] mep-*-* mn10200-*-*
 
 COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains . sections:
    \[Index\]    Name
index 7d606008bb147a0fe429e3419140c9287c46050a..9880e4a1ef32f345688eae867b686d1d97af9787 100644 (file)
@@ -2,7 +2,7 @@
 #source: start.s
 #ld: --gc-sections
 #readelf: -s --wide
-#xfail: [is_generic] hppa*64*-*-hpux* mep-*-* mn10200-*-*
+#xfail: [is_generic] mep-*-* mn10200-*-*
 # generic linker targets don't support --gc-sections, nor do a bunch of others
 
 #...
index 4203289deade3c35666bc3af684af1bee63e7155..f2f21e4c115cf1cbdd6a48fc03691bb849b282dd 100644 (file)
@@ -2,7 +2,7 @@
 #readelf: -S --wide
 # generic linker targets don't support --gc-sections, nor do a bunch of
 # others.
-#xfail: [is_generic] hppa*64*-*-hpux* mep-*-* mn10200-*-*
+#xfail: [is_generic] mep-*-* mn10200-*-*
 
 #...
   \[[ 0-9]+\] \.preinit_array\.01000[ \t]+PREINIT_ARRAY[ \t0-9a-f]+WA?.*