From https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98708 GCC 11 may generate: [hjl@gnu-clx-1 tmp]$ cat foo.s .file "cxx11-ios_failure.cc" .file 1 "../../../../../src-master/libstdc++-v3/src/c++11/cxx11-ios_failure.cc" .file 0 "/export/gnu/import/git/gcc-test-master-intel64-native/bld/x86_64-pc-linux-gnu/libstdc++-v3/src/c++11" "../../../../../src-master/libstdc++-v3/src/c++11/cxx11-ios_failure.cc" .text nop [hjl@gnu-clx-1 tmp]$ gcc -c foo.s foo.s: Assembler messages: foo.s:3: Error: file number less than one [hjl@gnu-clx-1 tmp]$
It is a GCC bug.
I think it is very bad that $ as -o x.o x.s fails when x.s contains DWARF5 info generated by GCC 11. Assembler shouldn't require --gdwarf-5 to accept DWARF5 info. GCC 11 should emit an assembly directive to enable DWARF5 info in assembler.
A patch is posted at https://sourceware.org/pipermail/binutils/2021-January/114978.html
(In reply to H.J. Lu from comment #2) > I think it is very bad that > > $ as -o x.o x.s > > fails when x.s contains DWARF5 info generated by GCC 11. Assembler shouldn't > require --gdwarf-5 to accept DWARF5 info. GCC 11 should emit an assembly > directive to enable DWARF5 info in assembler. Wouldn't it just be easier to update gcc's spec file to add the --gdwarf-5 directive ? Eg by changing this part of asm_debug: %{!gstabs*:%{g*:--gdwarf2}} into: %{!gstabs*:%{g*:--gdwarf-%*}%{!g:--gdwarf-5}}
(In reply to Nick Clifton from comment #4) > (In reply to H.J. Lu from comment #2) > > I think it is very bad that > > > > $ as -o x.o x.s > > > > fails when x.s contains DWARF5 info generated by GCC 11. Assembler shouldn't > > require --gdwarf-5 to accept DWARF5 info. GCC 11 should emit an assembly > > directive to enable DWARF5 info in assembler. > > Wouldn't it just be easier to update gcc's spec file to add the --gdwarf-5 > directive ? Eg by changing this part of asm_debug: > > %{!gstabs*:%{g*:--gdwarf2}} > > into: > > %{!gstabs*:%{g*:--gdwarf-%*}%{!g:--gdwarf-5}} It is done in GCC. But it doesn't always work. If assembly codes have DWARF5 ".file 0" or ".loc 0" directives, assembler should turn on DWARF5 and accept them.
(In reply to H.J. Lu from comment #5) > It is done in GCC. But it doesn't always work. If assembly codes have > DWARF5 ".file 0" or ".loc 0" directives, assembler should turn on DWARF5 > and accept them. But your patch will not do that, unless the assembler source is updated in order to include the new directive. Plus if assembler source files are already using DWARF-5 only features then they must already be using --gdwarf-5 on the command line, right ?
Hi H.J. OK - patch approved. Please apply to the mainline. I have been talking to Jakub about this and he has persuaded me that your solution is the best idea. Cheers Nick
Argh - please ignore - I am confusing the two solutions to this problem. Reviewing the auto-enable-dwarf-5 patch now
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=705989f19adf20dd70c50237ec61cd708f2b0939 commit 705989f19adf20dd70c50237ec61cd708f2b0939 Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jan 18 06:25:05 2021 -0800 as: Automatically enable DWARF5 support Currently $ as -o x.o x.s fails when x.s contains DWARF5 ".file 0" or ".loc 0" directives. Update assembler to automatically enable DWARF5 support so that $ gcc -S -g -c x.c $ gcc -c x.s works. PR gas/27195 * dwarf2dbg.c (dwarf2_gen_line_info): Set dwarf_level to 5 if needed. (dwarf2_directive_filename): Likewise. (dwarf2_directive_loc): Likewise. * testsuite/gas/elf/dwarf-5-file0.d: Pass --gdwarf-3. * testsuite/gas/lns/lns-diag-1.l: Remove the "Error: file number less than one" errors.
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=4e02d082a3506578e6fe1d990593a29d3fc07f94 commit 4e02d082a3506578e6fe1d990593a29d3fc07f94 Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jan 18 06:25:05 2021 -0800 as: Automatically enable DWARF5 support Currently $ as -o x.o x.s fails when x.s contains DWARF5 ".file 0" or ".loc 0" directives. Update assembler to automatically enable DWARF5 support so that $ gcc -S -g -c x.c $ gcc -c x.s works. PR gas/27195 * dwarf2dbg.c (dwarf2_gen_line_info): Set dwarf_level to 5 if needed. (dwarf2_directive_filename): Likewise. (dwarf2_directive_loc): Likewise. * testsuite/gas/elf/dwarf-5-file0.d: Pass --gdwarf-3. * testsuite/gas/lns/lns-diag-1.l: Remove the "Error: file number less than one" errors. (cherry picked from commit 705989f19adf20dd70c50237ec61cd708f2b0939)
Fixed for 2.36.
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=74c2eff55954b850b8bc9804cbf4e599919a811a commit 74c2eff55954b850b8bc9804cbf4e599919a811a Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jan 18 06:25:05 2021 -0800 as: Automatically enable DWARF5 support Currently $ as -o x.o x.s fails when x.s contains DWARF5 ".file 0" or ".loc 0" directives. Update assembler to automatically enable DWARF5 support so that $ gcc -S -g -c x.c $ gcc -c x.s works. PR gas/27195 * dwarf2dbg.c (dwarf2_gen_line_info): Set dwarf_level to 5 if needed. (dwarf2_directive_filename): Likewise. (dwarf2_directive_loc): Likewise. * testsuite/gas/elf/dwarf-5-file0.d: Pass --gdwarf-3. * testsuite/gas/lns/lns-diag-1.l: Remove the "Error: file number less than one" errors. (cherry picked from commit 705989f19adf20dd70c50237ec61cd708f2b0939)
Also fixed on 2.35 branch.