Blame SOURCES/binutils-dwarf-5-dir0.patch

2e9b04
diff -rup binutils.orig/gas/dwarf2dbg.c binutils-2.35.2/gas/dwarf2dbg.c
2e9b04
--- binutils.orig/gas/dwarf2dbg.c	2021-08-09 17:50:48.324447191 +0100
2e9b04
+++ binutils-2.35.2/gas/dwarf2dbg.c	2021-08-09 17:51:03.308359865 +0100
2e9b04
@@ -616,7 +616,22 @@ get_directory_table_entry (const char *
2e9b04
   if (can_use_zero)
2e9b04
     {
2e9b04
       if (dirs == NULL || dirs[0] == NULL)
2e9b04
-	d = 0;
2e9b04
+	{
2e9b04
+	  const char * pwd = getpwd ();
2e9b04
+
2e9b04
+	  if (dwarf_level >= 5 && strcmp (dirname, pwd) != 0)
2e9b04
+	    {
2e9b04
+	      /* In DWARF-5 the 0 entry in the directory table is expected to be
2e9b04
+		 the same as the DW_AT_comp_dir (which is set to the current build
2e9b04
+		 directory).  Since we are about to create a directory entry that
2e9b04
+		 is not the same, allocate the current directory first.
2e9b04
+		 FIXME: Alternatively we could generate an error message here.  */
2e9b04
+	      (void) get_directory_table_entry (pwd, strlen (pwd), TRUE);
2e9b04
+	      d = 1;
2e9b04
+	    }
2e9b04
+	  else
2e9b04
+	    d = 0;
2e9b04
+	}
2e9b04
     }
2e9b04
   else if (d == 0)
2e9b04
     d = 1;
2e9b04
@@ -624,8 +639,8 @@ get_directory_table_entry (const char *
2e9b04
   if (d >= dirs_allocated)
2e9b04
     {
2e9b04
       unsigned int old = dirs_allocated;
2e9b04
-
2e9b04
-      dirs_allocated = d + 32;
2e9b04
+#define DIR_TABLE_INCREMENT 32
2e9b04
+      dirs_allocated = d + DIR_TABLE_INCREMENT;
2e9b04
       dirs = XRESIZEVEC (char *, dirs, dirs_allocated);
2e9b04
       memset (dirs + old, 0, (dirs_allocated - old) * sizeof (char *));
2e9b04
     }
2e9b04
@@ -820,7 +835,7 @@ allocate_filename_to_slot (const char *
2e9b04
       dirlen = strlen (dirname);
2e9b04
       file = filename;
2e9b04
     }
2e9b04
-  
2e9b04
+
2e9b04
   d = get_directory_table_entry (dirname, dirlen, num == 0);
2e9b04
   i = num;
2e9b04
 
2e9b04
@@ -2062,7 +2077,12 @@ out_dir_and_file_list (segT line_seg, in
2e9b04
 	 Otherwise use pwd as main file directory.  */
2e9b04
       if (dirs_in_use > 0 && dirs != NULL && dirs[0] != NULL)
2e9b04
 	dir = remap_debug_filename (dirs[0]);
2e9b04
-      else if (dirs_in_use > 1 && dirs != NULL && dirs[1] != NULL)
2e9b04
+      else if (dirs_in_use > 1
2e9b04
+	       && dirs != NULL
2e9b04
+	       && dirs[1] != NULL
2e9b04
+	       /* DWARF-5 directory tables expect dir[0] to be the same as
2e9b04
+		  DW_AT_comp_dir, which is the same as pwd.  */
2e9b04
+	       && dwarf_level < 5)
2e9b04
 	dir = remap_debug_filename (dirs[1]);
2e9b04
       else
2e9b04
 	dir = remap_debug_filename (getpwd ());
2e9b04
@@ -2165,8 +2185,8 @@ out_dir_and_file_list (segT line_seg, in
2e9b04
 	     uses slot zero, but that is only set explicitly using a
2e9b04
 	     .file 0 directive.  If that isn't used, but file 1 is,
2e9b04
 	     then use that as main file name.  */
2e9b04
-	  if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1)
2e9b04
-	      files[0].filename = files[1].filename;
2e9b04
+	  if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1 && files[0].filename == NULL)
2e9b04
+	    files[0].filename = files[1].filename;
2e9b04
 	  else
2e9b04
 	    files[i].filename = "";
2e9b04
 	  if (DWARF2_LINE_VERSION < 5 || i != 0)
2e9b04
Only in binutils-2.35.2/gas/: dwarf2dbg.c.orig
2e9b04
Only in binutils-2.35.2/gas/: dwarf2dbg.c.rej
2e9b04
diff -rup binutils.orig/gas/testsuite/gas/elf/dwarf-5-file0.d binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-file0.d
2e9b04
--- binutils.orig/gas/testsuite/gas/elf/dwarf-5-file0.d	2021-08-09 17:50:48.394446783 +0100
2e9b04
+++ binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-file0.d	2021-08-09 17:53:36.567466668 +0100
2e9b04
@@ -3,17 +3,18 @@
2e9b04
 #readelf: -wl
2e9b04
 
2e9b04
 #...
2e9b04
- The Directory Table \(offset 0x.*, lines 3, columns 1\):
2e9b04
+ The Directory Table \(offset 0x.*, lines 4, columns 1\):
2e9b04
   Entry	Name
2e9b04
-  0	\(indirect line string, offset: 0x.*\): master directory
2e9b04
-  1	\(indirect line string, offset: 0x.*\): secondary directory
2e9b04
-  2	\(indirect line string, offset: 0x.*\): /tmp
2e9b04
+#...
2e9b04
+  1	\(indirect line string, offset: 0x.*\): master directory
2e9b04
+  2	\(indirect line string, offset: 0x.*\): secondary directory
2e9b04
+  3	\(indirect line string, offset: 0x.*\): /tmp
2e9b04
 
2e9b04
  The File Name Table \(offset 0x.*, lines 3, columns 3\):
2e9b04
   Entry	Dir	MD5				Name
2e9b04
-  0	0 0x00000000000000000000000000000000	\(indirect line string, offset: 0x.*\): master source file
2e9b04
-  1	1 0x00000000000000000000000000000000	\(indirect line string, offset: 0x.*\): secondary source file
2e9b04
-  2	2 0x95828e8bc4f7404dbf7526fb7bd0f192	\(indirect line string, offset: 0x.*\): foo.c
2e9b04
+  0	1 0x00000000000000000000000000000000	\(indirect line string, offset: 0x.*\): master source file
2e9b04
+  1	2 0x00000000000000000000000000000000	\(indirect line string, offset: 0x.*\): secondary source file
2e9b04
+  2	3 0x95828e8bc4f7404dbf7526fb7bd0f192	\(indirect line string, offset: 0x.*\): foo.c
2e9b04
 #pass
2e9b04
 
2e9b04
 
2e9b04
Only in binutils-2.35.2/gas/testsuite/gas/elf: dwarf-5-file0.d.orig
2e9b04
Only in binutils-2.35.2/gas/testsuite/gas/elf: dwarf-5-file0.d.rej
2e9b04
diff -rup binutils.orig/gas/testsuite/gas/elf/elf.exp binutils-2.35.2/gas/testsuite/gas/elf/elf.exp
2e9b04
--- binutils.orig/gas/testsuite/gas/elf/elf.exp	2021-08-09 17:50:48.395446778 +0100
2e9b04
+++ binutils-2.35.2/gas/testsuite/gas/elf/elf.exp	2021-08-09 17:51:03.308359865 +0100
2e9b04
@@ -274,6 +274,7 @@ if { [is_elf_format] } then {
2e9b04
     run_dump_test "dwarf2-18" $dump_opts
2e9b04
     run_dump_test "dwarf2-19" $dump_opts
2e9b04
     run_dump_test "dwarf-5-file0" $dump_opts
2e9b04
+    run_dump_test "dwarf-5-dir0" $dump_opts
2e9b04
     run_dump_test "dwarf-4-cu" $dump_opts
2e9b04
     run_dump_test "dwarf-5-cu" $dump_opts
2e9b04
     run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
2e9b04
Only in binutils-2.35.2/gas/testsuite/gas/elf: elf.exp.orig
2e9b04
diff -rup binutils.orig/gas/testsuite/gas/i386/dwarf5-line-1.d binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-1.d
2e9b04
--- binutils.orig/gas/testsuite/gas/i386/dwarf5-line-1.d	2021-08-09 17:50:48.363446964 +0100
2e9b04
+++ binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-1.d	2021-08-09 17:51:03.308359865 +0100
2e9b04
@@ -33,7 +33,7 @@ Raw dump of debug contents of section \.
2e9b04
 
2e9b04
  The Directory Table \(offset 0x.*, lines 2, columns 1\):
2e9b04
   Entry	Name
2e9b04
-  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
2e9b04
+  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite
2e9b04
   1	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
2e9b04
 
2e9b04
  The File Name Table \(offset 0x.*, lines 2, columns 3\):
2e9b04
diff -rup binutils.orig/gas/testsuite/gas/i386/dwarf5-line-2.d binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-2.d
2e9b04
--- binutils.orig/gas/testsuite/gas/i386/dwarf5-line-2.d	2021-08-09 17:50:48.365446953 +0100
2e9b04
+++ binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-2.d	2021-08-09 17:51:03.308359865 +0100
2e9b04
@@ -33,7 +33,7 @@ Raw dump of debug contents of section \.
2e9b04
 
2e9b04
  The Directory Table \(offset 0x.*, lines 2, columns 1\):
2e9b04
   Entry	Name
2e9b04
-  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
2e9b04
+  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite
2e9b04
   1	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
2e9b04
 
2e9b04
  The File Name Table \(offset 0x.*, lines 1, columns 3\):
2e9b04
--- /dev/null	2021-08-09 07:51:33.817495606 +0100
2e9b04
+++ binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-dir0.s	2021-08-09 17:55:06.745941103 +0100
2e9b04
@@ -0,0 +1,19 @@
2e9b04
+	.section	.debug_info,"",%progbits
2e9b04
+	.4byte	0x8a
2e9b04
+	.2byte  0x2
2e9b04
+	.4byte	.Ldebug_abbrev0
2e9b04
+	.byte	0x4
2e9b04
+	.uleb128 0x1
2e9b04
+
2e9b04
+	.file 0 "../not-the-build-directory/master-source-file.c"
2e9b04
+	.line 1
2e9b04
+	.text
2e9b04
+	.octa 0x12345678901234567890123456789012
2e9b04
+
2e9b04
+	.file 1 "secondary directory/secondary source file"
2e9b04
+	.line 2
2e9b04
+	.word 2
2e9b04
+
2e9b04
+	.file 2 "/tmp" "foo.c" md5 0x95828e8bc4f7404dbf7526fb7bd0f192
2e9b04
+	.line 5
2e9b04
+	.word 6
2e9b04
--- /dev/null	2021-08-09 07:51:33.817495606 +0100
2e9b04
+++ binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-dir0.d	2021-08-09 17:55:06.745941103 +0100
2e9b04
@@ -0,0 +1,20 @@
2e9b04
+#as: --gdwarf-5
2e9b04
+#name: DWARF5 dir[0]
2e9b04
+#readelf: -wl
2e9b04
+
2e9b04
+#...
2e9b04
+ The Directory Table \(offset 0x.*, lines 4, columns 1\):
2e9b04
+  Entry	Name
2e9b04
+  0	\(indirect line string, offset: 0x0\): .*/gas/testsuite
2e9b04
+  1	\(indirect line string, offset: 0x.*\): ../not-the-build-directory
2e9b04
+  2	\(indirect line string, offset: 0x.*\): secondary directory
2e9b04
+  3	\(indirect line string, offset: 0x.*\): /tmp
2e9b04
+
2e9b04
+ The File Name Table \(offset 0x.*, lines 3, columns 3\):
2e9b04
+  Entry	Dir	MD5				Name
2e9b04
+  0	1 0x0+	\(indirect line string, offset: 0x.*\): master-source-file.c
2e9b04
+  1	2 0x0+	\(indirect line string, offset: 0x.*\): secondary source file
2e9b04
+  2	3 0x95828e8bc4f7404dbf7526fb7bd0f192	\(indirect line string, offset: 0x.*\): foo.c
2e9b04
+#pass
2e9b04
+
2e9b04
+