| 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 | . "$(dirname "$0")/../lib.sh"
|
| 30 |
|
| 31 | setup
|
| 32 | clang_only "ThinLTO requires clang"
|
| 33 |
|
| 34 | find_thinlto_toolchain ||
|
| 35 | probe_skip "no matching clang/lld pair for a ThinLTO link; set THIN_LD to one"
|
| 36 |
|
| 37 | build_thinlto() |
| 38 | {
|
| 39 | local t
|
| 40 | for t in "" -DTU_B -DTU_C; do
|
| 41 | $THIN_CC -flto=thin -O2 -ffunction-sections -fdata-sections \
|
| 42 | $2 $t -c "$FIXTURES_DIR/thinlto_ambiguity.c" \
|
| 43 | -o "$workdir/tu$t.o" 2>/dev/null || return 1
|
| 44 | done
|
| 45 | "$THIN_LD" -r "$workdir/tu.o" "$workdir/tu-DTU_B.o" "$workdir/tu-DTU_C.o" \
|
| 46 | -o "$1" 2>/dev/null || return 1
|
| 47 | }
|
| 48 |
|
| 49 | build_thinlto "$workdir/orig.o" "" ||
|
| 50 | probe_skip "ThinLTO build failed ($THIN_CC, $THIN_LD)"
|
| 51 | build_thinlto "$workdir/patched.o" -DPATCHED ||
|
| 52 | probe_skip "ThinLTO build failed ($THIN_CC, $THIN_LD)"
|
| 53 |
|
| 54 | |
| 55 | |
| 56 | |
| 57 | orig_syms="$(in_symbols orig.o | grep -oE 'helper\.llvm\.[0-9]+' | sort -u)"
|
| 58 | new_syms="$( in_symbols patched.o | grep -oE 'helper\.llvm\.[0-9]+' | sort -u)"
|
| 59 | [ "$(echo "$orig_syms" | wc -l)" = 2 ] && [ "$(echo "$new_syms" | wc -l)" = 2 ] ||
|
| 60 | probe_skip "ThinLTO did not promote two distinct helpers here"
|
| 61 |
|
| 62 | kept="$(comm -12 <(echo "$orig_syms") <(echo "$new_syms"))"
|
| 63 | moved="$(comm -13 <(echo "$orig_syms") <(echo "$new_syms"))"
|
| 64 | [ "$(echo "$kept" | wc -w)" = 1 ] && [ "$(echo "$moved" | wc -w)" = 1 ] ||
|
| 65 | probe_skip "expected one helper to keep its hash and one to move"
|
| 66 |
|
| 67 | run_diff
|
| 68 |
|
| 69 | |
| 70 | |
| 71 | assert_not_patched "$kept"
|
| 72 |
|
| 73 | n="$(out_sections | grep -cE '[[:space:]]\.text\.helper\.llvm\.[0-9]+[[:space:]]')"
|
| 74 | [ "$n" = 1 ] ||
|
| 75 | fail "expected 1 cloned helper, found $n"
|
| 76 |
|
| 77 | pass "ThinLTO helpers sharing a demangled name paired up correctly"
|