public inbox for
help / color / mirror / Atom feed
From: Jan Beulich <>
Subject: [binutils-gdb] ELF: emit symbol table when there are relocations
Date: Tue,  2 Aug 2022 13:43:36 +0000 (GMT)	[thread overview]
Message-ID: <> (raw);h=2ba2f096185c201607cdb1571e51e00e8b66e449

commit 2ba2f096185c201607cdb1571e51e00e8b66e449
Author: Jan Beulich <>
Date:   Tue Aug 2 15:43:26 2022 +0200

    ELF: emit symbol table when there are relocations
    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).
    While there also amend the affected function's leading comment to also
    mention gas.

 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.  */
 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_info *link_info)
 	  reloc_count += sec->reloc_count;
-      /* Clear HAS_RELOC if there are no relocations.  */
+      /* Set/clear HAS_RELOC depending on whether there are relocations.  */
       if (reloc_count == 0)
 	abfd->flags &= ~HAS_RELOC;
+      else
+	abfd->flags |= HAS_RELOC;
   for (sec = abfd->sections; sec; sec = sec->next)

                 reply	other threads:[~2022-08-02 13:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).