Quellcode durchsuchen

Update LLVM to a recent commit (#6599)

This brings some fixes:
- The handling of `zlib` and `zstd` are much cleaner
- Three of our patches are no longer needed

This also includes the fixes from #6562

It also moves us from `zlib` to `zlib-ng` which is a much better basis
for what we want, and likely makes our toolchain faster when generating
debug info at least.

It fixes another API change in terms of which headers provide the
`createInvocation` we use.

Lastly, it cleans up the deps test to correctly recognize the wrappers
for `zlib-ng` and `zstd`, as well as improving the documentation for why
we allow dependencies on them.
Chandler Carruth vor 3 Monaten
Ursprung
Commit
9861c31476

+ 4 - 7
MODULE.bazel

@@ -95,7 +95,7 @@ http_archive(
 # Required for llvm-project.
 bazel_dep(name = "platforms", version = "1.0.0")
 bazel_dep(name = "protobuf", version = "33.1", repo_name = "com_google_protobuf")
-bazel_dep(name = "zlib", version = "1.3.1.bcr.6", repo_name = "llvm_zlib")
+bazel_dep(name = "zlib-ng", version = "2.0.7", repo_name = "llvm_zlib")
 bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd")
 
 ###############################################################################
@@ -104,23 +104,20 @@ bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd")
 
 # We pin to specific upstream commits and try to track top-of-tree reasonably
 # closely rather than pinning to a specific release.
-# HEAD as of 2025-11-22.
-llvm_project_version = "20ebc7ea8209cb8f1ff3916706b6e7d8232c9f3f"
+# HEAD as of 2026-01-08.
+llvm_project_version = "21a1e6e6a70d70635c68b9aaa54f816ae36a6416"
 
 # Load a repository for the raw llvm-project, pre-overlay.
 http_archive(
     name = "llvm-raw",
     build_file_content = "# empty",
-    integrity = "sha256-/LVv96+cMl0CE3AxLZKzSE97CwbB1G2ic8h/Agqeafo=",
+    integrity = "sha256-ouWG2d4Cob9P6+dxCLZnV4RldSOqZp7mtwd6vd+ZK3Q=",
     patch_args = ["-p1"],
     patches = [
         "@carbon//bazel/llvm_project:0001_Patch_for_mallinfo2_when_using_Bazel_build_system.patch",
         "@carbon//bazel/llvm_project:0002_Added_Bazel_build_for_compiler_rt_fuzzer.patch",
-        "@carbon//bazel/llvm_project:0003_Comment_out_unloaded_proto_library_dependencies.patch",
         "@carbon//bazel/llvm_project:0004_Introduce_basic_sources_exporting_for_libunwind.patch",
         "@carbon//bazel/llvm_project:0005_Introduce_basic_sources_exporting_for_libcxx_and_libcxxabi.patch",
-        "@carbon//bazel/llvm_project:0006_Add_a_filegroup_containing__all__sources_to_the_libc_build_rules.patch",
-        "@carbon//bazel/llvm_project:0007_Remove_target_compatibility_restrictions_for_float128.patch",
         "@carbon//bazel/llvm_project:0008_Add_filegroups_for_installed_compiler-rt_headers.patch",
     ],
     strip_prefix = "llvm-project-{0}".format(llvm_project_version),

+ 4 - 3
MODULE.bazel.lock

@@ -236,12 +236,13 @@
     "https://bcr.bazel.build/modules/upb/0.0.0-20230516-61a97ef/MODULE.bazel": "c0df5e35ad55e264160417fd0875932ee3c9dda63d9fccace35ac62f45e1b6f9",
     "https://bcr.bazel.build/modules/xz/5.4.5.bcr.1/MODULE.bazel": "c037f75fa1b7e1ff15fbd15d807a8ce545e9b02f02df0a9777aa9aa7d8b268bb",
     "https://bcr.bazel.build/modules/xz/5.4.5.bcr.1/source.json": "766f28499a16fa9ed8dc94382d50e80ceda0d0ab80b79b7b104a67074ab10e1f",
+    "https://bcr.bazel.build/modules/zlib-ng/2.0.7/MODULE.bazel": "3ca640b745b55f287e95aa0477e6cd76dfa0a565725d5412b7d8dae4274436c8",
+    "https://bcr.bazel.build/modules/zlib-ng/2.0.7/source.json": "107bf3a70ecf9f87fe90f7002c9e35423564ffed070affec23d41478503bc5cf",
     "https://bcr.bazel.build/modules/zlib/1.2.11/MODULE.bazel": "07b389abc85fdbca459b69e2ec656ae5622873af3f845e1c9d80fe179f3effa0",
     "https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27",
     "https://bcr.bazel.build/modules/zlib/1.2.13/MODULE.bazel": "aa6deb1b83c18ffecd940c4119aff9567cd0a671d7bba756741cb2ef043a29d5",
     "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca",
-    "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.6/MODULE.bazel": "e937cf0a3772f93ad91f3c7af4f330b76a878bbfee06527ca1a9673b790eb896",
-    "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.6/source.json": "5f397158198f338129c865a4c3ae21bc5626a9664b3c3b40fa3b3c2ec1ff83bf",
+    "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806",
     "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198",
     "https://bcr.bazel.build/modules/zstd/1.5.6/MODULE.bazel": "471ebe7d3cdd8c6469390fcf623eb4779ff55fbee0a87f1dc57a1def468b96d4",
     "https://bcr.bazel.build/modules/zstd/1.5.7/MODULE.bazel": "f5780cdbd6f4c5bb985a20f839844316fe48fb5e463056f372dbc37cfabdf450",
@@ -267,7 +268,7 @@
     },
     "//bazel/llvm_project:llvm_project.bzl%llvm_project": {
       "general": {
-        "bzlTransitiveDigest": "WeP75HuuSuHfiMXYgJJVbnizIcDpw7xlAckhEp137z0=",
+        "bzlTransitiveDigest": "xDeO6VeJOhQ/KmsAtVhSrY+/XoomqAxdF2SG/XbIkX4=",
         "usagesDigest": "uwwVdRj/NhFVoOIaadPP393kgC/Uu3/nTX9ln69oWp4=",
         "recordedFileInputs": {},
         "recordedDirentsInputs": {},

+ 0 - 7
bazel/cc_toolchains/clang_cc_toolchain_config.bzl

@@ -176,13 +176,6 @@ def _build_features(ctx):
                         # Pass the clang version as a define so that bazel
                         # caching is more likely to notice version changes.
                         "-DCLANG_VERSION_FOR_CACHE=\"%s\"" % clang_version_for_cache,
-
-                        # Enable the use of zlib and zstd in LLVM. We define
-                        # these here and use the normal Bazel builds of both
-                        # rather than using the custom zlib and zstd `BUILD`
-                        # files shipped with LLVM that use `defines`.
-                        "-DLLVM_ENABLE_ZLIB",
-                        "-DLLVM_ENABLE_ZSTD",
                     ]),
                     flag_group(
                         flags = ["-D%{preprocessor_defines}"],

+ 11 - 3
bazel/check_deps/check_non_test_cc_deps.py

@@ -52,6 +52,14 @@ for dep in deps:
             # While this is in a `third_party` directory, its code is documented
             # as part of LLVM and for use in compiler-rt.
             "third-party/siphash",
+        ) and (
+            package == "third-party"
+            and rule
+            not in (
+                # LLVM wrappers for zlib-ng and zstd, which are fine as linked.
+                "zlib",
+                "zstd",
+            )
         ):
             sys.exit(
                 "ERROR: unexpected dependency into the LLVM project: %s" % dep
@@ -79,10 +87,10 @@ for dep in deps:
     if repo in ("@@rules_cc+", "@@bazel_tools"):
         continue
 
-    # These are stubs wrapping system libraries for LLVM. They aren't
-    # distributed and so should be fine.
+    # These libraries have compatible licenses and are linked in without copying
+    # source, so fine for our binaries.
     if repo in (
-        "@@zlib+",
+        "@@zlib-ng+",
         "@@zstd+",
     ):
         continue

+ 0 - 69
bazel/llvm_project/0003_Comment_out_unloaded_proto_library_dependencies.patch

@@ -1,69 +0,0 @@
-From 01f35f954121def682097d8e697ac524b2c8acc6 Mon Sep 17 00:00:00 2001
-From: jonmeow <jperkins@google.com>
-Date: Mon, 3 Feb 2025 11:18:25 -0800
-Subject: [PATCH] Comment out unloaded proto_library dependencies
-
----
- .../llvm-project-overlay/clang/BUILD.bazel    | 46 +++++++++----------
- 1 file changed, 23 insertions(+), 23 deletions(-)
-
-diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
-index e3b20e43dd22..8b26e322a0ed 100644
---- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
-+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
-@@ -2603,29 +2603,29 @@ cc_library(
-     ],
- )
- 
--proto_library(
--    name = "cxx-proto",
--    srcs = ["tools/clang-fuzzer/cxx_proto.proto"],
--)
--
--cc_proto_library(
--    name = "cxx_cc_proto",
--    deps = [":cxx-proto"],
--)
--
--cc_library(
--    name = "proto-to-cxx-lib",
--    srcs = ["tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp"],
--    hdrs = ["tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h"],
--    includes = ["tools/clang-fuzzer"],
--    deps = [":cxx_cc_proto"],
--)
--
--cc_binary(
--    name = "clang-proto-to-cxx",
--    srcs = ["tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp"],
--    deps = [":proto-to-cxx-lib"],
--)
-+# proto_library(
-+#     name = "cxx-proto",
-+#     srcs = ["tools/clang-fuzzer/cxx_proto.proto"],
-+# )
-+#
-+# cc_proto_library(
-+#     name = "cxx_cc_proto",
-+#     deps = [":cxx-proto"],
-+# )
-+#
-+# cc_library(
-+#     name = "proto-to-cxx-lib",
-+#     srcs = ["tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.cpp"],
-+#     hdrs = ["tools/clang-fuzzer/proto-to-cxx/proto_to_cxx.h"],
-+#     includes = ["tools/clang-fuzzer"],
-+#     deps = [":cxx_cc_proto"],
-+# )
-+#
-+# cc_binary(
-+#     name = "clang-proto-to-cxx",
-+#     srcs = ["tools/clang-fuzzer/proto-to-cxx/proto_to_cxx_main.cpp"],
-+#     deps = [":proto-to-cxx-lib"],
-+# )
- 
- cc_library(
-     name = "clang-fuzzer-initialize",
--- 
-2.48.1
-

+ 0 - 31
bazel/llvm_project/0006_Add_a_filegroup_containing__all__sources_to_the_libc_build_rules.patch

@@ -1,31 +0,0 @@
-Commit ID: e524424ed32e945bdced8c19ca480f461d04397a
-Change ID: lslousqwyovpkqlxvyrzmmypxkxxulwn
-Bookmarks: push-lslousqwyovp push-lslousqwyovp@git push-lslousqwyovp@origin
-Author   : Chandler Carruth <chandlerc@gmail.com> (2025-11-20 03:05:36)
-Committer: Chandler Carruth <chandlerc@gmail.com> (2025-11-22 09:23:52)
-
-    Add a filegroup containing _all_ sources to the libc build rules
-
-    These rules already expose a filegroup containing the _dependencies_,
-    but that misses the source files directly in the top level library.
-
-    Without this filegroup, there isn't a way to access the source files
-    used by libcxx when building it, etc.
-
-diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
-index 0f2965369c..c871334dd9 100644
---- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
-+++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
-@@ -247,6 +247,12 @@
-         **kwargs
-     )
- 
-+    _libc_srcs_filegroup(
-+        name = name + "_hdrs",
-+        libs = [":" + name],
-+        enforce_headers_only = True,
-+    )
-+
- def libc_generated_header(name, hdr, yaml_template, other_srcs = []):
-     """Generates a libc header file from YAML template.
- 

+ 0 - 36
bazel/llvm_project/0007_Remove_target_compatibility_restrictions_for_float128.patch

@@ -1,36 +0,0 @@
-Commit ID: 94325bae07213d2dd8263945f5362720dee7bcb9
-Change ID: kskkxwvnyqwuzkswkuxpnmyovqxoypnz
-Bookmarks: push-kskkxwvnyqwu push-kskkxwvnyqwu@git push-kskkxwvnyqwu@origin
-Author   : Chandler Carruth <chandlerc@gmail.com> (2025-11-24 07:26:06)
-Committer: Chandler Carruth <chandlerc@gmail.com> (2025-11-24 07:40:58)
-
-    Remove target compatibility restrictions for float128
-
-    The restrictions here aren't nearly as much about the OS as the compiler
-    and architecture, but the Bazel restriction was OS-based. Everything
-    seems to work well on even Arm64 macOS, and I would expect most BSDs and
-    other OSes to work well with Clang's support on x86-64.
-
-    The source code here already handles detecting when there is compiler
-    support for the type. And the users of this don't `select` or do
-    anything else to conditionally include the header, so it seems better to
-    not restrict access to the header from the build system, and instead
-    continue making the source code compatible or a no-op on relevant
-    configurations.
-
-diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
-index bd48222856..e3962d9b5f 100644
---- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
-+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
-@@ -171,11 +171,6 @@
- libc_support_library(
-     name = "llvm_libc_types_float128",
-     hdrs = ["include/llvm-libc-types/float128.h"],
--    target_compatible_with = select({
--        "@platforms//os:linux": [],
--        "@platforms//os:windows": [],
--        "//conditions:default": ["@platforms//:incompatible"],
--    }),
-     deps = [":llvm_libc_macros_float_macros"],
- )
- 

+ 4 - 1
scripts/fix_cc_deps.py

@@ -160,7 +160,10 @@ def get_rules(bazel: str, targets: str, keep_going: bool) -> dict[str, Rule]:
             elif rule_class == "genrule":
                 if list_name == "outs":
                     outs = get_bazel_list(list_child, True)
-            elif rule_class == "tree_sitter_cc_library":
+            elif rule_class in ("tree_sitter_cc_library", "cc_library_wrapper"):
+                # Note that `cc_library_wrapper` isn't a general rule, it is a
+                # specialized rule from inside LLVM wrapping some of its
+                # dependencies and injecting configuration macro defines.
                 continue
             else:
                 exit(f"unexpected rule type: {rule_class}")

+ 1 - 1
testing/file_test/run_test.cpp

@@ -121,7 +121,7 @@ auto RunTestFile(const FileTestBase& test_base, bool dump_output,
 
   // stdin needs to exist on-disk for compatibility. We'll use a pointer for it.
   FILE* input_stream = nullptr;
-  auto erase_input_on_exit = llvm::make_scope_exit([&input_stream]() {
+  auto erase_input_on_exit = llvm::scope_exit([&input_stream]() {
     if (input_stream) {
       // fclose should delete the tmpfile.
       fclose(input_stream);

+ 1 - 0
toolchain/base/BUILD

@@ -59,6 +59,7 @@ cc_library(
         "//common:string_helpers",
         "//toolchain/diagnostics:diagnostic_emitter",
         "@llvm-project//clang:basic",
+        "@llvm-project//clang:driver",
         "@llvm-project//clang:frontend",
         "@llvm-project//llvm:Support",
     ],

+ 1 - 0
toolchain/base/clang_invocation.cpp

@@ -7,6 +7,7 @@
 #include <filesystem>
 #include <string>
 
+#include "clang/Driver/CreateInvocationFromArgs.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/Utils.h"
 #include "common/string_helpers.h"

+ 1 - 1
toolchain/check/cpp/import.cpp

@@ -1307,7 +1307,7 @@ static auto CreateFunctionSignatureInsts(Context& context, SemIR::LocId loc_id,
     -> std::optional<FunctionSignatureInsts> {
   context.full_pattern_stack().PushFullPattern(
       FullPatternStack::Kind::ImplicitParamList);
-  std::optional pop = llvm::make_scope_exit(
+  std::optional pop = llvm::scope_exit(
       [&context] { context.full_pattern_stack().PopFullPattern(); });
   auto implicit_param_patterns_id =
       MakeImplicitParamPatternsBlockId(context, loc_id, *clang_decl);

+ 1 - 1
toolchain/driver/compile_subcommand.cpp

@@ -1163,7 +1163,7 @@ auto CompileSubcommand::Run(DriverEnv& driver_env) -> DriverResult {
     unit->SetMultiUnitCache(&cache);
   }
 
-  auto on_exit = llvm::make_scope_exit([&]() {
+  auto on_exit = llvm::scope_exit([&]() {
     // Finish compilation units. This flushes their diagnostics in the order in
     // which they were specified on the command line.
     for (auto& unit : units) {

+ 1 - 1
toolchain/driver/driver_test.cpp

@@ -70,7 +70,7 @@ class DriverTest : public testing::Test {
     std::filesystem::current_path(test_dir, ec);
     CARBON_CHECK(!ec, "Could not change the current working dir to '{0}': {1}",
                  test_dir, ec.message());
-    return llvm::make_scope_exit([original_dir, test_dir] {
+    return llvm::scope_exit([original_dir, test_dir] {
       std::error_code ec;
       std::filesystem::current_path(original_dir, ec);
       CARBON_CHECK(!ec,

+ 3 - 3
toolchain/driver/runtimes_cache_test.cpp

@@ -114,7 +114,7 @@ TEST_F(RuntimesCacheTest, BuildSystemCache) {
   constexpr const char* HomeEnv = "HOME";
   const char* orig_xdg_cache = getenv(XdgCacheEnv);
   const char* orig_home = getenv(HomeEnv);
-  auto restore_env = llvm::make_scope_exit([&] {
+  auto restore_env = llvm::scope_exit([&] {
     for (const auto [env, orig] : {std::pair{XdgCacheEnv, orig_xdg_cache},
                                    std::pair{HomeEnv, orig_home}}) {
       if (orig) {
@@ -337,7 +337,7 @@ TEST_F(RuntimesCacheTest, ConcurrentBuilds) {
   // Use a scoped join to avoid leaking the thread as some platforms don't have
   // `std::jthread`.
   auto scoped_join =
-      llvm::make_scope_exit([&build2_thread] { build2_thread.join(); });
+      llvm::scope_exit([&build2_thread] { build2_thread.join(); });
 
   // Commit the first built runtime.
   auto commit_result = std::move(builder1).Commit();
@@ -435,7 +435,7 @@ TEST_F(RuntimesCacheTest, ConcurrentBuildsWithFailedLocking) {
   // Use a scoped join to avoid leaking the thread as some platforms don't have
   // `std::jthread`.
   auto scoped_join =
-      llvm::make_scope_exit([&build2_thread] { build2_thread.join(); });
+      llvm::scope_exit([&build2_thread] { build2_thread.join(); });
 
   // As soon as the second thread notifies that its build is started and ready
   // to commit, also commit the first built runtime.