[binutils-gdb] bfd: SEC_DEBUGGING in bfd_generic_get_relocated_section_contents()

Jan Beulich via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=548951122bceee5a1b765c9ed8da412518522b5f

commit 548951122bceee5a1b765c9ed8da412518522b5f
Author: Jan Beulich <[email protected]>
Date:   Fri Aug 14 10:36:01 2026 +0200

    bfd: SEC_DEBUGGING in bfd_generic_get_relocated_section_contents()
    
    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.

Diff:
---
 bfd/reloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/bfd/reloc.c b/bfd/reloc.c
index 29288f8099d..e06ec4d4fa1 100644
--- a/bfd/reloc.c
+++ b/bfd/reloc.c
@@ -8152,8 +8152,9 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
 	    {
 	      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;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.