[binutils-gdb] explicitly state code assumptions on output section in AArch64 ld handlers

Matthieu Longo 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=6310293bfbd362223dc51675cd516d20e0084c2b

commit 6310293bfbd362223dc51675cd516d20e0084c2b
Author: Matthieu Longo <[email protected]>
Date:   Tue Sep 9 11:10:43 2025 +0100

    explicitly state code assumptions on output section in AArch64 ld handlers
    
    When support for non-contiguous memory was added, some corner cases when
    sections were removed from the output object, did not emit fatal error and
    reached code paths that correctly assumed every input section had a valid
    output section, and this led to crashes due to segfault.
    
    This patch adds BFD_ASSERTs in the previously segfaulting code, to
    explicitly state code assumptions.

Diff:
---
 bfd/elfnn-aarch64.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index de68f24e86d..66049c81edf 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -3275,6 +3275,7 @@ aarch64_build_one_stub (struct bfd_hash_entry *gen_entry,
 			    stub_entry->target_section);
 
   stub_sec = stub_entry->stub_sec;
+  BFD_ASSERT (stub_sec->output_section != NULL);
 
   /* The layout must not change when a stub may be the target of another.  */
   if (htab->has_double_stub)
@@ -7083,6 +7084,7 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
 	  sym = local_syms + r_symndx;
 	  sym_type = ELFNN_ST_TYPE (sym->st_info);
 	  sec = local_sections[r_symndx];
+	  BFD_ASSERT (sec->output_section != NULL);
 
 	  /* An object file might have a reference to a local
 	     undefined symbol.  This is a daft object file, but we
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.