LoadLibClang binds eleven symbols twice, names the first candidate rather than the library it loaded when a symbol is missing, and has no name for LLVM 23's libclang #57

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

Summary

Two small defects in LoadLibClang (implementations/Crafter.Build-Lint.cpp), and a gap in the list of names it tries:

  • The bind list repeats itself: :183-193 bind again the eleven slots that :172-182 bound, clang_Cursor_getBinaryOpcode through clang_EvalResult_dispose. The second pass writes the same pointers, so lint works. Where the library lacks one of those symbols, though, the error names it twice.
  • That error says loaded <candidates.front()> but it is missing ... (:196): the first name of the list it tried, not the one that opened, which the loop at :119-123 does not keep. Without a pinned library the list is LibClangNames (:31-34), so where libclang.so does not open and libclang.so.21.1 does, the message names libclang.so. The handle of the library that did open is then dropped without dlclose (:195).
  • LibClangNames has libclang.so.22.1, .21.1 and .20.1, but not libclang.so.23.1, the soname of LLVM 23's libclang. On Arch, readelf -d /usr/lib/libclang.so gives Library soname: [libclang.so.23.1], and the Flatpak's /app/lib/libclang.so links to libclang.so.23.1 too. A system that has LLVM 23's libclang under that name only, without the unversioned libclang.so link, which a distribution may keep for a development package, opens none of the names, unless the Toolchain names the library itself (CRAFTER_BUILD_LIBCLANG, or lib/libclang.so of a prefix, as in the Flatpak).

Read from the code; not run. Found by the pre-push review of 6.4.3.

Line numbers refer to cb8914d (6.4.3).

Proposal

Drop :183-193. Keep the name that opened for the error, and dlclose the handle before dropping it. Add libclang.so.23.1, or make the versioned name from the Toolchain's clang version, so that the list does not need an edit for every LLVM release.

## Summary Two small defects in `LoadLibClang` (`implementations/Crafter.Build-Lint.cpp`), and a gap in the list of names it tries: - The bind list repeats itself: `:183-193` bind again the eleven slots that `:172-182` bound, `clang_Cursor_getBinaryOpcode` through `clang_EvalResult_dispose`. The second pass writes the same pointers, so lint works. Where the library lacks one of those symbols, though, the error names it twice. - That error says `loaded <candidates.front()> but it is missing ...` (`:196`): the first name of the list it tried, not the one that opened, which the loop at `:119-123` does not keep. Without a pinned library the list is `LibClangNames` (`:31-34`), so where `libclang.so` does not open and `libclang.so.21.1` does, the message names `libclang.so`. The handle of the library that did open is then dropped without `dlclose` (`:195`). - `LibClangNames` has `libclang.so.22.1`, `.21.1` and `.20.1`, but not `libclang.so.23.1`, the soname of LLVM 23's libclang. On Arch, `readelf -d /usr/lib/libclang.so` gives `Library soname: [libclang.so.23.1]`, and the Flatpak's `/app/lib/libclang.so` links to `libclang.so.23.1` too. A system that has LLVM 23's libclang under that name only, without the unversioned `libclang.so` link, which a distribution may keep for a development package, opens none of the names, unless the Toolchain names the library itself (`CRAFTER_BUILD_LIBCLANG`, or `lib/libclang.so` of a prefix, as in the Flatpak). Read from the code; not run. Found by the pre-push review of 6.4.3. Line numbers refer to `cb8914d` (6.4.3). ## Proposal Drop `:183-193`. Keep the name that opened for the error, and `dlclose` the handle before dropping it. Add `libclang.so.23.1`, or make the versioned name from the Toolchain's clang version, so that the list does not need an edit for every LLVM release.
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#57
No description provided.