The scan passes no -resource-dir, so a clang-scan-deps of another LLVM release than clang++ looks for clang's own headers where its own release would keep them #58

Closed
opened 2026-11-27 18:28:37 +00:00 by jorijnvdgraaf · 0 comments

Summary

Since 6.4.2 a build reads what each .cppm and .cpp declares and imports with clang-scan-deps over the source's compile command (ScanSource, implementations/Crafter.Build-Clang.cpp:1171-1179). That command has no -resource-dir, and clang-scan-deps then works the resource directory out as a driver does, from the command's first word: <its directory>/../lib/clang/<major>, with the major of the release clang-scan-deps was built from, not the compiler's. In LLVM 23.1.2, --resource-dir-recipe is modify-compiler-path unless it is given (clang/tools/clang-scan-deps/ClangScanDeps.cpp:79-82, :112, :239-253); only invoke-compiler asks the compiler (:945-952); and the directory is made with CLANG_VERSION_MAJOR_STRING (clang/lib/Options/OptionUtils.cpp:226-236). The compile works it out with the compiler's own major.

The two are of one release where the Toolchain takes them from one prefix, CRAFTER_BUILD_LLVM_DIR or a toolchain beside crafter-build, as in the Flatpak. Without one, the compiler is the bare clang++ and the scanner the bare clang-scan-deps (implementations/Crafter.Build-Toolchain.cpp:223-228), each the first of its name on PATH, and those can come from different installations: say, a PATH whose clang++ is LLVM 23's and whose clang-scan-deps is another release's. The scan then looks for stddef.h, which libc++'s headers include, in a directory named for the scanner's release under the compiler's installation. Where there is none, the scan of every source that includes a header of the C++ standard library fails on 'stddef.h' file not found, and the build with it, though the compile would find the header. A scan whose first word leads to no resource directory fails in just that way: it is how a compiler reached through a link from another directory failed its scan in 6.4.2, which 6.4.3 fixed.

Which directory the scan works it out from changed in 6.4.3. Through 6.4.2 the first word was clang++ as the Toolchain has it, which clang-scan-deps looks up on PATH without following a link; since 6.4.3 it is the compiler in the directory clang++ --version names (ScannedAs, implementations/Crafter.Build-Clang.cpp:1141-1162). Which of the two has a lib/clang/<scanner's major> depends on how the installations are laid out.

Lint's parse gives libclang a -resource-dir from clang++ -print-resource-dir, for the same reason with a libclang of another release than the compiler (ClangResourceDir, implementations/Crafter.Build-Lint.cpp:710-725, used at :782).

Not run: only one LLVM major is at hand, 23.1.3 natively and 23.1.2 in the Flatpak. Found by the pre-push review of 6.4.3. #52 is about clang-scan-deps of another release as well.

Line numbers refer to cb8914d (6.4.3), and LLVM's to 23.1.2.

Proposal

Give the scan the compile's resource directory: -resource-dir= from the compiler, as lint has it, with ClangResourceDir moved into the Toolchain so that both read one answer, or --resource-dir-recipe=invoke-compiler, which has clang-scan-deps run <first word> -print-resource-dir once per compiler. Or, where the Toolchain comes from PATH, take clang-scan-deps from the directory the compiler is installed in (installedDir) when it is there, and llvm-ar and llvm-readelf with it, so that the tools of one build cannot be of two releases.

## Summary Since 6.4.2 a build reads what each `.cppm` and `.cpp` declares and imports with clang-scan-deps over the source's compile command (`ScanSource`, `implementations/Crafter.Build-Clang.cpp:1171-1179`). That command has no `-resource-dir`, and clang-scan-deps then works the resource directory out as a driver does, from the command's first word: `<its directory>/../lib/clang/<major>`, with the major of the release clang-scan-deps was built from, not the compiler's. In LLVM 23.1.2, `--resource-dir-recipe` is `modify-compiler-path` unless it is given (`clang/tools/clang-scan-deps/ClangScanDeps.cpp:79-82`, `:112`, `:239-253`); only `invoke-compiler` asks the compiler (`:945-952`); and the directory is made with `CLANG_VERSION_MAJOR_STRING` (`clang/lib/Options/OptionUtils.cpp:226-236`). The compile works it out with the compiler's own major. The two are of one release where the Toolchain takes them from one prefix, `CRAFTER_BUILD_LLVM_DIR` or a toolchain beside crafter-build, as in the Flatpak. Without one, the compiler is the bare `clang++` and the scanner the bare `clang-scan-deps` (`implementations/Crafter.Build-Toolchain.cpp:223-228`), each the first of its name on PATH, and those can come from different installations: say, a PATH whose `clang++` is LLVM 23's and whose `clang-scan-deps` is another release's. The scan then looks for `stddef.h`, which libc++'s headers include, in a directory named for the scanner's release under the compiler's installation. Where there is none, the scan of every source that includes a header of the C++ standard library fails on `'stddef.h' file not found`, and the build with it, though the compile would find the header. A scan whose first word leads to no resource directory fails in just that way: it is how a compiler reached through a link from another directory failed its scan in 6.4.2, which 6.4.3 fixed. Which directory the scan works it out from changed in 6.4.3. Through 6.4.2 the first word was `clang++` as the Toolchain has it, which clang-scan-deps looks up on PATH without following a link; since 6.4.3 it is the compiler in the directory `clang++ --version` names (`ScannedAs`, `implementations/Crafter.Build-Clang.cpp:1141-1162`). Which of the two has a `lib/clang/<scanner's major>` depends on how the installations are laid out. Lint's parse gives libclang a `-resource-dir` from `clang++ -print-resource-dir`, for the same reason with a libclang of another release than the compiler (`ClangResourceDir`, `implementations/Crafter.Build-Lint.cpp:710-725`, used at `:782`). Not run: only one LLVM major is at hand, 23.1.3 natively and 23.1.2 in the Flatpak. Found by the pre-push review of 6.4.3. #52 is about clang-scan-deps of another release as well. Line numbers refer to `cb8914d` (6.4.3), and LLVM's to 23.1.2. ## Proposal Give the scan the compile's resource directory: `-resource-dir=` from the compiler, as lint has it, with `ClangResourceDir` moved into the Toolchain so that both read one answer, or `--resource-dir-recipe=invoke-compiler`, which has clang-scan-deps run `<first word> -print-resource-dir` once per compiler. Or, where the Toolchain comes from PATH, take clang-scan-deps from the directory the compiler is installed in (`installedDir`) when it is there, and llvm-ar and llvm-readelf with it, so that the tools of one build cannot be of two releases.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Catcrafts/Crafter.Build#58
No description provided.