Hi, I'm wondering if we'd be able to improve path handling in the -f*- prefix-map compiler options to cover relative paths?
Currently it works well for absolute paths but if a file uses a relative path or a path with a symlink in, or a non-absolute path, it will miss those cases. For relative paths in particular it is problematic as you can't easily construct a compiler commandline that would cover all relative path options. At first glance this is relatively straight forward, for example: Index: gcc-12.1.0/gcc/file-prefix-map.cc =================================================================== --- gcc-12.1.0.orig/gcc/file-prefix-map.cc +++ gcc-12.1.0/gcc/file-prefix-map.cc @@ -70,19 +70,25 @@ remap_filename (file_prefix_map *maps, c file_prefix_map *map; char *s; const char *name; + char *realname; size_t name_len; + realname = lrealpath (filename); + for (map = maps; map; map = map->next) - if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) + if (filename_ncmp (realname, map->old_prefix, map->old_len) == 0) break; - if (!map) + if (!map) { + free (realname); return filename; - name = filename + map->old_len; + } + name = realname + map->old_len; name_len = strlen (name) + 1; s = (char *) ggc_alloc_atomic (name_len + map->new_len); memcpy (s, map->new_prefix, map->new_len); memcpy (s + map->new_len, name, name_len); + free (realname); return s; } which address a realpath() call into the prefix mapping code. I did experiment with this and found it breaks compiling ruby and xen-tools which both have code which does: #include __FILE__ It may be possible to make the remapping conditional of not being directly in a #include statement but I didn't find the gcc code responsible for that as yet. I also noticed some valgrind tests fails after it, I've not looked into why that would be yet. I wanted to ask if there would be any interest in adding support for something like this? I suspect the include/__FILE__ issue is probably a latent bug anyway. If anyone has any pointers to the code I could improve my patch with I'm also happy to have them! In case it helps, my background on what I'm working on and why we'd find this useful follows: I work on Yocto Project which cross compiles complete software stacks, we use gcc heavily and the resulting builds are all around us. We care deeply about build reproducibility. With autotools, we long ago realised that we were best off separating the source and the build output where we could and to do it we used relative paths, which removed a lot of problematic hardcoded paths in our output. More recently we've been using -fdebug-prefix-map and -fmacro-prefix- map (we need both since some of binutils doesn't seem to support the combined version yet). We use the debug information (split separately) to support on target debugging but where relative paths were used, we miss information as the remapping either doesn't happen correctly or is mangled. We'd like to fix our debug output but we're finding that hard without relative path support for *prefix-map. Cheers, Richard