43 lines · cpp
1/* This test check that the negate-ra-state CFIs are properly emitted in case of2 function splitting. The test checks two things:3 - we split at the correct location: to test the feature,4 we need to split *before* the bl __cxa_throw@PLT call is made,5 so the unwinder has to unwind from the split (cold) part.6 7 - the BOLTed binary runs, and returns the string from foo.8 9# REQUIRES: system-linux,bolt-runtime10 11# FDATA: 1 main #split# 1 _Z3foov 0 0 112 13# RUN: %clangxx --target=aarch64-unknown-linux-gnu \14# RUN: -mbranch-protection=pac-ret %s -o %t.exe -Wl,-q15# RUN: link_fdata %s %t.exe %t.fdata16# RUN: llvm-bolt %t.exe -o %t.bolt --split-functions --split-eh \17# RUN: --split-strategy=profile2 --split-all-cold --print-split \18# RUN: --print-only=_Z3foov --data=%t.fdata 2>&1 | FileCheck \19# RUN: --check-prefix=BOLT-CHECK %s20# RUN: %t.bolt | FileCheck %s --check-prefix=RUN-CHECK21 22# BOLT-CHECK-NOT: bl __cxa_throw@PLT23# BOLT-CHECK: ------- HOT-COLD SPLIT POINT -------24# BOLT-CHECK: bl __cxa_throw@PLT25 26# RUN-CHECK: Exception caught: Exception from foo().27*/28 29#include <cstdio>30#include <stdexcept>31 32void foo() { throw std::runtime_error("Exception from foo()."); }33 34int main() {35 try {36 __asm__ __volatile__("split:");37 foo();38 } catch (const std::exception &e) {39 printf("Exception caught: %s\n", e.what());40 }41 return 0;42}43