Andrew Geissler | ea144b0 | 2023-01-27 16:03:57 -0600 | [diff] [blame^] | 1 | Relative paths don't work with -fdebug-prefix-map and friends. This |
| 2 | can lead to paths which the user wanted to be remapped being missed. |
| 3 | Setting -fdebug-prefix-map to work with a relative path isn't practical |
| 4 | either. |
| 5 | |
| 6 | Instead, call gcc's realpath function on the incomming path name before |
| 7 | comparing it with the remapping. This means other issues like symlinks |
| 8 | are also accounted for and leads to a more consistent remapping experience. |
| 9 | |
| 10 | Upstream-Status: Submitted [https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599885.html] |
| 11 | [Also https://gcc.gnu.org/pipermail/gcc-patches/2022-August/599884.html] |
| 12 | Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> |
| 13 | |
| 14 | |
| 15 | Index: gcc-12.1.0/gcc/file-prefix-map.cc |
| 16 | =================================================================== |
| 17 | --- gcc-12.1.0.orig/gcc/file-prefix-map.cc |
| 18 | +++ gcc-12.1.0/gcc/file-prefix-map.cc |
| 19 | @@ -70,19 +70,28 @@ remap_filename (file_prefix_map *maps, c |
| 20 | file_prefix_map *map; |
| 21 | char *s; |
| 22 | const char *name; |
| 23 | + char *realname; |
| 24 | size_t name_len; |
| 25 | |
| 26 | + if (lbasename (filename) == filename) |
| 27 | + return filename; |
| 28 | + |
| 29 | + realname = lrealpath (filename); |
| 30 | + |
| 31 | for (map = maps; map; map = map->next) |
| 32 | - if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) |
| 33 | + if (filename_ncmp (realname, map->old_prefix, map->old_len) == 0) |
| 34 | break; |
| 35 | - if (!map) |
| 36 | + if (!map) { |
| 37 | + free (realname); |
| 38 | return filename; |
| 39 | - name = filename + map->old_len; |
| 40 | + } |
| 41 | + name = realname + map->old_len; |
| 42 | name_len = strlen (name) + 1; |
| 43 | |
| 44 | s = (char *) ggc_alloc_atomic (name_len + map->new_len); |
| 45 | memcpy (s, map->new_prefix, map->new_len); |
| 46 | memcpy (s + map->new_len, name, name_len); |
| 47 | + free (realname); |
| 48 | return s; |
| 49 | } |
| 50 | |
| 51 | Index: gcc-12.1.0/libcpp/macro.cc |
| 52 | =================================================================== |
| 53 | --- gcc-12.1.0.orig/libcpp/macro.cc |
| 54 | +++ gcc-12.1.0/libcpp/macro.cc |
| 55 | @@ -563,7 +563,7 @@ _cpp_builtin_macro_text (cpp_reader *pfi |
| 56 | if (!name) |
| 57 | abort (); |
| 58 | } |
| 59 | - if (pfile->cb.remap_filename) |
| 60 | + if (pfile->cb.remap_filename && !pfile->state.in_directive) |
| 61 | name = pfile->cb.remap_filename (name); |
| 62 | len = strlen (name); |
| 63 | buf = _cpp_unaligned_alloc (pfile, len * 2 + 3); |