Find reason for LLVM/opt crash when trying to instrument some functions
When compiling code that is to be linked with libfiber, instrumenting some functions/loops fails as follows:
opt -O3 -load 'build/Yield/libYield.so' '-yield' 'build/fiber_pre.bc' -o 'build/fiber_post.bc'
Running on function main, loop <unnamed loop>
Running on function main
Running on function llvm.lifetime.start.p0i8
Running on function fiber_manager_init
Running on function fiber_create
Running on function bench_function, loop .preheader
Running on function bench_function
Running on function fiber_join
Running on function llvm.lifetime.end.p0i8
Running on function fprintf
Running on function calloc
Running on function perror
Running on function exit
Running on function __errno_location
Stack dump:
0. Program arguments: opt -O3 -load build/Yield/libYield.so -yield build/fiber_pre.bc -o build/fiber_post.bc
1. Running pass 'ayekat's test pass' on module 'build/fiber_pre.bc'.
LLVMSymbolizer: error reading file: No such file or directory
#0 0x00007f4590714b1b llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/bin/../lib/libLLVM-7.so+0x8feb1b)
#1 0x00007f4590712f74 llvm::sys::RunSignalHandlers() (/usr/bin/../lib/libLLVM-7.so+0x8fcf74)
#2 0x00007f45907130fe (/usr/bin/../lib/libLLVM-7.so+0x8fd0fe)
#3 0x00007f458fae0e00 __restore_rt (/usr/bin/../lib/libc.so.6+0x37e00)
#4 0x00007f459057b284 dlerror (/usr/bin/../lib/libLLVM-7.so+0x765284)
#5 0x00007f458d4d050a llvm::BasicBlock::getTerminator() (build/Yield/libYield.so+0x1350a)
#6 0x00007f458d4cf10d (anonymous namespace)::Yield::insertGlobalCountIncrement(llvm::BasicBlock&) (build/Yield/libYield.so+0x1210d)
#7 0x00007f458d4cf0a0 (anonymous namespace)::Yield::runOnFunction(llvm::Function&) (build/Yield/libYield.so+0x120a0)
#8 0x00007f458d4ced4f (anonymous namespace)::Yield::runOnModule(llvm::Module&) (build/Yield/libYield.so+0x11d4f)
#9 0x00007f459080e720 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/bin/../lib/libLLVM-7.so+0x9f8720)
#10 0x00005625a3440691 (opt+0x26691)
#11 0x00007f458facd223 __libc_start_main (/usr/bin/../lib/libc.so.6+0x24223)
#12 0x00005625a344149e (opt+0x2749e)
make: *** [Makefile:39: build/fiber_post.bc] Segmentation fault (core dumped)
rm build/fiber_pre.bc
For now, I have to skip those "problematic" functions in the pass, but that is not a real option (because I haven't found a specific pattern for which functions fail and which don't, so potentially any function could fail to be instrumented).