From 2ec50b7e3d54a55860986110e096b784ed15827f Mon Sep 17 00:00:00 2001 From: Matthew Lugg Date: Mon, 25 May 2026 07:32:05 +0100 Subject: [PATCH] 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! --- cmake/Findclang.cmake | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmake/Findclang.cmake b/cmake/Findclang.cmake index b34c9ce57fd59b2eb2897a5c02e0cd8105286a10..7650b7d0cba0fc370ce3c2c47282248925a7020a 100644 --- a/cmake/Findclang.cmake +++ b/cmake/Findclang.cmake @@ -56,11 +56,8 @@ else() FIND_AND_ADD_CLANG_LIB(clangAnalysisLifetimeSafety) FIND_AND_ADD_CLANG_LIB(clangAnalysis) FIND_AND_ADD_CLANG_LIB(clangASTMatchers) - FIND_AND_ADD_CLANG_LIB(clangAST) FIND_AND_ADD_CLANG_LIB(clangParse) - FIND_AND_ADD_CLANG_LIB(clangSema) FIND_AND_ADD_CLANG_LIB(clangAPINotes) - FIND_AND_ADD_CLANG_LIB(clangBasic) FIND_AND_ADD_CLANG_LIB(clangEdit) FIND_AND_ADD_CLANG_LIB(clangLex) FIND_AND_ADD_CLANG_LIB(clangRewriteFrontend) @@ -73,6 +70,7 @@ else() FIND_AND_ADD_CLANG_LIB(clangSupport) FIND_AND_ADD_CLANG_LIB(clangInstallAPI) FIND_AND_ADD_CLANG_LIB(clangAST) + FIND_AND_ADD_CLANG_LIB(clangBasic) endif() if (MSVC) -- 2.54.0