1// This test check that LSDA section named by .gcc_except_table.main is
2// disassembled by BOLT.
3
4// RUN: %clang++ %cxxflags -O3 -no-pie -c %s -o %t.o
5// RUN: %clang++ %cxxflags -no-pie -fuse-ld=lld %t.o -o %t.exe \
6// RUN: -Wl,-q -Wl,--script=%S/Inputs/lsda.ldscript
7// RUN: llvm-readelf -SW %t.exe | FileCheck %s
8// RUN: llvm-bolt %t.exe -o %t.bolt
9
10// CHECK: .gcc_except_table.main
11
12#include <iostream>
13
14class MyException : public std::exception {
15public:
16 const char *what() const throw() {
17 return "Custom Exception: an error occurred!";
18 }
19};
20
21int divide(int a, int b) {
22 if (b == 0) {
23 throw MyException();
24 }
25 return a / b;
26}
27
28int main() {
29 try {
30 int result = divide(a: 10, b: 2); // normal case
31 std::cout << "Result: " << result << std::endl;
32 result = divide(a: 5, b: 0); // will cause exception
33 std::cout << "Result: " << result << std::endl;
34 // this line will not execute
35 } catch (const MyException &e) {
36 // catch custom exception
37 std::cerr << "Caught exception: " << e.what() << std::endl;
38 } catch (const std::exception &e) {
39 // catch other C++ exceptions
40 std::cerr << "Caught exception: " << e.what() << std::endl;
41 } catch (...) {
42 // catch all other exceptions
43 std::cerr << "Caught unknown exception" << std::endl;
44 }
45
46 return 0;
47}
48

source code of bolt/test/lsda-section-name.cpp