fix: real argv[0] via SYS_GETEXECPATH - GCC driver finds its backends

The GCC driver relocates its install prefix from argv[0]. crt1
hardcoded argv[0] as "prog", so make_relative_prefix cwd-joined it
and computed exec prefixes relative to the current directory
(0:/users/admin/../libexec/gcc/...), and because the computed
gcc_exec_prefix is non-NULL the standard /sdk prefixes were never
searched. cc1plus was unreachable from anywhere except (by accident
of the path arithmetic) 0:/sdk/bin. sdk-diag proved the kernel and
libc layers all worked; only the driver's self-relocation was lost.

New SYS_GETEXECPATH (151) returns the absolute path the process was
spawned from (Process::name); crt1 uses it for argv[0] with a "prog"
fallback. With a real argv[0], make_relative_prefix computes
0:/sdk/bin/../libexec/gcc/ from any cwd. Native GCC relinked against
the new crt1; sdk-diag ships in the SDK as a permanent probe; the
montauk.h TCC mirror gains the wrapper (checker enforced it).

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
2026-07-17 10:43:59 +02:00
co-authored by Claude Fable 5
parent 2f1010b02e
commit 1c851a3627
12 changed files with 83 additions and 6 deletions
+44
View File
@@ -0,0 +1,44 @@
/*
* sdk-diag.c
* Probes the exact libc/kernel layers the GCC driver depends on:
* access/stat on the compiler backends, and a direct posix_spawn
* of cc1plus. Prints one line per probe.
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <spawn.h>
#include <sys/wait.h>
#define CC1PLUS "/sdk/libexec/gcc/x86_64-montauk/14.2.0/cc1plus"
static void probe(const char *p) {
struct stat st;
int a = access(p, X_OK);
int s = stat(p, &st);
printf("%-52s access=%d stat=%d", p, a, s);
if (s == 0) {
printf(" mode=%o size=%ld", (unsigned)st.st_mode, (long)st.st_size);
}
printf("\n");
}
int main(void) {
probe(CC1PLUS);
probe("/sdk/libexec/gcc/x86_64-montauk/14.2.0");
probe("/sdk/libexec/gcc");
probe("/sdk/bin/as.elf");
probe("/tmp");
pid_t pid = -1;
char *argv[] = { (char *)"cc1plus", (char *)"--version", 0 };
int r = posix_spawn(&pid, CC1PLUS, 0, 0, argv, 0);
printf("posix_spawn(cc1plus --version) = %d pid=%d\n", r, (int)pid);
if (r == 0) {
int st = -1;
waitpid(pid, &st, 0);
printf("cc1plus wait status = %d (exit %d)\n", st, (st >> 8) & 0xFF);
}
return 0;
}