1 diff -rup binutils.orig/gas/dwarf2dbg.c binutils-2.35.2/gas/dwarf2dbg.c
2 --- binutils.orig/gas/dwarf2dbg.c 2021-08-09 17:50:48.324447191 +0100
3 +++ binutils-2.35.2/gas/dwarf2dbg.c 2021-08-09 17:51:03.308359865 +0100
4 @@ -616,7 +616,22 @@ get_directory_table_entry (const char *
7 if (dirs == NULL || dirs[0] == NULL)
10 + const char * pwd = getpwd ();
12 + if (dwarf_level >= 5 && strcmp (dirname, pwd) != 0)
14 + /* In DWARF-5 the 0 entry in the directory table is expected to be
15 + the same as the DW_AT_comp_dir (which is set to the current build
16 + directory). Since we are about to create a directory entry that
17 + is not the same, allocate the current directory first.
18 + FIXME: Alternatively we could generate an error message here. */
19 + (void) get_directory_table_entry (pwd, strlen (pwd), TRUE);
28 @@ -624,8 +639,8 @@ get_directory_table_entry (const char *
29 if (d >= dirs_allocated)
31 unsigned int old = dirs_allocated;
33 - dirs_allocated = d + 32;
34 +#define DIR_TABLE_INCREMENT 32
35 + dirs_allocated = d + DIR_TABLE_INCREMENT;
36 dirs = XRESIZEVEC (char *, dirs, dirs_allocated);
37 memset (dirs + old, 0, (dirs_allocated - old) * sizeof (char *));
39 @@ -820,7 +835,7 @@ allocate_filename_to_slot (const char *
40 dirlen = strlen (dirname);
45 d = get_directory_table_entry (dirname, dirlen, num == 0);
48 @@ -2062,7 +2077,12 @@ out_dir_and_file_list (segT line_seg, in
49 Otherwise use pwd as main file directory. */
50 if (dirs_in_use > 0 && dirs != NULL && dirs[0] != NULL)
51 dir = remap_debug_filename (dirs[0]);
52 - else if (dirs_in_use > 1 && dirs != NULL && dirs[1] != NULL)
53 + else if (dirs_in_use > 1
56 + /* DWARF-5 directory tables expect dir[0] to be the same as
57 + DW_AT_comp_dir, which is the same as pwd. */
59 dir = remap_debug_filename (dirs[1]);
61 dir = remap_debug_filename (getpwd ());
62 @@ -2165,8 +2185,8 @@ out_dir_and_file_list (segT line_seg, in
63 uses slot zero, but that is only set explicitly using a
64 .file 0 directive. If that isn't used, but file 1 is,
65 then use that as main file name. */
66 - if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1)
67 - files[0].filename = files[1].filename;
68 + if (DWARF2_LINE_VERSION >= 5 && i == 0 && files_in_use >= 1 && files[0].filename == NULL)
69 + files[0].filename = files[1].filename;
71 files[i].filename = "";
72 if (DWARF2_LINE_VERSION < 5 || i != 0)
73 Only in binutils-2.35.2/gas/: dwarf2dbg.c.orig
74 Only in binutils-2.35.2/gas/: dwarf2dbg.c.rej
75 diff -rup binutils.orig/gas/testsuite/gas/elf/dwarf-5-file0.d binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-file0.d
76 --- binutils.orig/gas/testsuite/gas/elf/dwarf-5-file0.d 2021-08-09 17:50:48.394446783 +0100
77 +++ binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-file0.d 2021-08-09 17:53:36.567466668 +0100
82 - The Directory Table \(offset 0x.*, lines 3, columns 1\):
83 + The Directory Table \(offset 0x.*, lines 4, columns 1\):
85 - 0 \(indirect line string, offset: 0x.*\): master directory
86 - 1 \(indirect line string, offset: 0x.*\): secondary directory
87 - 2 \(indirect line string, offset: 0x.*\): /tmp
89 + 1 \(indirect line string, offset: 0x.*\): master directory
90 + 2 \(indirect line string, offset: 0x.*\): secondary directory
91 + 3 \(indirect line string, offset: 0x.*\): /tmp
93 The File Name Table \(offset 0x.*, lines 3, columns 3\):
95 - 0 0 0x00000000000000000000000000000000 \(indirect line string, offset: 0x.*\): master source file
96 - 1 1 0x00000000000000000000000000000000 \(indirect line string, offset: 0x.*\): secondary source file
97 - 2 2 0x95828e8bc4f7404dbf7526fb7bd0f192 \(indirect line string, offset: 0x.*\): foo.c
98 + 0 1 0x00000000000000000000000000000000 \(indirect line string, offset: 0x.*\): master source file
99 + 1 2 0x00000000000000000000000000000000 \(indirect line string, offset: 0x.*\): secondary source file
100 + 2 3 0x95828e8bc4f7404dbf7526fb7bd0f192 \(indirect line string, offset: 0x.*\): foo.c
104 Only in binutils-2.35.2/gas/testsuite/gas/elf: dwarf-5-file0.d.orig
105 Only in binutils-2.35.2/gas/testsuite/gas/elf: dwarf-5-file0.d.rej
106 diff -rup binutils.orig/gas/testsuite/gas/elf/elf.exp binutils-2.35.2/gas/testsuite/gas/elf/elf.exp
107 --- binutils.orig/gas/testsuite/gas/elf/elf.exp 2021-08-09 17:50:48.395446778 +0100
108 +++ binutils-2.35.2/gas/testsuite/gas/elf/elf.exp 2021-08-09 17:51:03.308359865 +0100
109 @@ -274,6 +274,7 @@ if { [is_elf_format] } then {
110 run_dump_test "dwarf2-18" $dump_opts
111 run_dump_test "dwarf2-19" $dump_opts
112 run_dump_test "dwarf-5-file0" $dump_opts
113 + run_dump_test "dwarf-5-dir0" $dump_opts
114 run_dump_test "dwarf-4-cu" $dump_opts
115 run_dump_test "dwarf-5-cu" $dump_opts
116 run_dump_test "dwarf-5-nop-for-line-table" $dump_opts
117 Only in binutils-2.35.2/gas/testsuite/gas/elf: elf.exp.orig
118 diff -rup binutils.orig/gas/testsuite/gas/i386/dwarf5-line-1.d binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-1.d
119 --- binutils.orig/gas/testsuite/gas/i386/dwarf5-line-1.d 2021-08-09 17:50:48.363446964 +0100
120 +++ binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-1.d 2021-08-09 17:51:03.308359865 +0100
121 @@ -33,7 +33,7 @@ Raw dump of debug contents of section \.
123 The Directory Table \(offset 0x.*, lines 2, columns 1\):
125 - 0 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
126 + 0 \(indirect line string, offset: 0x.*\): .*/gas/testsuite
127 1 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
129 The File Name Table \(offset 0x.*, lines 2, columns 3\):
130 diff -rup binutils.orig/gas/testsuite/gas/i386/dwarf5-line-2.d binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-2.d
131 --- binutils.orig/gas/testsuite/gas/i386/dwarf5-line-2.d 2021-08-09 17:50:48.365446953 +0100
132 +++ binutils-2.35.2/gas/testsuite/gas/i386/dwarf5-line-2.d 2021-08-09 17:51:03.308359865 +0100
133 @@ -33,7 +33,7 @@ Raw dump of debug contents of section \.
135 The Directory Table \(offset 0x.*, lines 2, columns 1\):
137 - 0 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
138 + 0 \(indirect line string, offset: 0x.*\): .*/gas/testsuite
139 1 \(indirect line string, offset: 0x.*\): .*/gas/testsuite/gas/i386
141 The File Name Table \(offset 0x.*, lines 1, columns 3\):
142 --- /dev/null 2021-08-09 07:51:33.817495606 +0100
143 +++ binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-dir0.s 2021-08-09 17:55:06.745941103 +0100
145 + .section .debug_info,"",%progbits
148 + .4byte .Ldebug_abbrev0
152 + .file 0 "../not-the-build-directory/master-source-file.c"
155 + .octa 0x12345678901234567890123456789012
157 + .file 1 "secondary directory/secondary source file"
161 + .file 2 "/tmp" "foo.c" md5 0x95828e8bc4f7404dbf7526fb7bd0f192
164 --- /dev/null 2021-08-09 07:51:33.817495606 +0100
165 +++ binutils-2.35.2/gas/testsuite/gas/elf/dwarf-5-dir0.d 2021-08-09 17:55:06.745941103 +0100
168 +#name: DWARF5 dir[0]
172 + The Directory Table \(offset 0x.*, lines 4, columns 1\):
174 + 0 \(indirect line string, offset: 0x0\): .*/gas/testsuite
175 + 1 \(indirect line string, offset: 0x.*\): ../not-the-build-directory
176 + 2 \(indirect line string, offset: 0x.*\): secondary directory
177 + 3 \(indirect line string, offset: 0x.*\): /tmp
179 + The File Name Table \(offset 0x.*, lines 3, columns 3\):
181 + 0 1 0x0 \(indirect line string, offset: 0x.*\): master-source-file.c
182 + 1 2 0x0 \(indirect line string, offset: 0x.*\): secondary source file
183 + 2 3 0x95828e8bc4f7404dbf7526fb7bd0f192 \(indirect line string, offset: 0x.*\): foo.c