diff options
author | Jakub Jelinek <jakub@redhat.com> | 2023-03-10 10:21:23 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2023-03-10 10:21:23 +0100 |
commit | 2eb0191aa104badf3cab127f7f87d371c0fef92b (patch) | |
tree | 654950039a8351536312789b1189f80a5527b38a /gcc/doc | |
parent | 2c63cc7268fd5615997989f153e9405d0f5aaa50 (diff) | |
download | gcc-2eb0191aa104badf3cab127f7f87d371c0fef92b.zip gcc-2eb0191aa104badf3cab127f7f87d371c0fef92b.tar.gz gcc-2eb0191aa104badf3cab127f7f87d371c0fef92b.tar.bz2 |
file-prefix-map: Fix up -f*-prefix-map= [PR108464]
On Tue, Nov 01, 2022 at 01:46:20PM -0600, Jeff Law via Gcc-patches wrote:
> > 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.
As mentioned in the PR, this patch breaks e.g. ccache testsuite.
I strongly doubt most of the users want such a behavior, because it
makes all filenames absolute when -f*-prefix-map= options remap one
absolute path to another one.
Say if I'm in /tmp and /tmp is the canonical path and there is
src/test.c file, with -fdebug-prefix-map=/tmp=/blah
previously there would be DW_AT_comp_dir "/blah" and it is still there,
but DW_AT_name which was previouly "src/test.c" (relative against
DW_AT_comp_dir) is now "/blah/src/test.c" instead.
Even worse, the canonicalization is only done on the remap_filename
argument, but not on the old_prefix side. That is e.g. what breaks
ccache. If there is
/tmp/foobar1 directory and
ln -sf foobar1 /tmp/foobar2
cd /tmp/foobar2
then -fdebug-prefix-map=`pwd`:/blah will just not work, while
src/test.c will be canonicalized to /tmp/foobar1/src/test.c,
old_prefix is still what the user provided which is /tmp/foobar2.
User would need to change their uses to use -fdebug-prefix-map=`realpath $(pwd)`=/blah
I've created 3 patches for this.
The first patch just reverts the patch (and its follow-up patch).
The second introduces a new option, -f{,no}-canon-prefix-map which affects
the behavior of -f{file,macro,debug,profile}-prefix-map=, if on it
canonicalizes the old path of the prefix map option and compares that
against the canonicalized filename for absolute paths but not relative.
And last is like the second, but does that also for relative paths except
for filenames with no / (or / or \ on DOS based fs). So, the third patch
gets an optional behavior of what has been on the trunk lately with the
difference that the old_prefix is canonicalized by the compiler.
Initially I've thought I'd just add some magic syntax to the OLD=NEW
argument of those options (because there are 4 of them), but as noted
in the comments, = is valid char in OLD (just not new), so it would
be hard to figure out some syntax. So instead a new option, which one
can turn on and off for different -f*-prefix-map= options if needed.
-fdebug-prefix-map=/path1=/mypath1 -fcanon-prefix-map \
-fdebug-prefix-map=/path2=/mypath2 -fno-canon-prefix-map \
-fdebug-prefix-map=/path3=/mypath3
will use the old behavior for the /path1 and /path3 handling and
the new one only for /path2 handling.
This commit is the third patch described above.
2023-03-10 Jakub Jelinek <jakub@redhat.com>
PR other/108464
* common.opt (fcanon-prefix-map): New option.
* opts.cc: Include file-prefix-map.h.
(flag_canon_prefix_map): New variable.
(common_handle_option): Handle OPT_fcanon_prefix_map.
(gen_command_line_string): Ignore OPT_fcanon_prefix_map.
* file-prefix-map.h (flag_canon_prefix_map): Declare.
* file-prefix-map.cc (struct file_prefix_map): Add canonicalize
member.
(add_prefix_map): Initialize canonicalize member from
flag_canon_prefix_map, and if true canonicalize it using lrealpath.
(remap_filename): Revert 2022-11-01 and 2022-11-07 changes,
use lrealpath result only for map->canonicalize map entries.
* lto-opts.cc (lto_write_options): Ignore OPT_fcanon_prefix_map.
* opts-global.cc (handle_common_deferred_options): Clear
flag_canon_prefix_map at the start and handle OPT_fcanon_prefix_map.
* doc/invoke.texi (-fcanon-prefix-map): Document.
(-ffile-prefix-map, -fdebug-prefix-map, -fprofile-prefix-map): Add
see also for -fcanon-prefix-map.
* doc/cppopts.texi (-fmacro-prefix-map): Likewise.
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/cppopts.texi | 2 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 24 |
2 files changed, 19 insertions, 7 deletions
diff --git a/gcc/doc/cppopts.texi b/gcc/doc/cppopts.texi index 872629e..ce22554 100644 --- a/gcc/doc/cppopts.texi +++ b/gcc/doc/cppopts.texi @@ -305,7 +305,7 @@ to change an absolute path to a relative path by using @file{.} for @var{new} which can result in more reproducible builds that are location independent. This option also affects @code{__builtin_FILE()} during compilation. See also -@option{-ffile-prefix-map}. +@option{-ffile-prefix-map} and @option{-fcanon-prefix-map}. @opindex fexec-charset @cindex character set, execution diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index beb606f..3a6a978 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -191,7 +191,7 @@ in the following sections. -dumpdir @var{dumppfx} -x @var{language} @gol -v -### --help@r{[}=@var{class}@r{[},@dots{}@r{]]} --target-help --version @gol -pass-exit-codes -pipe -specs=@var{file} -wrapper @gol -@@@var{file} -ffile-prefix-map=@var{old}=@var{new} @gol +@@@var{file} -ffile-prefix-map=@var{old}=@var{new} -fcanon-prefix-map @gol -fplugin=@var{file} -fplugin-arg-@var{name}=@var{arg} @gol -fdump-ada-spec@r{[}-slim@r{]} -fada-spec-parent=@var{unit} -fdump-go-spec=@var{file}} @@ -2207,9 +2207,20 @@ files resided in directory @file{@var{new}} instead. Specifying this option is equivalent to specifying all the individual @option{-f*-prefix-map} options. This can be used to make reproducible builds that are location independent. Directories referenced by -directives are not affected by these options. See also -@option{-fmacro-prefix-map}, @option{-fdebug-prefix-map} and -@option{-fprofile-prefix-map}. +directives are not affected by these options. See also +@option{-fmacro-prefix-map}, @option{-fdebug-prefix-map}, +@option{-fprofile-prefix-map} and @option{-fcanon-prefix-map}. + +@item -fcanon-prefix-map +@opindex fcanon-prefix-map +For the @option{-f*-prefix-map} options normally comparison +of @file{@var{old}} prefix against the filename that would be normally +referenced in the result of the compilation is done using textual +comparison of the prefixes, or ignoring character case for case insensitive +filesystems and considering slashes and backslashes as equal on DOS based +filesystems. The @option{-fcanon-prefix-map} causes such comparisons +to be done on canonicalized paths of @file{@var{old}} +and the referenced filename. @opindex fplugin @item -fplugin=@var{name}.so @@ -11362,7 +11373,8 @@ build-time path with an install-time path in the debug info. It can also be used to change an absolute path to a relative path by using @file{.} for @var{new}. This can give more reproducible builds, which are location independent, but may require an extra command to tell GDB -where to find the source files. See also @option{-ffile-prefix-map}. +where to find the source files. See also @option{-ffile-prefix-map} +and @option{-fcanon-prefix-map}. @opindex fvar-tracking @item -fvar-tracking @@ -16550,7 +16562,7 @@ When compiling files residing in directory @file{@var{old}}, record profiling information (with @option{--coverage}) describing them as if the files resided in directory @file{@var{new}} instead. -See also @option{-ffile-prefix-map}. +See also @option{-ffile-prefix-map} and @option{-fcanon-prefix-map}. @opindex fprofile-update @item -fprofile-update=@var{method} |