]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
elf: Return false if output_section is NULL
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 13 Jun 2025 05:33:32 +0000 (13:33 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 13 Jun 2025 07:07:07 +0000 (15:07 +0800)
Return false if output_section is NULL so that on input

https://sourceware.org/bugzilla/attachment.cgi?id=16131

objcopy generates

objcopy: /tmp/objcopy-poc(OrcError.cpp.o): invalid entry (0x22000000) in group [3]
objcopy: /tmp/objcopy-poc(OrcError.cpp.o): invalid entry (0x21000000) in group [3]
objcopy: /tmp/objcopy-poc(OrcError.cpp.o)(.text._ZNK12_GLOBAL__N_116OrcErrorCategory7messageB5cxx11Ei): relocation 29 has invalid symbol index 1160982879
objcopy: /tmp/stv73zYw/OrcError.cpp.o[.text._ZN4llvm3orc8orcErrorENS0_12OrcErrorCodeE]: bad value

instead of

objcopy: /tmp/objcopy-poc(OrcError.cpp.o): invalid entry (0x22000000) in group [3]
objcopy: /tmp/objcopy-poc(OrcError.cpp.o): invalid entry (0x21000000) in group [3]
objcopy: /tmp/objcopy-poc(OrcError.cpp.o)(.text._ZNK12_GLOBAL__N_116OrcErrorCategory7messageB5cxx11Ei): relocation 29 has invalid symbol index 1160982879
Segmentation fault (core dumped)

PR binutils/33075
* elf.c (elf_map_symbols): Return false if output_section is
NULL.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
bfd/elf.c

index 17492b97f742f525c12d75d8718477f5d1564794..14ce15c72545222a7f01c079f197f5d3780e23a7 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -4502,7 +4502,11 @@ elf_map_symbols (bfd *abfd, unsigned int *pnum_locals)
          asection *sec = sym->section;
 
          if (sec->owner != abfd)
-           sec = sec->output_section;
+           {
+             sec = sec->output_section;
+             if (sec == NULL)
+               return false;
+           }
 
          sect_syms[sec->index] = syms[idx];
        }