Closed
Description
When using bolt to optimize the new version of the database, I encountered the following error and wanted to ask if anyone has encountered this issue before and how you resolved it. I was able to reproduce this error on a small test case. Is this error expected or is there something wrong with my linker script or compile options?
/home/test/llvm/build4/bin/llvm-bolt pre.exe -o pre.opt
BOLT-INFO: Target architecture: aarch64
BOLT-INFO: BOLT version: 042c444c9a68
BOLT-INFO: first alloc address is 0x0
BOLT-INFO: creating new program header table at address 0x200000, offset 0x200000
BOLT-INFO: enabling relocation mode
BOLT-INFO: disabling -align-macro-fusion on non-x86 platform
llvm-bolt: /home/test/llvm/llvm/include/llvm/Support/ErrorOr.h:237: llvm::ErrorOr<T>::storage_type* llvm::ErrorOr<T>::getStorage() [with T = llvm::bolt::BinarySection&; llvm::ErrorOr<T>::storage_type = std::reference_wrapper<llvm::bolt::BinarySection>]: Assertion `!HasError && "Cannot get value when an error exists!"' failed.
#0 0x0000aaaaeb2e5738 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/test/llvm/llvm/lib/Support/Unix/Signals.inc:565:22
#1 0x0000aaaaeb2e5808 PrintStackTraceSignalHandler(void*) /home/test/llvm/llvm/lib/Support/Unix/Signals.inc:632:1
#2 0x0000aaaaeb2e3640 llvm::sys::RunSignalHandlers() /home/test/llvm/llvm/lib/Support/Signals.cpp:103:20
#3 0x0000aaaaeb2e4fd0 SignalHandler(int) /home/test/llvm/llvm/lib/Support/Unix/Signals.inc:407:1
#4 0x0000ffff9570e7c0 (linux-vdso.so.1+0x7c0)
#5 0x0000ffff953c4e80 raise (/lib64/libc.so.6+0x34e80)
#6 0x0000ffff953c6374 abort (/lib64/libc.so.6+0x36374)
#7 0x0000ffff953bddd4 (/lib64/libc.so.6+0x2ddd4)
#8 0x0000ffff953bde5c (/lib64/libc.so.6+0x2de5c)
#9 0x0000aaaaeb3849d0 llvm::ErrorOr<llvm::bolt::BinarySection&>::getStorage() /home/test/llvm/llvm/include/llvm/Support/ErrorOr.h:238:54
#10 0x0000aaaaeb383c90 llvm::ErrorOr<llvm::bolt::BinarySection&>::operator->() /home/test/llvm/llvm/include/llvm/Support/ErrorOr.h:158:21
#11 0x0000aaaaeb3950c8 llvm::bolt::RewriteInstance::getLSDAData() /home/test/llvm/bolt/lib/Rewrite/RewriteInstance.cpp:1658:48
#12 0x0000aaaaeb39c8ec llvm::bolt::RewriteInstance::disassembleFunctions() /home/test/llvm/bolt/lib/Rewrite/RewriteInstance.cpp:3033:25
#13 0x0000aaaaeb390c74 llvm::bolt::RewriteInstance::run() /home/test/llvm/bolt/lib/Rewrite/RewriteInstance.cpp:823:27
#14 0x0000aaaaea278258 main /home/test/llvm/bolt/tools/driver/llvm-bolt.cpp:244:29
#15 0x0000ffff953b0bec __libc_start_main (/lib64/libc.so.6+0x20bec)
#16 0x0000aaaaea2771dc _start (/home/test/llvm/build4/bin/llvm-bolt+0x53d1dc)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/test/llvm/build4/bin/llvm-bolt pre.exe -o pre.opt
./test.sh: line 9: 74574 Aborted (core dumped) $CPATH/llvm-bolt $1.exe -o $1.opt
pre.cpp:
#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;
}
mylld.lds:
SECTIONS {
.text : { *(.text*) }
. = 0x20000;
.eh_frame : { *(.eh_frame) }
. = 0x80000;
}
Reproduction steps and commands:
cd /home/test/test/issue/
/home/test/llvm/build4/bin/clang++ -O3 pre.cpp -c -o pre.o -O3 -flto=thin -Wl,-q -L/home/test/llvm/build/lib/aarch64-unknown-linux-gnu -lunwind -w
/home/test/llvm/build4/bin/clang++ pre.o -O3 -Wl,-q -fuse-ld=lld -no-pie -o pre.exe -O3 -flto=thin -Wl,-q -L/home/test/llvm/build/lib/aarch64-unknown-linux-gnu -lunwind -Wl,--script=mylld.lds
/home/test/llvm/build4/bin/llvm-bolt pre.exe -o pre.opt