[PATCH] gas: Reuse the input file entry in the file table
H.J. Lu
hjl.tools@gmail.com
Fri Oct 16 02:01:42 GMT 2020
Some instructions can be emitted (dwarf2_emit_insn is called) before the
first .file <NUMBER> directive has been seen which allocate 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.
* 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.
---
gas/dwarf2dbg.c | 26 +++++--------
gas/testsuite/gas/i386/dwarf5-line-1.d | 51 ++++++++++++++++++++++++++
gas/testsuite/gas/i386/dwarf5-line-1.s | 6 +++
gas/testsuite/gas/i386/i386.exp | 1 +
4 files changed, 67 insertions(+), 17 deletions(-)
create mode 100644 gas/testsuite/gas/i386/dwarf5-line-1.d
create mode 100644 gas/testsuite/gas/i386/dwarf5-line-1.s
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 1c21d58c591..01bad5f2ed3 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -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
+ 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)
diff --git a/gas/testsuite/gas/i386/dwarf5-line-1.d b/gas/testsuite/gas/i386/dwarf5-line-1.d
new file mode 100644
index 00000000000..ad0281cb05a
--- /dev/null
+++ b/gas/testsuite/gas/i386/dwarf5-line-1.d
@@ -0,0 +1,51 @@
+#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
+
+
+#pass
diff --git a/gas/testsuite/gas/i386/dwarf5-line-1.s b/gas/testsuite/gas/i386/dwarf5-line-1.s
new file mode 100644
index 00000000000..6e343ad0d36
--- /dev/null
+++ b/gas/testsuite/gas/i386/dwarf5-line-1.s
@@ -0,0 +1,6 @@
+ .text
+ .global kretprobe_trampoline
+kretprobe_trampoline:
+ ret
+ .file 0 "core.c" md5 0xbbd69fc03ce253b2dbaab2522dd519ae
+ .file 1 "types.h"
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index f5727678e23..87147c66480 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -613,6 +613,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"
--
2.26.2
More information about the Binutils
mailing list