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 <noreply@anthropic.com>
This commit is contained in:
@@ -405,6 +405,7 @@ ifneq ($(wildcard $(NATIVE_BIN)/as),)
|
||||
cp -r ../toolchain/local/x86_64-montauk/include/c++ $(BINDIR)/sdk/include/c++
|
||||
../toolchain/local/bin/x86_64-montauk-gcc -O2 ../toolchain/files/tls-test.c -o $(BINDIR)/sdk/bin/tls-test.elf
|
||||
../toolchain/local/bin/x86_64-montauk-g++ -O2 ../toolchain/files/cxx-test.cpp -o $(BINDIR)/sdk/bin/cxx-test.elf
|
||||
../toolchain/local/bin/x86_64-montauk-gcc -O2 ../toolchain/files/sdk-diag.c -o $(BINDIR)/sdk/bin/sdk-diag.elf
|
||||
ifneq ($(wildcard ../toolchain/native-gcc/sdk/bin/gcc),)
|
||||
cp ../toolchain/native-gcc/sdk/bin/gcc $(BINDIR)/sdk/bin/gcc.elf
|
||||
cp ../toolchain/native-gcc/sdk/bin/g++ $(BINDIR)/sdk/bin/g++.elf
|
||||
|
||||
@@ -204,7 +204,10 @@ namespace montauk::abi {
|
||||
static constexpr uint64_t SYS_POWERINFO = 149; // (PowerInfo*) -> 0, -1 unsupported
|
||||
|
||||
// Framebuffer page flip (double-buffered scanout)
|
||||
static constexpr uint64_t SYS_FBFLIP = 150; // (index, flags) -> new front index; index=-1 queries support (1/0); flags bit0 = wait vsync
|
||||
static constexpr uint64_t SYS_FBFLIP = 150;
|
||||
|
||||
// Absolute path of the running executable (for argv[0]).
|
||||
static constexpr uint64_t SYS_GETEXECPATH = 151; // (index, flags) -> new front index; index=-1 queries support (1/0); flags bit0 = wait vsync
|
||||
|
||||
// Tunable parameters (for SYS_SDR_SETPARAM / SYS_SDR_GETPARAM).
|
||||
static constexpr int SDR_PARAM_FREQ = 0; // center frequency, Hz
|
||||
|
||||
@@ -174,6 +174,7 @@ extern "C" {
|
||||
#define MTK_SYS_SDR_GETPARAM 148
|
||||
#define MTK_SYS_POWERINFO 149
|
||||
#define MTK_SYS_FBFLIP 150
|
||||
#define MTK_SYS_GETEXECPATH 151
|
||||
/* @SYSCALLS-END */
|
||||
|
||||
#define MTK_SOCK_TCP 1
|
||||
@@ -410,6 +411,10 @@ static inline int mtk_getargs(char *buf, unsigned long max_len) {
|
||||
return (int)_mtk_syscall2(MTK_SYS_GETARGS, (long)buf, (long)max_len);
|
||||
}
|
||||
|
||||
static inline int mtk_getexecpath(char *buf, unsigned long maxLen) {
|
||||
return (int)mtk_syscall2(MTK_SYS_GETEXECPATH, (long)buf, (long)maxLen);
|
||||
}
|
||||
|
||||
static inline int mtk_chdir(const char *path) {
|
||||
return (int)_mtk_syscall1(MTK_SYS_CHDIR, (long)path);
|
||||
}
|
||||
|
||||
@@ -31,8 +31,9 @@ static inline long _sys2(long nr, long a1, long a2) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define SYS_EXIT 0
|
||||
#define SYS_GETARGS 25
|
||||
#define SYS_EXIT 0
|
||||
#define SYS_GETARGS 25
|
||||
#define SYS_GETEXECPATH 151
|
||||
|
||||
extern int main(int argc, char** argv);
|
||||
|
||||
@@ -71,12 +72,17 @@ static void _run_fini_array(void) {
|
||||
void _start(void) {
|
||||
/* Static: 4 KiB args + 256 argv slots would crowd a 32 KiB stack. */
|
||||
static char argbuf[4096];
|
||||
static char pathbuf[256];
|
||||
static char* argv[256];
|
||||
int len = (int)_sys2(SYS_GETARGS, (long)argbuf, (long)sizeof(argbuf));
|
||||
|
||||
int argc = 0;
|
||||
|
||||
argv[argc++] = (char*)"prog";
|
||||
/* Real argv[0]: tools like the GCC driver relocate their install
|
||||
prefix from it, so "prog" placeholders send them to garbage
|
||||
paths. Fall back to "prog" on kernels without the syscall. */
|
||||
int plen = (int)_sys2(SYS_GETEXECPATH, (long)pathbuf, (long)sizeof(pathbuf));
|
||||
argv[argc++] = (plen > 0) ? pathbuf : (char*)"prog";
|
||||
|
||||
if (len > 0) {
|
||||
if (len > (int)sizeof(argbuf) - 1) {
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user