Bug 25878 - Error: file table slot 1 is already occupied by a different file
Summary: Error: file table slot 1 is already occupied by a different file
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: 2.36
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 26740 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-04-27 03:17 UTC by Nick Desaulniers
Modified: 2024-02-22 03:45 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2020-04-27 00:00:00


Attachments
core.s (206 bytes, text/plain)
2020-04-27 03:17 UTC, Nick Desaulniers
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Desaulniers 2020-04-27 03:17:34 UTC
Created attachment 12492 [details]
core.s

I spent some more time this weekend looking to enable DWARF-5 support in the Linux kernel.  We make further progress, then hit a snag.  I ran into an issue with GAS that looks like maybe a bug in GAS?

Attached is a pared down assembler source file.  If I run it through GAS via:

$ as -gdwarf-5 core.s
core.s: Assembler messages:
core.s:13: Error: file table slot 1 is already occupied by a different file (/home/nick/linux/core.s vs ./include/linux/types.h)

I suspect that slot 1 was auto assigned the filename? (maybe that should be skipped for dwarf-5?)
Comment 1 Nick Clifton 2020-04-27 09:33:53 UTC
Hi Nick,

  Indeed, it was auto-assigned.  I am currently testing a patch that
  allows auto-assigned entries to be reassigned should a later .file
  directive want to use the file slot that they are currently using.

Cheers
  Nick
Comment 2 Sourceware Commits 2020-04-27 10:36:31 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit 714e6c969ff1ce0fdb0cd3703d41ef2fef424535
Author: Nick Clifton <nickc@redhat.com>
Date:   Mon Apr 27 11:35:25 2020 +0100

    GAS: Allow automatically assigned entries in the file table to be reassigned if the source file specifically requests to use the assigned slot.
    
            PR 25878
            * dwarf2dbg.c (struct file_entry): Add auto_assigned field.
            (assign_file_to_slot): New function.  Fills in an entry in the
            files table.
            (allocate_filenum): Use new function.
            (allocate_filename_to_slot): Use new function.  If the specified
            slot entry is already in use, but was chosen automatically then
            reassign the automatic entry.
Comment 3 Nick Clifton 2020-04-27 10:41:17 UTC
OK, I have updated the assembler to automatically reassign slots to make room for entries specifically requested by the ".file" pseudo-op.  Please give it a try.
Comment 4 Nick Desaulniers 2020-05-01 03:01:22 UTC
Thanks Nick. With that fix:

$ readelf --debug-dump=info vmlinux | head -n 5 
Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0x133f (32-bit)
   Version:       5
                  ^

I'll cc you on the kernel patches when I send them.
Comment 5 H.J. Lu 2020-10-16 01:19:40 UTC
*** Bug 26740 has been marked as a duplicate of this bug. ***
Comment 6 H.J. Lu 2020-10-16 01:20:44 UTC
[hjl@gnu-cfl-2 pr26740]$ cat y.s 
	.text
	.global kretprobe_trampoline
kretprobe_trampoline:
	ret
	.file	0 "core.c" md5 0xbbd69fc03ce253b2dbaab2522dd519ae
	.file	1 "types.h"
[hjl@gnu-cfl-2 pr26740]$ ./as --gdwarf-5  -o y.o y.s -32
[hjl@gnu-cfl-2 pr26740]$ readelf -wl y.o
Raw dump of debug contents of section .debug_line:

  Offset:                      0x0
  Length:                      118
  DWARF Version:               5
  Address size (bytes):        4
  Segment selector (bytes):    0
  Prologue Length:             97
  Minimum Instruction Length:  1
  Maximum Ops per Instruction: 1
  Initial value of 'is_stmt':  1
  Line Base:                   -5
  Line Range:                  14
  Opcode Base:                 13

 Opcodes:
  Opcode 1 has 0 args
  Opcode 2 has 1 arg
  Opcode 3 has 1 arg
  Opcode 4 has 1 arg
  Opcode 5 has 1 arg
  Opcode 6 has 0 args
  Opcode 7 has 0 args
  Opcode 8 has 0 args
  Opcode 9 has 1 arg
  Opcode 10 has 0 args
  Opcode 11 has 0 args
  Opcode 12 has 1 arg

 The Directory Table (offset 0x22, lines 1, columns 1):
  Entry	Name
  0	(indirect line string, offset: 0x0): /export/home/hjl/bugs/binutils/pr26740

 The File Name Table (offset 0x2e, lines 3, columns 3):
  Entry	Dir	MD5				Name
  0	0 0xbbd69fc03ce253b2dbaab2522dd519ae	(indirect line string, offset: 0x27): core.c
  1	0 0x00000000000000000000000000000000	(indirect line string, offset: 0x2e): types.h
  2	0 0x00000000000000000000000000000000	(indirect line string, offset: 0x36): y.s
