[binutils-gdb] PR 33676 ld segfaults when using binary input inside NOLOAD

Alan Modra amodra@sourceware.org
Mon Dec 8 09:40:20 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ce2197f48d59db89f9ce4c2adfd9d47f0730ecc8

commit ce2197f48d59db89f9ce4c2adfd9d47f0730ecc8
Author: Magnus Wållberg <magnus@tagpad.net>
Date:   Mon Dec 8 20:03:40 2025 +1030

    PR 33676 ld segfaults when using binary input inside NOLOAD
    
    The code at ldlang.c:2840-2841 checks if the output BFD is ELF format,
    then unconditionally uses elf_section_type() on the input section
    without verifying the input section is also ELF format.
    
    This was introduced in commit d87be451e (PR ld/32787) which added
    special handling for NOLOAD note sections.
    
            PR 33676
            PR 32787
            * ldlang.c (lang_add_section): Check section owner's BFD
            flavour before using elf_section_type.

Diff:
---
 ld/ldlang.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/ld/ldlang.c b/ld/ldlang.c
index 53bbff1f2a6..9963d5eb98f 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -2835,6 +2835,7 @@ lang_add_section (lang_statement_list_type *ptr,
 	 section.  Unlike a .bss style section, if a note section is
 	 marked as NOLOAD, also clear SEC_ALLOC.  */
       if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+	  && bfd_get_flavour (section->owner) == bfd_target_elf_flavour
 	  && elf_section_type (section) != SHT_NOTE)
 	flags &= ~SEC_HAS_CONTENTS;
       else


More information about the Binutils-cvs mailing list