···
1
-
From b10785c1be469319a09b10bc69db21159b0599ee Mon Sep 17 00:00:00 2001
1
+
From 30908556fece379ffd7c0da96c774d8bd297e459 Mon Sep 17 00:00:00 2001
From: Sergei Trofimovich <siarheit@google.com>
Date: Fri, 22 Sep 2023 22:41:49 +0100
Subject: [PATCH] gcc/file-prefix-map.cc: always mangle __FILE__ into invalid
···
For this reason we want to remove the occurrences of hashes in the
expansion of `__FILE__`. `nuke-references` does it by replacing hashes
17
-
by `eeeeee...` but those paths are also used for debug symbols. It is
18
-
handy to be able to invert the transformation to go back to the original
19
-
store path for debuginfod servers. The chosen solution is to make the
17
+
by `eeeeee...`. It is handy to be able to invert the transformation to
18
+
go back to the original store path. The chosen solution is to make the
- it does not trigger runtime references (except for all digit hashes,
which are unlikely enough)
···
45
+
To reverse the effect of the mangle use new `NIX_GCC_DONT_MANGLE_PREFIX_MAP`
46
+
environment variable. It should not normally be needed.
--- a/gcc/file-prefix-map.cc
+++ b/gcc/file-prefix-map.cc
47
-
@@ -60,6 +60,9 @@ add_prefix_map (file_prefix_map *&maps, const char *arg, const char *opt)
51
-
+/* Forward declaration for a $NIX_STORE remap hack below. */
52
-
+static file_prefix_map *macro_prefix_maps; /* -fmacro-prefix-map */
54
-
/* Perform user-specified mapping of filename prefixes. Return the
55
-
GC-allocated new name corresponding to FILENAME or FILENAME if no
49
+
@@ -65,7 +65,7 @@ add_prefix_map (file_prefix_map *&maps, const char *arg, const char *opt)
remapping was performed. */
57
-
@@ -76,7 +79,31 @@ remap_filename (file_prefix_map *maps, const char *filename)
53
+
-remap_filename (file_prefix_map *maps, const char *filename)
54
+
+remap_filename (file_prefix_map *maps, const char *filename, bool mangle_nix_store = false)
56
+
file_prefix_map *map;
58
+
@@ -76,7 +76,31 @@ remap_filename (file_prefix_map *maps, const char *filename)
if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
63
-
+ if (maps == macro_prefix_maps)
64
+
+ if (mangle_nix_store && getenv("NIX_GCC_DONT_MANGLE_PREFIX_MAP") == NULL)
+ /* Remap the 32 characters after $NIX_STORE/ to uppercase
···
+ s = (char *) ggc_alloc_atomic (name_len + 1);
+ memcpy(s, name, name_len + 1);
79
-
+ for (int i = nix_store_len + 1; i < nix_store_len + 1 + 32; i++) {
80
+
+ for (size_t i = nix_store_len + 1; i < nix_store_len + 1 + 32; i++) {
···
name = filename + map->old_len;
name_len = strlen (name) + 1;
90
-
@@ -90,7 +117,6 @@ remap_filename (file_prefix_map *maps, const char *filename)
91
-
ignore it in DW_AT_producer (dwarf2out.cc). */
93
-
/* Linked lists of file_prefix_map structures. */
94
-
-static file_prefix_map *macro_prefix_maps; /* -fmacro-prefix-map */
95
-
static file_prefix_map *debug_prefix_maps; /* -fdebug-prefix-map */
96
-
static file_prefix_map *profile_prefix_maps; /* -fprofile-prefix-map */
91
+
@@ -129,7 +153,7 @@ add_profile_prefix_map (const char *arg)
93
+
remap_macro_filename (const char *filename)
95
+
- return remap_filename (macro_prefix_maps, filename);
96
+
+ return remap_filename (macro_prefix_maps, filename, true);
99
+
/* Remap using -fdebug-prefix-map. Return the GC-allocated new name