From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1386) id A794A3856095; Tue, 2 Aug 2022 13:43:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A794A3856095 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jan Beulich To: bfd-cvs@sourceware.org Subject: [binutils-gdb] ELF: emit symbol table when there are relocations X-Act-Checkin: binutils-gdb X-Git-Author: Jan Beulich X-Git-Refname: refs/heads/master X-Git-Oldrev: 976f16630b1f7421d6693011333cf0f51417c498 X-Git-Newrev: 2ba2f096185c201607cdb1571e51e00e8b66e449 Message-Id: <20220802134336.A794A3856095@sourceware.org> Date: Tue, 2 Aug 2022 13:43:36 +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, 02 Aug 2022 13:43:36 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D2ba2f096185c= 201607cdb1571e51e00e8b66e449 commit 2ba2f096185c201607cdb1571e51e00e8b66e449 Author: Jan Beulich Date: Tue Aug 2 15:43:26 2022 +0200 ELF: emit symbol table when there are relocations =20 Even when there are no symbols (e.g. all relocations being against absolute values), a symbol table (with just the first placeholder entry) needs to be emitted. Otherwise tools like objdump won't properly process the relocations. The respective checks in assign_section_numbers() and _bfd_elf_compute_section_file_positions() support also this view. Oddly enough so far HAS_RELOC was only set when reading in an object file, but not when generating one anew; the flag would only have been cleared when no relocations were found (anymore). =20 While there also amend the affected function's leading comment to also mention gas. Diff: --- bfd/elf.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index 89484ceb233..25f4bca34f0 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -3674,7 +3674,7 @@ elf_get_reloc_section (asection *reloc_sec) /* Assign all ELF section numbers. The dummy first section is handled here too. The link/info pointers for the standard section types are filled in here too, while we're at it. LINK_INFO will be 0 when arriving - here for objcopy, and when using the generic ELF linker. */ + here for gas, objcopy, and when using the generic ELF linker. */ =20 static bool assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) @@ -3717,9 +3717,11 @@ assign_section_numbers (bfd *abfd, struct bfd_link_i= nfo *link_info) reloc_count +=3D sec->reloc_count; } =20 - /* Clear HAS_RELOC if there are no relocations. */ + /* Set/clear HAS_RELOC depending on whether there are relocations. = */ if (reloc_count =3D=3D 0) abfd->flags &=3D ~HAS_RELOC; + else + abfd->flags |=3D HAS_RELOC; } =20 for (sec =3D abfd->sections; sec; sec =3D sec->next)