Vladislav Khmelevsky c5a306f07e
[BOLT] Fix LSDA section handling (#71821)
Currently BOLT finds LSDA secition by it's name .gcc_except_table.main .
But sometimes it might have suffix e.g. .gcc_except_table.main. Find
LSDA section by it's address, rather by it's name.
Fixes #71804
2023-11-15 23:21:50 +04:00

48 lines
1.3 KiB
C++

// This test check that LSDA section named by .gcc_except_table.main is
// disassembled by BOLT.
// RUN: %clang++ %cxxflags -O3 -flto=thin -no-pie -c %s -o %t.o
// RUN: %clang++ %cxxflags -flto=thin -no-pie -fuse-ld=lld %t.o -o %t.exe \
// RUN: -Wl,-q -Wl,--script=%S/Inputs/lsda.ldscript
// RUN: llvm-readelf -SW %t.exe | FileCheck %s
// RUN: llvm-bolt %t.exe -o %t.bolt
// CHECK: .gcc_except_table.main
#include <iostream>
class MyException : public std::exception {
public:
const char *what() const throw() {
return "Custom Exception: an error occurred!";
}
};
int divide(int a, int b) {
if (b == 0) {
throw MyException();
}
return a / b;
}
int main() {
try {
int result = divide(10, 2); // normal case
std::cout << "Result: " << result << std::endl;
result = divide(5, 0); // will cause exception
std::cout << "Result: " << result << std::endl;
// this line will not execute
} catch (const MyException &e) {
// catch custom exception
std::cerr << "Caught exception: " << e.what() << std::endl;
} catch (const std::exception &e) {
// catch other C++ exceptions
std::cerr << "Caught exception: " << e.what() << std::endl;
} catch (...) {
// catch all other exceptions
std::cerr << "Caught unknown exception" << std::endl;
}
return 0;
}