From patchwork Thu May 7 19:00:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John David Anglin X-Patchwork-Id: 134645 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3F214BA2E36 for ; Thu, 7 May 2026 19:00:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3F214BA2E36 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=bell.net header.i=@bell.net header.a=rsa-sha256 header.s=selector1 header.b=HSjfLfXL X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from cmx-mtlrgo001.bell.net (mta-mtl-001.bell.net [209.71.208.11]) by sourceware.org (Postfix) with ESMTP id 2E9004BA2E30 for ; Thu, 7 May 2026 19:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E9004BA2E30 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=bell.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=bell.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2E9004BA2E30 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=209.71.208.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778180413; cv=none; b=j1mi9Dn/qMkeB1FdOuumYZGbNkxtLV6rdgaW4jKS7vdil6B8GzkF4PIHoWYDmYd54pOUJMFsmzCBgkEZ3MpCj+mjZDxoZJU3zHHdntEQBXrxTRcaF5zQL1USd6DEnb3wiCtcEemzvxfODLJPcuuwsPB+0l+F/kjbP69n35paDg8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778180413; c=relaxed/simple; bh=Od45U1cGfdYAkChUjdCLJErC7a10PfYkvB2TxXiRhBM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=J8Vj7dJ7CaLVyiZTQ3NZgTxiVT9tj/a3qCHMAWeJped0KSGzOS/b8N5Hw7wGG/m/aalaI7kA4jdBJ/QC/rWVIKzrGUKcZdiMaVOSPjCv6/AvbGS3Tu0MgpWkAaTYAPuiGEKfnTL4yF3dugnUHXdEyrv/npORYVm4z6db1wdwgzE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=bell.net header.i=@bell.net header.a=rsa-sha256 header.s=selector1 header.b=HSjfLfXL DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E9004BA2E30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bell.net; s=selector1; t=1778180413; bh=8ISjVsGaQ0XqKlIVNOy2NQKsTqn0MPUEcArjNhAzgVc=; h=Date:From:To:Subject:Message-ID:MIME-Version:Content-Type; b=HSjfLfXLlLBxYmdOziKSSCuW0Xl2DafAh9R3pzeS/ZDdPxfI1cx5LXhRoSYpZgMuaMaL9SGDJIpJqRenXWv3TttRbWgVpN6dFrtxEYkg0DV8ufqaxLUDWDyPFN21Q+brmAEXkgLJGyvF7f0KrB1Q6SAmbRvCChuXOp1niwXTCdtWBoiI9qEkcQlYneQwtsS+EneQt/byHBFR18PkW6coYnpzzL04ieRU93BepZqpY0qpwAF4/P2ea743qUITiP535sBIpJd7Pb+kj21Y2aOKCeGavqiQ6G/rbobBjkvHEkCYcia9F9mr891bb/AHdJJZaTVxJfU4r71rdl//X+6e7A== X-RG-SOPHOS: Clean X-RG-VADE-SC: 0 X-RG-VADE: Clean X-Originating-IP: [70.26.67.152] X-RG-Env-Sender: dave.anglin@bell.net X-RG-Rigid: 69BEEF9306CD2B29 X-RazorGate-Vade: dmFkZTEplwBULrNtRxm1HKJL38ENsBuIisovQPylP7QdLpJqcp6o/nMrqy0aRqbk62gSu7HoBheLdAD02KMWyPX75toljYVqNxt805TDchg8k2RBoznM2AljJMbizuaH1Zo90Jx1L5R02GJcLF+WOAGsHySeuFN8Jmb0k3GN08oCIX+wd7TisuloYPo7OVwXTE1Z3AFgFXwBEsYRGu2KXddSuVp2WpwRq88yAi9H3tVAGG0Fd7OIVSmc0KOUacRnv2oXDJpxUoMD4tdakl5vpNJAWMuObcWSkPJKru1U9dg9lKrEbrgTPLAU91NwZFafyVFW3frKyZLK+YLfKPRp16uGIMELf3hLKdCeiJ5Q3FzBAQKTnZu7RFdILXihtcYTQiDhjioGNtpg5fStclkFFZqXU2upTd7PyOkHGpsWE75LL++hkWIHffoq/Yk4ddJdrGTs7RrNyiO7qMW6GKzOREwvne67CbOeQ5Q5DK3bzwfal1LgXQJ5/sJjV2DE3wEtOSg+Kyjl1elPZHwH2PTS8lYjVTvEHPn7VA7pN8HdTFrn3SzWkOpFrqn8BcTPPrzCA2yBfdnp0XadLRo54gLT3ayGfcxEWbvXffQKn+xnZwGnD8MiLO/JIRvaUA2H1Q9LgkKMEHgxvOKVXSo7+J0J95eXk3rWeFAIQ9djfVD+P1xHG+JF9A X-RazorGate-Vade-Verdict: clean 0 X-RazorGate-Vade-Classification: clean Received: from mx3210.local (70.26.67.152) by cmx-mtlrgo001.bell.net (authenticated as dave.anglin@bell.net) id 69BEEF9306CD2B29; Thu, 7 May 2026 15:00:12 -0400 Date: Thu, 7 May 2026 15:00:11 -0400 From: John David Anglin To: Binutils Subject: [committed] hppa64: Re-enable -gc-section support on hppa*64*-*-hpux* Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org Tested on hppa64-hp-hpux11.11 and x86_64-pc-linux-gnu. Committed to master. Dave --- hppa64: Re-enable -gc-section support on hppa*64*-*-hpux* 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 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. diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c index 4f405c32f35..8de91622465 100644 --- a/bfd/elf64-hppa.c +++ b/bfd/elf64-hppa.c @@ -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 diff --git a/ld/emulparams/elf64hppa.sh b/ld/emulparams/elf64hppa.sh index 9f185ee491f..9708d172f48 100644 --- a/ld/emulparams/elf64hppa.sh +++ b/ld/emulparams/elf64hppa.sh @@ -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= diff --git a/ld/testsuite/ld-elf/group8a.d b/ld/testsuite/ld-elf/group8a.d index 34e17636778..09320f6cdf9 100644 --- a/ld/testsuite/ld-elf/group8a.d +++ b/ld/testsuite/ld-elf/group8a.d @@ -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 diff --git a/ld/testsuite/ld-elf/group8b.d b/ld/testsuite/ld-elf/group8b.d index acfbd68eb67..a3851d00529 100644 --- a/ld/testsuite/ld-elf/group8b.d +++ b/ld/testsuite/ld-elf/group8b.d @@ -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 diff --git a/ld/testsuite/ld-elf/group9a.d b/ld/testsuite/ld-elf/group9a.d index 4fb7021721b..9b481637dd5 100644 --- a/ld/testsuite/ld-elf/group9a.d +++ b/ld/testsuite/ld-elf/group9a.d @@ -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 diff --git a/ld/testsuite/ld-elf/group9b.d b/ld/testsuite/ld-elf/group9b.d index 08bd6138653..09cdb1f27cf 100644 --- a/ld/testsuite/ld-elf/group9b.d +++ b/ld/testsuite/ld-elf/group9b.d @@ -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 diff --git a/ld/testsuite/ld-elf/pr12851.d b/ld/testsuite/ld-elf/pr12851.d index 7d606008bb1..9880e4a1ef3 100644 --- a/ld/testsuite/ld-elf/pr12851.d +++ b/ld/testsuite/ld-elf/pr12851.d @@ -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 #... diff --git a/ld/testsuite/ld-elf/pr22677.d b/ld/testsuite/ld-elf/pr22677.d index 4203289dead..f2f21e4c115 100644 --- a/ld/testsuite/ld-elf/pr22677.d +++ b/ld/testsuite/ld-elf/pr22677.d @@ -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?.*