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