From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 6F9913858D33; Tue, 12 Jul 2022 03:01:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F9913858D33 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb/binutils-2_39-branch] PR29355, ld segfaults with -r/-q and custom-named section .rela* X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/binutils-2_39-branch X-Git-Oldrev: c596fcd2a030414064d76818c6ca5b3839305012 X-Git-Newrev: 23b1320eb51e6c52608074526bc9833ffa4129ec Message-Id: <20220712030131.6F9913858D33@sourceware.org> Date: Tue, 12 Jul 2022 03:01:31 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jul 2022 03:01:31 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D23b1320eb51e= 6c52608074526bc9833ffa4129ec commit 23b1320eb51e6c52608074526bc9833ffa4129ec Author: Alan Modra Date: Tue Jul 12 10:51:52 2022 +0930 PR29355, ld segfaults with -r/-q and custom-named section .rela* =20 The bug testcase uses an output section named .rel or .rela which has input .data sections mapped to it. The input .data section has relocations. When counting output relocations SHT_REL and SHT_RELA section reloc_count is ignored, with the justification that reloc sections themselves can't have relocations and some backends use reloc_count in reloc sections. However, the test wrongly used the output section type (which normally would match input section type). Fix that. Note that it is arguably wrong for ld to leave the output .rel/.rela section type as SHT_REL/SHT_RELA when non-empty non-reloc sections are written to it, but I'm not going to change that since it might be useful to hand-craft relocs in a data section that is then written to a SHT_REL/SHT_RELA output section. =20 PR 29355 * elflink.c (bfd_elf_final_link): Use input section type rather than output section type to determine whether to exclude using reloc_count from that section. =20 (cherry picked from commit 35c5dcc666082f0edf6dd559e46b98d0e7986a2e) Diff: --- bfd/elflink.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bfd/elflink.c b/bfd/elflink.c index dcafac32800..2b1450fa4e1 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12413,8 +12413,10 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_inf= o *info) && elf_symtab_shndx_list (sec->owner) !=3D NULL) max_sym_shndx_count =3D sym_count; =20 - if (esdo->this_hdr.sh_type =3D=3D SHT_REL - || esdo->this_hdr.sh_type =3D=3D SHT_RELA) + esdi =3D elf_section_data (sec); + + if (esdi->this_hdr.sh_type =3D=3D SHT_REL + || esdi->this_hdr.sh_type =3D=3D SHT_RELA) /* Some backends use reloc_count in relocation sections to count particular types of relocs. Of course, reloc sections themselves can't have relocations. */ @@ -12432,8 +12434,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info= *info) else if (bed->elf_backend_count_relocs) reloc_count =3D (*bed->elf_backend_count_relocs) (info, sec); =20 - esdi =3D elf_section_data (sec); - if ((sec->flags & SEC_RELOC) !=3D 0) { size_t ext_size =3D 0;