libcpp: Avoid remapping filenames within directives

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.
This commit is contained in:
Richard Purdie
2022-11-18 13:13:50 -07:00
committed by Jeff Law
parent 59cc4da605
commit 11543b27fe
2 changed files with 3 additions and 2 deletions

View 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);