feat: port gcc to MontaukOS

This commit is contained in:
2026-07-17 15:47:45 +02:00
parent 324b18edda
commit 8e6b619b02
14 changed files with 493 additions and 19 deletions
@@ -59,3 +59,32 @@
$as_echo "#define HAVE_HYPOT 1" >>confdefs.h
--- a/gcc/collect2.cc
+++ b/gcc/collect2.cc
@@ -1049,6 +1049,26 @@
prefix_from_env ("COMPILER_PATH", &cpath);
prefix_from_env ("PATH", &path);
+#ifdef __montauk__
+ /* MontaukOS does not pass environment variables across spawn yet, so
+ COMPILER_PATH and PATH above are always empty. Derive the compiler
+ search path from argv[0] instead: the driver invokes collect2 by its
+ full path (the kernel provides the real exec path in argv[0]), and
+ `ld` lives in the same libexec directory. Also seed PATH with the
+ SDK bin directories so the nm/strip/tooldir fallbacks work. */
+ if (cpath.plist == NULL && argv[0] != NULL)
+ {
+ const char *slash = strrchr (argv[0], '/');
+ if (slash != NULL)
+ add_prefix (&cpath, xstrndup (argv[0], slash - argv[0] + 1));
+ }
+ if (path.plist == NULL)
+ {
+ add_prefix (&path, "/sdk/x86_64-montauk/bin/");
+ add_prefix (&path, "/sdk/bin/");
+ }
+#endif
+
/* Try to discover a valid linker/nm/strip to use. */
/* Maybe we know the right file to use (if not cross). */