Bug 27659 - BFD (GNU Binutils for Debian) 2.36.1 internal error, aborting at ../../bfd/elfcode.h:224 in bfd_elf32_swap_symbol_out
Summary: BFD (GNU Binutils for Debian) 2.36.1 internal error, aborting at ../../bfd/el...
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-03-28 19:09 UTC by Gianfranco
Modified: 2024-03-26 08:41 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
segfault with 2.35.2 (1.11 KB, text/plain)
2021-03-28 19:09 UTC, Gianfranco
Details
object files (99.63 KB, application/gzip)
2021-03-28 19:10 UTC, Gianfranco
Details
LLVMgold.so library (29.56 KB, application/x-sharedlib)
2021-05-31 09:45 UTC, Gianfranco
Details
libgcc_s.so.1 library (40.32 KB, application/x-sharedlib)
2021-05-31 09:45 UTC, Gianfranco
Details
log file (3.01 KB, text/plain)
2021-06-29 08:33 UTC, Gianfranco
Details
Proposed patch (274 bytes, patch)
2021-07-05 12:58 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Gianfranco 2021-03-28 19:09:48 UTC
Created attachment 13333 [details]
segfault with 2.35.2

Hello, as said in the title, bfd linker segfaults while trying to link a clang-12 (but also previous clang versions are affected) on armhf.

Short story, from bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980957

echo '#include <stdio.h>
int main() {
if (1==1) {
  printf("true");
}else{
  printf("false");
  return 42;
}
return 0;}' > foo.c
Testing linking ...
rm foo bar.cc

clang-$VERSION -flto foo.c -o foo
clang: error: unable to execute command: Segmentation fault
clang: error: linker command failed due to signal (use -v to see invocation)
autopkgtest [02:17:39]: ERROR: testbed failure: testbed auxverb failed
with exit code 254


I can say something about this:
a) this happens only on armhf, not on amd64 nor on i386 (not sure about the others, sorry)

binutils from sid: 2.35.2 + patches from stable branch

1) bfd FAILS with segfault (attached the backtrace)
2) bfd SUCCEED if I copy the .o files from usr/lib to the current directory and I launch them from here
3) gold SUCCEED



binutils from experimental: 2.36.1 + patches from stable branch
1) bfd FAILS with segfault
2) bfd FAILS if I copy the .o files from usr/lib to the current directory and I launch them from here
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.36.1 internal error, aborting at ../../bfd/elfcode.h:224 in bfd_elf32_swap_symbol_out
3) gold SUCCEED

So, 2.36.1 seems to be regressing with respect to 2.35.2, but in any case, the segfault is on the very same place of code.


e.g.:
binutils from experimental

/usr/bin/ld -EL -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo crt1.o crti.o crtbegin.o -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10 -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../../lib -L/usr/lib/llvm-12/bin/../lib -L/lib/arm-linux-gnueabihf -L/lib/../lib -L/usr/lib/arm-linux-gnueabihf -L/usr/lib/../lib -L/usr/lib/arm-linux-gnueabihf/../../lib -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../.. -L/usr/lib/llvm-12/bin/../lib -L/lib -L/usr/lib -plugin ./LLVMgold.so -plugin-opt=mcpu=generic foo-a6d584.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
Segmentation fault

/usr/bin/ld -EL -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo -L. crt1.o crti.o crtbegin.o -L. -L/usr/lib -plugin ./LLVMgold.so -plugin-opt=mcpu=generic foo-a6d584.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.36.1 internal error, aborting at ../../bfd/elfcode.h:224 in bfd_elf32_swap_symbol_out

/usr/bin/ld: Please report this bug.


/usr/bin/ld -EL -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo -L. crt1.o crti.o crtbegin.o -L. -L/usr/lib -plugin ./LLVMgold.so -plugin-opt=mcpu=generic foo-a6d584.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.36.1 internal error, aborting at ../../bfd/elfcode.h:224 in bfd_elf32_swap_symbol_out

/usr/bin/ld: Please report this bug.


/usr/bin/ld.gold -EL -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo crt1.o crti.o crtbegin.o -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10 -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../../lib -L/usr/lib/llvm-12/bin/../lib -L/lib/arm-linux-gnueabihf -L/lib/../lib -L/usr/lib/arm-linux-gnueabihf -L/usr/lib/../lib -L/usr/lib/arm-linux-gnueabihf/../../lib -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../.. -L/usr/lib/llvm-12/bin/../lib -L/lib -L/usr/lib -plugin ./LLVMgold.so -plugin-opt=mcpu=generic foo-a6d584.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
echo $?
0

(experimental_armhf-dchroot)locutusofborg@amdahl:~/bar$ /usr/bin/ld -EL -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo /usr/lib/arm-linux-gnueabihf/crt1.o /usr/lib/arm-linux-gnueabihf/crti.o /usr/lib/gcc/arm-linux-gnueabihf/10/crtbegin.o -L. -L/usr/lib -plugin ./LLVMgold.so -plugin-opt=mcpu=generic foo-a6d584.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/arm-linux-gnueabihf/10/crtend.o /usr/lib/arm-linux-gnueabihf/crtn.o
/usr/bin/ld: BFD (GNU Binutils for Debian) 2.36.1 internal error, aborting at ../../bfd/elfcode.h:224 in bfd_elf32_swap_symbol_out

/usr/bin/ld: Please report this bug.


