| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 |
|
| 8 | . "$(dirname "$0")/../lib.sh"
|
| 9 |
|
| 10 | setup
|
| 11 | clang_only "ThinLTO requires clang"
|
| 12 |
|
| 13 | find_thinlto_toolchain ||
|
| 14 | probe_skip "no matching clang/lld pair for a ThinLTO link; set THIN_LD to one"
|
| 15 |
|
| 16 | build_thinlto() |
| 17 | {
|
| 18 | $THIN_CC -flto=thin -O2 -ffunction-sections -fdata-sections $2 \
|
| 19 | -c "$FIXTURES_DIR/thinlto_local.c" -o "$workdir/tu_a.o" 2>/dev/null || return 1
|
| 20 | $THIN_CC -flto=thin -O2 -ffunction-sections -fdata-sections $2 -DTU_B \
|
| 21 | -c "$FIXTURES_DIR/thinlto_local.c" -o "$workdir/tu_b.o" 2>/dev/null || return 1
|
| 22 | "$THIN_LD" -r "$workdir/tu_a.o" "$workdir/tu_b.o" -o "$1" 2>/dev/null || return 1
|
| 23 | }
|
| 24 |
|
| 25 | build_thinlto "$workdir/orig.o" "" ||
|
| 26 | probe_skip "ThinLTO build failed ($THIN_CC, $THIN_LD)"
|
| 27 | build_thinlto "$workdir/patched.o" -DPATCHED ||
|
| 28 | probe_skip "ThinLTO build failed ($THIN_CC, $THIN_LD)"
|
| 29 |
|
| 30 | orig_sym="$(in_symbols orig.o | grep -o 'counter\.llvm\.[0-9]*' | head -1)"
|
| 31 | new_sym="$( in_symbols patched.o | grep -o 'counter\.llvm\.[0-9]*' | head -1)"
|
| 32 |
|
| 33 | [ -n "$orig_sym" ] && [ -n "$new_sym" ] ||
|
| 34 | probe_skip "$THIN_CC did not promote the local symbol"
|
| 35 |
|
| 36 | |
| 37 | [ "$orig_sym" != "$new_sym" ] ||
|
| 38 | probe_skip "$THIN_CC gave the same ThinLTO hash for both builds"
|
| 39 |
|
| 40 | run_diff
|
| 41 | assert_patched target
|
| 42 |
|
| 43 | out_symbols | grep -q "\.klp\.sym\.vmlinux\.$orig_sym," ||
|
| 44 | fail "expected a klp relocation naming $orig_sym"
|
| 45 | out_symbols | grep -q "\.klp\.sym\.vmlinux\.$new_sym," &&
|
| 46 | fail "klp relocation names $new_sym, which the running kernel does not have"
|
| 47 |
|
| 48 | pass "ThinLTO-mangled local correlated across differing hashes ($THIN_CC, $THIN_LD)"
|