From patchwork Mon Jan 6 11:01:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Korsgaard X-Patchwork-Id: 2030215 Return-Path: X-Original-To: incoming-buildroot@patchwork.ozlabs.org Delivered-To: patchwork-incoming-buildroot@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=buildroot.org (client-ip=140.211.166.137; helo=smtp4.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver=patchwork.ozlabs.org) Received: from smtp4.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4YRWTK5pKHz1yPH for ; Mon, 6 Jan 2025 22:01:41 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by smtp4.osuosl.org (Postfix) with ESMTP id 42F5B4031C; Mon, 6 Jan 2025 11:01:40 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp4.osuosl.org ([127.0.0.1]) by localhost (smtp4.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id 31ig2x4_Rbgs; Mon, 6 Jan 2025 11:01:39 +0000 (UTC) X-Comment: SPF check N/A for local connections - client-ip=140.211.166.142; helo=lists1.osuosl.org; envelope-from=buildroot-bounces@buildroot.org; receiver= DKIM-Filter: OpenDKIM Filter v2.11.0 smtp4.osuosl.org 123F64032E Received: from lists1.osuosl.org (lists1.osuosl.org [140.211.166.142]) by smtp4.osuosl.org (Postfix) with ESMTP id 123F64032E; Mon, 6 Jan 2025 11:01:39 +0000 (UTC) X-Original-To: buildroot@buildroot.org Delivered-To: buildroot@buildroot.org Received: from smtp3.osuosl.org (smtp3.osuosl.org [IPv6:2605:bc80:3010::136]) by lists1.osuosl.org (Postfix) with ESMTP id C5B17D92 for ; Mon, 6 Jan 2025 11:01:37 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp3.osuosl.org (Postfix) with ESMTP id 96AED606AA for ; Mon, 6 Jan 2025 11:01:37 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id wf5n8Bnd5WwC for ; Mon, 6 Jan 2025 11:01:36 +0000 (UTC) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=217.70.183.196; helo=relay4-d.mail.gandi.net; envelope-from=peko@korsgaard.com; receiver= DMARC-Filter: OpenDMARC Filter v1.4.2 smtp3.osuosl.org 0BCF560623 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp3.osuosl.org 0BCF560623 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp3.osuosl.org (Postfix) with ESMTPS id 0BCF560623 for ; Mon, 6 Jan 2025 11:01:35 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 23D17E0006; Mon, 6 Jan 2025 11:01:31 +0000 (UTC) Received: from peko by dell.be.48ers.dk with local (Exim 4.96) (envelope-from ) id 1tUkrT-00Bu96-1C; Mon, 06 Jan 2025 12:01:31 +0100 From: Peter Korsgaard To: buildroot@buildroot.org Date: Mon, 6 Jan 2025 12:01:29 +0100 Message-Id: <20250106110130.2837398-1-peter@korsgaard.com> X-Mailer: git-send-email 2.39.5 MIME-Version: 1.0 X-GND-Sasl: peter@korsgaard.com X-Mailman-Original-Authentication-Results: smtp3.osuosl.org; dmarc=none (p=none dis=none) header.from=korsgaard.com Subject: [Buildroot] [PATCH] toolchain/toolchain-wrapper.c: do not pass linker flags if not linking X-BeenThere: buildroot@buildroot.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Discussion and development of buildroot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Romain Naour , Giulio Benetti , Thomas Petazzoni Errors-To: buildroot-bounces@buildroot.org Sender: "buildroot" Fixes: https://gitlab.com/buildroot.org/buildroot/-/issues/55 When gcc sees a linker option (-Wl,..) it executes the linker, leading to confusing error messages if no source files are provided, E.G.: % gcc gcc: fatal error: no input files compilation terminated. % gcc -Wl,-z,now /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o: in function `_start': (.text+0x17): undefined reference to `main' collect2: error: ld returned 1 exit status It is not really trivial to detect in the wrapper if linking will be done, but we can at least check if any non-option arguments (E.G. source/object files) are passed and skip the -Wl,.. options if not. % ./host/bin/aarch64-linux-gcc aarch64-linux-gcc.br_real: fatal error: no input files compilation terminated. With this fixed we no longer need the special case for --help -v from commit 9954315fc5b2 ("toolchain/toolchain-wrapper: make gcc --help -v work correctly"), so drop that. Signed-off-by: Peter Korsgaard --- toolchain/toolchain-wrapper.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/toolchain/toolchain-wrapper.c b/toolchain/toolchain-wrapper.c index db11cdb6ab..8b1fb79dde 100644 --- a/toolchain/toolchain-wrapper.c +++ b/toolchain/toolchain-wrapper.c @@ -245,7 +245,7 @@ int main(int argc, char **argv) char *progpath = argv[0]; char *basename; char *env_debug; - int ret, i, count = 0, debug = 0, found_shared = 0; + int ret, i, count = 0, debug = 0, found_shared = 0, found_nonoption = 0; /* Debug the wrapper to see arguments it was called with. * If environment variable BR2_DEBUG_WRAPPER is: @@ -311,13 +311,11 @@ int main(int argc, char **argv) return 3; } - /* skip all processing --help is specified */ + /* any non-option (E.G. source / object files) arguments passed? */ for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "--help")) { - argv[0] = path; - if (execv(path, argv)) - perror(path); - return 1; + if (argv[i][0] != '-') { + found_nonoption = 1; + break; } } @@ -342,8 +340,11 @@ int main(int argc, char **argv) } /* start with predefined args */ - memcpy(cur, predef_args, sizeof(predef_args)); - cur += sizeof(predef_args) / sizeof(predef_args[0]); + for (i = 0; i < sizeof(predef_args) / sizeof(predef_args[0]); i++) { + /* skip linker flags when we know we are not linking */ + if (found_nonoption || strncmp(predef_args[i], "-Wl,", strlen("-Wl,"))) + *cur++ = predef_args[i]; + } #ifdef BR_FLOAT_ABI /* add float abi if not overridden in args */ @@ -463,7 +464,7 @@ int main(int argc, char **argv) !strcmp(argv[i], "-D__UBOOT__")) break; } - if (i == argc) { + if (i == argc && found_nonoption) { /* https://wiki.gentoo.org/wiki/Hardened/Toolchain#Mark_Read-Only_Appropriate_Sections */ #ifdef BR2_RELRO_PARTIAL *cur++ = "-Wl,-z,relro";