I'm also attaching the directory with the sources and object files
Comment 1 Gianfranco 2021-03-28 19:10:23 UTC
Created attachment 13334 [details]
object files
Comment 2 Nick Clifton 2021-04-06 14:29:11 UTC
Hi Gianfranco,

  I am currently unable to reproduce this bug. :-(  The object files
  that you uploaded help, but there are still one important file
  missing (libgcc_s.so.1) and the LLVMgold.so plugin is an ARM 
  executable and I do not have an ARM box available for testing. :-(

  Is there any chance you could reduce the testcase to a smaller set
  of files ?  I did try just linking foo-a6d584.o on its own, but I
  was given this message:

    error: Failed to link module foo-a6d584.o: Invalid summary 
    version 9. Version should be in the range [1-8].

  I guess that this is because I am using an old version of LLVM
  (llvm-libs-10.0.1-4.fc32.x86_64).

  The bug itself appears to be triggered by an unexpected section index
  in the section header of one of the input files.  (Probably foo-a6d584.o).
  But since this file is in LLVM IR format, I do not know how to decode
  it.

Cheers
  Nick
Comment 3 Gianfranco 2021-05-31 09:45:15 UTC
Created attachment 13475 [details]
LLVMgold.so library
Comment 4 Gianfranco 2021-05-31 09:45:35 UTC
Created attachment 13476 [details]
libgcc_s.so.1 library
Comment 5 Gianfranco 2021-05-31 09:46:12 UTC
Hello Nick, I attached the two missing libraries, I hope they can help moving the issue a little bit further
Comment 6 Nick Clifton 2021-06-01 09:15:36 UTC
Hi Gianfranco,

> Hello Nick, I attached the two missing libraries, I hope they can help moving
> the issue a little bit further

Thanks - that should help.  Just a quick note however - I am on PTO this week,
so I will not get a chance to look at the bug again until next week.

Cheers
   Nick
Comment 7 Nick Clifton 2021-06-11 15:24:03 UTC
Hi Gianfranco,

*sigh*   Sorry - I still cannot reproduce this failure. :-(

With the libgcc.so.1 file I was able to complete a link (using a fake C library), but the link succeeded, there were no errors.

There is a possibility that this is due to the fact that I was using a linker built from the latest development sources, rather than the 2.36.1 release sources.

There is also the possibility that this is the same bug as:

  https://bugzilla.redhat.com/show_bug.cgi?id=1918924

There is a patch uploaded to that BZ.  Are you able to give it a try and see if it results in a more helpful error message ?

Cheers
  Nick
Comment 8 Gianfranco 2021-06-29 08:33:39 UTC
Created attachment 13516 [details]
log file

Hello, looks like your patch was already into master branch, and then in Ubuntu development release "2.36.50.20210628" version.

Sadly, I couldn't get anything more other than a "segmentation fault"

but I could run it with "--verbose" flag, maybe it helps?
Comment 9 Nick Clifton 2021-06-30 10:57:59 UTC
(In reply to Gianfranco from comment #8)
Hi Gianfranco,

> but I could run it with "--verbose" flag, maybe it helps?

Not really, but thanks for trying.  Are you able to run the linker from inside a debugger ?  If you can find out which function is calling elf_swap_symbol_out() with a NULL value for shndx that would help.  If you can find out why that parameter is NULL that would help even more.

Cheers
  Nick
Comment 10 Gianfranco 2021-07-05 12:28:45 UTC
does this help?

#0  elf32_arm_swap_symbol_out (abfd=0x528c58, src=0x5285d0, cdst=0x548998, shndx=0x0) at ../../bfd/elf32-arm.c:19701
        newsym = {st_value = 0, st_size = 5540248, st_name = 0, st_info = 8 '\b', st_other = 134 '\206', st_target_internal = 82 'R', st_shndx = 3070119428}
#1  0xb6f477ec in swap_out_syms (info=0x0, relocatable_p=<optimized out>, sttp=<synthetic pointer>, abfd=0x2) at ../../bfd/elf.c:8442
        elfsym = 0x0
        bed = 0x528c58
        symcount = 1
        syms = <optimized out>
        idx = <optimized out>
        symtab_hdr = 0x48
        symstrtab_hdr = 0xb8
        outbound_syms_index = <optimized out>
        outbound_shndx_index = 0
        num_locals = <optimized out>
        name_local_sections = false
        stt = 0x528d48
        symstrtab = 0x0
        outbound_syms = 0x0
        outbound_shndx = <optimized out>
        symtab_shndx_hdr = <optimized out>
        amt = <optimized out>
        bed = <optimized out>
        symcount = <optimized out>
        syms = <optimized out>
        stt = <optimized out>
        symtab_hdr = <optimized out>
        symtab_shndx_hdr = <optimized out>
        symstrtab_hdr = <optimized out>
        symstrtab = <optimized out>
        outbound_syms = <optimized out>
        outbound_shndx = <optimized out>
        outbound_syms_index = <optimized out>
        outbound_shndx_index = <optimized out>
        idx = <optimized out>
        num_locals = <optimized out>
        amt = <optimized out>
        name_local_sections = <optimized out>
        error_no_mem = <optimized out>
        error_return = <optimized out>
        sym = {st_value = <optimized out>, st_size = <optimized out>, st_name = <optimized out>, st_info = <optimized out>, st_other = <optimized out>, st_target_internal = <optimized out>, 
          st_shndx = <optimized out>}
        sym = {st_value = <optimized out>, st_size = <optimized out>, st_name = <optimized out>, st_info = <optimized out>, st_other = <optimized out>, st_target_internal = <optimized out>, 
          st_shndx = <optimized out>}
        value = <optimized out>
        type_ptr = <optimized out>
        flags = <optimized out>
        type = <optimized out>
        sec = <optimized out>
        shndx = <optimized out>
        sec2 = <optimized out>
        bind = <optimized out>
        elfsym = <optimized out>
#2  _bfd_elf_compute_section_file_positions (abfd=0x2, link_info=0x0) at ../../bfd/elf.c:4299
        relocatable_p = <optimized out>
        bed = <optimized out>
        fsargs = {link_info = 0x0, failed = false}
        failed = false
        strtab = 0x0
        shstrtab_hdr = <optimized out>
        need_symtab = true
#3  0xb6f4859c in _bfd_elf_write_object_contents (abfd=0x528c58) at ../../bfd/elf.c:6652
        bed = 0x1
        i_shdrp = <optimized out>
        failed = false
        count = <optimized out>
        num_sec = <optimized out>
        t = <optimized out>
#4  0xb6f0a864 in bfd_make_readable (abfd=abfd@entry=0x528c58) at ../../bfd/opncls.c:972
No locals.
#5  0x00421aec in plugin_object_p (ibfd=0x528a40) at ../../ld/plugin.c:1247
        claimed = 1
        input = 0x548860
        file = {name = 0x548898 "/tmp/foo-32e6ed.o", fd = 8, offset = 0, filesize = 2928, handle = 0x548860}
        abfd = 0x528c58
#6  0xb6f001a8 in bfd_check_format_matches (abfd=0x528a40, format=format@entry=bfd_object, matching=0xb6fd3824 <bfd_default_hash_table_size>, matching@entry=0x0) at ../../bfd/format.c:343
        high_water = 0xbeffee0c
        target = 0xb6fcf624 <_bfd_target_vector.lto_priv.0+48>
        matching_vector = 0x0
        save_targ = 0xb6fd1c48 <plugin_vec>
        right_targ = <optimized out>
        ar_right_targ = <optimized out>
        match_targ = <optimized out>
        match_count = <optimized out>
        best_count = 0
        best_match = 49
        ar_match_index = 1
        initial_section_id = 3068020339
        preserve = {marker = 0x538f70, tdata = 0x0, flags = 32768, arch_info = 0xb6fd1fe0 <bfd_default_arch_struct>, sections = 0x0, section_last = 0x0, section_count = 0, section_id = 49, 
          section_htab = {table = 0x540e78, newfunc = 0xb6f084e8 <bfd_section_hash_newfunc>, memory = 0x528998, size = 13, count = 0, entsize = 200, frozen = 0}, build_id = 0x0, cleanup = 0x0}
        preserve_match = {marker = 0x0, tdata = 0x1, flags = 0, arch_info = 0xb6e8a260, sections = 0x38, section_last = 0x7, section_count = 24, section_id = 3068700524, section_htab = {table = 0x0, 
            newfunc = 0x5b, memory = 0x4c900c, size = 110, count = 3, entsize = 40, frozen = 0}, build_id = 0x77, cleanup = 0x0}
        cleanup = <optimized out>
#7  0xb6f00508 in bfd_check_format (abfd=<optimized out>, format=format@entry=bfd_object) at ../../bfd/format.c:94
No locals.
#8  0x0041fc98 in ldfile_try_open_bfd (attempt=<optimized out>, entry=entry@entry=0x4c92c0) at ../../ld/ldfile.c:319
No locals.
#9  0x0041f858 in ldfile_open_file (entry=entry@entry=0x4c92c0) at ../../ld/ldfile.c:403
No locals.
#10 0x0041f2e4 in load_symbols (entry=entry@entry=0x4c92c0, place=0xbeffef38, place@entry=0xbeffef30) at ../../ld/ldlang.c:3024
        matching = 0x0
        __PRETTY_FUNCTION__ = "load_symbols"
#11 0x0041f0c0 in open_input_bfds (s=0x4c92c0, mode=OPEN_BFD_NORMAL) at ../../ld/ldlang.c:3627
        os_tail = 0x51603c
        add = {head = 0x0, tail = 0xbeffef38}
        abfd = <optimized out>
#12 0x0041b674 in lang_process () at ../../ld/ldlang.c:7958
No locals.
#13 0x0042b9e8 in main (argc=<optimized out>, argv=<optimized out>) at ../../ld/ldmain.c:495
        emulation = <optimized out>
        start_time = 5013504
Comment 11 Gianfranco 2021-07-05 12:30:01 UTC
#0  elf32_arm_swap_symbol_out (abfd=0x528c58, src=0x5285ec, cdst=0x5489a8, shndx=0x0) at ../../bfd/elf32-arm.c:19701
        newsym = {st_value = 5408208, st_size = 1, st_name = 0, st_info = 152 '\230', st_other = 137 '\211', st_target_internal = 84 'T', st_shndx = 3070119428}
#1  0xb6f478c4 in swap_out_syms (info=0x0, relocatable_p=<optimized out>, sttp=<synthetic pointer>, abfd=0x2) at ../../bfd/elf.c:8442
        elfsym = 0x0
        bed = 0x528c58
        symcount = 1
        syms = <optimized out>
        idx = <optimized out>
        symtab_hdr = 0x48
        symstrtab_hdr = 0xb8
        outbound_syms_index = <optimized out>
        outbound_shndx_index = 0
        num_locals = <optimized out>
        name_local_sections = false
        stt = 0x528d48
        symstrtab = 0x0
        outbound_syms = 0x0
        outbound_shndx = <optimized out>
        symtab_shndx_hdr = <optimized out>
        amt = <optimized out>
        bed = <optimized out>
        symcount = <optimized out>
        syms = <optimized out>
        stt = <optimized out>
        symtab_hdr = <optimized out>
        symtab_shndx_hdr = <optimized out>
        symstrtab_hdr = <optimized out>
        symstrtab = <optimized out>
        outbound_syms = <optimized out>
        outbound_shndx = <optimized out>
        outbound_syms_index = <optimized out>
        outbound_shndx_index = <optimized out>
        idx = <optimized out>
        num_locals = <optimized out>
        amt = <optimized out>
        name_local_sections = <optimized out>
        error_no_mem = <optimized out>
        error_return = <optimized out>
        sym = {st_value = <optimized out>, st_size = <optimized out>, st_name = <optimized out>, st_info = <optimized out>, st_other = <optimized out>, st_target_internal = <optimized out>, 
          st_shndx = <optimized out>}
        sym = {st_value = <optimized out>, st_size = <optimized out>, st_name = <optimized out>, st_info = <optimized out>, st_other = <optimized out>, st_target_internal = <optimized out>, 
          st_shndx = <optimized out>}
        value = <optimized out>
        type_ptr = <optimized out>
        flags = <optimized out>
        type = <optimized out>
        sec = <optimized out>
        shndx = <optimized out>
        sec2 = <optimized out>
        bind = <optimized out>
        elfsym = <optimized out>
#2  _bfd_elf_compute_section_file_positions (abfd=0x2, link_info=0x0) at ../../bfd/elf.c:4299
        relocatable_p = <optimized out>
        bed = <optimized out>
        fsargs = {link_info = 0x0, failed = false}
        failed = false
        strtab = 0x0
        shstrtab_hdr = <optimized out>
        need_symtab = true
#3  0xb6f4859c in _bfd_elf_write_object_contents (abfd=0x528c58) at ../../bfd/elf.c:6652
        bed = 0x1
        i_shdrp = <optimized out>
        failed = false
        count = <optimized out>
        num_sec = <optimized out>
        t = <optimized out>
#4  0xb6f0a864 in bfd_make_readable (abfd=abfd@entry=0x528c58) at ../../bfd/opncls.c:972
No locals.
#5  0x00421aec in plugin_object_p (ibfd=0x528a40) at ../../ld/plugin.c:1247
        claimed = 1
        input = 0x548860
        file = {name = 0x548898 "/tmp/foo-32e6ed.o", fd = 8, offset = 0, filesize = 2928, handle = 0x548860}
        abfd = 0x528c58
#6  0xb6f001a8 in bfd_check_format_matches (abfd=0x528a40, format=format@entry=bfd_object, matching=0xb6fd3824 <bfd_default_hash_table_size>, matching@entry=0x0) at ../../bfd/format.c:343
        high_water = 0xbeffee0c
        target = 0xb6fcf624 <_bfd_target_vector.lto_priv.0+48>
        matching_vector = 0x0
        save_targ = 0xb6fd1c48 <plugin_vec>
        right_targ = <optimized out>
        ar_right_targ = <optimized out>
        match_targ = <optimized out>
        match_count = <optimized out>
        best_count = 0
        best_match = 49
        ar_match_index = 1
        initial_section_id = 3068020339
        preserve = {marker = 0x538f70, tdata = 0x0, flags = 32768, arch_info = 0xb6fd1fe0 <bfd_default_arch_struct>, sections = 0x0, section_last = 0x0, section_count = 0, section_id = 49, 
          section_htab = {table = 0x540e78, newfunc = 0xb6f084e8 <bfd_section_hash_newfunc>, memory = 0x528998, size = 13, count = 0, entsize = 200, frozen = 0}, build_id = 0x0, cleanup = 0x0}
        preserve_match = {marker = 0x0, tdata = 0x1, flags = 0, arch_info = 0xb6e8a260, sections = 0x38, section_last = 0x7, section_count = 24, section_id = 3068700524, section_htab = {table = 0x0, 
            newfunc = 0x5b, memory = 0x4c900c, size = 110, count = 3, entsize = 40, frozen = 0}, build_id = 0x77, cleanup = 0x0}
        cleanup = <optimized out>
#7  0xb6f00508 in bfd_check_format (abfd=<optimized out>, format=format@entry=bfd_object) at ../../bfd/format.c:94
No locals.
#8  0x0041fc98 in ldfile_try_open_bfd (attempt=<optimized out>, entry=entry@entry=0x4c92c0) at ../../ld/ldfile.c:319
No locals.
#9  0x0041f858 in ldfile_open_file (entry=entry@entry=0x4c92c0) at ../../ld/ldfile.c:403
No locals.
#10 0x0041f2e4 in load_symbols (entry=entry@entry=0x4c92c0, place=0xbeffef38, place@entry=0xbeffef30) at ../../ld/ldlang.c:3024
        matching = 0x0
        __PRETTY_FUNCTION__ = "load_symbols"
#11 0x0041f0c0 in open_input_bfds (s=0x4c92c0, mode=OPEN_BFD_NORMAL) at ../../ld/ldlang.c:3627
        os_tail = 0x51603c
        add = {head = 0x0, tail = 0xbeffef38}
        abfd = <optimized out>
#12 0x0041b674 in lang_process () at ../../ld/ldlang.c:7958
No locals.
#13 0x0042b9e8 in main (argc=<optimized out>, argv=<optimized out>) at ../../ld/ldmain.c:495
        emulation = <optimized out>
        start_time = 5013504
Comment 12 Nick Clifton 2021-07-05 12:58:06 UTC
Created attachment 13538 [details]
Proposed patch

Hi Gianfranco,

  Hmm, that does help a bit.  It may be that a NULL shndx pointer is actually allowed, and the bug is that the abort should not be there at all.  Maybe...

  Can you try out the uploaded patch and see if it solves the problem for you ?

Cheers
  Nick
Comment 13 Gianfranco 2021-07-05 13:50:35 UTC
sure, maybe something like this:
commit 8384fb8f0c3c451f7aa8164fc87e162eb9816925
Author: Alan Modra <****@*****.com>
Date:   Fri Sep 22 13:16:45 2006 +0000

            * elfcode.h (elf_swap_symbol_in): Return bfd_boolean.  Don't abort
            on error.
            * elf-bfd.h (elf_size_info <swap_symbol_in>): Adjust decl.
            (bfd_elf32_swap_symbol_in, bfd_elf64_swap_symbol_in): Likewise.
            * elf.c (bfd_elf_get_elf_syms): Test return of swap_symbol_in,
            and report error.
            * elf32-arm.c (elf32_arm_swap_symbol_in): Return bfd_boolean.

diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index a285a133088..d58cf344718 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -166,7 +166,7 @@ static void elf_debug_file (Elf_Internal_Ehdr *);
 /* Translate an ELF symbol in external format into an ELF symbol in internal
    format.  */
 
-void
+bfd_boolean
 elf_swap_symbol_in (bfd *abfd,
                    const void *psrc,
                    const void *pshn,
@@ -188,9 +188,10 @@ elf_swap_symbol_in (bfd *abfd,
   if (dst->st_shndx == SHN_XINDEX)
     {
       if (shndx == NULL)
-       abort ();
+       return FALSE;
       dst->st_shndx = H_GET_32 (abfd, shndx->est_shndx);
     }
+  return TRUE;
 }
 
 /* Translate an ELF symbol in internal format into an ELF symbol in external



needs to be done on elf_swap_symbol_out too?
Comment 14 Nick Clifton 2021-07-05 14:05:23 UTC
(In reply to Gianfranco from comment #13)

> sure, maybe something like this:

Err, I am  not sure which sources you are using, but the patch that you suggested has already been applied ... and in fact has been in there for a while now.

Cheers
  Nick
Comment 15 Gianfranco 2021-07-05 21:22:21 UTC
Hello, I meant to apply that patch already in mainline (applied to elf_swap_symbol_in), also to elf_swap_symbol_out function!

Anyway, I applied your patch and rebuilt binutils in Ubuntu (latest snapshot of 2.37)
https://launchpad.net/~costamagnagianfranco/+archive/ubuntu/locutusofborg-ppa/+sourcepub/12524652/+listing-archive-extra

and then tried to run on a qemu-arm chroot (sadly I can't gdb or strace here!)


"/usr/bin/ld" -EL -X --hash-style=both --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crt1.o /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crti.o /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/crtbegin.o -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10 -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../../lib -L/usr/lib/llvm-12/bin/../lib -L/lib/arm-linux-gnueabihf -L/lib/../lib -L/usr/lib/arm-linux-gnueabihf -L/usr/lib/../lib -L/usr/lib/arm-linux-gnueabihf/../../lib -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../.. -L/usr/lib/llvm-12/bin/../lib -L/lib -L/usr/lib -plugin /usr/lib/llvm-12/bin/../lib/LLVMgold.so -plugin-opt=mcpu=generic /tmp/foo-0c2a01.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/crtend.o /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crtn.o --verbose
GNU ld (GNU Binutils for Ubuntu) 2.36.90.20210705
  Supported emulations:
   armelf_linux_eabi
   armelfb_linux_eabi
using internal linker script:
==================================================
/* Script for -z combreloc */
/* Copyright (C) 2014-2021 Free Software Foundation, Inc.
   Copying and distribution of this script, with or without modification,
   are permitted in any medium without royalty provided the copyright
   notice and this notice are preserved.  */
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
	      "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SEARCH_DIR("=/usr/local/lib/arm-linux-gnueabihf"); SEARCH_DIR("=/lib/arm-linux-gnueabihf"); SEARCH_DIR("=/usr/lib/arm-linux-gnueabihf"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/arm-linux-gnueabihf/lib");
SECTIONS
{
  /* Read-only sections, merged into text segment: */
  PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x00010000)); . = SEGMENT_START("text-segment", 0x00010000) + SIZEOF_HEADERS;
  .interp         : { *(.interp) }
  .note.gnu.build-id  : { *(.note.gnu.build-id) }
  .hash           : { *(.hash) }
  .gnu.hash       : { *(.gnu.hash) }
  .dynsym         : { *(.dynsym) }
  .dynstr         : { *(.dynstr) }
  .gnu.version    : { *(.gnu.version) }
  .gnu.version_d  : { *(.gnu.version_d) }
  .gnu.version_r  : { *(.gnu.version_r) }
  .rel.dyn        :
    {
      *(.rel.init)
      *(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
      *(.rel.fini)
      *(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
      *(.rel.data.rel.ro .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*)
      *(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
      *(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
      *(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
      *(.rel.ctors)
      *(.rel.dtors)
      *(.rel.got)
      *(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
      PROVIDE_HIDDEN (__rel_iplt_start = .);
      *(.rel.iplt)
      PROVIDE_HIDDEN (__rel_iplt_end = .);
    }
  .rela.dyn       :
    {
      *(.rela.init)
      *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
      *(.rela.fini)
      *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
      *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
      *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
      *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
      *(.rela.ctors)
      *(.rela.dtors)
      *(.rela.got)
      *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
      PROVIDE_HIDDEN (__rela_iplt_start = .);
      *(.rela.iplt)
      PROVIDE_HIDDEN (__rela_iplt_end = .);
    }
  .rel.plt        :
    {
      *(.rel.plt)
    }
  .rela.plt       :
    {
      *(.rela.plt)
    }
  .init           :
  {
    KEEP (*(SORT_NONE(.init)))
  }
  .plt            : { *(.plt) }
  .iplt           : { *(.iplt) }
  .text           :
  {
    *(.text.unlikely .text.*_unlikely .text.unlikely.*)
    *(.text.exit .text.exit.*)
    *(.text.startup .text.startup.*)
    *(.text.hot .text.hot.*)
    *(SORT(.text.sorted.*))
    *(.text .stub .text.* .gnu.linkonce.t.*)
    /* .gnu.warning sections are handled specially by elf.em.  */
    *(.gnu.warning)
    *(.glue_7t) *(.glue_7) *(.vfp11_veneer) *(.v4_bx)
  }
  .fini           :
  {
    KEEP (*(SORT_NONE(.fini)))
  }
  PROVIDE (__etext = .);
  PROVIDE (_etext = .);
  PROVIDE (etext = .);
  .rodata         : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
  .rodata1        : { *(.rodata1) }
  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
  .ARM.exidx   :
    {
      PROVIDE_HIDDEN (__exidx_start = .);
      *(.ARM.exidx* .gnu.linkonce.armexidx.*)
      PROVIDE_HIDDEN (__exidx_end = .);
    }
  .eh_frame_hdr   : { *(.eh_frame_hdr) *(.eh_frame_entry .eh_frame_entry.*) }
  .eh_frame       : ONLY_IF_RO { KEEP (*(.eh_frame)) *(.eh_frame.*) }
  .gcc_except_table   : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
  .gnu_extab   : ONLY_IF_RO { *(.gnu_extab*) }
  /* These sections are generated by the Sun/Oracle C++ compiler.  */
  .exception_ranges   : ONLY_IF_RO { *(.exception_ranges*) }
  /* Adjust the address for the data segment.  We want to adjust up to
     the same address within the page on the next page up.  */
  . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
  /* Exception handling  */
  .eh_frame       : ONLY_IF_RW { KEEP (*(.eh_frame)) *(.eh_frame.*) }
  .gnu_extab      : ONLY_IF_RW { *(.gnu_extab) }
  .gcc_except_table   : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
  .exception_ranges   : ONLY_IF_RW { *(.exception_ranges*) }
  /* Thread Local Storage sections  */
  .tdata	  :
   {
     PROVIDE_HIDDEN (__tdata_start = .);
     *(.tdata .tdata.* .gnu.linkonce.td.*)
   }
  .tbss		  : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
  .preinit_array    :
  {
    PROVIDE_HIDDEN (__preinit_array_start = .);
    KEEP (*(.preinit_array))
    PROVIDE_HIDDEN (__preinit_array_end = .);
  }
  .init_array    :
  {
    PROVIDE_HIDDEN (__init_array_start = .);
    KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
    KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
    PROVIDE_HIDDEN (__init_array_end = .);
  }
  .fini_array    :
  {
    PROVIDE_HIDDEN (__fini_array_start = .);
    KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))
    KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))
    PROVIDE_HIDDEN (__fini_array_end = .);
  }
  .ctors          :
  {
    /* gcc uses crtbegin.o to find the start of
       the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't look for a file to match a
       wildcard.  The wildcard also means that it
       doesn't matter which directory crtbegin.o
       is in.  */
    KEEP (*crtbegin.o(.ctors))
    KEEP (*crtbegin?.o(.ctors))
    /* We don't want to include the .ctor section from
       the crtend.o file until after the sorted ctors.
       The .ctor section from the crtend file contains the
       end of ctors marker and it must be last */
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
  }
  .dtors          :
  {
    KEEP (*crtbegin.o(.dtors))
    KEEP (*crtbegin?.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*(.dtors))
  }
  .jcr            : { KEEP (*(.jcr)) }
  .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }
  .dynamic        : { *(.dynamic) }
  . = DATA_SEGMENT_RELRO_END (0, .);
  .got            : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }
  .data           :
  {
    PROVIDE (__data_start = .);
    *(.data .data.* .gnu.linkonce.d.*)
    SORT(CONSTRUCTORS)
  }
  .data1          : { *(.data1) }
  _edata = .; PROVIDE (edata = .);
  . = .;
  __bss_start = .;
  __bss_start__ = .;
  .bss            :
  {
   *(.dynbss)
   *(.bss .bss.* .gnu.linkonce.b.*)
   *(COMMON)
   /* Align here to ensure that the .bss section occupies space up to
      _end.  Align after .bss to ensure correct alignment even if the
      .bss section disappears because there are no input sections.
      FIXME: Why do we need it? When there is no .bss section, we do not
      pad the .data section.  */
   . = ALIGN(. != 0 ? 32 / 8 : 1);
  }
  _bss_end__ = .; __bss_end__ = .;
  . = ALIGN(32 / 8);
  . = SEGMENT_START("ldata-segment", .);
  . = ALIGN(32 / 8);
  __end__ = .;
  _end = .; PROVIDE (end = .);
  . = DATA_SEGMENT_END (.);
  /* Stabs debugging sections.  */
  .stab          0 : { *(.stab) }
  .stabstr       0 : { *(.stabstr) }
  .stab.excl     0 : { *(.stab.excl) }
  .stab.exclstr  0 : { *(.stab.exclstr) }
  .stab.index    0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment       0 : { *(.comment) }
  .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
  /* DWARF debug sections.
     Symbols in the DWARF debugging sections are relative to the beginning
     of the section so we begin them at 0.  */
  /* DWARF 1.  */
  .debug          0 : { *(.debug) }
  .line           0 : { *(.line) }
  /* GNU DWARF 1 extensions.  */
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
  .debug_sfnames  0 : { *(.debug_sfnames) }
  /* DWARF 1.1 and DWARF 2.  */
  .debug_aranges  0 : { *(.debug_aranges) }
  .debug_pubnames 0 : { *(.debug_pubnames) }
  /* DWARF 2.  */
  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
  .debug_abbrev   0 : { *(.debug_abbrev) }
  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end) }
  .debug_frame    0 : { *(.debug_frame) }
  .debug_str      0 : { *(.debug_str) }
  .debug_loc      0 : { *(.debug_loc) }
  .debug_macinfo  0 : { *(.debug_macinfo) }
  /* SGI/MIPS DWARF 2 extensions.  */
  .debug_weaknames 0 : { *(.debug_weaknames) }
  .debug_funcnames 0 : { *(.debug_funcnames) }
  .debug_typenames 0 : { *(.debug_typenames) }
  .debug_varnames  0 : { *(.debug_varnames) }
  /* DWARF 3.  */
  .debug_pubtypes 0 : { *(.debug_pubtypes) }
  .debug_ranges   0 : { *(.debug_ranges) }
  /* DWARF 5.  */
  .debug_addr     0 : { *(.debug_addr) }
  .debug_line_str 0 : { *(.debug_line_str) }
  .debug_loclists 0 : { *(.debug_loclists) }
  .debug_macro    0 : { *(.debug_macro) }
  .debug_names    0 : { *(.debug_names) }
  .debug_rnglists 0 : { *(.debug_rnglists) }
  .debug_str_offsets 0 : { *(.debug_str_offsets) }
  .debug_sup      0 : { *(.debug_sup) }
  .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
  .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }
  /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }
}


