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.
This commit is contained in:
H.J. Lu 2020-10-16 04:03:20 -07:00
parent 23ae20f5e3
commit 6915020bb1
5 changed files with 84 additions and 19 deletions

View File

@ -1,6 +1,22 @@
2020-10-16 H.J. Lu <hongjiu.lu@intel.com>
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.
2020-10-16 Lili Cui <lili.cui@intel.com>
* config/tc-i386.c: Move Pseudo Prefix check to match_template.
* config/tc-i386.c (cpu_flags_match): Move Pseudo Prefix check
to ...
(match_template): Here.
* testsuite/gas/i386/avx-vnni-inval.l: New file.
* testsuite/gas/i386/avx-vnni-inval.s: Likewise.
* testsuite/gas/i386/avx-vnni.d: Delete invalid {vex2} test.

View File

@ -211,7 +211,6 @@ struct file_entry
{
const char * filename;
unsigned int dir;
bfd_boolean auto_assigned;
unsigned char md5[NUM_MD5_BYTES];
};
@ -633,7 +632,7 @@ get_directory_table_entry (const char * dirname,
}
static bfd_boolean
assign_file_to_slot (unsigned long i, const char *file, unsigned int dir, bfd_boolean auto_assign)
assign_file_to_slot (unsigned long i, const char *file, unsigned int dir)
{
if (i >= files_allocated)
{
@ -653,7 +652,6 @@ assign_file_to_slot (unsigned long i, const char *file, unsigned int dir, bfd_bo
files[i].filename = file;
files[i].dir = dir;
files[i].auto_assigned = auto_assign;
memset (files[i].md5, 0, NUM_MD5_BYTES);
if (files_in_use < i + 1)
@ -717,7 +715,7 @@ allocate_filenum (const char * pathname)
return i;
}
if (!assign_file_to_slot (i, file, dir, TRUE))
if (!assign_file_to_slot (i, file, dir))
return -1;
last_used = i;
@ -792,18 +790,12 @@ allocate_filename_to_slot (const char * dirname,
}
fail:
/* If NUM was previously allocated automatically then
choose another slot for it, so that we can reuse NUM. */
if (files[num].auto_assigned)
{
/* Find an unused slot. */
for (i = 1; i < files_in_use; ++i)
if (files[i].filename == NULL)
break;
if (! assign_file_to_slot (i, files[num].filename, files[num].dir, TRUE))
return FALSE;
files[num].filename = NULL;
}
/* Reuse NUM if it is 1 and was assigned to the input file before
the first .file <NUMBER> directive was seen. */
file = as_where_physical (&i);
file = get_basename (file);
if (num == 1 && filename_cmp (file, files[num].filename) == 0)
files[num].filename = NULL;
else
{
as_bad (_("file table slot %u is already occupied by a different file (%s%s%s vs %s%s%s)"),
@ -833,7 +825,7 @@ allocate_filename_to_slot (const char * dirname,
d = get_directory_table_entry (dirname, dirlen, num == 0);
i = num;
if (! assign_file_to_slot (i, file, d, FALSE))
if (! assign_file_to_slot (i, file, d))
return FALSE;
if (with_md5)
@ -902,7 +894,7 @@ dwarf2_where (struct dwarf2_line_info *line)
const char *filename;
memset (line, 0, sizeof (*line));
filename = as_where (&line->line);
filename = as_where_physical (&line->line);
line->filenum = allocate_filenum (filename);
/* FIXME: We should check the return value from allocate_filenum. */
line->column = 0;

View File

@ -0,0 +1,50 @@
#as: -gdwarf-5
#readelf: -wl
#name: DWARF5 .debug_line 1
Raw dump of debug contents of section \.z?debug_line:
Offset: 0x0
Length: .*
DWARF Version: 5
Address size \(bytes\): .*
Segment selector \(bytes\): 0
Prologue Length: .*
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 0x.*, lines 2, columns 1\):
Entry Name
0 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
1 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
The File Name Table \(offset 0x.*, lines 2, columns 3\):
Entry Dir MD5 Name
0 0 0xbbd69fc03ce253b2dbaab2522dd519ae \(indirect line string, offset: 0x.*\): core.c
1 0 0x00000000000000000000000000000000 \(indirect line string, offset: 0x.*\): types.h
Line Number Statements:
\[0x.*\] Extended opcode 2: set Address to 0x0
\[0x.*\] Special opcode 8: advance Address by 0 to 0x0 and Line by 3 to 4
\[0x.*\] Advance PC by 1 to 0x1
\[0x.*\] Extended opcode 1: End of Sequence

View File

@ -0,0 +1,6 @@
.text
.global kretprobe_trampoline
kretprobe_trampoline:
ret
.file 0 "core.c" md5 0xbbd69fc03ce253b2dbaab2522dd519ae
.file 1 "types.h"

View File

@ -614,6 +614,7 @@ if [gas_32_check] then {
run_dump_test "dwarf2-line-2"
run_dump_test "dwarf2-line-3"
run_dump_test "dwarf2-line-4"
run_dump_test "dwarf5-line-1"
run_dump_test "dw2-compress-2"
run_dump_test "dw2-compressed-2"