1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
SUITE_distributed_thinlto_clang_PROBE() {
echo 'int main() { return 0; }' >test.c
if ! $COMPILER_TYPE_CLANG; then
echo "compiler is not Clang"
elif ! $COMPILER -fuse-ld=lld test.c 2>/dev/null; then
echo "compiler does not support lld"
elif ! $COMPILER --help | grep -q -- -fthinlto-index 2>/dev/null; then
echo "compiler does not support thinlto-index"
fi
}
SUITE_distributed_thinlto_clang_SETUP() {
cat <<EOF >test.c
#include <stdio.h>
// define in lib1.c
int lib1();
// define in lib2.c
int lib2();
int main(void) { printf("result: %d\\n", lib1() + lib2()); return 0;}
EOF
cat <<EOF >lib1.c
int lib1() { return 1; }
EOF
cat <<EOF >lib2.c
int lib2() { return 2; }
EOF
$COMPILER -flto=thin -O2 -c -o test.o test.c
$COMPILER -flto=thin -O2 -c -o lib1.o lib1.c
$COMPILER -flto=thin -O2 -c -o lib2.o lib2.c
# Use compiler to generate thinlto.index.bc.
$COMPILER -fuse-ld=lld -Wl,--thinlto-index-only=test.rst test.o lib1.o lib2.o
backdate *.c *.o *.bc
unset CCACHE_NODIRECT
}
SUITE_distributed_thinlto_clang() {
# -------------------------------------------------------------------------
TEST "-fthinlto-index=test.o.thinlto.bc"
$CCACHE_COMPILE -c -fthinlto-index=lib1.o.thinlto.bc lib1.o -o lib1.native.o
expect_stat direct_cache_hit 0
expect_stat cache_miss 1
$CCACHE_COMPILE -c -fthinlto-index=lib1.o.thinlto.bc lib1.o -o lib1.native.o
expect_stat direct_cache_hit 1
expect_stat cache_miss 1
$CCACHE_COMPILE -c -fthinlto-index=test.o.thinlto.bc test.o -o test.native.o
expect_stat direct_cache_hit 1
expect_stat cache_miss 2
$CCACHE_COMPILE -c -fthinlto-index=test.o.thinlto.bc test.o -o test.native.o
expect_stat direct_cache_hit 2
expect_stat cache_miss 2
# Modify lib2.c, only affect test.o.thinlto.bc, but not affect lib1.o.thinlto.bc.
echo 'int tmp_x;' >>lib2.c
$COMPILER -O2 -flto=thin -c -o lib2.o lib2.c
$COMPILER -fuse-ld=lld -Wl,--thinlto-index-only=test.rst test.o lib1.o lib2.o
backdate *.c *.o *.bc
$CCACHE_COMPILE -c -fthinlto-index=lib1.o.thinlto.bc lib1.o -o lib1.native.o
expect_stat direct_cache_hit 3
expect_stat cache_miss 2
$CCACHE_COMPILE -c -fthinlto-index=test.o.thinlto.bc test.o -o test.native.o
expect_stat direct_cache_hit 3
expect_stat cache_miss 3
# -------------------------------------------------------------------------
}
|