From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CLS/FcDgCmKragAAWB0awg (envelope-from ) for ; Mon, 14 Feb 2022 18:07:44 -0500 Received: by simark.ca (Postfix, from userid 112) id 5717E1F3C5; Mon, 14 Feb 2022 18:07:44 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 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 (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id C79C71EA69 for ; Mon, 14 Feb 2022 18:07:43 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 690093858024 for ; Mon, 14 Feb 2022 23:07:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 690093858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1644880063; bh=QyjV2vy403mySbUDg6wFe6XF8kAZKWRPJ69QsN1GCoM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=CuXEaPAFh4Bg7/3Wh2e5OwGSBKQp197ht/cLAgdTAoRaifeAWjc0Hm0LhuKlgxOfO fWwZmVWPdcR+3brFGO/g8UnzAdTuYem7H/uooOSW0qDcEcQ8ZLP7eK1Pwuv6LtyWYu f5Uc93Tqe2gJGC79xGprjTxCjPQ1B08kyjkg24P8= Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by sourceware.org (Postfix) with ESMTPS id 4227B3858D3C for ; Mon, 14 Feb 2022 23:07:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4227B3858D3C To: Subject: [PATCH 11/12] sim/testsuite/cris: Remove faulty use of basename in C tests MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8BIT Message-ID: <20220214230724.2C0AA20439@pchp3.se.axis.com> Date: Tue, 15 Feb 2022 00:07:24 +0100 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Hans-Peter Nilsson via Gdb-patches Reply-To: Hans-Peter Nilsson Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Calls to basename were added here as part of commit e1e1ae6e9b5e "sim: testsuite: fix objdir handling", but that commit missed adding "#include " or the equivalent GNU extension, see basename(3). Fixing that shows a logical error in the change to openpf1.c; the non-/-prefixed code-path was changed instead of the "/"-prefixed code-path, which is the one executed after that commit. For "newlib" these tests failed linking after that commit. Recent newlib has the (asm-renamed) GNU-extension-variant of basename, but we're better off not using it at all. Unfortunately, compilation failures for C tests run by the machinery in c.exp are currently just marked "unresolved", in contrast to C and assembler tests run by calling run_sim_test. The interaction of calling with the full program-path vs. use of --sysroot exposes a consistency problem: when --sysroot is used, argv[0] isn't the path by which the program can find itself. It's undecided whether argv[0] for the program running in the simulator should be edited (related to the naked argument to the simulator before passing on to the simulated program) to remove a leading --sysroot. Either way, such a change would be out of scope for this commit. * c/stat3.c (mybasename): New macro. Use it instead of basename. * c/openpf1.c: Correct basename-related change and update related comment. --- sim/testsuite/cris/c/openpf1.c | 8 +++++--- sim/testsuite/cris/c/stat3.c | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sim/testsuite/cris/c/openpf1.c b/sim/testsuite/cris/c/openpf1.c index 92d12bfc4371..37940d709fbb 100644 --- a/sim/testsuite/cris/c/openpf1.c +++ b/sim/testsuite/cris/c/openpf1.c @@ -3,8 +3,8 @@ We assume, with EXE being the name of the executable: - The simulator executes with cwd the same directory where the executable - is located (so argv[0] contains a plain filename without directory - components). + is located (also argv[0] contains a plain filename without directory + components -or- argv[0] contains the full non-sysroot path to EXE). - There's no /EXE on the host file system. */ #include @@ -21,8 +21,10 @@ int main (int argc, char *argv[]) if (fnam == NULL) abort (); strcpy (fnam, "/"); - strcat (fnam, basename (argv[0])); + strcat (fnam, argv[0]); } + else + fnam = strrchr (argv[0], '/'); f = fopen (fnam, "rb"); if (f == NULL) diff --git a/sim/testsuite/cris/c/stat3.c b/sim/testsuite/cris/c/stat3.c index eac4da9ea8d9..c44143d353e6 100644 --- a/sim/testsuite/cris/c/stat3.c +++ b/sim/testsuite/cris/c/stat3.c @@ -7,13 +7,14 @@ #include #include #include +#define mybasename(x) ({ const char *x_ = (x), *y_ = strrchr (x_, '/'); y_ != NULL ? y_ + 1 : x_; }) int main (int argc, char *argv[]) { char path[1024] = "/"; struct stat buf; - strcat (path, basename (argv[0])); + strcat (path, mybasename(argv[0])); if (stat (".", &buf) != 0 || !S_ISDIR (buf.st_mode)) abort (); -- 2.30.2