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
21class Base {
22public:
23 virtual void foo();
24 virtual void bar();
25 virtual void goo();
26};
27
28class Derived : public Base {
29public:
30 virtual void foo() override;
31 virtual void bar() override;
32 virtual void goo() override;
33};
34
35;--- tt.cpp
36#include "tt.h"
37void Derived::goo() { printf("derived_goo\n"); }
38
39;--- main.cpp
40#include "tt.h"
41#pragma clang optimize off
42
43void Base::foo() { printf("base_foo\n"); }
44void Base::bar() { printf("base_bar\n"); }
45void Base::goo() { printf("base_goo\n"); }
46
47void Derived::foo() { printf("derived_foo\n"); }
48void Derived::bar() { printf("derived_bar\n"); }
49
50int main() {
51 Derived D;
52 Base *ptr = &D;
53 ptr->foo();
54 ptr->bar();
55 ptr->goo();
56 return 0;
57}
58

source code of bolt/test/runtime/relative-vftable.cpp