facebookarchive / BOLT

Binary Optimization and Layout Tool - A linux command-line utility used for optimizing performance of binaries
2.51k stars 177 forks source link

[C++] Exceptions catch leads to Segmentation fault #317

Closed LuJiaWeiwei closed 1 year ago

LuJiaWeiwei commented 1 year ago

I compile the following code with /home/distcc/clang-11.1.0/bin/clang++ 1.cpp -pthread -fPIC -std=libc++ -Wl,-q -lc++abi -std=gnu++14 -no-pie -o bolt_try_catch

`#include

include

class ExceptionA{}; using namespace std;

bool UnitOverBudgetCheck(const int64_t unit_id, const int64_t current_time) { try{ throw ExceptionA(); }catch(ExceptionA&){ return false; } }

int main() { for(int j =0; j < 100; j++){ for(int i = 0; i < 100; i++) { bool r = UnitOverBudgetCheck(i, i * 3); printf("result is : %d\n", r); } }

return 0; }

`

and then ./llvm-bolt bolt_try_catch -o bolt_try_catch.bolt

BOLT-INFO: Target architecture: x86_64 BOLT-INFO: BOLT version: 88c70afe9d388ad430cc150cc158641701397f70 BOLT-INFO: first alloc address is 0x400000 BOLT-INFO: creating new program header table at address 0x600000, offset 0x200000 BOLT-INFO: enabling relocation mode BOLT-INFO: enabling -align-macro-fusion=all since no profile was specified BOLT-INFO: enabling lite mode BOLT-WARNING: Ignored 0 functions due to cold fragments. BOLT-INFO: forcing -jump-tables=move as PIC jump table was detected in function _ZN10__cxxabiv1L18readEncodedPointerEPPKhh/1(*2) BOLT-INFO: 0 out of 394 functions in the binary (0.0%) have non-empty execution profile BOLT-INFO: the input contains 54 (dynamic count : 0) opportunities for macro-fusion optimization that are going to be fixed BOLT-INFO: 2257 instructions were shortened BOLT-INFO: removed 103 empty blocks BOLT-INFO: removed 2 'repz' prefixes with estimated execution count of 0 times. BOLT-INFO: UCE removed 0 blocks and 0 bytes of code. BOLT-INFO: SCTC: patched 4 tail calls (4 forward) tail calls (0 backward) from a total of 4 while removing 0 double jumps and removing 3 basic blocks totalling 15 bytes of code. CTCs total execution count is 0 and the number of times CTCs are taken is 0. BOLT-INFO: setting _end to 0x432160