Bug 27195 - Error: file number less than one
Summary: Error: file number less than one
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: 2.36
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-17 02:04 UTC by H.J. Lu
Modified: 2021-01-26 14:27 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2021-01-17 02:04:28 UTC
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]$
Comment 1 H.J. Lu 2021-01-17 03:46:47 UTC
It is a GCC bug.
Comment 2 H.J. Lu 2021-01-17 03:57:49 UTC
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.
Comment 3 H.J. Lu 2021-01-17 04:49:16 UTC
A patch is posted at

https://sourceware.org/pipermail/binutils/2021-January/114978.html
Comment 4 Nick Clifton 2021-01-18 12:52:37 UTC
(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}}
Comment 5 H.J. Lu 2021-01-18 13:41:24 UTC
(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.
Comment 6 Nick Clifton 2021-01-18 14:17:54 UTC
(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 ?
Comment 7 Nick Clifton 2021-01-18 14:21:25 UTC
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
Comment 8 Nick Clifton 2021-01-18 14:26:11 UTC
Argh - please ignore - I am confusing the two solutions to this problem.
Reviewing the auto-enable-dwarf-5 patch now
Comment 9 Sourceware Commits 2021-01-18 14:28:49 UTC
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.
Comment 10 Sourceware Commits 2021-01-18 14:46:04 UTC
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)
Comment 11 H.J. Lu 2021-01-18 14:46:39 UTC
Fixed for 2.36.
Comment 12 Sourceware Commits 2021-01-26 14:25:58 UTC
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)
Comment 13 H.J. Lu 2021-01-26 14:27:58 UTC
Also fixed on 2.35 branch.