Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 1 | From 49008eeedc97014f44e12afe179d3785e4438372 Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Richard Biener <rguenther@suse.de> |
| 3 | Date: Tue, 20 Jul 2021 11:00:33 +0200 |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 4 | Subject: [PATCH] debug/101473 - apply debug prefix maps before checksumming |
| 5 | DIEs |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 6 | |
| 7 | The following makes sure to apply the debug prefix maps to filenames |
| 8 | before checksumming DIEs to create the global symbol for the CU DIE |
| 9 | used by LTO to link the late debug to the early debug. This avoids |
| 10 | binary differences (in said symbol) when compiling with toolchains |
| 11 | installed under a different path and that compensated with appropriate |
| 12 | -fdebug-prefix-map options. |
| 13 | |
| 14 | The easiest and most scalable way is to record both the unmapped |
| 15 | and the remapped filename in the dwarf_file_data so the remapping |
| 16 | process takes place at a single point and only once (otherwise it |
| 17 | creates GC garbage at each point doing that). |
| 18 | |
| 19 | 2021-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 | |
| 33 | Upstream-Status: Backport [https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=7cc2df084b7977653a9b59cbc34a9ad500ae619c] |
| 34 | |
| 35 | The upstream patch was modified to compensate for the definition of |
| 36 | "struct dwarf_file_data" being in dwarf2out.c rather than dwarf2out.h in |
| 37 | this version of gcc. |
| 38 | |
| 39 | Signed-off-by: Tony Battersby <tonyb@cybernetics.com> |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 40 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 41 | --- |
Patrick Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 42 | gcc/dwarf2out.c | 13 +++++++------ |
| 43 | 1 file changed, 7 insertions(+), 6 deletions(-) |
| 44 | |
| 45 | diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c |
| 46 | index e5d3ce4966d..41ac3008507 100644 |
| 47 | --- a/gcc/dwarf2out.c |
| 48 | +++ b/gcc/dwarf2out.c |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 49 | @@ -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 Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 57 | @@ -12335,7 +12336,7 @@ file_name_acquire (dwarf_file_data **slot, file_name_acquire_data *fnad) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 58 | |
| 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 Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 66 | @@ -27259,13 +27260,13 @@ dwarf2out_ignore_block (const_tree block) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 67 | 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 Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 82 | @@ -27295,7 +27296,8 @@ lookup_filename (const char *file_name) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 83 | 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 Williams | 2194f50 | 2022-10-16 14:26:09 -0500 | [diff] [blame^] | 92 | @@ -27321,8 +27323,7 @@ maybe_emit_file (struct dwarf_file_data * fd) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 93 | 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 | } |