From patchwork Wed May 22 09:54:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1937731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=mtCvR87x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4Vkmr14Fgbz2020 for ; Wed, 22 May 2024 19:54:57 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B86D43858CD1 for ; Wed, 22 May 2024 09:54:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B86D43858CD1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716371695; bh=rUJpzx+JHgu3Hlfzk7KmIw6yTSxlNyL9cUPbY9ZU6rw=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=mtCvR87xZNQb/Ivhvpjjlx7BoTWNXsR0iBOyV6sJ/JB7jWZfGOsbIeQC6B0VUwwSi HDAcQV6eTQL258tqe3QtxA9XwoOFbZRxIC6h1/7kTHf/Fh8l20CmUtAFdLAADISk0Q 1hEuovlnIV358xVaAAhT198mO3g/KJniqYOBnVPU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by sourceware.org (Postfix) with ESMTPS id B34BD3858D26 for ; Wed, 22 May 2024 09:54:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B34BD3858D26 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 B34BD3858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716371662; cv=none; b=JxCeDsJmCI0uRZ/yRAeo7U8rO3Shkx0xfrN84bWa1ePgNMXKgoHDwkYu6/hUN6CJrduURrxeBdoigwGOEdll4cXRgcFzcvJRyX72uSY5ocwYjAY3g/isMtGmYsAg/ve1vxnmZ3kfyIYntUItYB0OyKNdm1uUJPDRnPdyLSRmjkM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716371662; c=relaxed/simple; bh=QHiOsVZNLijr/M6T6pFxlNoqkHNFJY4p2PIEretkW1Y=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=MvDTw9ehs1PVSgmNdpG33kGuvUtFy3g/bDUEQpEfv0MyF2XXWcr8k1/XrF4zCVv/ZoezMcxO8EVJWIZQ3WRaiXCTDwbXD0djMSaU9WX+Lc6aYfrzGxi95X2UFOdr9i0k1Toz/cAX0JRtV4EyJVxNerAdTvpBYZYoLrcFs65Anpo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1edc696df2bso9072745ad.0 for ; Wed, 22 May 2024 02:54:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716371659; x=1716976459; 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=rUJpzx+JHgu3Hlfzk7KmIw6yTSxlNyL9cUPbY9ZU6rw=; b=JIaYAfX43/giWf42a+LIJlj0Yy/YS9gnbHvhMkvy9ailVEEUCdtODivrg/PmwqspYt YtdrnqupcqSLCf3fz6gWSQ3oKaBw1b7M4poP7XxLY7tCchA+gSUCSyhCFjCwUMce0GlZ Bn7CVElR2tplTKEaZAzq+mdfHdgSpga1WxvDOe2xHS7hAF5jlXT69r6cwzylAl8F7B7D anymAzpofwB9mItwn+BcsyzYQXIWuaMa72wiq5KyPiC7VWzmTn/J78rZeoodEs4ou7Fd NsSWAgd5KLR3FfH8x0XXwTykAgm9w7+2d6ezr2rpWAgRV1dLrM9ZpG7AritPTTqeF+jP V5iA== X-Gm-Message-State: AOJu0YyMR01jnbVjxEB3fHNglg/JnRnU2GaSOd5nDcDOWNDaRarxlCp8 gu4KG5LKbokl/AIHWg55Iror2bmfPyawrVEx4AUp73pQrsZbyKdaNg4Nt056q4j/9A== X-Google-Smtp-Source: AGHT+IEtUJJi/pS27ApBO9590nK5lSvtHs66OjbPs6EDH3wSKWQp1Kkdj7JvXkgdhGNUqK3hr95Y/g== X-Received: by 2002:a17:903:200c:b0:1f2:f5a3:9c98 with SMTP id d9443c01a7336-1f31c966f5cmr9513635ad.1.1716371659193; Wed, 22 May 2024 02:54:19 -0700 (PDT) Received: from localhost.localdomain ([104.238.152.18]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bad8a89sm236178695ad.102.2024.05.22.02.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:54:18 -0700 (PDT) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: pinskia@gmail.com, jeffreyalaw@gmail.com, doko@debian.org Subject: [PATCH v2 1/2] driver: Use -as/ld/objcopy as final fallback instead of native ones for cross Date: Wed, 22 May 2024 17:54:03 +0800 Message-Id: <20240522095404.1825269-1-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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_H3, RCVD_IN_MSPIKE_WL, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org If `find_a_program` cannot find `as/ld/objcopy` and we are a cross toolchain, the final fallback is `as/ld` of system. In fact, we can have a try with -as/ld/objcopy before fallback to native as/ld/objcopy. This patch is derivatived from Debian's patch: gcc-search-prefixed-as-ld.diff gcc * gcc.cc(execute): Looks for -as/ld/objcopy before fallback to native as/ld/objcopy. --- gcc/gcc.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 830a4700a87..3dc6348d761 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -3293,6 +3293,26 @@ 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], commands[0].prog) + && (!strcmp (commands[0].prog, "as") + || !strcmp (commands[0].prog, "ld") + || !strcmp (commands[0].prog, "objcopy"))) + { + string = concat (DEFAULT_REAL_TARGET_MACHINE, "-", + commands[0].prog, NULL); + 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++) From patchwork Wed May 22 09:54:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YunQiang Su X-Patchwork-Id: 1937732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=LcjAwcLc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4VkmrF1WYtz20PS for ; Wed, 22 May 2024 19:55:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B6223858416 for ; Wed, 22 May 2024 09:55:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6B6223858416 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1716371707; bh=EjSZbbFDn7lpITKUAPgWcS1kkIvmJXH6rIlSybNymFc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=LcjAwcLcD2QvD2zbgvscl1fwrVYGtWr/i1IDZw1ztemqxYNmrOpr5Wkyy+KWeVXi7 Nk58ABBkE4TB24OUx1gAZkkjyQzpniZRtw67NeYKR+2vcpAGIF8vpluOjQcenqwHaR bgv+7FmDe91+xMSLi5RUwOMbyrRfhXgGoGnCo2fU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by sourceware.org (Postfix) with ESMTPS id 19FD63858CD1 for ; Wed, 22 May 2024 09:54:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 19FD63858CD1 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 19FD63858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716371666; cv=none; b=vWfLnAsXZwCA4xL+3ylQ5lh/9bdNPufCXWl8e2y/u+2Fo8rahCUur5g9E+G6ZAEPDW9Wf8QglP2YlCUMxFw+24l30aneDYYIsua93u1uKA6x/VUtVTejdBX6TCunICAq60y07mPVFu/O2RFFLTR+v29AL/LI8GFDI3mBDcngD/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716371666; c=relaxed/simple; bh=YER1os5WLUw2EmmzRUnUyYycAxk9H+dRznamxlN/Vew=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=oxuqeFxacCm0hJpD4aamP1QwL9qixHlC1VN/zNy0EIlC+KVqQijGMOwc97l5rCwzYmT42AccDII9GOs+3j4wlPNLP/gqLGSo0B1JbPe+8GTRyRIyN/Z94kBeKkDNWyO6Fb2YDSDddtOsEOuYW6gMDujZkcTxK+PC5qD8DAcptPQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6f47787a0c3so1223657b3a.0 for ; Wed, 22 May 2024 02:54:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716371663; x=1716976463; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EjSZbbFDn7lpITKUAPgWcS1kkIvmJXH6rIlSybNymFc=; b=IEmbA2GywLfGlBXPwX/JUBQrYr24bSyowEL1osbT71AbsCGp6OHluOthWsPodoRofo bfFx6J/j5Nfq3h7+gSisw2xnDg0lgZ1iWXPzMfurzG3/X37l3XWAUrWysCBjOrH6Id3W afkM2g/Mo722BA1ekUITAm5bLQBTkDOYNNPOvbwnhn5RcD5pNkc8MJGNHvlZ6/CVG3i6 2rpSyVc85AInIVds7WqGUGbsi1m/ekCnQXf4JS0gqBBtRW5kA5uupykhjUZfbDsPoKnA YS4kuj7hLLJNTpLiTJUyqdYQfXYWlu5354fHCbpwPp6ITzDj/oEgNByxZagntFKPe5Mx ZaUQ== X-Gm-Message-State: AOJu0YwVkZkoXL2qloo5ghznkIX81SUfX7TZ6mi6ohqlour7kBUE9lwq D7Ejw6YISmE4cDo2LgSbLkT2HPMCWyB9Napuo7wyaQIldOfKczEPNZDVqEafyZuvAA== X-Google-Smtp-Source: AGHT+IFGbJgyfnbsQ/8BIj7/xI1scTme2b0ArcOEmka+U7tOpvLyq4XLjOyTMw9/AQdJdCN7vhBW3w== X-Received: by 2002:a05:6a21:6d9f:b0:1af:d35f:f282 with SMTP id adf61e73a8af0-1b1f8838ec8mr1754276637.14.1716371663545; Wed, 22 May 2024 02:54:23 -0700 (PDT) Received: from localhost.localdomain ([104.238.152.18]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1ef0bad8a89sm236178695ad.102.2024.05.22.02.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 02:54:23 -0700 (PDT) From: YunQiang Su To: gcc-patches@gcc.gnu.org Cc: pinskia@gmail.com, jeffreyalaw@gmail.com, doko@debian.org Subject: [PATCH v2 2/2] driver: Search -as/ld/objcopy before non-triple ones Date: Wed, 22 May 2024 17:54:04 +0800 Message-Id: <20240522095404.1825269-2-syq@gcc.gnu.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240522095404.1825269-1-syq@gcc.gnu.org> References: <20240522095404.1825269-1-syq@gcc.gnu.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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+incoming=patchwork.ozlabs.org@gcc.gnu.org When looking for as/ld/objcopy, `find_a_program/file_at_path` only try to find the raw name, but won't find the one with - prefix. This patch is derivatived from Debian's patch: gcc-search-prefixed-as-ld.diff gcc * gcc.cc(for_each_path): Add more space for -. (file_at_path): Search -as/ld/objcopy before non-triple ones. --- gcc/gcc.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index 3dc6348d761..0fa2eafea84 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -2820,6 +2820,8 @@ for_each_path (const struct path_prefix *paths, { len = paths->max_len + extra_space + 1; len += MAX (MAX (suffix_len, multi_os_dir_len), multiarch_len); + /* triplet prefix for as, ld. */ + len += MAX (strlen (DEFAULT_REAL_TARGET_MACHINE), multiarch_len) + 2; path = XNEWVEC (char, len); } @@ -3033,6 +3035,17 @@ file_at_path (char *path, void *data) struct file_at_path_info *info = (struct file_at_path_info *) data; size_t len = strlen (path); + /* search for the -as / -ld / objcopy first. */ + if (! strcmp (info->name, "as") || ! strcmp (info->name, "ld") + || ! strcmp (info->name, "objcopy")) + { + struct file_at_path_info prefix_info = *info; + prefix_info.name = concat (DEFAULT_REAL_TARGET_MACHINE, "-", + info->name, NULL); + prefix_info.name_len = strlen (prefix_info.name); + if (file_at_path (path, &prefix_info)) + return path; + } memcpy (path + len, info->name, info->name_len); len += info->name_len;