|
| 1 | +/* This test check that the negate-ra-state CFIs are properly emitted in case of |
| 2 | + 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-runtime |
| 10 | +
|
| 11 | +# FDATA: 1 main #split# 1 _Z3foov 0 0 1 |
| 12 | +
|
| 13 | +# RUN: %clangxx --target=aarch64-unknown-linux-gnu \ |
| 14 | +# RUN: -mbranch-protection=pac-ret %s -o %t.exe -Wl,-q |
| 15 | +# RUN: link_fdata %s %t.exe %t.fdata |
| 16 | +# 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 %s |
| 20 | +# RUN: %t.bolt | FileCheck %s --check-prefix=RUN-CHECK |
| 21 | +
|
| 22 | +# BOLT-CHECK-NOT: bl __cxa_throw@PLT |
| 23 | +# BOLT-CHECK: ------- HOT-COLD SPLIT POINT ------- |
| 24 | +# BOLT-CHECK: bl __cxa_throw@PLT |
| 25 | +
|
| 26 | +# RUN-CHECK: Exception caught: Exception from foo(). |
| 27 | +*/ |
| 28 | + |
| 29 | +#include <cstdio> |
| 30 | +#include <stdexcept> |
| 31 | + |
| 32 | +void foo() { throw std::runtime_error("Exception from foo()."); } |
| 33 | + |
| 34 | +int 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 | +} |
0 commit comments