diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 90827dd..661def4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -208,6 +208,10 @@ jobs: - name: This package's own tests run: | + # The run's own status decides as well: through `tee' without + # pipefail a program that failed to compile in a subdirectory of + # tests/ passed the step, since the list below names tests/*.cpp only. + set -o pipefail mcpp test 2>&1 | tee tests.log # A suite that discovered nothing reports success, so every suite is # asserted to have run. The list is derived from the files present @@ -468,15 +472,22 @@ jobs: rm -f "$RUNNER_TEMP/android.bad" echo "both Android ABIs build from this implementation unchanged, and name no C library symbol" - # A THIRTY-TWO BIT BUILD RUNS (openkal 0.25.1, clause 5.5). The same - # sources, standalone, for i386: built with the toolchain's clang and lld - # and RUN here, since an x86_64 kernel executes a static i386 program. A - # file past four gibibytes, a task with its own thread-local storage and a - # sleep through the sixty-four bit clock; the conformance suite runs for - # i686 where the family's C library and C++ runtime are built for it. - - name: An i386 build of this implementation runs + # THE ARCHITECTURES THIS MACHINE DOES NOT RUN NATIVELY RUN (tools/arch-check.sh). + # The same sources, standalone, built with the toolchain's clang and lld: + # i386 (openkal 0.25.1, clause 5.5) runs here, since an x86_64 kernel + # executes a static i386 program; riscv64 runs under qemu's user-mode + # translator. Each architecture's gate and numbers, the kernel's records, the + # thread pointer, the clock, a handler's record with the frame chain, and + # published instructions; the conformance suite runs for these rows where + # the family's C library and C++ runtime are built for them. + - name: The i386 and riscv64 builds of this implementation run if: matrix.toolchain == 'llvm@22.1.8' - run: OPENKAL_INCLUDE="$PWD/.spec/include" bash tools/word32-check.sh + run: | + set -euo pipefail + sudo apt-get install -y -qq qemu-user > /dev/null + for arch in i386 riscv64; do + OPENKAL_INCLUDE="$PWD/.spec/include" bash tools/arch-check.sh "$arch" + done # A checker is only useful if it fails when it should. - name: The independence check detects a dependence diff --git a/README.md b/README.md index c75e7cd..8a8cb8f 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,39 @@ for Linux, written on the kernel's own system-call interface. openkal = "0.26.0" [target.'cfg(os = "linux")'.dependencies] -openkal-linux = "0.27.0" +openkal-linux = "0.27.1" ``` +## What 0.27.1 adds + +**riscv64.** The kernel's riscv64 gate (`ecall`, the number in `a7`, the arguments in +`a0` to `a5`) beside aarch64's, over the one table of numbers both take from the +kernel's architecture-independent header; riscv64 has no `renameat`, and a rename +that replaces is `renameat2` without flags there (`okl::renameat`). The thread pointer +is `tp`, the storage beginning at it (variant I without a gap); `_start` sets the +global pointer before anything else; `clone` is the generic order. Its kernel's +records: the `O_DIRECTORY` and `O_NOFOLLOW` of the architecture-independent header, +which x86_64 and i386 take as well, and a handler's record without a restorer (the +kernel returns through its vDSO's `__vdso_rt_sigreturn`), which every unit builds +through `okl::handler_action`; the clock is the vDSO's `__vdso_clock_gettime`. A +sample and a fault report read the context's `pc`, `sp` and `s0`, and the frame chain +from the two words below each frame pointer. Published instructions are made visible +to the instruction path through `riscv_flush_icache`, the maintenance the kernel +offers as a call of its own (`kal_exec_publish`, `kal_exec_publish_part`). + +**A frame chain without `process_vm_readv`.** A kernel built without +CROSS_MEMORY_ATTACH, and qemu's user-mode translator (measured with 8.2.2), answer +ENOSYS, and every sample and fault report then ended at its first frame. The words +of a frame pass through a pipe of the read's own instead, whose write answers EFAULT +for an address that cannot be read. + +`tools/arch-check.sh` (formerly `tools/word32-check.sh`) builds the implementation +standalone for i386 and riscv64 and runs `tests/arch/runs.cpp`, i386 on the x86_64 +machine and riscv64 under `qemu-riscv64`: a file past four gibibytes, a node's kind +and size, a directory made, opened and listed, a rename into it, a task with its own +thread-local storage, the clock, the processor time, a sample holding the frames +above the work, and published instructions run. + ## What 0.27 changes (openkal 0.26) **A start is bounded by the kernel alone** (clause 7.6). An argument vector or an diff --git a/mcpp.toml b/mcpp.toml index 33795fe..0c6340b 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-linux" -version = "0.27.0" +version = "0.27.1" description = "The reference implementation of openkal for Linux, written on the kernel's own system-call interface so that it can be placed beneath a C library as well as above one." license = "Apache-2.0" @@ -95,10 +95,10 @@ flags = [ "-fno-asynchronous-unwind-tables"] }, ] -# tests/word32/ is built standalone for i386 by tools/word32-check.sh, with the C library facilities -# it supplies itself; the host's test programs are the others. +# tests/arch/ is built standalone for i386 and riscv64 by tools/arch-check.sh, with the C library +# facilities it supplies itself; the host's test programs are the others. [test] -discover = ["tests/**/*.cpp", "!tests/word32/**"] +discover = ["tests/**/*.cpp", "!tests/arch/**"] [features] default = [] diff --git a/src/env.cpp b/src/env.cpp index 128f750..b7f0913 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -137,7 +137,8 @@ bool recover(char*** argv_out, int* argc_out, char*** envp_out) { // started program the disposition this one was started with (process.cpp). [[gnu::constructor(101)]] void quiet_the_signal_openkal_cannot_report() { using okl::k_sigaction; - k_sigaction ignore{ reinterpret_cast(1) /* SIG_IGN */, 0, nullptr, 0 }; + k_sigaction ignore{}; + ignore.handler = reinterpret_cast(1); // SIG_IGN k_sigaction found{}; if (!okl::failed(okl::sys(okl::nr_rt_sigaction, 13 /* SIGPIPE */, reinterpret_cast(&ignore), diff --git a/src/exec.cpp b/src/exec.cpp index fb9b9ea..75fe60c 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -56,6 +56,16 @@ bool branch_targets() { return false; #endif } +// The instruction path made to observe the data path's writes, where the +// environment offers it as a call of its own (kal_exec_publish). +void sync_instructions(void* at, okl_uptr bytes) { +#if defined(__riscv) + const auto from = reinterpret_cast(at); + okl::sys(okl::nr_riscv_flush_icache, from, from + static_cast(bytes), 0); +#else + (void)at; (void)bytes; +#endif +} } // namespace extern "C" { @@ -136,6 +146,10 @@ int kal_exec_publish(void* p, kal_uintptr size) { // // All three agree about what the PROGRAM must do, which is what the // specification actually states. + // + // riscv64 is the case the rule names: its kernel offers the maintenance as + // a system call (`riscv_flush_icache'), so it is performed there. + sync_instructions(p, bytes); return kal_ok; } @@ -150,7 +164,9 @@ int kal_exec_publish_part(void* region, kal_uintptr offset, kal_uintptr size) { const okl_long r = okl::sys(okl::nr_mprotect, reinterpret_cast(static_cast(region) + offset), static_cast(size), okl::prot_read | okl::prot_exec); - return okl::failed(r) ? okl::translate(r) : kal_ok; + if (okl::failed(r)) return okl::translate(r); + sync_instructions(static_cast(region) + offset, size); + return kal_ok; } // SEALED READ-ONLY (0.23): the protection, and, for ever, `mseal' (Linux 6.10) diff --git a/src/fs.cpp b/src/fs.cpp index a3f30ff..e41b380 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -826,8 +826,7 @@ int kal_fs_rename(kal_dir from, const char* a, kal_uintptr alen, okl::terminated ta(a, alen), tb(b, blen); if (!ta.ok || !tb.ok) return kal_err_invalid; if (refused_write(f) || refused_write(t2)) return kal_err_permission; - const okl_long r = okl::sys(okl::nr_renameat, f, reinterpret_cast(ta.buf), - t2, reinterpret_cast(tb.buf)); + const okl_long r = okl::renameat(f, ta.buf, t2, tb.buf); if (okl::failed(r)) return okl::translate(r); wrote(f, a, alen); wrote(t2, b, blen); diff --git a/src/observe.cpp b/src/observe.cpp index a690bf0..d792526 100644 --- a/src/observe.cpp +++ b/src/observe.cpp @@ -42,10 +42,28 @@ bool peek(okl_uptr at, void* out, okl_uptr n) { iov local{ out, n }; iov remote{ reinterpret_cast(at), n }; static okl_long self = 0; + static int readv_absent = 0; if (self == 0) self = okl::sys(okl::nr_getpid); - const okl_long r = okl::sys(okl::nr_process_vm_readv, self, reinterpret_cast(&local), 1, - reinterpret_cast(&remote), 1, 0); - return r == static_cast(n); + if (!__atomic_load_n(&readv_absent, __ATOMIC_RELAXED)) { + const okl_long r = okl::sys(okl::nr_process_vm_readv, self, reinterpret_cast(&local), 1, + reinterpret_cast(&remote), 1, 0); + if (r != -okl::e_nosys) return r == static_cast(n); + __atomic_store_n(&readv_absent, 1, __ATOMIC_RELAXED); + } + // WITHOUT `process_vm_readv' (a kernel built without CROSS_MEMORY_ATTACH; + // qemu's user-mode translator answers ENOSYS, measured with 8.2.2 on + // riscv64, and every chain then ended at its first frame) the bytes pass + // through a pipe of this call's own: its write answers EFAULT for an address + // that cannot be read, and no other context shares it. + int fds[2] = { -1, -1 }; + if (okl::failed(okl::sys(okl::nr_pipe2, reinterpret_cast(fds), okl::o_cloexec))) return false; + const bool ok = okl::sys(okl::nr_write, fds[1], static_cast(at), static_cast(n)) + == static_cast(n) + && okl::sys(okl::nr_read, fds[0], reinterpret_cast(out), static_cast(n)) + == static_cast(n); + okl::sys(okl::nr_close, fds[0]); + okl::sys(okl::nr_close, fds[1]); + return ok; } // --- writing without a C library ------------------------------------------ @@ -244,10 +262,27 @@ frame_regs from_context(void* uc) { okl::copy(&r.fp, b + mc + 8 + 29 * 8, 8); okl::copy(&r.sp, b + mc + 8 + 31 * 8, 8); okl::copy(&r.pc, b + mc + 8 + 32 * 8, 8); +#elif defined(__riscv) + // flags, link, stack (24), the signal mask with its reserve (128), then + // the sigcontext at a sixteen-byte boundary (its floating-point state is + // aligned so): pc, then x1..x31 --- ra, sp at x2, the frame pointer s0 at x8. + constexpr okl_uptr mc = 176; + okl::copy(&r.pc, b + mc, 8); + okl::copy(&r.sp, b + mc + 2 * 8, 8); + okl::copy(&r.fp, b + mc + 8 * 8, 8); #endif return r; } +// Where a frame's record {the caller's frame pointer, the return address} lies +// relative to the frame pointer: at it on x86_64, i386 and aarch64; on riscv64 +// the frame pointer is the frame's top, and the record is the two words below. +#if defined(__riscv) +constexpr okl_uptr frame_record_below = 2 * sizeof(okl_uptr); +#else +constexpr okl_uptr frame_record_below = 0; +#endif + // The return addresses of a chain of frame pointers. int walk(frame_regs r, okl_uptr* pcs, int max) { int n = 0; @@ -256,7 +291,7 @@ int walk(frame_regs r, okl_uptr* pcs, int max) { for (int i = 0; i < 256 && n < max; ++i) { if (fp == 0 || (fp & (sizeof(okl_uptr) - 1)) != 0 || fp < r.sp) break; okl_uptr pair[2]; - if (!peek(fp, pair, sizeof pair)) break; + if (!peek(fp - frame_record_below, pair, sizeof pair)) break; if (pair[1] == 0) break; pcs[n++] = pair[1]; if (pair[0] <= fp) break; // a chain runs toward older frames @@ -309,7 +344,7 @@ void report(int signo, void* info, void* uc) { using okl::k_sigaction; -constexpr unsigned long sa_siginfo = 4, sa_onstack = 0x08000000, sa_restorer = 0x04000000, +constexpr unsigned long sa_siginfo = 4, sa_onstack = 0x08000000, sa_resethand = 0x80000000, sa_restart = 0x10000000; alignas(16) unsigned char g_alt_stack[256 * 1024]; @@ -331,9 +366,8 @@ alignas(16) unsigned char g_alt_stack[256 * 1024]; // A disposition the program was started with, other than the default, // is the program's to keep. if (old.handler != nullptr) continue; - k_sigaction act{ reinterpret_cast(&okl_fault_handler), - sa_siginfo | sa_onstack | sa_restorer, - reinterpret_cast(&okl_signal_return), 0 }; + k_sigaction act = okl::handler_action(reinterpret_cast(&okl_fault_handler), + sa_siginfo | sa_onstack); okl::sys(okl::nr_rt_sigaction, signo, reinterpret_cast(&act), 0, sizeof act.mask); } } @@ -542,8 +576,8 @@ int kal_prof_sample_begin(kal_u32 per_second) { g_ring.ready = reinterpret_cast(m + static_cast(cap * sizeof(kal_prof_sample))); g_ring.cap = cap; } - k_sigaction act{ reinterpret_cast(&okl_sample_handler), sa_siginfo | sa_restart | sa_restorer, - reinterpret_cast(&okl_signal_return), 0 }; + k_sigaction act = okl::handler_action(reinterpret_cast(&okl_sample_handler), + sa_siginfo | sa_restart); if (okl::failed(okl::sys(okl::nr_rt_sigaction, 27 /* SIGPROF */, reinterpret_cast(&act), reinterpret_cast(&g_prof_before), sizeof act.mask))) return kal_err_not_supported; @@ -608,8 +642,8 @@ int kal_prof_touch_begin(const void* at, kal_uintptr size) { if (now.handler != reinterpret_cast(&okl_fault_handler)) { g_segv_before = now; g_segv_replaced = true; - k_sigaction act{ reinterpret_cast(&okl_fault_handler), sa_siginfo | sa_onstack | sa_restorer, - reinterpret_cast(&okl_signal_return), 0 }; + k_sigaction act = okl::handler_action(reinterpret_cast(&okl_fault_handler), + sa_siginfo | sa_onstack); okl::sys(okl::nr_rt_sigaction, 11, reinterpret_cast(&act), 0, sizeof act.mask); } const int k = __atomic_load_n(&g_part_count, __ATOMIC_ACQUIRE); diff --git a/src/process.cpp b/src/process.cpp index 65cca18..f33693a 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -772,7 +772,7 @@ int start_image(void* arg) { // SIGPIPE AS THIS PROGRAM WAS STARTED WITH, not as this implementation // set it for its own writes (env.cpp): an ignore would outlive `execve'. if (!okl::g_pipe_started_ignored) { - okl::k_sigaction standard{ nullptr /* SIG_DFL */, 0, nullptr, 0 }; + okl::k_sigaction standard{}; // SIG_DFL okl::sys(okl::nr_rt_sigaction, 13 /* SIGPIPE */, reinterpret_cast(&standard), 0, sizeof standard.mask); } diff --git a/src/start.cpp b/src/start.cpp index 29acb92..ed01e55 100644 --- a/src/start.cpp +++ b/src/start.cpp @@ -106,6 +106,28 @@ __asm__( " brk #0\n" ".size _start,.-_start\n" ); +#elif defined(__riscv) +// The global pointer is established first, without relaxation: a relaxed +// `lla' would itself be addressed through the register it sets. +__asm__( +".text\n" +".globl _start\n" +".type _start,%function\n" +"_start:\n" +" .weak __global_pointer$\n" +" .hidden __global_pointer$\n" +" .option push\n" +" .option norelax\n" +" lla gp, __global_pointer$\n" +" .option pop\n" +" li fp,0\n" +" li ra,0\n" +" mv a0,sp\n" +" andi sp,sp,-16\n" +" call __okl_start_c\n" +" ebreak\n" +".size _start,.-_start\n" +); #endif extern "C" [[noreturn]] void __okl_start_c(long* sp) { diff --git a/src/sys.h b/src/sys.h index 320baf6..5f33a2c 100644 --- a/src/sys.h +++ b/src/sys.h @@ -142,8 +142,13 @@ enum : okl_long { nr_landlock_restrict_self = 446, nr_sysinfo = 99, }; -#elif defined(__aarch64__) +#elif defined(__aarch64__) || (defined(__riscv) && __riscv_xlen == 64) +// TWO ARCHITECTURES, ONE TABLE. aarch64 and riscv64 take the kernel's +// architecture-independent numbers (include/uapi/asm-generic/unistd.h); they +// differ in the gate and its registers, and riscv64 has no `renameat', which +// `okl::renameat' below reaches through `renameat2'. +#if defined(__aarch64__) #define OKL_SVC(...) \ register okl_long x8 __asm__("x8") = n; \ register okl_long x0 __asm__("x0") = a0; \ @@ -199,6 +204,58 @@ inline okl_long sys(okl_long n, okl_long a, okl_long b, okl_long c, okl_long d, : "r"(x8) : "memory", "cc"); return x0; } +#else +// THE GATE IS `ecall', the number in a7 and the arguments in a0 to a5; the +// result returns in a0. Every argument register is an in/out operand, as on the +// other architectures: a system-call translator may leave them rewritten. +inline okl_long sys(okl_long n) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0"); + __asm__ __volatile__("ecall" : "=r"(a0) : "r"(a7) : "memory"); + return a0; +} +inline okl_long sys(okl_long n, okl_long a) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0") = a; + __asm__ __volatile__("ecall" : "+r"(a0) : "r"(a7) : "memory"); + return a0; +} +inline okl_long sys(okl_long n, okl_long a, okl_long b) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0") = a; + register okl_long a1 __asm__("a1") = b; + __asm__ __volatile__("ecall" : "+r"(a0), "+r"(a1) : "r"(a7) : "memory"); + return a0; +} +inline okl_long sys(okl_long n, okl_long a, okl_long b, okl_long c) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0") = a; + register okl_long a1 __asm__("a1") = b; register okl_long a2 __asm__("a2") = c; + __asm__ __volatile__("ecall" : "+r"(a0), "+r"(a1), "+r"(a2) : "r"(a7) : "memory"); + return a0; +} +inline okl_long sys(okl_long n, okl_long a, okl_long b, okl_long c, okl_long d) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0") = a; + register okl_long a1 __asm__("a1") = b; register okl_long a2 __asm__("a2") = c; + register okl_long a3 __asm__("a3") = d; + __asm__ __volatile__("ecall" : "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3) : "r"(a7) : "memory"); + return a0; +} +inline okl_long sys(okl_long n, okl_long a, okl_long b, okl_long c, okl_long d, okl_long e) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0") = a; + register okl_long a1 __asm__("a1") = b; register okl_long a2 __asm__("a2") = c; + register okl_long a3 __asm__("a3") = d; register okl_long a4 __asm__("a4") = e; + __asm__ __volatile__("ecall" : "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), "+r"(a4) + : "r"(a7) : "memory"); + return a0; +} +inline okl_long sys(okl_long n, okl_long a, okl_long b, okl_long c, okl_long d, + okl_long e, okl_long f) { + register okl_long a7 __asm__("a7") = n; register okl_long a0 __asm__("a0") = a; + register okl_long a1 __asm__("a1") = b; register okl_long a2 __asm__("a2") = c; + register okl_long a3 __asm__("a3") = d; register okl_long a4 __asm__("a4") = e; + register okl_long a5 __asm__("a5") = f; + __asm__ __volatile__("ecall" : "+r"(a0), "+r"(a1), "+r"(a2), "+r"(a3), "+r"(a4), "+r"(a5) + : "r"(a7) : "memory"); + return a0; +} +#endif enum : okl_long { nr_getcwd = 17, nr_ioctl = 29, nr_mkdirat = 34, nr_unlinkat = 35, @@ -209,7 +266,12 @@ enum : okl_long { nr_nanosleep = 101, nr_clock_gettime = 113, nr_clock_getres = 114, nr_sched_yield = 124, nr_kill = 129, nr_tgkill = 131, nr_gettid = 178, nr_getpid = 172, nr_mmap = 222, nr_munmap = 215, nr_mprotect = 226, nr_msync = 227, - nr_clone = 220, nr_execve = 221, nr_wait4 = 260, nr_renameat = 38, +#if defined(__aarch64__) + nr_renameat = 38, +#else + nr_renameat = -1, +#endif + nr_clone = 220, nr_execve = 221, nr_wait4 = 260, nr_dup3 = 24, nr_execveat = 281, nr_close_range = 436, nr_prlimit64 = 261, nr_dup2 = -1, nr_fcntl = 25, nr_prctl = 167, nr_sched_getaffinity = 123, nr_getppid = 173, @@ -243,6 +305,11 @@ enum : okl_long { nr_setitimer = 103, nr_rt_sigreturn = 139, nr_process_vm_readv = 270, nr_landlock_create_ruleset = 444, nr_landlock_add_rule = 445, nr_landlock_restrict_self = 446, nr_sysinfo = 179, +#if defined(__riscv) + // Only here: the instruction cache made to observe the data path's writes + // (arch/riscv/include/uapi/asm/unistd.h, __NR_arch_specific_syscall + 15). + nr_riscv_flush_icache = 259, +#endif }; #elif defined(__i386__) @@ -343,7 +410,7 @@ enum : okl_long { }; #else -#error "openkal-linux supports x86_64, aarch64 and i386" +#error "openkal-linux supports x86_64, aarch64, riscv64 and i386" #endif // --- error values, as the kernel returns them ------------------------------ @@ -367,11 +434,12 @@ enum : int { // THREE OF THESE ARE NOT THE SAME NUMBER ON BOTH ARCHITECTURES, AND WERE // WRITTEN AS THOUGH THEY WERE. // -// `O_DIRECTORY', `O_NOFOLLOW' and `O_DIRECT' have one set of values on x86_64 -// and another in the kernel's architecture-independent header, which is what -// aarch64 uses. The three values below were x86_64's: +// `O_DIRECTORY', `O_NOFOLLOW' and `O_DIRECT' have one set of values in the +// kernel's architecture-independent header (include/uapi/asm-generic/fcntl.h), +// which x86_64, i386 and riscv64 take, and another in aarch64's own +// (arch/arm64/include/uapi/asm/fcntl.h). The three values below were x86_64's: // -// x86_64 aarch64 (asm-generic) +// asm-generic aarch64 // O_DIRECTORY 0200000 040000 // O_NOFOLLOW 0400000 0100000 // O_DIRECT 040000 0200000 @@ -431,10 +499,10 @@ enum : okl_long { // "End this context when the one that started it ends", which is what // binding a started program's lifetime is expressed as here. pr_set_pdeathsig = 1, -#if defined(__x86_64__) || defined(__i386__) - o_directory = 0200000, o_nofollow = 0400000, -#else +#if defined(__aarch64__) o_directory = 040000, o_nofollow = 0100000, +#else + o_directory = 0200000, o_nofollow = 0400000, #endif at_fdcwd = -100, at_removedir = 0x200, at_symlink_nofollow = 0x100, prot_read = 1, prot_write = 2, prot_exec = 4, prot_none = 0, @@ -646,8 +714,15 @@ constexpr okl_uptr si_code_at = 8; constexpr okl_uptr si_fields_at = sizeof(void*) == 8 ? 16 : 12; constexpr okl_uptr si_pid_at = si_fields_at; constexpr okl_uptr si_status_at = si_fields_at + 8; +// riscv64 has no SA_RESTORER: its record has no restorer field, and the kernel +// returns from every handler through its vDSO's `__vdso_rt_sigreturn'. A +// restorer written there would be read as the mask. +#if defined(__riscv) +struct k_sigaction { void* handler; okl_ulong flags; ksigset mask; }; +#else struct k_sigaction { void* handler; okl_ulong flags; void* restorer; ksigset mask; }; constexpr okl_ulong sa_restorer_flag = 0x04000000u; // SA_RESTORER +#endif // The return from a handler this implementation installs, which a handler // installed without a C library must name on x86_64 and i386: one sequence @@ -655,6 +730,19 @@ constexpr okl_ulong sa_restorer_flag = 0x04000000u; // SA_RESTORER // unit's symbol outside this namespace (the independence check). void* signal_return(); +// A handler's record, with this implementation's return where the record has +// one. Every unit that installs a handler with a restorer builds it here. +inline k_sigaction handler_action(void* handler, okl_ulong flags) { + k_sigaction act{}; + act.handler = handler; + act.flags = flags; +#if !defined(__riscv) + act.flags |= sa_restorer_flag; + act.restorer = signal_return(); +#endif + return act; +} + // --- the calls whose arguments are not the same on every architecture ---------- // // EVERY CALLER USES THESE, ON EVERY ARCHITECTURE. On x86_64 and aarch64 each is @@ -714,6 +802,15 @@ inline okl_long openat(okl_long dirfd, okl_long path, okl_long flags, okl_long m return sys(nr_openat, dirfd, path, flags, mode); } +// A rename that replaces: `renameat2' without flags where the table has no +// `renameat' (riscv64), the same call. +inline okl_long renameat(okl_long from, const char* a, okl_long to, const char* b) { + if constexpr (nr_renameat < 0) + return sys(nr_renameat2, from, reinterpret_cast(a), to, reinterpret_cast(b), 0); + else + return sys(nr_renameat, from, reinterpret_cast(a), to, reinterpret_cast(b)); +} + inline okl_long fstat(okl_long fd, kstat* st) { #if defined(__i386__) return statx_into(fd, "", 0x1000 /* AT_EMPTY_PATH */, st); diff --git a/src/task.cpp b/src/task.cpp index 2d73af5..65b8e9e 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -119,6 +119,33 @@ __asm__( " svc #0\n" ".size __okl_clone,.-__okl_clone\n" ); +#elif defined(__riscv) +__asm__( +".text\n" +".globl __okl_clone\n" +".hidden __okl_clone\n" +".type __okl_clone,%function\n" +"__okl_clone:\n" // a0=fn a1=stack a2=flags a3=arg a4=ptid a5=tls a6=ctid +" andi a1,a1,-16\n" +" addi a1,a1,-16\n" +" sd a0,0(a1)\n" +" sd a3,8(a1)\n" +" slli a0,a2,32\n" // the flags, zero-extended +" srli a0,a0,32\n" +" mv a2,a4\n" +" mv a3,a5\n" +" mv a4,a6\n" +" li a7,220\n" // SYS_clone +" ecall\n" +" beqz a0,1f\n" +" ret\n" +"1:ld a1,0(sp)\n" +" ld a0,8(sp)\n" +" jalr a1\n" +" li a7,93\n" // SYS_exit, this context only +" ecall\n" +".size __okl_clone,.-__okl_clone\n" +); #endif // In both arrangements: a program is started by it as well (process.cpp, diff --git a/src/time.cpp b/src/time.cpp index 54210a5..9505abd 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -29,7 +29,7 @@ struct elf_phdr { unsigned type, flags; okl_u64 offset, vaddr, paddr, filesz, me struct elf_dyn { long long tag; okl_u64 val; }; struct elf_sym { unsigned name; unsigned char info, other; unsigned short shndx; okl_u64 value, size; }; -#if defined(__x86_64__) +#if defined(__x86_64__) || defined(__riscv) constexpr const char kClockName[] = "__vdso_clock_gettime"; #else constexpr const char kClockName[] = "__kernel_clock_gettime"; diff --git a/src/tls.h b/src/tls.h index 792e7fa..908240b 100644 --- a/src/tls.h +++ b/src/tls.h @@ -178,6 +178,17 @@ inline tls_block make_tls(void* (*alloc)(okl_uptr, okl_uptr)) { fill(base, 0, b.bytes); if (im.data && im.filesz) copy(base + gap, im.data, im.filesz); b.tp = base; +#elif defined(__riscv) + // Variant I without a gap: the thread pointer addresses the first byte of + // the storage (the psABI's TLS offsets begin at zero), aligned as the + // segment states. + b.bytes = round_up(im.memsz, laid_out) + 64; + b.base = alloc(b.bytes, align); + if (!b.base) return b; + auto* base = static_cast(b.base); + fill(base, 0, b.bytes); + if (im.data && im.filesz) copy(base, im.data, im.filesz); + b.tp = base; #endif return b; } @@ -213,6 +224,8 @@ inline void set_thread_pointer(void* tp) { sys(nr_arch_prctl, 0x1002 /* ARCH_SET_FS */, reinterpret_cast(tp)); #elif defined(__aarch64__) __asm__ __volatile__("msr tpidr_el0, %0" :: "r"(tp)); +#elif defined(__riscv) + __asm__ __volatile__("mv tp, %0" :: "r"(tp)); #endif } diff --git a/tests/arch/runs.cpp b/tests/arch/runs.cpp new file mode 100644 index 0000000..46eee3b --- /dev/null +++ b/tests/arch/runs.cpp @@ -0,0 +1,155 @@ +// A build of this implementation for an architecture the building machine does not run natively +// runs: built standalone by tools/arch-check.sh, run on the machine that built it (i386: clause 5.5 +// of the specification, a thirty-two bit word with sixty-four bit positions and times) or under +// qemu's user-mode translator (riscv64). What differs between architectures is each a check: the +// gate and its numbers (a file past four gibibytes, a directory opened and listed, a rename), the +// kernel's records (a node's kind and size), the thread pointer (a task with its own thread-local +// storage), the clock, a handler's record and the frame chain (a sample of the program's own stack), +// and published instructions run. The program supplies the C library facilities the compiler calls. +#include +#include +#include +#include +#include +#include +#include +#include + +#if defined(__i386__) +#define OKL_ARCH "i386" +constexpr kal_uintptr word = 4; +// mov $42, %eax; ret +constexpr unsigned char answer_code[] = { 0xb8, 0x2a, 0x00, 0x00, 0x00, 0xc3 }; +#elif defined(__riscv) && __riscv_xlen == 64 +#define OKL_ARCH "riscv64" +constexpr kal_uintptr word = 8; +// li a0, 42; ret +constexpr unsigned char answer_code[] = { 0x13, 0x05, 0xa0, 0x02, 0x67, 0x80, 0x00, 0x00 }; +#else +#error "tests/arch/runs.cpp is built for i386 and riscv64 (tools/arch-check.sh)" +#endif + +static int failures = 0; +static void say(const char* s) { kal_uintptr n = 0; while (s[n]) ++n; kal_stream_write(kal_stdout(), s, n); } +static void check(bool ok, const char* what) { say(ok ? " ok " : " FAIL "); say(what); say("\n"); if (!ok) ++failures; } + +thread_local int tlv = 7; +static volatile int shared = 0; +static void task_body(void*) { tlv = 99; shared = tlv + 1; } + +// Work the sampler finds on the stack, two frames deep. +[[gnu::noinline]] static kal_u64 sampled_inner(kal_duration until) { + volatile kal_u64 sink = 0; + while (kal_time_monotonic() < until) sink = sink + 1; + return sink; +} +[[gnu::noinline]] static kal_u64 sampled(kal_duration ns) { return sampled_inner(kal_time_monotonic() + ns) + 1; } + +extern "C" int main(int, char**, char**) { + say("openkal-linux on " OKL_ARCH "\n"); + check(sizeof(void*) == word, "a pointer is the architecture's word"); + kal_dir work{}; + char name[256]; kal_uintptr name_len = 0; + const kal_uintptr n = kal_fs_preopen_count(); + bool found = false; + for (kal_uintptr i = 0; i < n && !found; ++i) + if (kal_fs_preopen(i, &work, name, sizeof name, &name_len) == kal_ok) { + found = true; // the first is the working directory + } + check(found, "a directory was supplied"); + kal_file f{}; + const char fname[] = "okl-arch-big"; + int rc = kal_fs_open(work, fname, sizeof fname - 1, KAL_OPEN_READ | KAL_OPEN_WRITE | KAL_OPEN_CREATE | KAL_OPEN_TRUNCATE, &f); + check(rc == kal_ok, "a file is created"); + const kal_u64 far = (kal_u64{5} << 30); + check(kal_fs_write_at(f, "0123456789", 10, far) == 10, "ten bytes are written at 5 GiB"); + char back[10] = {}; + check(kal_fs_read_at(f, back, 10, far) == 10 && back[0] == '0' && back[9] == '9', "they are read back at 5 GiB"); + kal_node_info info{}; info.self_size = sizeof info; + rc = kal_fs_file_info(f, KAL_INFO_SIZE, &info); + check(rc == kal_ok && info.size == far + 10, "the file's size is past 4 GiB"); + kal_u64 at = 0; + rc = kal_fs_seek(f, 0, KAL_SEEK_END, &at); + check(rc == kal_ok && at == far + 10, "a seek to the end answers a position past 4 GiB"); + kal_fs_close_file(f); + info = kal_node_info{}; info.self_size = sizeof info; + rc = kal_fs_info(work, fname, sizeof fname - 1, 0, KAL_INFO_KIND | KAL_INFO_SIZE, &info); + check(rc == kal_ok && info.kind == kal_node_file && info.size == far + 10, + "the kernel's record of the node: a file, of its size"); + const char dname[] = "okl-arch-dir", moved[] = "okl-arch-big2"; + check(kal_fs_mkdir(work, dname, sizeof dname - 1) == kal_ok, "a directory is made"); + kal_dir sub{}; + check(kal_fs_open_dir(work, dname, sizeof dname - 1, &sub) == kal_ok, "it is opened as a directory"); + check(kal_fs_rename(work, fname, sizeof fname - 1, sub, moved, sizeof moved - 1) == kal_ok, + "the file is renamed into it"); + kal_uintptr iter = 0; char entry[64]; kal_uintptr entry_len = 0; int kind = 0; int listed = 0; + if (kal_fs_list_begin(sub, &iter) == kal_ok) + while (kal_fs_list_next(sub, &iter, entry, sizeof entry, &entry_len, &kind) == kal_ok) + if (entry_len == sizeof moved - 1 && kind == kal_node_file) ++listed; + check(listed == 1, "the directory lists it"); + check(kal_fs_remove(sub, moved, sizeof moved - 1) == kal_ok, "the file is removed"); + kal_fs_close_dir(sub); + check(kal_fs_remove(work, dname, sizeof dname - 1) == kal_ok, "the directory is removed"); + kal_task t{}; + check(kal_task_start(task_body, nullptr, &t) == kal_ok, "a task starts"); + check(kal_task_join(t) == kal_ok, "it is joined"); + check(shared == 100, "the task saw its own thread-local value"); + check(tlv == 7, "this context's thread-local value is its own"); + const kal_duration before = kal_time_monotonic(); + kal_time_sleep(20u * 1000u * 1000u); + check(kal_time_monotonic() - before >= 20u * 1000u * 1000u, "a sleep of 20 ms lasts at least that"); + // The processor time is read through the sixty-four bit clock as well: worked for about + // 50 ms, it is more than 10 ms and less than the time since the program started. + const kal_duration spin = kal_time_monotonic(); + volatile kal_u64 sink = 0; + while (kal_time_monotonic() - spin < 50u * 1000u * 1000u) sink = sink + 1; + kal_process me{}; + kal_program_info pi{}; pi.self_size = sizeof pi; + check(kal_process_self(&me) == kal_ok && kal_process_info(me, KAL_PINFO_CPU, &pi) == kal_ok + && (pi.present & KAL_PINFO_CPU) && pi.cpu_ns > 10u * 1000u * 1000u + && pi.cpu_ns < kal_time_monotonic() - before + 1000u * 1000u * 1000u, + "the processor time counts the work done"); + kal_process_close(me); + // A handler's record and the frame chain: a sample of this program's stack names the work and + // the frames above it. + if (kal_prof_props() & KAL_PROF_PROP_SAMPLES) { + check(kal_prof_sample_begin(1000) == kal_ok, "sampling begins"); + sampled(200u * 1000u * 1000u); + static kal_prof_sample samples[64]; + const kal_intptr got = kal_prof_sample_take(samples, 64); + kal_prof_sample_end(); + bool deep = false; + for (kal_intptr i = 0; i < got; ++i) deep = deep || (samples[i].depth >= 3 && samples[i].pc[0] != 0); + check(got > 0 && deep, "a sample holds the work and the frames above it"); + } + // Published instructions run. + void* code = kal_exec_alloc(sizeof answer_code); + bool ran = false; + if (code != nullptr) { + auto* to = static_cast(code); + for (kal_uintptr i = 0; i < sizeof answer_code; ++i) to[i] = answer_code[i]; + if (kal_exec_publish(code, sizeof answer_code) == kal_ok) + ran = reinterpret_cast(code)() == 42; + kal_exec_free(code, sizeof answer_code); + } + check(ran, "published instructions run"); + say(failures ? "FAILED\n" : "all held\n"); + return failures; +} + +// What the compiler calls and a C library would supply. +extern "C" { +void* memcpy(void* d, const void* s, __SIZE_TYPE__ n) { auto* o = static_cast(d); auto* i = static_cast(s); while (n--) *o++ = *i++; return d; } +void* memset(void* d, int c, __SIZE_TYPE__ n) { auto* o = static_cast(d); while (n--) *o++ = static_cast(c); return d; } +unsigned long long __udivmoddi4(unsigned long long a, unsigned long long b, unsigned long long* rem) { + unsigned long long q = 0, r = 0; + for (int i = 63; i >= 0; --i) { + r = (r << 1) | ((a >> i) & 1u); + if (r >= b) { r -= b; q |= 1ull << i; } + } + if (rem) *rem = r; + return q; +} +unsigned long long __udivdi3(unsigned long long a, unsigned long long b) { return __udivmoddi4(a, b, nullptr); } +unsigned long long __umoddi3(unsigned long long a, unsigned long long b) { unsigned long long r; __udivmoddi4(a, b, &r); return r; } +} diff --git a/tests/word32/runs.cpp b/tests/word32/runs.cpp deleted file mode 100644 index bc67f27..0000000 --- a/tests/word32/runs.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// A thirty-two bit build of this implementation runs (clause 5.5 of the specification): built -// standalone for i386 by tools/word32-check.sh and run on the machine that built it. A file past -// four gibibytes, a task with its own thread-local storage, a sleep through the sixty-four bit -// clock. The program supplies the C library facilities the compiler calls. -#include -#include -#include -#include -#include -#include - -static int failures = 0; -static void say(const char* s) { kal_uintptr n = 0; while (s[n]) ++n; kal_stream_write(kal_stdout(), s, n); } -static void check(bool ok, const char* what) { say(ok ? " ok " : " FAIL "); say(what); say("\n"); if (!ok) ++failures; } - -thread_local int tlv = 7; -static volatile int shared = 0; -static void task_body(void*) { tlv = 99; shared = tlv + 1; } - -extern "C" int main(int, char**, char**) { - say("openkal-linux on i386\n"); - check(sizeof(void*) == 4, "a pointer is four bytes"); - kal_dir work{}; - char name[256]; kal_uintptr name_len = 0; - const kal_uintptr n = kal_fs_preopen_count(); - bool found = false; - for (kal_uintptr i = 0; i < n && !found; ++i) - if (kal_fs_preopen(i, &work, name, sizeof name, &name_len) == kal_ok) { - found = true; // the first is the working directory - } - check(found, "a directory was supplied"); - kal_file f{}; - const char fname[] = "okl-i386-big"; - int rc = kal_fs_open(work, fname, sizeof fname - 1, KAL_OPEN_READ | KAL_OPEN_WRITE | KAL_OPEN_CREATE | KAL_OPEN_TRUNCATE, &f); - check(rc == kal_ok, "a file is created"); - const kal_u64 far = (kal_u64{5} << 30); - check(kal_fs_write_at(f, "0123456789", 10, far) == 10, "ten bytes are written at 5 GiB"); - char back[10] = {}; - check(kal_fs_read_at(f, back, 10, far) == 10 && back[0] == '0' && back[9] == '9', "they are read back at 5 GiB"); - kal_node_info info{}; info.self_size = sizeof info; - rc = kal_fs_file_info(f, KAL_INFO_SIZE, &info); - check(rc == kal_ok && info.size == far + 10, "the file's size is past 4 GiB"); - kal_u64 at = 0; - rc = kal_fs_seek(f, 0, KAL_SEEK_END, &at); - check(rc == kal_ok && at == far + 10, "a seek to the end answers a position past 4 GiB"); - kal_fs_close_file(f); - check(kal_fs_remove(work, fname, sizeof fname - 1) == kal_ok, "the file is removed"); - kal_task t{}; - check(kal_task_start(task_body, nullptr, &t) == kal_ok, "a task starts"); - check(kal_task_join(t) == kal_ok, "it is joined"); - check(shared == 100, "the task saw its own thread-local value"); - check(tlv == 7, "this context's thread-local value is its own"); - const kal_duration before = kal_time_monotonic(); - kal_time_sleep(20u * 1000u * 1000u); - check(kal_time_monotonic() - before >= 20u * 1000u * 1000u, "a sleep of 20 ms lasts at least that"); - // The processor time is read through the sixty-four bit clock as well: worked for about - // 50 ms, it is more than 10 ms and less than the time since the program started. - const kal_duration spin = kal_time_monotonic(); - volatile kal_u64 sink = 0; - while (kal_time_monotonic() - spin < 50u * 1000u * 1000u) sink = sink + 1; - kal_process me{}; - kal_program_info pi{}; pi.self_size = sizeof pi; - check(kal_process_self(&me) == kal_ok && kal_process_info(me, KAL_PINFO_CPU, &pi) == kal_ok - && (pi.present & KAL_PINFO_CPU) && pi.cpu_ns > 10u * 1000u * 1000u - && pi.cpu_ns < kal_time_monotonic() - before + 1000u * 1000u * 1000u, - "the processor time counts the work done"); - kal_process_close(me); - say(failures ? "FAILED\n" : "all held\n"); - return failures; -} - -// What the compiler calls and a C library would supply. -extern "C" { -void* memcpy(void* d, const void* s, __SIZE_TYPE__ n) { auto* o = static_cast(d); auto* i = static_cast(s); while (n--) *o++ = *i++; return d; } -void* memset(void* d, int c, __SIZE_TYPE__ n) { auto* o = static_cast(d); while (n--) *o++ = static_cast(c); return d; } -unsigned long long __udivmoddi4(unsigned long long a, unsigned long long b, unsigned long long* rem) { - unsigned long long q = 0, r = 0; - for (int i = 63; i >= 0; --i) { - r = (r << 1) | ((a >> i) & 1u); - if (r >= b) { r -= b; q |= 1ull << i; } - } - if (rem) *rem = r; - return q; -} -unsigned long long __udivdi3(unsigned long long a, unsigned long long b) { return __udivmoddi4(a, b, nullptr); } -unsigned long long __umoddi3(unsigned long long a, unsigned long long b) { unsigned long long r; __udivmoddi4(a, b, &r); return r; } -} diff --git a/tools/arch-check.sh b/tools/arch-check.sh new file mode 100755 index 0000000..296c992 --- /dev/null +++ b/tools/arch-check.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +# Builds this implementation standalone for an architecture the building machine does not run +# natively, and runs tests/arch/runs.cpp: i386 on the machine that built it (an x86_64 kernel runs a +# static i386 program; clause 5.5 of the specification, a thirty-two bit word with sixty-four bit +# positions and times), riscv64 under qemu's user-mode translator. The full conformance suite runs +# for these rows where the C library and the C++ runtime of this family are built for them +# (openkal-platform). +# +# tools/arch-check.sh i386|riscv64 [LLVM_BIN] # default: the llvm payload mcpp installed +set -euo pipefail +here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +arch="${1:?usage: tools/arch-check.sh i386|riscv64 [LLVM_BIN]}" +spec="${OPENKAL_INCLUDE:-}" +llvm="${2:-$(ls -d "${MCPP_HOME:-$HOME/.mcpp}"/registry/data/xpkgs/xim-x-llvm/*/bin 2>/dev/null | sort -V | tail -1)}" +[ -x "$llvm/clang++" ] || { echo "no clang++ in '$llvm'" >&2; exit 2; } +if [ -z "$spec" ]; then + spec="$(ls -d "${MCPP_HOME:-$HOME/.mcpp}"/xpkgs/mcpplibs-x-openkal/*/openkal-*/include 2>/dev/null | sort -V | tail -1)" +fi +[ -d "$spec/openkal" ] || { echo "no openkal include directory (set OPENKAL_INCLUDE)" >&2; exit 2; } +case "$arch" in + i386) target=(--target=i686-linux-musl -march=i686); emulation=elf_i386; run=() ;; + # lld relaxes no general-dynamic TLS access on riscv64, and a static program has no + # `__tls_get_addr': the accesses are compiled as the static link resolves them. + riscv64) target=(--target=riscv64-linux-musl -march=rv64gc -mabi=lp64d -ftls-model=initial-exec) + emulation=elf64lriscv + run=("${QEMU_RISCV64:-qemu-riscv64}") + command -v "${run[0]}" > /dev/null || { echo "no ${run[0]} to run a riscv64 program" >&2; exit 2; } ;; + *) echo "unknown architecture '$arch'" >&2; exit 2 ;; +esac +out="$(mktemp -d)" +trap 'rm -rf "$out"' EXIT +flags=("${target[@]}" -std=c++23 -O1 -ffreestanding -fno-exceptions -fno-rtti -nostdlibinc -fPIC + -fno-omit-frame-pointer -DOKL_STANDALONE -D__OPENKAL__ -I"$spec" -Werror) +for f in "$here"/src/*.cpp "$here"/tests/arch/runs.cpp; do + "$llvm/clang++" "${flags[@]}" -c "$f" -o "$out/$(basename "$f" .cpp).o" +done +"$llvm/ld.lld" -m "$emulation" -static -e _start -o "$out/runs" "$out"/*.o +( cd "$out" && "${run[@]}" ./runs ) diff --git a/tools/word32-check.sh b/tools/word32-check.sh deleted file mode 100755 index c19d59c..0000000 --- a/tools/word32-check.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash -# Builds this implementation standalone for i386 and runs tests/word32/runs.cpp on the machine that -# built it (an x86_64 kernel runs a static i386 program). Clause 5.5 of the specification: a -# thirty-two bit word, sixty-four bit positions and times. The full conformance suite runs for -# i686 where the C library and the C++ runtime of this family are built for it (openkal-platform). -# -# tools/word32-check.sh [LLVM_BIN] # default: the llvm payload mcpp installed -set -euo pipefail -here="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" -spec="${OPENKAL_INCLUDE:-}" -llvm="${1:-$(ls -d "${MCPP_HOME:-$HOME/.mcpp}"/registry/data/xpkgs/xim-x-llvm/*/bin 2>/dev/null | sort -V | tail -1)}" -[ -x "$llvm/clang++" ] || { echo "no clang++ in '$llvm'" >&2; exit 2; } -if [ -z "$spec" ]; then - spec="$(ls -d "${MCPP_HOME:-$HOME/.mcpp}"/xpkgs/mcpplibs-x-openkal/*/openkal-*/include 2>/dev/null | sort -V | tail -1)" -fi -[ -d "$spec/openkal" ] || { echo "no openkal include directory (set OPENKAL_INCLUDE)" >&2; exit 2; } -out="$(mktemp -d)" -trap 'rm -rf "$out"' EXIT -flags=(--target=i686-linux-musl -march=i686 -std=c++23 -O1 -ffreestanding -fno-exceptions -fno-rtti - -nostdlibinc -fPIC -DOKL_STANDALONE -D__OPENKAL__ -I"$spec" -Werror) -for f in "$here"/src/*.cpp "$here"/tests/word32/runs.cpp; do - "$llvm/clang++" "${flags[@]}" -c "$f" -o "$out/$(basename "$f" .cpp).o" -done -"$llvm/ld.lld" -m elf_i386 -static -e _start -o "$out/runs" "$out"/*.o -( cd "$out" && ./runs )