[compiler-rt] check-builtins is broken when multiple compiler-rt targets are built
For example, on AIX we build the compiler-rt for 32-bit and 64-bit PowerPC targets. All LIT tests in compiler-rt/test/builtins/Unit have the following compile+link command:
// RUN: %clang_builtins %s %librt -o %t
and after LIT substitution (defined in compiler-rt/test/builtins/Unit/lit.cfg.py) look like:
clang ... -fno-builtin -nodefaultlibs $BUILD/lib/clang/22/lib/<target-triple>/libclang_rt.builtins.a -lc -lm -o ...
The path to libclang_rt.builtins.a is computed off the config.compiler_rt_libdir field, which has a hardcoded path from cmake:
// compiler-rt/test/lit.common.configured.in
...
set_default("compiler_rt_libdir", "@COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR@")
So, we end up with using the same, in our case 64-bit, runtime for both 32-bit an 64-bit LIT tests, and that breaks all 32-bit LIT tests.
Other runtimes under compiler-rt, such as asan or profile don't seem to force the library on the link step (so they leave it to the compiler to choose the correct one from the runtimes built during the build), so this problem seems to be unique to the builtins library.
We considered two solutions:
- add a fixup logic for
config.compiler_rt_libdirincompiler-rt/test/lit.common.configured.in, which assumes we have a way to compute the correct triple. - fix the substitutions so that when
config.enable_per_target_runtime_diris ON, we let the compiler choose the runtime (essentially omit-fno-builtin -nodefaultlibs $BUILD/lib/clang/22/lib/<target-triple>/libclang_rt.builtins.a).
@daltenty can you please proofread the description above and correct any issues. Thanks