public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] driver: Use <triple>-as/ld/objcopy as final fallback instead of native ones for cross
@ 2024-05-22  9:54 YunQiang Su
  2024-05-22  9:54 ` [PATCH v2 2/2] driver: Search <triple>-as/ld/objcopy before non-triple ones YunQiang Su
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: YunQiang Su @ 2024-05-22  9:54 UTC (permalink / raw)
  To: gcc-patches; +Cc: pinskia, jeffreyalaw, doko

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
<triple>-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 <triple>-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++)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-06-10 10:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-22  9:54 [PATCH v2 1/2] driver: Use <triple>-as/ld/objcopy as final fallback instead of native ones for cross YunQiang Su
2024-05-22  9:54 ` [PATCH v2 2/2] driver: Search <triple>-as/ld/objcopy before non-triple ones YunQiang Su
2024-05-28 18:32 ` [PATCH v2 1/2] driver: Use <triple>-as/ld/objcopy as final fallback instead of native ones for cross YunQiang Su
2024-05-28 21:27 ` Richard Sandiford
2024-05-29  2:02   ` YunQiang Su
2024-06-06  2:41     ` YunQiang Su
2024-06-06  9:54       ` Richard Sandiford
2024-06-10 10:08         ` YunQiang Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).