blob: c8dcd74b9d55a05bd80311f861ffbdc69c5b8939 [file] [log] [blame]
Brad Bishopbec4ebc2022-08-03 09:55:16 -04001From 7cc2df084b7977653a9b59cbc34a9ad500ae619c Mon Sep 17 00:00:00 2001
2From: Richard Biener <rguenther@suse.de>
3Date: Tue, 20 Jul 2021 11:00:33 +0200
4Subject: [PATCH] debug/101473 - apply debug prefix maps before checksumming DIEs
5
6The following makes sure to apply the debug prefix maps to filenames
7before checksumming DIEs to create the global symbol for the CU DIE
8used by LTO to link the late debug to the early debug. This avoids
9binary differences (in said symbol) when compiling with toolchains
10installed under a different path and that compensated with appropriate
11-fdebug-prefix-map options.
12
13The easiest and most scalable way is to record both the unmapped
14and the remapped filename in the dwarf_file_data so the remapping
15process takes place at a single point and only once (otherwise it
16creates GC garbage at each point doing that).
17
182021-07-20 Richard Biener <rguenther@suse.de>
19
20 PR debug/101473
21 * dwarf2out.h (dwarf_file_data): Add key member.
22 * dwarf2out.c (dwarf_file_hasher::equal): Compare key.
23 (dwarf_file_hasher::hash): Hash key.
24 (lookup_filename): Remap the filename and store it in the
25 filename member of dwarf_file_data when creating a new
26 dwarf_file_data.
27 (file_name_acquire): Do not remap the filename again.
28 (maybe_emit_file): Likewise.
29
30[YOCTO #14481]
31
32Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=7cc2df084b7977653a9b59cbc34a9ad500ae619c]
33
34The upstream patch was modified to compensate for the definition of
35"struct dwarf_file_data" being in dwarf2out.c rather than dwarf2out.h in
36this version of gcc.
37
38Signed-off-by: Tony Battersby <tonyb@cybernetics.com>
39---
40diff -urpN a/gcc/dwarf2out.c b/gcc/dwarf2out.c
41--- a/gcc/dwarf2out.c 2021-04-27 06:00:13.000000000 -0400
42+++ b/gcc/dwarf2out.c 2021-07-23 16:40:06.141886167 -0400
43@@ -1283,6 +1283,7 @@ dwarf2out_switch_text_section (void)
44
45 /* Data about a single source file. */
46 struct GTY((for_user)) dwarf_file_data {
47+ const char * key;
48 const char * filename;
49 int emitted_number;
50 };
51@@ -12334,7 +12335,7 @@ file_name_acquire (dwarf_file_data **slo
52
53 fi = fnad->files + fnad->used_files++;
54
55- f = remap_debug_filename (d->filename);
56+ f = d->filename;
57
58 /* Skip all leading "./". */
59 while (f[0] == '.' && IS_DIR_SEPARATOR (f[1]))
60@@ -27231,13 +27232,13 @@ dwarf2out_ignore_block (const_tree block
61 bool
62 dwarf_file_hasher::equal (dwarf_file_data *p1, const char *p2)
63 {
64- return filename_cmp (p1->filename, p2) == 0;
65+ return filename_cmp (p1->key, p2) == 0;
66 }
67
68 hashval_t
69 dwarf_file_hasher::hash (dwarf_file_data *p)
70 {
71- return htab_hash_string (p->filename);
72+ return htab_hash_string (p->key);
73 }
74
75 /* Lookup FILE_NAME (in the list of filenames that we know about here in
76@@ -27267,7 +27268,8 @@ lookup_filename (const char *file_name)
77 return *slot;
78
79 created = ggc_alloc<dwarf_file_data> ();
80- created->filename = file_name;
81+ created->key = file_name;
82+ created->filename = remap_debug_filename (file_name);
83 created->emitted_number = 0;
84 *slot = created;
85 return created;
86@@ -27293,8 +27295,7 @@ maybe_emit_file (struct dwarf_file_data
87 if (output_asm_line_debug_info ())
88 {
89 fprintf (asm_out_file, "\t.file %u ", fd->emitted_number);
90- output_quoted_string (asm_out_file,
91- remap_debug_filename (fd->filename));
92+ output_quoted_string (asm_out_file, fd->filename);
93 fputc ('\n', asm_out_file);
94 }
95 }