58 lines · cpp
1// Test BOLT is able to handle relative virtual function table, i.e., when2// code is compiled with `-fexperimental-relative-c++-abi-vtables`.3 4// REQUIRES: system-linux5 6// RUN: split-file %s %t7// 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-vtables9// RUN: %t/main.so | FileCheck %s10 11// CHECK: derived_foo12// CHECK-NEXT: derived_bar13// CHECK-NEXT: derived_goo14 15// RUN: llvm-bolt %t/main.so -o %t/main.bolted.so --trap-old-code16// RUN: %t/main.bolted.so | FileCheck %s17 18;--- tt.h19#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.cpp36#include "tt.h"37void Derived::goo() { printf("derived_goo\n"); }38 39;--- main.cpp40#include "tt.h"41#pragma clang optimize off42 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