From patchwork Tue May 21 12:11:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 90583 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BBF96385828E for ; Tue, 21 May 2024 12:12:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBF96385828E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716293529; bh=5hk++OV0hiIvA+jFETCM8DNyn4R21m1tKQIGXsfyfrk=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=vAYVqijrdviqk25lbGArZ2qkO6hMe0IO+OFAwjvVxitK+aH8XfcAAsuho9DjUwJBJ 73ADcP+y36j7RX2yhIcx211UFPa9CBQutjIAsoafUJnYM4YeK1fHCkIXvjrmBb5nG3 XHct0rp3VMguA0tmbhx88qjQMxXOJdUfDkfTIZ94= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by sourceware.org (Postfix) with ESMTPS id D22353858D1E for ; Tue, 21 May 2024 12:11:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D22353858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D22353858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716293485; cv=none; b=Bh+XNzyRCR/XpKwOOV7aX/HCXlP6gkVPceyntOyXsOkiRKPEf3bG3mjR54ZDtDx4v8K/3FiZniREYxx2QjMjV/kk7U/C7SGdaeMltlDfwQpDjzM+2gpWW+JXhppdkIxTfZ6nYEJN6EZ6oHItLXq9U8qOPpPrJNFuckSYPuCOfgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716293485; c=relaxed/simple; bh=QJXi5846R6V/X+6PrPvTZlr+OQxC52CRKgeJTGavFvU=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=opjLGGtyBxilCCKDy2YSMpYiF99/JO700BnKrRwu0Qaz+QORMphFsy3/e2PY4qoflHEMLpNTyzIS6aiwpu+gESLoCfiSB7ZhBJ9tuinI9WBa7AEaFfYAHgjKDiMSocIXEuYVFIBRwm2AMNjzM9QtvZE1S4hy4kA9z4zuTAENEo8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1f05b669b6cso749395ad.3 for ; Tue, 21 May 2024 05:11:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716293479; x=1716898279; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5hk++OV0hiIvA+jFETCM8DNyn4R21m1tKQIGXsfyfrk=; b=EAkS8SQDd3bNmRkTeGLlfOBRtE3kkuDlBNQbnObcIEreAPJgtrn975s/xexJ9fA3yW V0EWNsumR55GS4wSxc3tWTHfjdZ1oLmHYgkyF1qZz/pe1QajFYi7CXqvV0aUNHKM2IVB lU7SFsTujHdafO90VacwzjLJQntzQrWVPVowRKSHlOhv5IH2GiHdsxEGHrfNlBC0iibk T5SxygDlWkY7vbcRzky9T2MQISvX9VDgcyH0qwnoQoBu6/sDc/XwCNlHITnrk9h7vV5m w7R2t7M64XsOnq6pUZ9o53jreIE8QdpX//NIN2aTOzf5fraqccY05shfTfsgGHGmFPCY IDUg== X-Gm-Message-State: AOJu0YzgXByNshqxsfXSvaq9WUyi+/aiAxeHVDxu7wUi2gNXltTmHKG/ bj1afoL228XDAaFlc6XVIx52U4K6dUpb4RWye6iGaYP79OX+JnYHturrNjFW X-Google-Smtp-Source: AGHT+IEw8g3S9i6neb3LReivMnYR9CwyZbYfHiIw6zxdgp6fSfZ2pCidOjdKeGJ9F/80dBYrxybjlA== X-Received: by 2002:a17:902:ce8f:b0:1f2:fb21:a6b4 with SMTP id d9443c01a7336-1f2fb21a775mr73241745ad.9.1716293474072; Tue, 21 May 2024 05:11:14 -0700 (PDT) Received: from localhost.localdomain ([2409:8700:2482:720:5054:ff:fe12:3456]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0b9d40c9sm225277115ad.49.2024.05.21.05.11.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 May 2024 05:11:13 -0700 (PDT) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: jeffreyalaw@gmail.com, doko@debian.org Subject: [PATCH] driver: Use -as/ld as final fallback instead of as/ld for cross Date: Tue, 21 May 2024 20:11:09 +0800 Message-Id: <20240521121109.3089022-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org If `find_a_program` cannot find `as/ld` and we are a cross toolchain, the final fallback is `as/ld` of system. In fact, we can have a try with -as/ld before fallback to native as/ld. This patch is derivatived from Debian's patch: gcc-search-prefixed-as-ld.diff gcc * gcc.cc(execute): Looks for -as/ld before fallback to native as/ld. --- gcc/gcc.cc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 830a4700a87..8a1bdb5e3e2 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -3293,6 +3293,27 @@ execute (void) string = find_a_program(commands[0].prog); if (string) commands[0].argv[0] = string; + else if (*cross_compile != '0' + && (!strcmp (commands[0].argv[0], "as") + || !strcmp (commands[0].argv[0], "ld"))) + { + string = XNEWVEC (char, strlen (commands[0].argv[0]) + 2 + + strlen (DEFAULT_REAL_TARGET_MACHINE)); + strcpy (string, DEFAULT_REAL_TARGET_MACHINE); + strcat (string, "-"); + strcat (string, commands[0].argv[0]); + const char *string_args[] = {string, "--version", NULL}; + int exit_status = 0; + int err = 0; + const char *errmsg = pex_one (PEX_SEARCH, string, + CONST_CAST (char **, string_args), string, + NULL, NULL, &exit_status, &err); + if (errmsg == NULL && exit_status == 0 && err == 0) + { + commands[0].argv[0] = string; + commands[0].prog = string; + } + } } for (n_commands = 1, i = 0; argbuf.iterate (i, &arg); i++)