Using GCC tip and binutils 2.36 I see the following issue: $ cat gets-chk.i void gets(); int __gets_chk() { gets(); } $ gcc gets-chk.i -fPIC -g ../sysdeps/x86_64/start.S:104: error: undefined reference to 'main' /usr/bin/ld.gold: internal error in read_header_prolog, at ../../gold/dwarf_reader.cc:1678 collect2: error: ld returned 1 exit status
Or there's an assembly snippet: $ cat a-gets-chk.s .file 1 "gets-chk.i" .cfi_startproc .cfi_endproc .section .debug_info,"",@progbits .quad .Ltext0 .file 0 "/home/marxin/Programming/testcases" "gets-chk.i" $ ./gold/ld-new /home/marxin/Programming/testcases/a-gets-chk.o header_.max_ops_per_insn:0 ./gold/ld-new: internal error in read_header_prolog, at ../../gold/dwarf_reader.cc:1679
A patch is posted https://sourceware.org/pipermail/binutils/2021-January/115122.html
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=0318cca4934fc5d85e83351842985ad2a3475146 commit 0318cca4934fc5d85e83351842985ad2a3475146 Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Jan 28 04:21:15 2021 -0800 gold: Skip address size and segment selector for DWARF5 The .debug_line secton in DWARF5 has a byte for address size and a byte for segment selector after DWARF version. Skip them for DWARF5. PR gold/27246 * dwarf_reader.cc (Sized_dwarf_line_info::read_header_prolog): Skip address size and segment selector for DWARF5.
The binutils-2_36-branch branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=69caaa81ae6296b1f01481874520174abcceac11 commit 69caaa81ae6296b1f01481874520174abcceac11 Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Jan 28 04:21:15 2021 -0800 gold: Skip address size and segment selector for DWARF5 The .debug_line secton in DWARF5 has a byte for address size and a byte for segment selector after DWARF version. Skip them for DWARF5. PR gold/27246 * dwarf_reader.cc (Sized_dwarf_line_info::read_header_prolog): Skip address size and segment selector for DWARF5. (cherry picked from commit 0318cca4934fc5d85e83351842985ad2a3475146)
The binutils-2_35-branch branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=756beae66817dcf3794028cb49c8371f4ba54bfa commit 756beae66817dcf3794028cb49c8371f4ba54bfa Author: H.J. Lu <hjl.tools@gmail.com> Date: Thu Jan 28 04:21:15 2021 -0800 gold: Skip address size and segment selector for DWARF5 The .debug_line secton in DWARF5 has a byte for address size and a byte for segment selector after DWARF version. Skip them for DWARF5. PR gold/27246 * dwarf_reader.cc (Sized_dwarf_line_info::read_header_prolog): Skip address size and segment selector for DWARF5. (cherry picked from commit 0318cca4934fc5d85e83351842985ad2a3475146)
Th gold crash has been fixed on master and 2.36/2.35 branches. Since gold still can't properly parse DWARF5 debug info, I am leaving this bug open.
Thanks for the patch!
I am seeing another failure with latest binutils trunk today, I have collected the objs and libs and a script a.sh with linker cmdline here https://uclibc.org/~kraj/gold-bug.tar.xz % /tmp/obj/gold/ld-new -v GNU gold (GNU Binutils 2.36.50.20210318) 1.16 % sh a.sh /tmp/obj/gold/ld-new: internal error in format_file_lineno, at /home/kraj/work/binutils-gdb/gold/dwarf_reader.cc:2278
(In reply to Khem Raj from comment #8) > I am seeing another failure with latest binutils trunk today, I have > collected the objs and libs and a script a.sh with linker cmdline here > > https://uclibc.org/~kraj/gold-bug.tar.xz > > % /tmp/obj/gold/ld-new -v > GNU gold (GNU Binutils 2.36.50.20210318) 1.16 > > > % sh a.sh > /tmp/obj/gold/ld-new: internal error in format_file_lineno, at > /home/kraj/work/binutils-gdb/gold/dwarf_reader.cc:2278 actually same crash can be triggered with one object /tmp/obj/gold/ld-new auth.o
further reduced test is #define overalloc_at(f, l) \ do { \ fatal_exit("ERROR: attempting to allocate too large block at %s:%d", f, l);\ } while (0) #define overalloc() overalloc_at(__FILE__, __LINE__) void foo() { overalloc(); } % gcc-11.0.1 /tmp/a.c -c -gdwarf-5 % /tmp/obj/gold/ld-new a.o /tmp/obj/gold/ld-new: internal error in format_file_lineno, at /home/kraj/work/binutils-gdb/gold/dwarf_reader.cc:2278 ICE not seen when -gdwarf-4 is used
(In reply to Khem Raj from comment #10) > further reduced test is > > #define overalloc_at(f, l) \ > do { \ > fatal_exit("ERROR: attempting to allocate too large block at %s:%d", > f, l);\ > } while (0) > > #define overalloc() overalloc_at(__FILE__, __LINE__) > > void foo() > { > overalloc(); > } > > % gcc-11.0.1 /tmp/a.c -c -gdwarf-5 > % /tmp/obj/gold/ld-new a.o > /tmp/obj/gold/ld-new: internal error in format_file_lineno, at > /home/kraj/work/binutils-gdb/gold/dwarf_reader.cc:2278 > > ICE not seen when -gdwarf-4 is used I compared the assembly output and difference ( dwarf4 vs dwarf5 ) that matters is that when dwarf5 is enabled then it emits this .file directive into .debug_line section which gold does not like @@ -289,38 +290,40 @@ .quad 0 .section .debug_line,"",@progbits .Ldebug_line0: + .file 0 "/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux/links/2.21-r0/links-2.21" "/tmp/a.c" .section .debug_str,"MS",@progbits,1
What version of gcc-11.0.1 do you use (--version)? I cannot reproduce your failure with the latest GCC and ld.gold built from source files.
(In reply to Martin Liska from comment #12) > What version of gcc-11.0.1 do you use (--version)? > I cannot reproduce your failure with the latest GCC and ld.gold built from > source files. % ../recipe-sysroot-native/usr/bin/x86_64-yoe-linux/x86_64-yoe-linux-gcc-11.0.1 -v Using built-in specs. COLLECT_GCC=../recipe-sysroot-native/usr/bin/x86_64-yoe-linux/x86_64-yoe-linux-gcc-11.0.1 COLLECT_LTO_WRAPPER=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux/links/2.21-r0/recipe-sysroot-native/usr/bin/x86_64-yoe-linux/../../libexec/x86_64-yoe-linux/gcc/x86_64-yoe-linux/11.0.1/lto-wrapper Target: x86_64-yoe-linux Configured with: ../../../../../../work-shared/gcc-11.0.1-r0/gcc-5074c6fa38cef1abb9a355d717b41441a44c4e6a/configure --build=x86_64-linux --host=x86_64-linux --target=x86_64-yoe-linux --prefix=/host-native/usr --exec_prefix=/host-native/usr --bindir=/host-native/usr/bin/x86_64-yoe-linux --sbindir=/host-native/usr/bin/x86_64-yoe-linux --libexecdir=/host-native/usr/libexec/x86_64-yoe-linux --datadir=/host-native/usr/share --sysconfdir=/host-native/etc --sharedstatedir=/host-native/com --localstatedir=/host-native/var --libdir=/host-native/usr/lib/x86_64-yoe-linux --includedir=/host-native/usr/include --oldincludedir=/host-native/usr/include --infodir=/host-native/usr/share/info --mandir=/host-native/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/host-native --enable-clocale=generic --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --disable-multilib --enable-default-pie --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=x86_64-yoe-linux- --without-local-prefix --disable-install-libiberty --disable-libssp --enable-libitm --enable-lto --disable-bootstrap --with-system-zlib --with-linker-hash-style=sysv --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl --with-gxx-include-dir=/not/exist/usr/include/c++/11.0.1 --with-sysroot=/not/exist --with-build-sysroot=/host --enable-poison-system-directories=error --with-system-zlib --disable-static --disable-nls --with-glibc-version=2.28 --enable-initfini-array --enable-__cxa_atexit Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.0.1 20210317 (experimental) (GCC)
(In reply to Khem Raj from comment #13) > (In reply to Martin Liska from comment #12) > > What version of gcc-11.0.1 do you use (--version)? > > I cannot reproduce your failure with the latest GCC and ld.gold built from > > source files. > > > % > ../recipe-sysroot-native/usr/bin/x86_64-yoe-linux/x86_64-yoe-linux-gcc-11.0. > 1 -v > Using built-in specs. > COLLECT_GCC=../recipe-sysroot-native/usr/bin/x86_64-yoe-linux/x86_64-yoe- > linux-gcc-11.0.1 > COLLECT_LTO_WRAPPER=/mnt/b/yoe/master/build/tmp/work/core2-64-yoe-linux/ > links/2.21-r0/recipe-sysroot-native/usr/bin/x86_64-yoe-linux/../../libexec/ > x86_64-yoe-linux/gcc/x86_64-yoe-linux/11.0.1/lto-wrapper > Target: x86_64-yoe-linux > Configured with: > ../../../../../../work-shared/gcc-11.0.1-r0/gcc- > 5074c6fa38cef1abb9a355d717b41441a44c4e6a/configure --build=x86_64-linux > --host=x86_64-linux --target=x86_64-yoe-linux --prefix=/host-native/usr > --exec_prefix=/host-native/usr > --bindir=/host-native/usr/bin/x86_64-yoe-linux > --sbindir=/host-native/usr/bin/x86_64-yoe-linux > --libexecdir=/host-native/usr/libexec/x86_64-yoe-linux > --datadir=/host-native/usr/share --sysconfdir=/host-native/etc > --sharedstatedir=/host-native/com --localstatedir=/host-native/var > --libdir=/host-native/usr/lib/x86_64-yoe-linux > --includedir=/host-native/usr/include > --oldincludedir=/host-native/usr/include > --infodir=/host-native/usr/share/info --mandir=/host-native/usr/share/man > --disable-silent-rules --disable-dependency-tracking > --with-libtool-sysroot=/host-native --enable-clocale=generic --with-gnu-ld > --enable-shared --enable-languages=c,c++ --enable-threads=posix > --disable-multilib --enable-default-pie --enable-c99 --enable-long-long > --enable-symvers=gnu --enable-libstdcxx-pch > --program-prefix=x86_64-yoe-linux- --without-local-prefix > --disable-install-libiberty --disable-libssp --enable-libitm --enable-lto > --disable-bootstrap --with-system-zlib --with-linker-hash-style=sysv > --enable-linker-build-id --with-ppl=no --with-cloog=no > --enable-checking=release --enable-cheaders=c_global --without-isl > --with-gxx-include-dir=/not/exist/usr/include/c++/11.0.1 > --with-sysroot=/not/exist --with-build-sysroot=/host > --enable-poison-system-directories=error --with-system-zlib --disable-static > --disable-nls --with-glibc-version=2.28 --enable-initfini-array > --enable-__cxa_atexit > Thread model: posix > Supported LTO compression algorithms: zlib zstd > gcc version 11.0.1 20210317 (experimental) (GCC) That's fine. Can you please attach the full .s file you feed to ld.gold?
here is revised testcase #include <stdio.h> #include <stdlib.h> #define overalloc_at(f, l) \ do { \ printf("ERROR: attempting to allocate too large block at %s:%d", f, l);\ exit(1);\ } while (0) #define overalloc() overalloc_at(__FILE__, __LINE__) void main() { overalloc(); } I am attaching the .s file as well.
Created attachment 13321 [details] asm output
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=5cde809b7b9da3ad3aa0d65f0e5e92ab199d64f0 commit 5cde809b7b9da3ad3aa0d65f0e5e92ab199d64f0 Author: Cary Coutant <ccoutant@gmail.com> Date: Wed Mar 17 21:31:15 2021 -0700 Add DWARF 5 support in gold. elfcpp/ PR gold/27246 * dwarf.h (enum DW_LNCT): Add line number table content type codes. (enum DW_LINE_OPS): Reformat. (enum DW_LINE_EXTENDED_OPS): Reformat. (enum DW_CHILDREN): Reformat. (enum DW_RLE): Add range list entry types. (enum DW_SECT): Update values for DWARF 5. gold/ PR gold/27246 * dwarf_reader.cc (Dwarf_abbrev_table::do_get_abbrev): Handle DW_FORM_implicit_const. (Dwarf_ranges_table::read_ranges_table): Add version parameter; Adjust all callers. Look for .debug_rnglists section if DWARF 5. (Dwarf_ranges_table::read_range_list_v5): New method. (Dwarf_die::read_attributes): Handle new DWARF 5 DW_FORM codes. (Dwarf_die::skip_attributes): Likewise. (Dwarf_info_reader::do_parse): Support DWARF 5 unit header format. (Dwarf_info_reader::read_3bytes_from_pointer): New method. (Sized_dwarf_line_info::Sized_dwarf_line_info): Initialize str_buffer_, str_buffer_start, reloc_map_, line_number_map_. Look for .debug_line_str section. (Sized_dwarf_line_info::read_header_prolog): Support DWARF 5 prolog. (Sized_dwarf_line_info::read_header_tables): Rename to... (Sized_dwarf_line_info::read_header_tables_v2): ... this. (Sized_dwarf_line_info::read_header_tables_v5): New method. (Sized_dwarf_line_info::process_one_opcode): Insert missing "this->". Change advance_line to signed int64_t. (Sized_dwarf_line_info::read_lines): Add endptr parameter; adjust callers. Insert missing "this->". (Sized_dwarf_line_info::read_line_mappings): Support DWARF 5. (Sized_dwarf_line_info::do_addr2line): Add debug code. * dwarf_reader.h (Dwarf_abbrev_table::Attribute): Add implicit_const field. Adjust constructor. (Dwarf_abbrev_table::add_sttribute): Add implicit_const parameter. (Dwarf_ranges_table::read_ranges_table): Add version parameter. (Dwarf_ranges_table::read_range_list_v5): New method. (Dwarf_die): Remove unused attr_off field. (Dwarf_info_reader::Dwarf_info_reader): Initialize unit_type_ field. (Dwarf_info_reader::is_type_unit): New method. (Dwarf_info_reader::read_3bytes_from_pointer): New method. (Dwarf_info_reader::read_range_list): Call read_range_list_v5 for DWARF 5 range lists. (Dwarf_info_reader::is_type_unit_): Remove. (Dwarf_info_reader::unit_type_): New field. (Sized_dwarf_line_info::~Sized_dwarf_line_info): Delete str_buffer_start_. (Sized_dwarf_line_info::read_header_tables): Rename to... (Sized_dwarf_line_info::read_header_tables_v2): ... this. (Sized_dwarf_line_info::read_header_tables_v5): New method. (Sized_dwarf_line_info::read_lines): Add endptr parameter. (Sized_dwarf_line_info::Dwarf_line_infoHeader): Add address_size field. (Sized_dwarf_line_info::str_buffer_): New field. (Sized_dwarf_line_info::str_buffer_end_): New field. (Sized_dwarf_line_info::str_buffer_start_): New field. (Sized_dwarf_line_info::end_of_header_length_): New field. (Sized_dwarf_line_info::end_of_unit_): New field.
Fixed on trunk.
it fixed my problem as well.
*** Bug 27971 has been marked as a duplicate of this bug. ***
If the ld.gold, which install on my system default, don't merge such patch, is there any option can avoid such bug? eg: -gdwarf-2
(In reply to Allen from comment #21) > If the ld.gold, which install on my system default, don't merge such patch, > is there any option can avoid such bug? > > eg: -gdwarf-2 Yes, you can compile all objects that are linked e.g. with -gdwarf-4.