]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libcpp: Avoid remapping filenames within directives
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 18 Nov 2022 20:13:50 +0000 (13:13 -0700)
committerJeff Law <jlaw@ventanamicro.com>
Fri, 18 Nov 2022 20:13:50 +0000 (13:13 -0700)
Code such as:

 #include __FILE__

can interact poorly with the *-prefix-map options when cross compiling. In
general you're after to remap filenames for use in target context but the
local paths should be used to find include files at compile time. Ingoring
filename remapping for directives allows avoiding such failures.

Fix this to improve such usage and then document this against file-prefix-map
(referenced by the other *-prefix-map options) to make the behaviour clear
and defined.

libcpp/ChangeLog:

* macro.cc (_cpp_builtin_macro_text): Don't remap filenames within
directives.

gcc/ChangeLog:

* doc/invoke.texi: Document prefix-maps don't affect directives.

gcc/doc/invoke.texi
libcpp/macro.cc

index 31d031cd25cc4111cdb24ccc83387067943d10b4..0f6a1833ef1ed254c0cbb25a072521d87f47385e 100644 (file)
@@ -2201,7 +2201,8 @@ any references to them in the result of the compilation as if the
 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.  See also
+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}.
 
index 8ebf360c03c6c0a2ab50f0eb9eaee452ee2991d4..7d5a0d0fd2e7a83b92f8a1b3181cc9827fd7e978 100644 (file)
@@ -563,7 +563,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node,
            if (!name)
              abort ();
          }
-       if (pfile->cb.remap_filename)
+       if (pfile->cb.remap_filename && !pfile->state.in_directive)
          name = pfile->cb.remap_filename (name);
        len = strlen (name);
        buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);