From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2119) id C3E2A3857C51; Fri, 18 Nov 2022 20:14:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C3E2A3857C51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668802471; bh=xvIOQ2nEqe2XTGoHaa1TEfP69QlQkDJ+RX5OzXyvtBs=; h=From:To:Subject:Date:From; b=t1292Zim+BoJz+/nI2OoSS3R8lIdNjdzQ1LprxYS6uMJz+7JUo9YWq681b1inI7UF yJJ25zY0wreFIw+73vcV4WczwtkShZVdoVOtpDrKV4lc7m3XFz39jLH9xdOz9r/fUT y/wuT3i4x3zIqFOG7MVLPg1L56MaE8ndHr44nFxk= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jeff Law To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-4149] libcpp: Avoid remapping filenames within directives X-Act-Checkin: gcc X-Git-Author: Richard Purdie X-Git-Refname: refs/heads/master X-Git-Oldrev: 59cc4da605e5cb8e31e9f1d54ef2b5ba47fc8f88 X-Git-Newrev: 11543b27fe16d81ca5483ecb98ec7a5b2426e0c0 Message-Id: <20221118201431.C3E2A3857C51@sourceware.org> Date: Fri, 18 Nov 2022 20:14:31 +0000 (GMT) List-Id: https://gcc.gnu.org/g:11543b27fe16d81ca5483ecb98ec7a5b2426e0c0 commit r13-4149-g11543b27fe16d81ca5483ecb98ec7a5b2426e0c0 Author: Richard Purdie Date: Fri Nov 18 13:13:50 2022 -0700 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. Diff: --- 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 31d031cd25c..0f6a1833ef1 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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}. 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);