From 9cf3c87e166b2f3728ae5c50c501f64f385e349e Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Fri, 19 Apr 2024 16:35:30 +0930 Subject: Re: elf: Strip unreferenced weak undefined symbols PR ld/31652 * elflink.c (_bfd_elf_link_output_relocs): Don't segfault on NULL rel_hash. --- bfd/elflink.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index 4f72d1b..6db6a9c 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -2985,12 +2985,13 @@ _bfd_elf_link_output_relocs (bfd *output_bfd, * bed->s->int_rels_per_ext_rel); while (irela < irelaend) { - if (*rel_hash) + if (rel_hash && *rel_hash) (*rel_hash)->has_reloc = 1; (*swap_out) (output_bfd, irela, erel); irela += bed->s->int_rels_per_ext_rel; erel += input_rel_hdr->sh_entsize; - rel_hash++; + if (rel_hash) + rel_hash++; } /* Bump the counter, so that we know where to add the next set of -- cgit v1.1