From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-wm1-x333.google.com with SMTP id t1so6708701wmi.4 for ; Wed, 02 Nov 2022 03:47:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=U+kvzgcXBWxtPUHA/dKBUoOkE5lAQ5Olbv8x3DLt/I0=; b=EFYp4kdCj1hkdJKwsGaBfvdcTKdJ4rA9W3C3WxBgEM35vRiS6PkvZzbwdrXFAHYfnT AFdB0M1V8hj5OxPZnbcvigQCCNe6nAFGTiwFgpRj49nm0vKLbiK0ItAi8IZTAG/4lWxW TPUdrBU9GU9S9WG6FkwVl8IAqJQ6PIEBRE8K4= 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-Google-Smtp-Source: AMsMyM6MtITw055CPnjgwmHxnbvFYLFxK9oJrhXlP6vY528wyMSlBtbN9lH49XjKzj7AWPoVXRXQOQ== 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) From: Richard Purdie 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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); -- 2.34.1