209 lines · plain
1; REQUIRES: x862;; Test that dynamically exported symbols prevent devirtualization.3 4;; First check that we get devirtualization without any export dynamic options.5 6;; Index based WPD7;; Generate unsplit module with summary for ThinLTO index-based WPD.8; RUN: opt --thinlto-bc -o %t2.o %s9; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \10; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK11; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR12;; --export-dynamic without .dynsym does not prevent devirtualization.13; RUN: ld.lld %t2.o -o %t3 -save-temps --lto-whole-program-visibility \14; RUN: -mllvm -pass-remarks=. \15; RUN: --export-dynamic 2>&1 | FileCheck %s --check-prefix=REMARK16 17;; Hybrid WPD18;; Generate split module with summary for hybrid Thin/Regular LTO WPD.19; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t.o %s20; RUN: ld.lld %t.o -o %t3 -save-temps --lto-whole-program-visibility \21; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK22; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR23 24;; Regular LTO WPD25; RUN: opt -o %t4.o %s26; RUN: ld.lld %t4.o -o %t3 -save-temps --lto-whole-program-visibility \27; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK28; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR29 30; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi31; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi32 33;; Check that all WPD fails with --export-dynamic.34 35; RUN: echo '.globl foo; foo:' > %ta.s36; RUN: llvm-mc -filetype=obj -triple=x86_64 %ta.s -o %ta.o37; RUN: ld.lld -shared -soname=ta %ta.o -o %ta.so38 39;; Index based WPD40 41; RUN: ld.lld %t2.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \42; RUN: -mllvm -pass-remarks=. \43; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty44; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR45 46;; Hybrid WPD47; RUN: ld.lld %t.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \48; RUN: -mllvm -pass-remarks=. \49; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty50; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR51 52;; Regular LTO WPD53; RUN: ld.lld %t4.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \54; RUN: -mllvm -pass-remarks=. \55; RUN: --export-dynamic 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty56; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR57 58;; Check that WPD fails for target _ZN1D1mEi with --export-dynamic-symbol=_ZTV1D.59 60;; Index based WPD61; RUN: ld.lld %t2.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \62; RUN: -mllvm -pass-remarks=. \63; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY64; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR65 66;; Hybrid WPD67; RUN: ld.lld %t.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \68; RUN: -mllvm -pass-remarks=. \69; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY70; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR71 72;; Regular LTO WPD73; RUN: ld.lld %t4.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \74; RUN: -mllvm -pass-remarks=. \75; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY76; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR77 78; REMARK-AONLY-NOT: single-impl:79; REMARK-AONLY: single-impl: devirtualized a call to _ZN1A1nEi80; REMARK-AONLY-NOT: single-impl:81 82;; Check that WPD fails for target _ZN1D1mEi with _ZTV1D in --dynamic-list.83; RUN: echo "{ _ZTV1D; };" > %t.list84 85;; Index based WPD86; RUN: ld.lld %t2.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \87; RUN: -mllvm -pass-remarks=. \88; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY89; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR90 91;; Hybrid WPD92; RUN: ld.lld %t.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \93; RUN: -mllvm -pass-remarks=. \94; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY95; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR96 97;; Regular LTO WPD98; RUN: ld.lld %t4.o %ta.so -o %t3 -save-temps --lto-whole-program-visibility \99; RUN: -mllvm -pass-remarks=. \100; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY101; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR102 103 104;; Check that all WPD fails with when linking against a shared library containing105;; preemptible versions of the vtables. In this case the symbols in the object being106;; linked against the shared library must be exported to .dynsym to allow the runtime107;; preemption, even without any options.108 109;; Index based WPD110; RUN: opt -relocation-model=pic --thinlto-bc -o %t5.o %s111; RUN: ld.lld %t5.o -o %t5.so -shared112; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \113; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty114 115;; Hybrid WPD116; RUN: opt -relocation-model=pic --thinlto-bc --thinlto-split-lto-unit -o %t5.o %s117; RUN: ld.lld %t5.o -o %t5.so -shared118; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \119; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty120 121;; Regular LTO WPD122; RUN: opt -relocation-model=pic -o %t5.o %s123; RUN: ld.lld %t5.o -o %t5.so -shared124; RUN: ld.lld %t5.o %t5.so -o %t5 -save-temps --lto-whole-program-visibility \125; RUN: -mllvm -pass-remarks=. 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty126 127target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"128target triple = "x86_64-grtev4-linux-gnu"129 130%struct.A = type { ptr }131%struct.B = type { %struct.A }132%struct.C = type { %struct.A }133%struct.D = type { ptr }134 135@_ZTV1B = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !5136@_ZTV1C = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !5137@_ZTV1D = linkonce_odr unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !5138 139;; Prevent the vtables from being dead code eliminated.140@llvm.used = appending global [3 x ptr] [ ptr @_ZTV1B, ptr @_ZTV1C, ptr @_ZTV1D]141 142; CHECK-IR-LABEL: define dso_local {{(noundef )?}}i32 @_start143define i32 @_start(ptr %obj, ptr %obj2, i32 %a) {144entry:145 %vtable = load ptr, ptr %obj146 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")147 call void @llvm.assume(i1 %p)148 %fptrptr = getelementptr ptr, ptr %vtable, i32 1149 %fptr1 = load ptr, ptr %fptrptr, align 8150 151 ;; Check that the call was devirtualized.152 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi153 ; CHECK-AONLY-IR: %call = tail call i32 @_ZN1A1nEi154 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1155 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)156 157 %fptr22 = load ptr, ptr %vtable, align 8158 159 ;; We still have to call it as virtual.160 ; CHECK-IR: %call3 = tail call i32 %fptr22161 ; CHECK-AONLY-IR: %call3 = tail call i32 %fptr22162 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22163 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)164 165 %vtable2 = load ptr, ptr %obj2166 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)167 call void @llvm.assume(i1 %p2)168 169 %fptr33 = load ptr, ptr %vtable2, align 8170 171 ;; Check that the call was devirtualized.172 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi173 ; CHECK-AONLY-IR: %call4 = tail call i32 %fptr33174 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33175 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)176 ret i32 %call4177}178; CHECK-IR-LABEL: ret i32179; CHECK-IR-LABEL: }180 181declare i1 @llvm.type.test(ptr, metadata)182declare void @llvm.assume(i1)183 184define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {185 ret i32 0;186}187 188define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {189 ret i32 0;190}191 192define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {193 ret i32 0;194}195 196define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {197 ret i32 0;198}199 200;; Make sure we don't inline or otherwise optimize out the direct calls.201attributes #0 = { noinline optnone }202 203!0 = !{i64 16, !"_ZTS1A"}204!1 = !{i64 16, !"_ZTS1B"}205!2 = !{i64 16, !"_ZTS1C"}206!3 = !{i64 16, !4}207!4 = distinct !{}208!5 = !{i64 0}209