[PATCH 2/2] libcpp: Avoid remapping filenames within directives

Richard Purdie richard.purdie@linuxfoundation.org
Wed Aug 17 12:15:34 GMT 2022


Code such as:

can interact poorly with file-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 is one way to avoid such failures.

libcpp/ChangeLog:

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

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 libcpp/macro.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

I wasn't sure if this should apply to all directives or whether this may need
filtering to includes (along the lines of pfile->directive.flags & INCL). That
gets a little more complex as the flag isn't available outside of directives.cc
and would need a helper function.

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



More information about the Gcc-patches mailing list