From patchwork Thu Nov 18 11:01:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xi Ruoyao X-Patchwork-Id: 1556574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=EYxfUNtN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HvxhK44Ngz9sPf for ; Thu, 18 Nov 2021 22:02:08 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C79873858406 for ; Thu, 18 Nov 2021 11:02:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C79873858406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637233324; bh=aCIgGNtU/cxphQZHFNNQnRwn4jpL8tG4geuZFqV4RDk=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=EYxfUNtNteviW1OM/aKFmkynu3n5lmxzAOf9z8cAkdoHDqYRf0/7fXtkR/sXb/HqX hmZnCyoOQ0kV4iCTQkmCoD0X9iLftpdqojbtv/mlaAE1t3pPv1PXV0zyc6+dy/XgK1 LpRQN7Z36HHvV5eT1d+St/jJpuv80LyKqIT44/4k= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 137F53858406 for ; Thu, 18 Nov 2021 11:01:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 137F53858406 Received: from [IPv6:240e:35a:10fb:fb00:dc73:854d:832e:2] (unknown [IPv6:240e:35a:10fb:fb00:dc73:854d:832e:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id 0213D660E5; Thu, 18 Nov 2021 06:01:17 -0500 (EST) Message-ID: Subject: [PATCH] fixincludes: don't abort() on access failure [PR103306] To: gcc-patches@gcc.gnu.org Date: Thu, 18 Nov 2021 19:01:11 +0800 User-Agent: Evolution 3.42.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3039.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Xi Ruoyao via Gcc-patches From: Xi Ruoyao Reply-To: Xi Ruoyao Cc: Jakub Jelinek , Zdenek Sojka , Bruce Korb Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Some distro may ship dangling symlinks in include directories, triggers the access failure. Skip it and continue to next header instead of being to panic. Restore to old behavior before r12-5234 but without resurrecting the problematic getcwd() call, by using the environment variable "INPUT" exported by fixinc.sh. Tested on x86_64-linux-gnu, with a dangling symlink in /usr/include. fixincludes/ PR bootstrap/103306 * fixincl.c (process): Don't call abort(). --- fixincludes/fixincl.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fixincludes/fixincl.c b/fixincludes/fixincl.c index a17b65866c3..81939ee5ffa 100644 --- a/fixincludes/fixincl.c +++ b/fixincludes/fixincl.c @@ -1352,10 +1352,19 @@ process (void) if (access (pz_curr_file, R_OK) != 0) { - /* Some really strange error happened. */ - fprintf (stderr, "Cannot access %s: %s\n", pz_curr_file, + /* It may happens if for e. g. the distro ships some broken symlinks + * in /usr/include. */ + + /* "INPUT" is exported in fixinc.sh, which is the pwd where fixincl + * runs. It's used instead of getcwd to avoid allocating a buffer + * with unknown length. */ + const char *cwd = getenv ("INPUT"); + if (!cwd) + cwd = "the working directory"; + + fprintf (stderr, "Cannot access %s from %s: %s\n", pz_curr_file, cwd, xstrerror (errno)); - abort (); + return; } pz_curr_data = load_file (pz_curr_file);