[lld] [llvm] [DTLTO] Do not serialize inputs that hit in the ThinLTO cache (PR #204104)

Ben Dunbobbin via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 24 04:14:20 PDT 2026


================
@@ -0,0 +1,101 @@
+REQUIRES: ld.lld
+
+# Show that DTLTO input file extraction interacts correctly with the
+# ThinLTO cache.
+#
+# To handle bitcode inputs that are not in individual files on disk, such as
+# members of non-thin archives, DTLTO extracts such input bitcode to a
+# temporary individual file on disk. This extraction should only be
+# performed if the backend compilation is required. A backend compilation is
+# only required if there is a miss in the ThinLTO cache for that module, or a
+# module is imported by a module that has missed in the ThinLTO cache.
+#
+# Test DTLTO input extraction across three cases:
+#   1. None of the backend compilations hit in the ThinLTO cache.
+#   2. All of the backend compilations hit in the ThinLTO cache.
+#   3. Some backend compilations hit in the ThinLTO cache and some miss.
+
+RUN: rm -rf %t && split-file %s %t && cd %t
+
+RUN: %clang --target=x86_64-linux-gnu -O2 -flto=thin -c f1.c f2.c
+RUN: llvm-ar rcs f1.a f1.o
+RUN: llvm-ar rcs f2.a f2.o
+
+RUN: mkdir cache.dir
+
+DEFINE: %{link} =  \
+DEFINE:    %clang --target=x86_64-linux-gnu -fuse-ld=lld -shared -nostdlib \
+DEFINE:     -O2 -flto=thin \
+DEFINE:     -fthinlto-distributor=%python \
+DEFINE:     -Xthinlto-distributor=%llvm_src_root/utils/dtlto/local.py \
+DEFINE:     -Wl,--thinlto-cache-dir=cache.dir \
+DEFINE:     -Wl,--save-temps
+
+# 1. None of the backend compilations hit in the ThinLTO cache.
+#
+# Both f1.o and f2.o require backend compilation, so both should be extracted.
+# Each backend compilation should produce:
+#   * a native object
+#   * a thinlto.bc file
+#   * a temporary bitcode file (extracted archive member)
+RUN: mkdir none
+RUN: %{link} -Wl,--whole-archive f1.a f2.a -o none/out.elf
+RUN: ls none | sort | FileCheck %s --check-prefix=NONE
+NONE-NOT: {{^}}f1
----------------
bd1976bris wrote:

I had some ordering related failures with these `CHECK`s when I updated the filenames in this test vs the original `cache-serialization.test`. The new `-NOT: {{^}}f1/2/3` approach doesn't depend on any of the other temporary files that are generated and is clearer.

https://github.com/llvm/llvm-project/pull/204104


More information about the llvm-commits mailing list