[binutils-gdb] gas: Clear all auto-assigned file slots

H.J. Lu hjl@sourceware.org
Mon Oct 26 13:18:31 GMT 2020


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

commit ae9d2233e61a98ff8dba56be10219aa5306ffc9a
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Oct 26 06:16:08 2020 -0700

    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.

Diff:
---
 gas/ChangeLog                          | 11 ++++++++
 gas/dwarf2dbg.c                        | 24 ++++++++--------
 gas/testsuite/gas/i386/dwarf4-line-1.d | 50 ++++++++++++++++++++++++++++++++++
 gas/testsuite/gas/i386/dwarf4-line-1.s | 14 ++++++++++
 gas/testsuite/gas/i386/i386.exp        |  1 +
 5 files changed, 89 insertions(+), 11 deletions(-)

diff --git a/gas/ChangeLog b/gas/ChangeLog
index 20929b5aa17..a52eb2bd036 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,14 @@
+2020-10-26  H.J. Lu  <hongjiu.lu@intel.com>
+
+	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.
+
 2020-10-26  Cooper Qu <cooper.qu@linux.alibaba.com>
 
 	* config/tc-csky.c (dump_literals): Fix the literal dump
diff --git a/gas/dwarf2dbg.c b/gas/dwarf2dbg.c
index 75ef7c43e39..4e03c637d76 100644
--- a/gas/dwarf2dbg.c
+++ b/gas/dwarf2dbg.c
@@ -218,6 +218,7 @@ struct file_entry
 static struct file_entry *files;
 static unsigned int files_in_use;
 static unsigned int files_allocated;
+static unsigned int num_of_auto_assigned;
 
 /* Table of directories used by .debug_line.  */
 static char **       dirs = NULL;
@@ -718,6 +719,8 @@ allocate_filenum (const char * pathname)
   if (!assign_file_to_slot (i, file, dir))
     return -1;
 
+  num_of_auto_assigned++;
+
   last_used = i;
   last_used_dir_len = dir_len;
 
@@ -1013,6 +1016,7 @@ dwarf2_directive_filename (void)
   char *filename;
   const char * dirname = NULL;
   int filename_len;
+  unsigned int i;
 
   /* Continue to accept a bare string and pass it off.  */
   SKIP_WHITESPACE ();
@@ -1079,18 +1083,16 @@ dwarf2_directive_filename (void)
       return NULL;
     }
 
-  if (files_in_use == 2)
+  if (num_of_auto_assigned)
     {
-      /* Clear the slot 1 if it was assigned to the input file before
-	 the first .file <NUMBER> directive was seen.  */
-      unsigned int lineno;
-      const char *file = as_where (&lineno);
-      file = get_basename (file);
-      if (filename_cmp (file, files[1].filename) == 0)
-	{
-	  files[1].filename = NULL;
-	  files_in_use = 0;
-	}
+      /* Clear slots auto-assigned before the first .file <NUMBER>
+	 directive was seen.  */
+      if (files_in_use != (num_of_auto_assigned + 1))
+	abort ();
+      for (i = 1; i < files_in_use; i++)
+	files[i].filename = NULL;
+      files_in_use = 0;
+      num_of_auto_assigned = 0;
     }
 
   if (! allocate_filename_to_slot (dirname, filename, (unsigned int) num,
diff --git a/gas/testsuite/gas/i386/dwarf4-line-1.d b/gas/testsuite/gas/i386/dwarf4-line-1.d
new file mode 100644
index 00000000000..4f8321e9bfd
--- /dev/null
+++ b/gas/testsuite/gas/i386/dwarf4-line-1.d
@@ -0,0 +1,50 @@
+#as: -gdwarf-4
+#readelf: -wl
+#name: DWARF4 .debug_line 1
+
+Raw dump of debug contents of section \.z?debug_line:
+
+  Offset:                      0x0
+  Length:                      .*
+  DWARF Version:               4
+  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.*\):
+  1	.*/gas/testsuite/gas/i386
+
+ The File Name Table \(offset 0x.*\):
+  Entry	Dir	Time	Size	Name
+  1	0	0	0	foo.c
+  2	0	0	0	foo.h
+
+ Line Number Statements:
+  \[0x.*\]  Extended opcode 2: set Address to 0x0
+  \[0x.*\]  Advance Line by 81 to 82
+  \[0x.*\]  Copy
+  \[0x.*\]  Set File Name to entry 2 in the File Name Table
+  \[0x.*\]  Advance Line by -73 to 9
+  \[0x.*\]  Special opcode 19: advance Address by 1 to 0x1 and Line by 0 to 9
+  \[0x.*\]  Advance PC by 3 to 0x4
+  \[0x.*\]  Extended opcode 1: End of Sequence
+
+
diff --git a/gas/testsuite/gas/i386/dwarf4-line-1.s b/gas/testsuite/gas/i386/dwarf4-line-1.s
new file mode 100644
index 00000000000..e558fdc0507
--- /dev/null
+++ b/gas/testsuite/gas/i386/dwarf4-line-1.s
@@ -0,0 +1,14 @@
+	.file	"foo.c"
+	.text
+bar:
+#APP
+# 82 "foo.h" 1
+	nop
+# 0 "" 2
+#NO_APP
+	ret
+foo:
+	.file 1 "foo.c"
+	nop
+	.file 2 "foo.h"
+	ret
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index 1e761e99d6b..c85ced1c918 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -619,6 +619,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 "dwarf4-line-1"
 	run_dump_test "dwarf5-line-1"
 	run_dump_test "dwarf5-line-2"
 	run_dump_test "dwarf5-line-3"


More information about the Binutils-cvs mailing list