From patchwork Wed Nov 2 10:47:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 14174 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3543175wru; Wed, 2 Nov 2022 03:48:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CcEKZIxgBYvmGW7G/oQZzI15gbVxp+fN7+u8O+zwVWdCwbS+3TI2+iovoOYXi+qnaqDzV X-Received: by 2002:a17:906:db0a:b0:781:f24:a782 with SMTP id xj10-20020a170906db0a00b007810f24a782mr23426516ejb.399.1667386082401; Wed, 02 Nov 2022 03:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667386082; cv=none; d=google.com; s=arc-20160816; b=rT2pkxGBe5Q+vNi6jdt99GS3GwNfg8znsiKCKEflJhuB/qMS91u/gLu75EcX+GSuhn MXXsC9ZUQargZNqPW+LWmxfgU2CFxWYJ7iT6y8o/eXdn7Ge1nv2VIIwFCwl2Fpa9Lm4b j2MHZryWGDPB/tXw4k/17F40WRVup2BgPqszKnbGxXdRZK7Er6vRqaYOBznPs/Dpmk9J HwNGXvbq2OtuxRgCCBMm0uYogHPuVmTeb2//NEpSozeOSei5PCpi+ekawVHWc/UuPlhq 7U0K+58CLtoN4EQgn/Fd+woIJQLlk+vCBK69Fq8+fdiqR9yG5InOfyhx8nUqkb5LCSxh i5FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=U+kvzgcXBWxtPUHA/dKBUoOkE5lAQ5Olbv8x3DLt/I0=; b=JB30if75LvFuBMdNxwO+WWuj3JtKjvQBRZAcj5jsRnoreyaKvBYoEGdhubF+gWsm7O 3EztMNStpGOZW0Ml4iV4MaZBGCr7VVa0KNbEf8DwY72ganR4FVISuyjMQGhpa+1MztN4 BQkweRNMETMs0tCOx3CiAxiO5WY3FhFySaNazjX3zQ1Dp0aIc6bRH1Cl//4hbNiI6ztH YFTCTR2RtyazqzAIB/PLk9bz9I/zVExFl+0khs+AX2yadkcC8tcbQJLrIPNyFqSzBcZW YejqD9tRlj6Ivrp5MxXLHmIMGNtV1Abqf3peHYFBIeeJ7atpNLbNZJ8wcaKRybFKbc4L brUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FGgjNw2z; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g16-20020a1709065d1000b007891fd91786si14667118ejt.151.2022.11.02.03.48.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 03:48:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FGgjNw2z; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 66D6638582AE for ; Wed, 2 Nov 2022 10:48:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 66D6638582AE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667386081; bh=U+kvzgcXBWxtPUHA/dKBUoOkE5lAQ5Olbv8x3DLt/I0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FGgjNw2zdzQsd05+F+Lex8WhiN5BHOPRa54CQ/OM7YQ0f3dRuoM7W9tSA78izsIYI Kzm8yurUsYbj1n7J+bkp/EbDFWAz1NYZDzvbDC0CPEX77D0j01B5e9ojTEUYeVN5x2 29pw3Ktl9AJIDFxUgwn6zm4f7djztHJGJAgZj6bA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 437333858D35 for ; Wed, 2 Nov 2022 10:47:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 437333858D35 Received: by mail-wm1-x333.google.com with SMTP id t1so6708701wmi.4 for ; Wed, 02 Nov 2022 03:47:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U+kvzgcXBWxtPUHA/dKBUoOkE5lAQ5Olbv8x3DLt/I0=; b=V4M+2Lah79kJ9OI8mtZfuXYHKES6Aamj1hsXHZXVtb1WrPgsFNIRXHCW09mlZOvFJc l93b9yazIRuKoVmVT3tXgpYzMzLBkDN5bqtyxxtV/HEe/2jrUf/WdUBtICRobYENsoP/ ANksmv//GEI2R/T18jvXpDS+ujWHC6iBeS+W1beAv2qAPdLPgtsIL3KubMetSA6Ankzr OPG8raALKpJIpbLT9iDHH3jOTwIrsHP7iaRBBZC0/cImH2j93uLKLlHZMpH0aqK0BibM wC3mCi3FG+CIvo1+ca+YklR3VeYRfjKMqo7qtd5cttcVYo2y57JHpR7lHvuiSpkXZcNh cozw== X-Gm-Message-State: ACrzQf0COwqZPvy0lOYwnMDrJkzc/R36KvdgjDHMIUGclK4omlhvCPhq EwvnQfUXndWK9YFzqEN9iFKWjs1p0bI1bw== X-Received: by 2002:a05:600c:a48:b0:3b9:af1f:1b38 with SMTP id c8-20020a05600c0a4800b003b9af1f1b38mr15312441wmq.185.1667386035199; Wed, 02 Nov 2022 03:47:15 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:b8b1:19d6:e9d8:a61a]) by smtp.gmail.com with ESMTPSA id bd12-20020a05600c1f0c00b003c6bbe910fdsm1762661wmb.9.2022.11.02.03.47.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 03:47:14 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2] libcpp: Avoid remapping filenames within directives Date: Wed, 2 Nov 2022 10:47:13 +0000 Message-Id: <20221102104713.643862-1-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Purdie via Gcc-patches From: Richard Purdie Reply-To: Richard Purdie Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748381028689591030?= X-GMAIL-MSGID: =?utf-8?q?1748381028689591030?= 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 --- 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);