From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 9E0133858C50; Thu, 30 Mar 2023 04:57:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E0133858C50 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] Setting sh_link for SHT_REL/SHT_RELA X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: ea7672c10e0b762c02fd40ce94d490b56bc14675 X-Git-Newrev: 6b958fe36b765f70878e8d3d002864967c4bc3a4 Message-Id: <20230330045741.9E0133858C50@sourceware.org> Date: Thu, 30 Mar 2023 04:57:41 +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: Thu, 30 Mar 2023 04:57:41 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D6b958fe36b76= 5f70878e8d3d002864967c4bc3a4 commit 6b958fe36b765f70878e8d3d002864967c4bc3a4 Author: Alan Modra Date: Thu Mar 30 12:10:16 2023 +1030 Setting sh_link for SHT_REL/SHT_RELA =20 It's wrong to have an alloc reloc section trying to use a non-alloc symbol table. =20 * elf.c (assign_section_numbers ): Correct comment. Always set sh_link to .dynsym for alloc reloc sections and to .symtab for non-alloc. Diff: --- bfd/elf.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index 45e53640e8f..027d0143735 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -3870,21 +3870,23 @@ assign_section_numbers (bfd *abfd, struct bfd_link_= info *link_info) { case SHT_REL: case SHT_RELA: - /* A reloc section which we are treating as a normal BFD - section. sh_link is the section index of the symbol - table. sh_info is the section index of the section to - which the relocation entries apply. We assume that an - allocated reloc section uses the dynamic symbol table - if there is one. Otherwise we guess the normal symbol - table. FIXME: How can we be sure? */ - if (d->this_hdr.sh_link =3D=3D 0 && (sec->flags & SEC_ALLOC) !=3D 0) - { - s =3D bfd_get_section_by_name (abfd, ".dynsym"); - if (s !=3D NULL) - d->this_hdr.sh_link =3D elf_section_data (s)->this_idx; - } + /* sh_link is the section index of the symbol table. + sh_info is the section index of the section to which the + relocation entries apply. */ if (d->this_hdr.sh_link =3D=3D 0) - d->this_hdr.sh_link =3D elf_onesymtab (abfd); + { + /* FIXME maybe: If this is a reloc section which we are + treating as a normal section then we likely should + not be assuming its sh_link is .dynsym or .symtab. */ + if ((sec->flags & SEC_ALLOC) !=3D 0) + { + s =3D bfd_get_section_by_name (abfd, ".dynsym"); + if (s !=3D NULL) + d->this_hdr.sh_link =3D elf_section_data (s)->this_idx; + } + else + d->this_hdr.sh_link =3D elf_onesymtab (abfd); + } =20 s =3D elf_get_reloc_section (sec); if (s !=3D NULL)