Repository navigation
codex: pin LIBCLANG_PATH to the default llvm, fail closed on any other libclang - #1391
Conversation
…r libclang `find /usr/lib -name 'libclang*.so' | head -1` picks by directory order. Once a prefixed llvm-<N> (e.g. llvm-21 under /usr/lib/llvm-21, pkgs#1339) shares the closure, that pick can land on the wrong LLVM. Point clang-sys at /usr/lib (the unprefixed default llvm build dep) and fail unless every libclang.so* there is the major /usr/bin/llvm-config reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
agent-137
left a comment
There was a problem hiding this comment.
Review on Karl's behalf. This is a comment, not an approval. Nothing was built for it. The findings come from reading the declarations and fetching upstream sources, and each one says how it was checked. The CI rollup on this head is now SUCCESS.
CI: all green, including minimal build. codex built and its tests passed on amd64 and arm64, so the guard accepts the real llvm 21.1.8 layout.
Should-fix: none.
Nit:
packages/codex/build.sh:22-25: if/usr/bin/llvm-configis missing, the build stops at the assignment on line 22 (set -euo pipefail; status 127) and prints only bash's "No such file" line. TheERROR: no default llvm (/usr/bin/llvm-config)message on line 25 never prints for that case. The build still fails closed, which the PR body says, but the message is dead code for the cause it names. An explicit[ -x /usr/bin/llvm-config ] || { echo …; exit 1; }before line 22 would make it print.packages/codex/build.sh:23: the guard checks onlylibclang.so*. On Linux, clang-sys also globslibclang-*.so*inLIBCLANG_PATH. The default llvm shipslibclang-cpp.so*in/usr/lib(thelibclangoutput glob isusr/lib/libclang*.{so*,a}), and the guard never checks it. It is the same major today, and llvm-21 installs under/usr/lib/llvm-21, so nothing goes wrong now. But "every libclang in it" in the comment is broader than what the code checks. Unverified: the clang-sys glob list is from my knowledge of its source, not checked against the vendored version.
Checked:
- The llvm package installs with
CMAKE_INSTALL_PREFIX=/usr(packages/llvm/build.sh:40). Its outputs shipusr/bin/*(llvm-config) andusr/lib/libclang*.so*, so/usr/liband/usr/bin/llvm-configare the right paths. - The libclang SOVERSION is the major (
libclang.so→.so.21→.so.21.1.8).readlink -fplussort -ureduces these to one file, and thecaseaccepts it. - The
"libclang.so.$llvm_major".*pattern needs a literal dot after the major, so a major of 21 cannot match.so.210. - The guard fails when:
- two different majors are present (the loop exits on the first mismatch),
- there is no match (
-execnever runs, the variable is empty, and line 24 exits), - the libclang file is unversioned (no pattern matches).
- codex depends only on the default
llvm, and rust's runtimellvmis the same package.
What
packages/codex/build.shfound its libclang withThat picks by directory order. Once #1339 lands (LLVM 21 frozen as
llvm-21under/usr/lib/llvm-21, defaultllvmat 23 in/usr/lib), any closure that holds both has two candidates (/usr/lib/libclang.soand/usr/lib/llvm-21/lib/libclang.so), and which one bindgen gets depends on filesystem order. That hurts reproducibility, and it can also build against the wrong LLVM.Change
LIBCLANG_PATH=/usr/libis now set explicitly, pointing at the unprefixed defaultllvmbuild dep. WhenLIBCLANG_PATHis set, clang-sys searches only that directory./usr/bin/llvm-config(the default llvm) orlibclang.soin/usr/libis missing, or if any/usr/lib/libclang.so*, after resolving symlinks, has a different major thanllvm-config --versionreports.This is correct before #1339 too, because it pins whatever the default llvm is (21 today, 23 after). It should merge after #1339 so the first bot build covers the 23 layout, but the order doesn't matter for correctness.
Verification
No local build: build-bot / CI will build it. I ran the new block by itself against fake
/usrtrees, with paths substituted:/usr/libfindon the first tree/usr/lib/libclang.soand/usr/lib/llvm-21/lib/libclang.so, so the result depends on orderOther
find | head/ls | headpicks on mainI grepped
packages/andstacks/forfind|ls ... | head|tailnear clang / llvm / lld / libLLVM. codex was the only toolchain-library pick. The remaining hits don't involve LLVM, so I left them alone:packages/llvm/versioned-build.sh:56:find ... | head -20lists stray files for an error message. Not a pick.packages/cocoalib/build.sh:35:ls /usr/lib/libgmp.so /usr/lib64/libgmp.so | head -1chooses between two fixed paths of one library.packages/{glibc-bedrock-2.42,stage0-gcc-15.2.0,stage0-gcc-10.4.0,gcc-15.2.0-glibc}/build.sh:ls /usr/include/c++/*/<tgt>/bits/c++config.h | head -n1. This is the same hazard for GCC: if two libstdc++ header trees ever share a closure, the pick is order-dependent. It isn't affected by llvm: freeze LLVM 21 as llvm-21, switch default llvm to 23.1.5 (LLVM plan steps 6+7) #1339, so it's out of scope here, but it's worth a follow-up.🤖 Generated with Claude Code
Summary by CodeRabbit