==================================================
/usr/bin/ld: mode armelf_linux_eabi
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crt1.o succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crt1.o
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crti.o succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crti.o
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/crtbegin.o succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/crtbegin.o
attempt to open /tmp/foo-0c2a01.o succeeded
/tmp/foo-0c2a01.o
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so succeeded
opened script file /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so
opened script file /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so.1 failed
attempt to open libgcc_s.so.1 failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so.1 failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/libgcc_s.so.1 failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../../lib/libgcc_s.so.1 failed
attempt to open /usr/lib/llvm-12/bin/../lib/libgcc_s.so.1 failed
attempt to open /lib/arm-linux-gnueabihf/libgcc_s.so.1 succeeded
/lib/arm-linux-gnueabihf/libgcc_s.so.1
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libc.so failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libc.a failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/libc.so succeeded
opened script file /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/libc.so
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/libc.so
opened script file /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/libc.so
attempt to open /lib/arm-linux-gnueabihf/libc.so.6 succeeded
/lib/arm-linux-gnueabihf/libc.so.6
attempt to open /usr/lib/arm-linux-gnueabihf/libc_nonshared.a succeeded
/usr/lib/arm-linux-gnueabihf/libc_nonshared.a
(/usr/lib/arm-linux-gnueabihf/libc_nonshared.a)elf-init.oS
attempt to open /lib/ld-linux-armhf.so.3 succeeded
/lib/ld-linux-armhf.so.3
/usr/lib/arm-linux-gnueabihf/libc_nonshared.a
/lib/ld-linux-armhf.so.3
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so succeeded
opened script file /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so
opened script file /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so.1 failed
attempt to open libgcc_s.so.1 failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc_s.so.1 failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/libgcc_s.so.1 failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../../lib/libgcc_s.so.1 failed
attempt to open /usr/lib/llvm-12/bin/../lib/libgcc_s.so.1 failed
attempt to open /lib/arm-linux-gnueabihf/libgcc_s.so.1 succeeded
/lib/arm-linux-gnueabihf/libgcc_s.so.1
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/crtend.o succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/crtend.o
attempt to open /usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crtn.o succeeded
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/../../../arm-linux-gnueabihf/crtn.o
attempt to open /tmp/lto-llvm-dc313c.o succeeded
/tmp/lto-llvm-dc313c.o
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
/lib/arm-linux-gnueabihf/libgcc_s.so.1
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
/usr/lib/arm-linux-gnueabihf/libc_nonshared.a
/lib/ld-linux-armhf.so.3
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
/lib/arm-linux-gnueabihf/libgcc_s.so.1
/usr/bin/../lib/gcc/arm-linux-gnueabihf/10/libgcc.a
ld-linux-armhf.so.3 needed by /lib/arm-linux-gnueabihf/libc.so.6
found ld-linux-armhf.so.3 at /lib/ld-linux-armhf.so.3
qemu: uncaught target signal 11 (Segmentation fault) - core dumped
Segmentation fault (core dumped)
Comment 16 Alan Modra 2021-07-06 02:09:16 UTC
(In reply to Nick Clifton from comment #12)
> It may be that a NULL shndx pointer is
> actually allowed
No, it isn't allowed (and passing a 0 as the *pointer* arg to H_PUT_32, see bfd_putl32/bfd_putb32, will surely result in a segfault).

The patch was commited with 6e0dfbf420, accidentally I assume..

If you have an internal st_shndx greater than a little less than 64k, then ELF requires those symbols to be represented externally with st_shndx 0xffff and have the actual section index stored in an array of 32-bit words in a SHT_SYMTAB_SHNDX section.  See elflink.c:bfd_elf_final_link

  /* The real buffer will be allocated in elf_link_swap_symbols_out.  */
  flinfo.symshndxbuf
    = (elf_numsections (abfd) > (SHN_LORESERVE & 0xFFFF)
       ? (Elf_External_Sym_Shndx *) -1 : NULL);

I think the most likely cause of this problem is a symbol st_shndx entry being overwritten with bogus data somehow.
Comment 17 Sourceware Commits 2021-07-07 15:52:12 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit ca52626babd59d58f3962dcaab94cf840e6aff82
Author: Nick Clifton <nickc@redhat.com>
Date:   Wed Jul 7 16:50:33 2021 +0100

    Remove an accidental change to elfcode.h included as part of commit 6e0dfbf420.
    
            PR 27659
            * elfcode.h (elf_swap_symbol_out): Revert accidental change that
            removed an abort if the shndx pointer is NULL.
Comment 18 Nick Clifton 2021-07-07 15:52:58 UTC
Sorry about that - I have removed the accidental commit.
Comment 19 Gianfranco 2023-07-23 16:54:45 UTC
Hello, now with neweer llvm and binutils, it fails with a more clear error (gold still good)

/usr/bin/arm-linux-gnueabihf-ld.bfd -EL -X --hash-style=gnu --build-id --eh-frame-hdr -m armelf_linux_eabi -dynamic-linker /lib/ld-linux-armhf.so.3 -o foo /lib/arm-linux-gnueabihf/Scrt1.o /lib/arm-linux-gnueabihf/crti.o /usr/bin/../lib/gcc/arm-linux-gnueabihf/13/crtbeginS.o -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/13 -L/usr/bin/../lib/gcc/arm-linux-gnueabihf/13/../../../../lib -L/lib/arm-linux-gnueabihf -L/lib/../lib -L/usr/lib/arm-linux-gnueabihf -L/usr/lib/../lib -L/lib -L/usr/lib -plugin /usr/lib/llvm-16/bin/../lib/LLVMgold.so -plugin-opt=mcpu=cortex-a7 ./foo.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/arm-linux-gnueabihf/13/crtendS.o /lib/arm-linux-gnueabihf/crtn.o
/usr/bin/arm-linux-gnueabihf-ld.bfd: ./foo.o (symbol from plugin): Number of symbols in input file has increased from 0 to 1


ii  binutils                     2.40.90.20230720-1             armhf        GNU assembler, linker and binary utilities
ii  binutils-arm-linux-gnueabihf 2.40.90.20230720-1             armhf        GNU binary utilities, for arm-linux-gnueabihf target
ii  binutils-common:armhf        2.40.90.20230720-1             armhf        Common files for the GNU assembler, linker and binary utilities
ii  libbinutils:armhf            2.40.90.20230720-1             armhf        GNU binary utilities (private shared library)
Comment 20 Nick Clifton 2023-07-24 10:28:47 UTC
(In reply to Gianfranco from comment #19)
Hi Gianfranco,

> /usr/bin/arm-linux-gnueabihf-ld.bfd: ./foo.o (symbol from plugin): Number of
> symbols in input file has increased from 0 to 1

This looks like it is probably a different bug, so please could you file a new bug report ?  If you can include a small reproducer that will really help.

Cheers
  Nick
Comment 21 Gianfranco 2023-07-26 09:39:22 UTC
Ok I opened https://sourceware.org/bugzilla/show_bug.cgi?id=30685 to track this new issue, thanks!
Comment 22 Gianfranco 2024-03-26 08:40:34 UTC
With binutils 2.42-4ubuntu1 looks like it is fixed.
Comment 23 Gianfranco 2024-03-26 08:41:23 UTC
With binutils 2.42-4ubuntu1 looks like it is fixed.
Comment 24 Gianfranco 2024-03-26 08:41:47 UTC
closing.