From 04e7e3d6d9ced6b50df2466d15d068da6fe29a8f Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 22 Nov 2026 18:06:45 +0900 Subject: [PATCH 1/5] probe: the Windows archive members' crash at start, by mcpp version (temporary) --- .github/workflows/probe-windows-archive.yml | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/probe-windows-archive.yml diff --git a/.github/workflows/probe-windows-archive.yml b/.github/workflows/probe-windows-archive.yml new file mode 100644 index 00000000..b173a20a --- /dev/null +++ b/.github/workflows/probe-windows-archive.yml @@ -0,0 +1,45 @@ +# Temporary probe (closed after it answers): which mcpp version makes the Windows +# archive members crash at start (exit 133), and where. +name: probe-windows-archive +on: + pull_request: + paths: ['.github/workflows/probe-windows-archive.yml'] +jobs: + probe: + runs-on: windows-2022 + timeout-minutes: 60 + strategy: + fail-fast: false + matrix: + mcpp: ["2026.11.3.1", "2026.11.13.1", "2026.11.20.1", "2026.11.21.1"] + defaults: + run: + shell: bash + steps: + - uses: actions/checkout@v4 + - name: mcpp ${{ matrix.mcpp }} + run: | + set -euo pipefail + curl -fsSL --retry 5 -o m.zip "https://github.com/mcpp-community/mcpp/releases/download/v${{ matrix.mcpp }}/mcpp-${{ matrix.mcpp }}-windows-x86_64.zip" + unzip -q m.zip + echo "$PWD/mcpp-${{ matrix.mcpp }}-windows-x86_64/bin" >> "$GITHUB_PATH" + echo "MCPP_HOME=$HOME/.mcpp-probe" >> "$GITHUB_ENV" + - name: the archive member + continue-on-error: true + run: | + mcpp --version + mcpp test -p archive-tests --toolchain llvm@23.1.3 2>&1 | tail -40 + - name: the crash, under cdb + continue-on-error: true + run: | + cdb="/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/cdb.exe" + ls "$cdb" || true + for exe in $(find target -name 'versions*.exe' -o -name 'compression*.exe' | head -4); do + echo "== $exe" + "$exe"; printf 'exit status %d (0x%08X)\n' $? $? + "$cdb" -g -G -o -c ".lastevent; r; kn 30; lm; q" "$exe" 2>&1 | tail -80 + done + - name: the link and compile lines + continue-on-error: true + run: | + for f in $(find target -name 'build.ninja' | head -2); do echo "== $f"; grep -n -i 'archive\|link\|/MD\|/MT\|-fms-runtime\|_DLL\|nodefaultlib' "$f" | grep -i 'versions\|runtime\|crt\|msvcrt\|libcmt\|ucrt' | head -40; done From c0b1f28b94c10906baf0bd2d6975f075e8efccf5 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 22 Nov 2026 18:11:59 +0900 Subject: [PATCH 2/5] probe: continue past the crash; the link lines of the test program --- .github/workflows/probe-windows-archive.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/probe-windows-archive.yml b/.github/workflows/probe-windows-archive.yml index b173a20a..e926eba2 100644 --- a/.github/workflows/probe-windows-archive.yml +++ b/.github/workflows/probe-windows-archive.yml @@ -32,6 +32,7 @@ jobs: - name: the crash, under cdb continue-on-error: true run: | + set +e cdb="/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/cdb.exe" ls "$cdb" || true for exe in $(find target -name 'versions*.exe' -o -name 'compression*.exe' | head -4); do @@ -42,4 +43,9 @@ jobs: - name: the link and compile lines continue-on-error: true run: | - for f in $(find target -name 'build.ninja' | head -2); do echo "== $f"; grep -n -i 'archive\|link\|/MD\|/MT\|-fms-runtime\|_DLL\|nodefaultlib' "$f" | grep -i 'versions\|runtime\|crt\|msvcrt\|libcmt\|ucrt' | head -40; done + set +e + for f in $(find target -name 'build.ninja' | head -3); do + echo "== $f" + grep -n 'compression' "$f" | head -20 | cut -c1-2000 + done + for f in $(find target -name '*.rsp' | grep -i 'compression' | head -3); do echo "== $f"; cat "$f" | tr ' ' '\n' | head -120; done From 2114baa27af072b3b7161f4f5eef1109c9a594a5 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 22 Nov 2026 18:15:03 +0900 Subject: [PATCH 3/5] probe: bisect 2026.11.3.1 (passes) to 2026.11.13.1 (crashes) --- .github/workflows/probe-windows-archive.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/probe-windows-archive.yml b/.github/workflows/probe-windows-archive.yml index e926eba2..b7cc6ac1 100644 --- a/.github/workflows/probe-windows-archive.yml +++ b/.github/workflows/probe-windows-archive.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - mcpp: ["2026.11.3.1", "2026.11.13.1", "2026.11.20.1", "2026.11.21.1"] + mcpp: ["2026.11.5.1", "2026.11.7.1", "2026.11.7.2", "2026.11.8.1", "2026.11.9.1", "2026.11.10.1", "2026.11.10.2", "2026.11.12.1"] defaults: run: shell: bash From edc9f8832e0934d942c8364fe99bc2d6cde481c5 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 22 Nov 2026 18:39:54 +0900 Subject: [PATCH 4/5] probe: link.exe against lld-link under /OPT:REF; compat.xz states LZMA_API_STATIC for its consumers --- .github/workflows/probe-windows-archive.yml | 69 +++++++++++---------- pkgs/c/compat.xz.lua | 16 +++++ 2 files changed, 53 insertions(+), 32 deletions(-) diff --git a/.github/workflows/probe-windows-archive.yml b/.github/workflows/probe-windows-archive.yml index b7cc6ac1..1980a187 100644 --- a/.github/workflows/probe-windows-archive.yml +++ b/.github/workflows/probe-windows-archive.yml @@ -1,51 +1,56 @@ -# Temporary probe (closed after it answers): which mcpp version makes the Windows -# archive members crash at start (exit 133), and where. +# Temporary probe (closed after it answers): (1) does MSVC's link.exe keep a +# locally defined function reached only through an __imp_ slot under /OPT:REF, +# where lld-link collects it; (2) does compat.xz stating LZMA_API_STATIC for its +# consumers (a default-implied feature) end the archive members' crash. name: probe-windows-archive on: pull_request: paths: ['.github/workflows/probe-windows-archive.yml'] jobs: - probe: + link: + runs-on: windows-2022 + timeout-minutes: 20 + steps: + - name: link.exe and lld-link under /OPT:REF + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" >nul + > a.c echo __declspec(dllimport) int foo(void); + >> a.c echo int main(void) { return foo(); } + > b.c echo int foo(void) { return 42; } + cl /nologo /O2 /Gy /c a.c b.c + link /nologo /OPT:REF a.obj b.obj /OUT:msvc.exe + msvc.exe + echo RESULT msvc link.exe /OPT:REF exit=%ERRORLEVEL% + "C:\Program Files\LLVM\bin\lld-link.exe" --version + "C:\Program Files\LLVM\bin\lld-link.exe" /OPT:REF a.obj b.obj /OUT:lld.exe + lld.exe + echo RESULT lld-link /OPT:REF exit=%ERRORLEVEL% + "C:\Program Files\LLVM\bin\lld-link.exe" /OPT:NOREF a.obj b.obj /OUT:lld-noref.exe + lld-noref.exe + echo RESULT lld-link /OPT:NOREF exit=%ERRORLEVEL% + exit /b 0 + archive: runs-on: windows-2022 timeout-minutes: 60 - strategy: - fail-fast: false - matrix: - mcpp: ["2026.11.5.1", "2026.11.7.1", "2026.11.7.2", "2026.11.8.1", "2026.11.9.1", "2026.11.10.1", "2026.11.10.2", "2026.11.12.1"] defaults: run: shell: bash steps: - uses: actions/checkout@v4 - - name: mcpp ${{ matrix.mcpp }} + - name: mcpp 2026.11.21.1 run: | set -euo pipefail - curl -fsSL --retry 5 -o m.zip "https://github.com/mcpp-community/mcpp/releases/download/v${{ matrix.mcpp }}/mcpp-${{ matrix.mcpp }}-windows-x86_64.zip" + curl -fsSL --retry 5 -o m.zip "https://github.com/mcpp-community/mcpp/releases/download/v2026.11.21.1/mcpp-2026.11.21.1-windows-x86_64.zip" unzip -q m.zip - echo "$PWD/mcpp-${{ matrix.mcpp }}-windows-x86_64/bin" >> "$GITHUB_PATH" + echo "$PWD/mcpp-2026.11.21.1-windows-x86_64/bin" >> "$GITHUB_PATH" echo "MCPP_HOME=$HOME/.mcpp-probe" >> "$GITHUB_ENV" - - name: the archive member - continue-on-error: true - run: | - mcpp --version - mcpp test -p archive-tests --toolchain llvm@23.1.3 2>&1 | tail -40 - - name: the crash, under cdb - continue-on-error: true - run: | - set +e - cdb="/c/Program Files (x86)/Windows Kits/10/Debuggers/x64/cdb.exe" - ls "$cdb" || true - for exe in $(find target -name 'versions*.exe' -o -name 'compression*.exe' | head -4); do - echo "== $exe" - "$exe"; printf 'exit status %d (0x%08X)\n' $? $? - "$cdb" -g -G -o -c ".lastevent; r; kn 30; lm; q" "$exe" 2>&1 | tail -80 - done - - name: the link and compile lines - continue-on-error: true + - name: the archive members with compat.xz's LZMA_API_STATIC run: | set +e - for f in $(find target -name 'build.ninja' | head -3); do - echo "== $f" - grep -n 'compression' "$f" | head -20 | cut -c1-2000 + for p in archive-tests libarchive-bundle; do + echo "== $p" + mcpp test -p "$p" --toolchain llvm@23.1.3 2>&1 | tail -25 + echo "RESULT $p exit=${PIPESTATUS[0]}" done - for f in $(find target -name '*.rsp' | grep -i 'compression' | head -3); do echo "== $f"; cat "$f" | tr ' ' '\n' | head -120; done + exit 0 diff --git a/pkgs/c/compat.xz.lua b/pkgs/c/compat.xz.lua index 979e12be..77c29ac9 100644 --- a/pkgs/c/compat.xz.lua +++ b/pkgs/c/compat.xz.lua @@ -52,6 +52,22 @@ package = { "*/src/liblzma/simple", "*/src/common", }, + + -- declares every function __declspec(dllimport) on Windows + -- unless LZMA_API_STATIC is defined, and this package is a static + -- library. A consumer that includes it without the macro calls through + -- `__imp_lzma_*` slots that lld-link makes for the locally defined + -- functions; a link that collects unreferenced sections (the release + -- profile, a test's link) drops the functions behind the slots, and + -- the first call jumps to the image's first byte. The macro reaches + -- every TU that includes the header the same way CURL_STATICLIB does + -- in compat.curl: a feature's `defines` reach the consumer, and + -- `default` implies it unconditionally. + features = { + ["default"] = { implies = { "staticlib" } }, + ["staticlib"] = { defines = { "LZMA_API_STATIC" } }, + }, + cflags = { "-D_GNU_SOURCE", "-DSIZEOF_SIZE_T=8", From 87a18a7bbe29c9742b18f96e83dc2f0bcc0ea127 Mon Sep 17 00:00:00 2001 From: Sunrisepeak Date: Sun, 22 Nov 2026 18:52:21 +0900 Subject: [PATCH 5/5] probe: compat.libarchive states LIBARCHIVE_STATIC for its consumers --- .github/workflows/probe-windows-archive.yml | 29 +++------------------ pkgs/c/compat.libarchive.lua | 14 +++++++++- 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/.github/workflows/probe-windows-archive.yml b/.github/workflows/probe-windows-archive.yml index 1980a187..74468f79 100644 --- a/.github/workflows/probe-windows-archive.yml +++ b/.github/workflows/probe-windows-archive.yml @@ -1,35 +1,12 @@ # Temporary probe (closed after it answers): (1) does MSVC's link.exe keep a # locally defined function reached only through an __imp_ slot under /OPT:REF, -# where lld-link collects it; (2) does compat.xz stating LZMA_API_STATIC for its -# consumers (a default-implied feature) end the archive members' crash. +# where lld-link collects it; (2) do compat.xz and compat.libarchive stating their static-API macros for +# their consumers (a default-implied feature) end the archive members' crash. name: probe-windows-archive on: pull_request: paths: ['.github/workflows/probe-windows-archive.yml'] jobs: - link: - runs-on: windows-2022 - timeout-minutes: 20 - steps: - - name: link.exe and lld-link under /OPT:REF - shell: cmd - run: | - call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" >nul - > a.c echo __declspec(dllimport) int foo(void); - >> a.c echo int main(void) { return foo(); } - > b.c echo int foo(void) { return 42; } - cl /nologo /O2 /Gy /c a.c b.c - link /nologo /OPT:REF a.obj b.obj /OUT:msvc.exe - msvc.exe - echo RESULT msvc link.exe /OPT:REF exit=%ERRORLEVEL% - "C:\Program Files\LLVM\bin\lld-link.exe" --version - "C:\Program Files\LLVM\bin\lld-link.exe" /OPT:REF a.obj b.obj /OUT:lld.exe - lld.exe - echo RESULT lld-link /OPT:REF exit=%ERRORLEVEL% - "C:\Program Files\LLVM\bin\lld-link.exe" /OPT:NOREF a.obj b.obj /OUT:lld-noref.exe - lld-noref.exe - echo RESULT lld-link /OPT:NOREF exit=%ERRORLEVEL% - exit /b 0 archive: runs-on: windows-2022 timeout-minutes: 60 @@ -45,7 +22,7 @@ jobs: unzip -q m.zip echo "$PWD/mcpp-2026.11.21.1-windows-x86_64/bin" >> "$GITHUB_PATH" echo "MCPP_HOME=$HOME/.mcpp-probe" >> "$GITHUB_ENV" - - name: the archive members with compat.xz's LZMA_API_STATIC + - name: the archive members with LZMA_API_STATIC and LIBARCHIVE_STATIC run: | set +e for p in archive-tests libarchive-bundle; do diff --git a/pkgs/c/compat.libarchive.lua b/pkgs/c/compat.libarchive.lua index e658a4ba..4e73656d 100644 --- a/pkgs/c/compat.libarchive.lua +++ b/pkgs/c/compat.libarchive.lua @@ -44,9 +44,21 @@ package = { include_dirs = {"*", "*/libarchive", "mcpp_generated/include"}, cflags = { "-D_GNU_SOURCE", - "-DLIBARCHIVE_STATIC", "-DPLATFORM_CONFIG_H=\\\"mcpp_libarchive_config.h\\\"", }, + -- archive.h and archive_entry.h declare every function + -- __declspec(dllimport) on Windows unless LIBARCHIVE_STATIC is defined, + -- and this package is a static library. Every TU that includes them + -- needs it, this package's and its consumers': a consumer without it + -- calls through `__imp_archive_*` slots that lld-link makes, and a link + -- that collects unreferenced sections drops the functions behind them + -- (the first call jumps to the image's first byte; compat.xz states the + -- measurement). A feature's `defines` reach the consumer, and `default` + -- implies it unconditionally, as CURL_STATICLIB in compat.curl. + features = { + ["default"] = { implies = { "staticlib" } }, + ["staticlib"] = { defines = { "LIBARCHIVE_STATIC" } }, + }, -- macOS with musl as the C library (an openkal graph). libarchive -- reads __APPLE__ as "the Apple SDK is present" (TargetConditionals.h, -- copyfile, quarantine) in four private translation units and in the