^^^^^^^^^^ This shouldn't be here.

 Line Number Statements:
  [0x0000006d]  Extended opcode 2: set Address to 0x0
  [0x00000074]  Special opcode 8: advance Address by 0 to 0x0 and Line by 3 to 4
  [0x00000075]  Advance PC by 1 to 0x1
  [0x00000077]  Extended opcode 1: End of Sequence


[hjl@gnu-cfl-2 pr26740]$
Comment 7 Sourceware Commits 2020-10-16 11:08:24 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=6915020bb134ae29fd772295c66fd67b5944962d

commit 6915020bb134ae29fd772295c66fd67b5944962d
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 16 04:03:20 2020 -0700

    gas: Reuse the input file entry in the file table
    
    Some instructions can be emitted (dwarf2_emit_insn is called) before the
    first .file <NUMBER> directive has been seen, which allocates the input
    file as the first file entry.  Reuse the input file entry in the file
    table.
    
            PR gas/25878
            PR gas/26740
            * dwarf2dbg.c (file_entry): Remove auto_assigned.
            (assign_file_to_slot): Remove the auto_assign argument.
            (allocate_filenum): Updated.
            (allocate_filename_to_slot): Reuse the input file entry in the
            file table.
            (dwarf2_where): Replace as_where with as_where_physical.
            * testsuite/gas/i386/dwarf5-line-1.d: New file.
            * testsuite/gas/i386/dwarf5-line-1.s: Likewise.
            * testsuite/gas/i386/i386.exp: Run dwarf5-line-1.
Comment 8 H.J. Lu 2020-10-16 13:29:44 UTC
Another bug:

[hjl@gnu-cfl-2 pr26740]$ cat foo.S
	.text
lbasename:
	.nop
[hjl@gnu-cfl-2 pr26740]$ make foo.o
gcc -B./ -m32 -g -Wa,--gdwarf-4 -c -o foo.o foo.S
[hjl@gnu-cfl-2 pr26740]$ readelf -w foo.o | grep -A4 File
 The File Name Table (offset 0x22):
  Entry	Dir	Time	Size	Name
  1	1	0	0	ccJZccC0.s

 Line Number Statements:
[hjl@gnu-cfl-2 pr26740]$ 

