1 | // Test BOLT is able to handle relative virtual function table, i.e., when |
2 | // code is compiled with `-fexperimental-relative-c++-abi-vtables`. |
3 | |
4 | // REQUIRES: system-linux |
5 | |
6 | // RUN: split-file %s %t |
7 | // RUN: %clang -fuse-ld=lld -o %t/main.so %t/tt.cpp %t/main.cpp -Wl,-q \ |
8 | // RUN: -fno-rtti -fexperimental-relative-c++-abi-vtables |
9 | // RUN: %t/main.so | FileCheck %s |
10 | |
11 | // CHECK: derived_foo |
12 | // CHECK-NEXT: derived_bar |
13 | // CHECK-NEXT: derived_goo |
14 | |
15 | // RUN: llvm-bolt %t/main.so -o %t/main.bolted.so --trap-old-code |
16 | // RUN: %t/main.bolted.so | FileCheck %s |
17 | |
18 | ;--- tt.h |
19 | #include <stdio.h> |
20 | |
21 | class Base { |
22 | public: |
23 | virtual void foo(); |
24 | virtual void bar(); |
25 | virtual void goo(); |
26 | }; |
27 | |
28 | class Derived : public Base { |
29 | public: |
30 | virtual void foo() override; |
31 | virtual void bar() override; |
32 | virtual void goo() override; |
33 | }; |
34 | |
35 | ;--- tt.cpp |
36 | #include "tt.h" |
37 | void Derived::goo() { printf("derived_goo\n" ); } |
38 | |
39 | ;--- main.cpp |
40 | #include "tt.h" |
41 | #pragma clang optimize off |
42 | |
43 | void Base::foo() { printf("base_foo\n" ); } |
44 | void Base::bar() { printf("base_bar\n" ); } |
45 | void Base::goo() { printf("base_goo\n" ); } |
46 | |
47 | void Derived::foo() { printf("derived_foo\n" ); } |
48 | void Derived::bar() { printf("derived_bar\n" ); } |
49 | |
50 | int main() { |
51 | Derived D; |
52 | Base *ptr = &D; |
53 | ptr->foo(); |
54 | ptr->bar(); |
55 | ptr->goo(); |
56 | return 0; |
57 | } |
58 | |