public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2] libcpp: Avoid remapping filenames within directives
@ 2022-11-02 10:47 Richard Purdie
  2022-11-18 20:14 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Richard Purdie @ 2022-11-02 10:47 UTC (permalink / raw)
  To: gcc-patches

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

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 gcc/doc/invoke.texi | 3 ++-
 libcpp/macro.cc     | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index c6323a53ad2..9d5dd3e20b7 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2213,7 +2213,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}.
 
diff --git a/libcpp/macro.cc b/libcpp/macro.cc
index 8ebf360c03c..7d5a0d0fd2e 100644
--- a/libcpp/macro.cc
+++ b/libcpp/macro.cc
@@ -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);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] libcpp: Avoid remapping filenames within directives
  2022-11-02 10:47 [PATCH v2] libcpp: Avoid remapping filenames within directives Richard Purdie
@ 2022-11-18 20:14 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2022-11-18 20:14 UTC (permalink / raw)
  To: Richard Purdie, gcc-patches


On 11/2/22 04:47, Richard Purdie via Gcc-patches wrote:
> 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

THanks.  Installed.  Sorry about the wait.

jeff



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-11-18 20:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-02 10:47 [PATCH v2] libcpp: Avoid remapping filenames within directives Richard Purdie
2022-11-18 20:14 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).