summaryrefslogtreecommitdiffstats
path: root/source/d/binutils/patches/binutils-dwarf-5-dir0.patch
blob: 24233cce8b0b2bee8a6076828b28895e06fec176 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
diff -rup binutils.orig/gas/dwarf2dbg.c binutils-2.37/gas/dwarf2dbg.c
--- binutils.orig/gas/dwarf2dbg.c	2021-08-09 17:28:17.743318315 +0100
+++ binutils-2.37/gas/dwarf2dbg.c	2021-08-09 17:28:27.043264112 +0100
@@ -620,7 +620,22 @@ get_directory_table_entry (const char *d
   if (can_use_zero)
     {
       if (dirs == NULL || dirs[0] == NULL)
-	d = 0;
+	{
+	  const char * pwd = getpwd ();
+
+	  if (dwarf_level >= 5 && strcmp (dirname, pwd) != 0)
+	    {
+	      /* In DWARF-5 the 0 entry in the directory table is expected to be
+		 the same as the DW_AT_comp_dir (which is set to the current build
+		 directory).  Since we are about to create a directory entry that
+		 is not the same, allocate the current directory first.
+		 FIXME: Alternatively we could generate an error message here.  */
+	      (void) get_directory_table_entry (pwd, strlen (pwd), true);
+	      d = 1;
+	    }
+	  else
+	    d = 0;
+	}
     }
   else if (d == 0)
     d = 1;
@@ -628,8 +643,8 @@ get_directory_table_entry (const char *d
   if (d >= dirs_allocated)
     {
       unsigned int old = dirs_allocated;
-
-      dirs_allocated = d + 32;
+#define DIR_TABLE_INCREMENT 32
+      dirs_allocated = d + DIR_TABLE_INCREMENT;
       dirs = XRESIZEVEC (char *, dirs, dirs_allocated);
       memset (dirs + old, 0, (dirs_allocated - old) * sizeof (char *));
     }
@@ -779,7 +794,7 @@ allocate_filename_to_slot (const char *d
 	    {
 	      if (dirs == NULL)
 		{
-		  dirs_allocated = files[num].dir + 32;
+		  dirs_allocated = files[num].dir + DIR_TABLE_INCREMENT;
 		  dirs = XCNEWVEC (char *, dirs_allocated);
 		}
 	      
@@ -807,7 +822,7 @@ allocate_filename_to_slot (const char *d
 		{
 		  if (dirs == NULL)
 		    {
-		      dirs_allocated = files[num].dir + 32;
+		      dirs_allocated = files[num].dir + DIR_TABLE_INCREMENT;
 		      dirs = XCNEWVEC (char *, dirs_allocated);
 		    }
 
@@ -840,7 +855,7 @@ allocate_filename_to_slot (const char *d
       dirlen = strlen (dirname);
       file = filename;
     }
-  
+
   d = get_directory_table_entry (dirname, dirlen, num == 0);
   i = num;
 
@@ -2082,7 +2097,12 @@ out_dir_and_file_list (segT line_seg, in
 	 Otherwise use pwd as main file directory.  */
       if (dirs_in_use > 0 && dirs != NULL && dirs[0] != NULL)
 	dir = remap_debug_filename (dirs[0]);
-      else if (dirs_in_use > 1 && dirs != NULL && dirs[1] != NULL)
+      else if (dirs_in_use > 1
+	       && dirs != NULL
+	       && dirs[1] != NULL
+	       /* DWARF-5 directory tables expect dir[0] to be the same as
+		  DW_AT_comp_dir, which is the same as pwd.  */
+	       && dwarf_level < 5)
 	dir = remap_debug_filename (dirs[1]);
       else
 	dir = remap_debug_filename (getpwd ());
@@ -2185,8 +2205,8 @@ out_dir_and_file_list (segT line_seg, in
 	     uses slot zero, but that is only set explicitly using a
 	     .file 0 directive.  If that isn't used, but file 1 is,
 	     then use that as main file name.  */
-	  if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1)
-	      files[0].filename = files[1].filename;
+	  if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1 && files[0].filename == NULL)
+	    files[0].filename = files[1].filename;
 	  else
 	    files[i].filename = "";
 	  if (DWARF2_LINE_VERSION < 5 || i != 0)
Only in binutils-2.37/gas/testsuite/gas/elf: dwarf-5-dir0.d
Only in binutils-2.37/gas/testsuite/gas/elf: dwarf-5-dir0.s
diff -rup binutils.orig/gas/testsuite/gas/elf/dwarf-5-file0.d binutils-2.37/gas/testsuite/gas/elf/dwarf-5-file0.d
--- binutils.orig/gas/testsuite/gas/elf/dwarf-5-file0.d	2021-08-09 17:28:17.817317884 +0100
+++ binutils-2.37/gas/testsuite/gas/elf/dwarf-5-file0.d	2021-08-09 17:28:27.043264112 +0100
@@ -3,17 +3,18 @@
 #readelf: -wl
 
 #...
- The Directory Table \(offset 0x.*, lines 3, columns 1\):
+ The Directory Table \(offset 0x.*, lines 4, columns 1\):
   Entry	Name
-  0	\(indirect line string, offset: 0x.*\): master directory
-  1	\(indirect line string, offset: 0x.*\): secondary directory
-  2	\(indirect line string, offset: 0x.*\): /tmp
+#...
+  1	\(indirect line string, offset: 0x.*\): master directory
+  2	\(indirect line string, offset: 0x.*\): secondary directory
+  3	\(indirect line string, offset: 0x.*\): /tmp
 
  The File Name Table \(offset 0x.*, lines 3, columns 3\):
   Entry	Dir	MD5				Name
-  0	0 0x0	\(indirect line string, offset: 0x.*\): master source file
-  1	1 0x0	\(indirect line string, offset: 0x.*\): secondary source file
-  2	2 0x95828e8bc4f7404dbf7526fb7bd0f192	\(indirect line string, offset: 0x.*\): foo.c
+  0	1 0x0	\(indirect line string, offset: 0x.*\): master source file
+  1	2 0x0	\(indirect line string, offset: 0x.*\): secondary source file
+  2	3 0x95828e8bc4f7404dbf7526fb7bd0f192	\(indirect line string, offset: 0x.*\): foo.c
 #pass
 
 
diff -rup binutils.orig/gas/testsuite/gas/elf/elf.exp binutils-2.37/gas/testsuite/gas/elf/elf.exp
--- binutils.orig/gas/testsuite/gas/elf/elf.exp	2021-08-09 17:28:17.817317884 +0100
+++ binutils-2.37/gas/testsuite/gas/elf/elf.exp	2021-08-09 17:28:27.044264106 +0100
@@ -297,6 +297,7 @@ if { [is_elf_format] } then {
     run_dump_test "dwarf2-19" $dump_opts
     run_dump_test "dwarf2-20" $dump_opts
     run_dump_test "dwarf-5-file0" $dump_opts
+    run_dump_test "dwarf-5-dir0" $dump_opts
     run_dump_test "dwarf-4-cu" $dump_opts
     run_dump_test "dwarf-5-cu" $dump_opts
     run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
diff -rup binutils.orig/gas/testsuite/gas/i386/dwarf5-line-1.d binutils-2.37/gas/testsuite/gas/i386/dwarf5-line-1.d
--- binutils.orig/gas/testsuite/gas/i386/dwarf5-line-1.d	2021-08-09 17:28:17.782318088 +0100
+++ binutils-2.37/gas/testsuite/gas/i386/dwarf5-line-1.d	2021-08-09 17:28:27.044264106 +0100
@@ -33,7 +33,7 @@ Raw dump of debug contents of section \.
 
  The Directory Table \(offset 0x.*, lines 2, columns 1\):
   Entry	Name
-  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
+  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite
   1	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
 
  The File Name Table \(offset 0x.*, lines 2, columns 3\):
diff -rup binutils.orig/gas/testsuite/gas/i386/dwarf5-line-2.d binutils-2.37/gas/testsuite/gas/i386/dwarf5-line-2.d
--- binutils.orig/gas/testsuite/gas/i386/dwarf5-line-2.d	2021-08-09 17:28:17.785318070 +0100
+++ binutils-2.37/gas/testsuite/gas/i386/dwarf5-line-2.d	2021-08-09 17:28:27.044264106 +0100
@@ -33,7 +33,7 @@ Raw dump of debug contents of section \.
 
  The Directory Table \(offset 0x.*, lines 2, columns 1\):
   Entry	Name
-  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
+  0	\(indirect line string, offset: 0x.*\): .*/gas/testsuite
   1	\(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
 
  The File Name Table \(offset 0x.*, lines 1, columns 3\):
--- /dev/null	2021-08-09 07:51:33.817495606 +0100
+++ binutils-2.37/gas/testsuite/gas/elf/dwarf-5-dir0.s	2021-08-09 17:28:54.787102415 +0100
@@ -0,0 +1,19 @@
+	.section	.debug_info,"",%progbits
+	.4byte	0x8a
+	.2byte  0x2
+	.4byte	.Ldebug_abbrev0
+	.byte	0x4
+	.uleb128 0x1
+
+	.file 0 "../not-the-build-directory/master-source-file.c"
+	.line 1
+	.text
+	.octa 0x12345678901234567890123456789012
+
+	.file 1 "secondary directory/secondary source file"
+	.line 2
+	.word 2
+
+	.file 2 "/tmp" "foo.c" md5 0x95828e8bc4f7404dbf7526fb7bd0f192
+	.line 5
+	.word 6
--- /dev/null	2021-08-09 07:51:33.817495606 +0100
+++ binutils-2.37/gas/testsuite/gas/elf/dwarf-5-dir0.d	2021-08-09 17:28:54.787102415 +0100
@@ -0,0 +1,20 @@
+#as: --gdwarf-5
+#name: DWARF5 dir[0]
+#readelf: -wl
+
+#...
+ The Directory Table \(offset 0x.*, lines 4, columns 1\):
+  Entry	Name
+  0	\(indirect line string, offset: 0x0\): .*/gas/testsuite
+  1	\(indirect line string, offset: 0x.*\): ../not-the-build-directory
+  2	\(indirect line string, offset: 0x.*\): secondary directory
+  3	\(indirect line string, offset: 0x.*\): /tmp
+
+ The File Name Table \(offset 0x.*, lines 3, columns 3\):
+  Entry	Dir	MD5				Name
+  0	1 0x0	\(indirect line string, offset: 0x.*\): master-source-file.c
+  1	2 0x0	\(indirect line string, offset: 0x.*\): secondary source file
+  2	3 0x95828e8bc4f7404dbf7526fb7bd0f192	\(indirect line string, offset: 0x.*\): foo.c
+#pass
+
+