From 2517d144f50040fd682a33632254a7b209dea59f Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 15 Nov 2026 19:13:27 +0900 Subject: [PATCH] 0.23.4: the stub of libSystem lists __bzero for x86_64 Clang lowers a zeroing memset to __bzero on this system's x86_64, and this package's objects carry such stores in a release build (src/process.cpp, src/fs.cpp). A link with no SDK, which the stub serves, stopped at `undefined symbol: __bzero', so a release build for x86_64-macos-musl failed for every program. The stub lists the name for x86_64; the program binds it to the system's library when it runs. CI links such a program on Linux, this working tree as the kernel-abi layer of openkal-platform's hosted arrangement, and runs it on an Intel Mac. --- .github/workflows/ci.yml | 73 ++++++++++++++++++++++++++++++++++++++++ README.md | 12 ++++++- mcpp.toml | 2 +- port/libSystem.tbd | 10 ++++++ 4 files changed, 95 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3b24b15..9e0fb7d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -505,6 +505,79 @@ jobs: if-no-files-found: ignore retention-days: 7 + # --------------------------------------------------------------------------- + # x86_64 WITHOUT AN SDK (0.23.4): a release build of a program above this + # package, linked on Linux for x86_64-macos-musl through openkal-platform's + # hosted arrangement (the stub of libSystem supplied, no SDK on the link), and + # run on an Intel Mac. Clang lowers a zeroing `memset' to `__bzero' on that + # architecture, which the stub did not list (undefined symbol: __bzero). + x86_64-no-sdk-link: + name: x86_64, linked with no SDK + runs-on: ubuntu-24.04 + timeout-minutes: 45 + steps: + - uses: actions/checkout@v4 + with: { path: openkal-macos } + - name: Install xlings and mcpp + run: | + curl -fsSL https://raw.githubusercontent.com/openxlings/xlings/main/tools/other/quick_install.sh | bash -s "$XLINGS_VERSION" + echo "$HOME/.xlings/subos/current/bin" >> "$GITHUB_PATH" + - name: mcpp + run: | + for attempt in 1 2 3 4 5; do + xlings update > /dev/null 2>&1 || true + xlings install "mcpp@$MCPP_VERSION" -y -g && break + [ "$attempt" = 5 ] && { echo "::error::mcpp could not be installed"; exit 1; } + sleep 60 + done + mcpp self config --mirror GLOBAL + - name: A release build, this package as the kernel-abi layer + run: | + set -euo pipefail + mkdir -p probe/src + cat > probe/mcpp.toml <<'TOML' + [package] + name = "zeroing" + version = "0.1.0" + [targets.zeroing] + kind = "bin" + main = "src/main.c" + [target.x86_64-macos-musl] + platform = "openkal-platform@0.28.0" + [target.x86_64-macos-musl.layers] + kernel-abi = { path = "../openkal-macos" } + TOML + cat > probe/src/main.c <<'C' + #include + #include + int main(int argc, char **argv) { + char b[256]; + memset(b, 0, sizeof b); + snprintf(b, sizeof b, "zeroed, %d argument(s)", argc - 1); + puts(b); + return 0; + } + C + cd probe + mcpp build --release --target x86_64-macos-musl 2>&1 | tee build.log + grep -q 'openkal-macos@0.23.4' build.log || { echo "::error::the working tree was not the kernel-abi layer"; exit 1; } + mkdir -p ../out && cp "$(find target -name zeroing -type f | head -1)" ../out/ + - uses: actions/upload-artifact@v4 + with: { name: zeroing-x86_64, path: out/ } + + x86_64-no-sdk-run: + name: x86_64, run on an Intel Mac + needs: x86_64-no-sdk-link + runs-on: macos-15-intel + timeout-minutes: 15 + steps: + - uses: actions/download-artifact@v4 + with: { name: zeroing-x86_64, path: out } + - name: Run + run: | + chmod +x out/zeroing + test "$(out/zeroing one two)" = "zeroed, 2 argument(s)" + # --------------------------------------------------------------------------- # EVERY JOB'S RUNS AS ONE REPORT (`mtest ci report`, the workflow run's group). report: diff --git a/README.md b/README.md index dcb4574..e6b0d61 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ written on the kernel's own calls. openkal = "0.25.0" [target.'cfg(os = "macos")'.dependencies] -openkal-macos = "0.23.3" +openkal-macos = "0.23.4" ``` Its purpose is as much to test the specification as to be used. A specification @@ -183,6 +183,16 @@ same image parses as fast on Linux arm64. Since 0.17.1 it is the same kernel ide this system's library keeps for each thread (`pthread_threadid_np`, a name no C library in this ecosystem defines). +## What 0.23.4 corrects + +**The stub of `libSystem` lists `__bzero` for x86_64.** Clang lowers a zeroing +`memset` to `__bzero` on this system's x86_64, and this package's objects carry +such stores in a release build. A link with no SDK --- the cross link that the +stub serves --- therefore stopped at `undefined symbol: __bzero`, so a release +build for `x86_64-macos-musl` failed for every program. The stub now lists the +name for x86_64, and the program binds it to the system's library when it runs. +CI links such a program on Linux and runs it on an Intel Mac. + ## What 0.23.3 corrects **The stub of `libSystem` is supplied only when the link has no SDK.** A build diff --git a/mcpp.toml b/mcpp.toml index 12357c0..f359817 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-macos" -version = "0.23.3" +version = "0.23.4" description = "An implementation of openkal for macOS, written on the kernel's own calls. Its purpose is as much to test the specification as to be used." license = "Apache-2.0" diff --git a/port/libSystem.tbd b/port/libSystem.tbd index 87b7617..e5a6fd4 100644 --- a/port/libSystem.tbd +++ b/port/libSystem.tbd @@ -67,6 +67,14 @@ current-version: 1351.0.0 # stops with `undefined symbol: dyld_stub_binder, referenced by lazy binding'. # The first measurement was made with one version, and one version is not # evidence about a format. +# +# `___bzero' (0.23.4), for x86_64 only, is of the same kind: no source here +# names it. Clang lowers a zeroing `memset' to it on this system's x86_64 +# (Darwin's library call for the operation), and this package's own objects +# carry such stores (src/process.cpp, src/fs.cpp in a release build). A link +# with no SDK therefore stopped at `undefined symbol: __bzero'. AArch64 has no +# such lowering. Measured by linking a release build of a program above +# openkal for x86_64-macos-musl on Linux; its one new import is this name. exports: - targets: [ arm64-macos, x86_64-macos ] symbols: [ __dyld_atfork_parent, __dyld_atfork_prepare, __dyld_fork_child, @@ -80,4 +88,6 @@ exports: __pthread_self, dyld_stub_binder, _mach_task_self_, _mach_vm_protect, _sandbox_init_with_parameters, __NSGetArgc, __NSGetArgv, __NSGetEnviron ] + - targets: [ x86_64-macos ] + symbols: [ ___bzero ] ...