diff options
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/gcc/patches/12/mangle-NIX_STORE-in-__FILE__.patch')
-rw-r--r-- | nixpkgs/pkgs/development/compilers/gcc/patches/12/mangle-NIX_STORE-in-__FILE__.patch | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/nixpkgs/pkgs/development/compilers/gcc/patches/12/mangle-NIX_STORE-in-__FILE__.patch b/nixpkgs/pkgs/development/compilers/gcc/patches/12/mangle-NIX_STORE-in-__FILE__.patch index 4e6c392ce76e..51078925eeb8 100644 --- a/nixpkgs/pkgs/development/compilers/gcc/patches/12/mangle-NIX_STORE-in-__FILE__.patch +++ b/nixpkgs/pkgs/development/compilers/gcc/patches/12/mangle-NIX_STORE-in-__FILE__.patch @@ -12,9 +12,20 @@ inputs to be retained in runtime closure. Typical examples are `nix` -> `nlohmann_json` and `pipewire` -> `lttng-ust.dev`. +For this reason we want to remove the occurrences of hashes in the +expansion of `__FILE__`. `nuke-references` does it by replacing hashes +by `eeeeee...` but those paths are also used for debug symbols. It is +handy to be able to invert the transformation to go back to the original +store path for debuginfod servers. The chosen solution is to make the +hash uppercase: +- it does not trigger runtime references (except for all digit hashes, + which are unlikely enough) +- it visually looks like a bogus store path +- it is easy to find the original store path if required + Ideally we would like to use `-fmacro-prefix-map=` feature of `gcc` as: - -fmacro-prefix-map=/nix/store/$hash1-nlohmann-json-ver=/nix/store/eeee.eee-nlohmann-json-ver + -fmacro-prefix-map=/nix/store/$hash1-nlohmann-json-ver=/nix/store/$HASH1-nlohmann-json-ver -fmacro-prefix-map=/nix/... In practice it quickly exhausts argument length limit due to `gcc` @@ -25,9 +36,9 @@ is present in the environment. Tested as: - $ printf "# 0 \"/nix/store/01234567890123456789012345678901-pppppp-vvvvvvv\" \nconst char * f(void) { return __FILE__; }" | NIX_STORE=/nix/store ./gcc/xgcc -Bgcc -x c - -S -o - + $ printf "# 0 \"/nix/store/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-pppppp-vvvvvvv\" \nconst char * f(void) { return __FILE__; }" | NIX_STORE=/nix/store ./gcc/xgcc -Bgcc -x c - -S -o - ... - .string "/nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-pppppp-vvvvvvv" + .string "/nix/store/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA-pppppp-vvvvvvv" ... Mangled successfully. @@ -43,7 +54,7 @@ Mangled successfully. /* Perform user-specified mapping of filename prefixes. Return the GC-allocated new name corresponding to FILENAME or FILENAME if no remapping was performed. */ -@@ -76,7 +79,30 @@ remap_filename (file_prefix_map *maps, const char *filename) +@@ -76,7 +79,31 @@ remap_filename (file_prefix_map *maps, const char *filename) if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) break; if (!map) @@ -51,8 +62,7 @@ Mangled successfully. + { + if (maps == macro_prefix_maps) + { -+ /* Remap all fo $NIX_STORE/.{32} paths to -+ * equivalent $NIX_STORE/e{32}. ++ /* Remap the 32 characters after $NIX_STORE/ to uppercase + * + * That way we avoid argument parameters explosion + * and still avoid embedding headers into runtime closure: @@ -66,7 +76,9 @@ Mangled successfully. + { + s = (char *) ggc_alloc_atomic (name_len + 1); + memcpy(s, name, name_len + 1); -+ memset(s + nix_store_len + 1, 'e', 32); ++ for (int i = nix_store_len + 1; i < nix_store_len + 1 + 32; i++) { ++ s[i] = TOUPPER(s[i]); ++ } + return s; + } + } @@ -75,7 +87,7 @@ Mangled successfully. name = filename + map->old_len; name_len = strlen (name) + 1; -@@ -90,7 +116,6 @@ remap_filename (file_prefix_map *maps, const char *filename) +@@ -90,7 +117,6 @@ remap_filename (file_prefix_map *maps, const char *filename) ignore it in DW_AT_producer (dwarf2out.cc). */ /* Linked lists of file_prefix_map structures. */ |