[PATCH] bfd: SEC_DEBUGGING in bfd_generic_get_relocated_section_contents()
Jan Beulich <[email protected]> Fri, 31 Jul 2026 11:49:52 +0200
| Newsgroups | gmane.comp.gnu.binutils |
|---|---|
| Message-ID | <[email protected]> |
Unilaterally excluding debugging sections as done by 810b19952d5d ("bfd:
generalize _bfd_elf_merge_sections()") is clearly wrong. I did test
linking of a decent size "real" binary without that, inspecting debug info
to all be fine. Then, upon finding quite a bit of testsuite fallout, I
added the check (as the comment there says, realizing it can't be quite
right) without re-testing on the real binary. Which (of course) ends up
with all broken debug info. Which in turn has become easily noticable in
2.47 due to bfd118583ed6 ("Add --debug-dir option to readelf and objdump.
Load separate debug info files when disassemblng."), resulting in warnings
from objdump doing disassembly of the resulting binary (which is part of
the overall build process there).
The issues spotted by the testsuite (many actually went silently [visible
only when inspecting ld.log], due to overly lax expectations) need dealing
with differently: Like done in the "if()" corresponding to the enclosing
"else" here, special treatment of calls from underneath
bfd_simple_get_relocated_section_contents() is necessary.
---
The SEC_DEBUGGING part of the checks (the one here and the other one
mentioned) still feels wrong (or at least redundant): If
bfd_simple_get_relocated_section_contents() was used on non-debugging
sections, comparing link_info->input_bfds against link_info->output_bfd
would be all that's wanted/needed.
Perhaps non-section symbols also need handling there, when they don't have
BSF_MERGE_RESOLVED set? Yet then that flag doesn't look to be set
consistently (e.g. not in elf_link_input_bfd()).
Similar code exists in _bfd_elf_mips_get_relocated_section_contents().
If MIPS was to support ELF -> COFF or ELF -> PE linking, a similar change
as the original one (with the adjustment here) would need doing there.
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -8148,8 +8148,9 @@ bfd_generic_get_relocated_section_conten
{
if ((symbol->flags & BSF_SECTION_SYM)
&& symbol->section->sec_info_type == SEC_INFO_TYPE_MERGE
- /* This, while apparently necessary, feels bogus. */
- && !(symbol->section->flags & SEC_DEBUGGING))
+ /* bfd_simple_get_relocated_section_contents() is special. */
+ && (!(input_section->flags & SEC_DEBUGGING)
+ || link_info->input_bfds != link_info->output_bfd))
{
asection *sec = symbol->section;