It breaks debug info on foo.S.
Comment 9 H.J. Lu 2020-10-16 18:30:53 UTC
(In reply to H.J. Lu from comment #8)
> Another bug:
> 
> [hjl@gnu-cfl-2 pr26740]$ cat foo.S
> 	.text
> lbasename:
> 	.nop
> [hjl@gnu-cfl-2 pr26740]$ make foo.o
> gcc -B./ -m32 -g -Wa,--gdwarf-4 -c -o foo.o foo.S
> [hjl@gnu-cfl-2 pr26740]$ readelf -w foo.o | grep -A4 File
>  The File Name Table (offset 0x22):
>   Entry	Dir	Time	Size	Name
>   1	1	0	0	ccJZccC0.s
> 
>  Line Number Statements:
> [hjl@gnu-cfl-2 pr26740]$ 
> 
> It breaks debug info on foo.S.

This patch

https://sourceware.org/pipermail/binutils/2020-October/113744.html

fixed it.
Comment 10 Sourceware Commits 2020-10-17 11:27:10 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=bd0c565edbf4ba8121fded38e389530d7fa6f963

commit bd0c565edbf4ba8121fded38e389530d7fa6f963
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Oct 17 04:24:22 2020 -0700

    gas: Always use as_where for preprocessed assembly codes
    
    Always clear the slot 1 if it was assigned to the input file before the
    first .file <NUMBER> directive has been seen.  Always use as_where to
    generate the correct debug infor for preprocessed assembly codes.
    
            PR gas/25878
            PR gas/26740
            * dwarf2dbg.c (allocate_filename_to_slot): Don't reuse the slot 1
            here.
            (dwarf2_where): Restore as_where.
            (dwarf2_directive_filename): Clear the slot 1 if it was assigned
            to the input file.
            * testsuite/gas/i386/dwarf5-line-2.d: New file.
            * testsuite/gas/i386/dwarf5-line-2.s: Likewise.
            * testsuite/gas/i386/dwarf5-line-3.d: Likewise.
            * testsuite/gas/i386/dwarf5-line-3.s: Likewise.
            * testsuite/gas/i386/i386.exp: Run dwarf5-line-2 and
            dwarf5-line-3.
Comment 11 H.J. Lu 2020-10-17 11:27:52 UTC
Fixed for 2.36 so far.
Comment 12 Sourceware Commits 2020-10-17 12:36:20 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=7ffdc9ae6ed88601e7f422ab117fe3abeef110dc

commit 7ffdc9ae6ed88601e7f422ab117fe3abeef110dc
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Oct 17 05:35:23 2020 -0700

    gas: Replace dwarf5-line-2.S with dwarf5-line-3.S
    
            PR gas/25878
            PR gas/26740
            * testsuite/gas/i386/dwarf5-line-3.s: Replace dwarf5-line-2.S
            with dwarf5-line-3.S.
            * testsuite/gas/i386/dwarf5-line-3.d: Updated.
Comment 13 Sourceware Commits 2020-10-17 12:53:51 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=9717970a4e374218fe74c99cf5bc7f1d45adbf0e

commit 9717970a4e374218fe74c99cf5bc7f1d45adbf0e
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sat Oct 17 05:52:13 2020 -0700

    gas: Add a -gdwarf-5 debug_line test with .s file
    
            PR gas/25878
            PR gas/26740
            * testsuite/gas/i386/dwarf5-line-4.d: New file.
            * testsuite/gas/i386/dwarf5-line-4.s: Likewise.
            * testsuite/gas/i386/i386.exp: Run dwarf5-line-4.
Comment 14 Sourceware Commits 2020-11-16 19:53:54 UTC
The binutils-2_35-branch branch has been updated by Mark Wielaard <mark@sourceware.org>:

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

commit ea873d892ebfae612aed5d308061b083b3f06636
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Oct 16 04:03:20 2020 -0700

    gas: Reuse the input file entry in the file table
    
    Some instructions can be emitted (dwarf2_emit_insn is called) before the
    first .file <NUMBER> directive has been seen, which allocates the input
    file as the first file entry.  Reuse the input file entry in the file
    table.
    
            PR gas/25878
            PR gas/26740
            * dwarf2dbg.c (file_entry): Remove auto_assigned.
            (assign_file_to_slot): Remove the auto_assign argument.
            (allocate_filenum): Updated.
            (allocate_filename_to_slot): Reuse the input file entry in the
            file table.
            (dwarf2_where): Replace as_where with as_where_physical.
            * testsuite/gas/i386/dwarf5-line-1.d: New file.
            * testsuite/gas/i386/dwarf5-line-1.s: Likewise.
            * testsuite/gas/i386/i386.exp: Run dwarf5-line-1.
    
    (cherry picked from commit 6915020bb134ae29fd772295c66fd67b5944962d)
    
    gas: Always use as_where for preprocessed assembly codes
    
    Always clear the slot 1 if it was assigned to the input file before the
    first .file <NUMBER> directive has been seen.  Always use as_where to
    generate the correct debug infor for preprocessed assembly codes.
    
            PR gas/25878
            PR gas/26740
            * dwarf2dbg.c (allocate_filename_to_slot): Don't reuse the slot 1
            here.
            (dwarf2_where): Restore as_where.
            (dwarf2_directive_filename): Clear the slot 1 if it was assigned
            to the input file.
            * testsuite/gas/i386/dwarf5-line-2.d: New file.
            * testsuite/gas/i386/dwarf5-line-2.s: Likewise.
            * testsuite/gas/i386/dwarf5-line-3.d: Likewise.
            * testsuite/gas/i386/dwarf5-line-3.s: Likewise.
            * testsuite/gas/i386/i386.exp: Run dwarf5-line-2 and
            dwarf5-line-3.
    
    (cherry picked from commit bd0c565edbf4ba8121fded38e389530d7fa6f963)
    
    gas: Clear all auto-assigned file slots
    
    Since a file slot is auto-assigned for the #APP marker appeared before
    the first .file <NUMBER> directive has been seen, clear all auto-assigned
    file slots when seeing the first .file <NUMBER> directive.
    
            PR gas/26778
            * * dwarf2dbg.c (num_of_auto_assigned): New.
            (allocate_filenum): Increment num_of_auto_assigned.
            (dwarf2_directive_filename): Clear the slots auto-assigned
            before the first .file <NUMBER> directive was seen.
            * testsuite/gas/i386/dwarf4-line-1.d: New file.
            * testsuite/gas/i386/dwarf4-line-1.s: Likewise.
            * testsuite/gas/i386/i386.exp: Run dwarf4-line-1.
    
    (cherry picked from commit ae9d2233e61a98ff8dba56be10219aa5306ffc9a)
Comment 15 Alan Modra 2024-02-22 03:45:06 UTC
Looks like this was fixed, just the bugzilla left in an odd state.