[PATCH] ELF: emit symbol table when there are relocations
Jan Beulich
jbeulich@suse.com
Wed Jun 29 06:14:44 GMT 2022
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.
---
I'm not adding a testcase as I don't see a good way to. The involved
relocations are target specific, and hence in principle one test per
target would be needed for sufficient coverage. I could drop the label
again in an x86-64 test I'm soon to submit, which is where I did
actually notice the issue (leading to me adding a label there to have a
non-empty symbol table).
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3674,7 +3674,7 @@ elf_get_reloc_section (asection *reloc_s
/* 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, struc
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)
More information about the Binutils
mailing list