On 8/17/22 06:15, Richard Purdie via Gcc-patches wrote:
Relative paths currently aren't remapped by -ffile-prefix-map and friends.
When cross compiling with separate 'source' and 'build' directories, the same
relative paths between directories may not be available on target as compared
to build time.
In order to be able to remap these relative build paths to paths that would
work on target, resolve paths within the file-prefix-map function using
realpath().
Understood.
This does cause a change of behaviour if users were previously relying upon
symlinks or absolute paths not being resolved.
I'm not too worried about this scenario.
Use basename to ensure plain filenames don't have paths added.
gcc/ChangeLog:
* file-prefix-map.cc (remap_filename): Allow remapping of relative paths
Basically OK. Just formatting nit:
Signed-off-by: Richard Purdie <richard.pur...@linuxfoundation.org>
---
gcc/file-prefix-map.cc | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/gcc/file-prefix-map.cc b/gcc/file-prefix-map.cc
index 24733f831d6..50d5d724a8f 100644
--- a/gcc/file-prefix-map.cc
+++ b/gcc/file-prefix-map.cc
@@ -70,19 +70,28 @@ remap_filename (file_prefix_map *maps, const char *filename)
file_prefix_map *map;
char *s;
const char *name;
+ char *realname;
size_t name_len;
+ if (lbasename (filename) == filename)
+ return filename;
+
+ 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;
+ }
Put the the curley braces go on their own lines, indented two
positions. The code inside the curleys is indented two more
positions. I fixed that and pushed this change to the trunk.
THanks,
jeff