authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-25 07:32:05+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-05-26 06:30:28+01:00
log2ec50b7e3d54a55860986110e096b784ed15827f
tree2581c10230046d91bc9d1330af1ba79f8dd5a3e5
parent2625e42a6860efdfe377bd48446c5cd103e7ac1a
signaturelock-open Commit is signed but in an unrecognized format.

cmake: remove duplicate Clang libraries

The list of Clang libraries to link against contained duplicates. However, while it doesn't look like Andrew realised this when he originally added these imports, there *was* a reason for them: they were seemingly necessary to deal with GNU ld's ridiculous requirements surrounding the order of static archives on the command line. (LLD does not have this constraint, so it is relevant only when using GNU ld, which under the modern bootstrap process only potentially occurs when building zig2.) This was causing issues when linking Zig against LLVM using Elf2, because that linker currently includes all archives eagerly. (I expect that it will always do this, but it should perhaps at least detect and ignore duplicate archives in future.) Luckily, it turns out there is a toplogical ordering for these libraries, i.e. an order which they can be passed in which contains no duplicates but also allows GNU ld to resolve all symbols. FWIW, if in future we start running into link errors again because of new dependencies between Clang/LLVM libraries, I'd probably prefer to just wrap the libraries in `--start-group` and `--end-group` on the linker command line if CMake has a way to do that... but hopefully we'll be able to instead implement https://github.com/ziglang/zig/issues/16270 before we hit such a problem!

1 files changed, 1 insertions(+), 3 deletions(-)

cmake/Findclang.cmake+1-3
...@@ -56,11 +56,8 @@ else()...@@ -56,11 +56,8 @@ else()
56 FIND_AND_ADD_CLANG_LIB(clangAnalysisLifetimeSafety)56 FIND_AND_ADD_CLANG_LIB(clangAnalysisLifetimeSafety)
57 FIND_AND_ADD_CLANG_LIB(clangAnalysis)57 FIND_AND_ADD_CLANG_LIB(clangAnalysis)
58 FIND_AND_ADD_CLANG_LIB(clangASTMatchers)58 FIND_AND_ADD_CLANG_LIB(clangASTMatchers)
59 FIND_AND_ADD_CLANG_LIB(clangAST)
60 FIND_AND_ADD_CLANG_LIB(clangParse)59 FIND_AND_ADD_CLANG_LIB(clangParse)
61 FIND_AND_ADD_CLANG_LIB(clangSema)
62 FIND_AND_ADD_CLANG_LIB(clangAPINotes)60 FIND_AND_ADD_CLANG_LIB(clangAPINotes)
63 FIND_AND_ADD_CLANG_LIB(clangBasic)
64 FIND_AND_ADD_CLANG_LIB(clangEdit)61 FIND_AND_ADD_CLANG_LIB(clangEdit)
65 FIND_AND_ADD_CLANG_LIB(clangLex)62 FIND_AND_ADD_CLANG_LIB(clangLex)
66 FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)63 FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend)
...@@ -73,6 +70,7 @@ else()...@@ -73,6 +70,7 @@ else()
73 FIND_AND_ADD_CLANG_LIB(clangSupport)70 FIND_AND_ADD_CLANG_LIB(clangSupport)
74 FIND_AND_ADD_CLANG_LIB(clangInstallAPI)71 FIND_AND_ADD_CLANG_LIB(clangInstallAPI)
75 FIND_AND_ADD_CLANG_LIB(clangAST)72 FIND_AND_ADD_CLANG_LIB(clangAST)
73 FIND_AND_ADD_CLANG_LIB(clangBasic)
76endif()74endif()
7775
78if (MSVC)76if (MSVC)