From patchwork Wed Aug 17 12:15:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Purdie X-Patchwork-Id: 578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp2608742pxh; Wed, 17 Aug 2022 05:16:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR4O8MFPwGhoiE2F/lr6T2bRcCojNYKPoRHnPx0v1ymWww+qze1WcgYgn/kDN/Qp1C8T+2ca X-Received: by 2002:a05:6402:518b:b0:43e:70be:97cd with SMTP id q11-20020a056402518b00b0043e70be97cdmr23128031edd.388.1660738590197; Wed, 17 Aug 2022 05:16:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660738590; cv=none; d=google.com; s=arc-20160816; b=KWpN9yXm6sIjkiP/l+IYrL5bD4xlSQlsXhkQExAxRwvUMJs7q423HLScRrvuGyG4EA OwroNhy8X+foGlyMS2fObpiojcwDAoJKBGA1WViR8G+BdHipf3SHKYF2kK3Uj4kuIg/C Dfmf0NwvSKQT3wWPO/2nKvZ05iXqsoK24waqNbhDDMw9aXeBjtSAu5pUqi0p7Od8wP3p FbtCv//EkEV2inUjsN7m1bR2cWyn9nhAxyuDdJr3ABH7H3a1maX7EBwBLTBUoFsDb3xs 5HJ3Mm9MEjAg/ME0JOyDwJkMPoN5e5KZkbXApkuOpOUxrF+H2BBkwAbKAIr2t5sf9CqZ v7VA== 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:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=hhoV687bg+ANc7Vocg6D4RdtpWqDnGnI7atRnNChFJk=; b=YmDHSwLur8UbVjzlgpSgnl4MDF/A56p2VoQqPJcGpLQhKrqTavCvk3zUQImeSWPhpz hT0bND6vie82XFn6ymiG3QCpLGhPY7lf9NTUYF60LKrUuUWnGyc86cVZCdzb9dxAonAA 4/ABffssmNt6LX6n+xNDGzRJwdUNW6ddCvOBDgtrzunvSdmumXnNrhuNWGVnp7+bd5CJ DSc1I+zCxqLf3wh9N1+bv+YQTDjsjBFXRBftJvK7YCimkNgD4M882l1bRSUgNxIz3NIj xlKPdW0NvyQjX35yrXICUZYEDgXuNBJ0FHiBcgUFARWESyCST2fDzAEgjULTcPxVKUkD kdcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iRj8khsS; 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 nd32-20020a17090762a000b007306e4fc2f2si12644396ejc.374.2022.08.17.05.16.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 05:16:30 -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=iRj8khsS; 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 9AC4E385802A for ; Wed, 17 Aug 2022 12:16:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9AC4E385802A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1660738582; bh=hhoV687bg+ANc7Vocg6D4RdtpWqDnGnI7atRnNChFJk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=iRj8khsSl6r+IWiiU6IiP7e7tFMURwHdeHIKK+R9is4INMTBxRFctaL39ZXD9KDyi CYefXIpr42tBhTsHn4a4P0byU/lbJpklRltkAXmeHmj2A9bbV+U44TsbkxGjfTArPK ryKFw9NKG+4XoCjFtVl9FuZLgg2zkr69qFcP3qqU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by sourceware.org (Postfix) with ESMTPS id ACE593858D39 for ; Wed, 17 Aug 2022 12:15:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACE593858D39 Received: by mail-wr1-x42d.google.com with SMTP id v3so16032932wrp.0 for ; Wed, 17 Aug 2022 05:15:38 -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:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=hhoV687bg+ANc7Vocg6D4RdtpWqDnGnI7atRnNChFJk=; b=wP2v/QSDpnwOIgmA9AKGoWMHFeJ6x/Xn2SX8omgjdLbv4U+QLJcXb05StBwn3Prkd+ ysS1LnxDYOCLywkQq8PJDOiJ+/ZmEhFhQeWSxYi5s9O4p2ThJqDA267kDpoMXd5ugV9o L3PbjxuRk5B/MLErdQMsS3EZJCt55SwoLUoiNoZeYBEUQ4SwxKbaVQ5Hmid1FrP7tw0H Py6bDauo9n8RxTCj2d5BTbt59g0Czrsgn+tanbxHwOwjU0MRmmrGvoRdQjqo24ht3uUi w3aRFbNHu5UH66SBeW7PixdmStnH0SeJ+wqpYRNj2d0ECdl4xr3QYr8KkGvrqwXXiWrB jE8A== X-Gm-Message-State: ACgBeo1mz2OixoTceqqIik93MBRYR+Rufbmfx7CiB9chRo6zXTofefHB Ek4qMILfkQIQrSx6UbsK48pJdEwr219LEg== X-Received: by 2002:adf:fa85:0:b0:225:1db8:fe6c with SMTP id h5-20020adffa85000000b002251db8fe6cmr3573480wrr.298.1660738537142; Wed, 17 Aug 2022 05:15:37 -0700 (PDT) Received: from max.int.rpsys.net ([2001:8b0:aba:5f3c:3694:2ef4:2932:37d5]) by smtp.gmail.com with ESMTPSA id t126-20020a1c4684000000b003a5fe5ed7edsm2408220wma.0.2022.08.17.05.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Aug 2022 05:15:36 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] libcpp: Avoid remapping filenames within directives Date: Wed, 17 Aug 2022 13:15:34 +0100 Message-Id: <20220817121534.1825108-2-richard.purdie@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817121534.1825108-1-richard.purdie@linuxfoundation.org> References: <20220817121534.1825108-1-richard.purdie@linuxfoundation.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 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, T_SCC_BODY_TEXT_LINE 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?1741410627572683319?= X-GMAIL-MSGID: =?utf-8?q?1741410627572683319?= 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 --- 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);