I am trying to get function arguments from a project code. At first, I tried to get arguments from a 1 function. It worked fine. I also tried to do the same for a couple of functions that has the word “publish” in them. It is dumping while using the pass to create an object of a particular file, “TxtSortingLineRun.cpp.” I have created the IR of that file and also checked if this file contains functions with publish word on it. There is a lot of functions like that, but clang is crashing at the end,
Here is the error that I am getting,
found:_ZN2ft20TxtMqttFactoryClient14publishSLD_AckENS_15TxtSldAckCode_tENS_11TxtWPType_tEil
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: clang++-14 --target=arm-linux-gnueabihf -flegacy-pass-manager -g -Xclang -load -Xclang /home/u18new/LLVM_passes/LogPasses-new/messagePublishFunc/instrument.so -std=gnu++0x -std$
c++0x -DDEBUG -DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_TRACE -ITxtSmartFactoryLib/include -ITxtSmartFactoryLib/libs -I/home/ubuntu-18/Desktop/paho.mqtt.c/build/_install/include/ -I/home/ubuntu-18/Desktop/paho.$
qtt.cpp/build/_install/include/ -Ideps/include -O0 -g3 -Wall -c -fmessage-length=0 -Wno-psabi -fPIC -MMD -MP -MFTxtSmartFactoryLib/Posix_Debug/src/TxtSortingLineRun.d -MTTxtSmartFactoryLib/Posix_Debug/sr$
/TxtSortingLineRun.o -o TxtSmartFactoryLib/Posix_Debug/src/TxtSortingLineRun.o TxtSmartFactoryLib/src/TxtSortingLineRun.cpp
1. <eof> parser at end of file
2. Per-module optimization passes
3. Running pass 'AFLCoverage Pass' on module 'TxtSmartFactoryLib/src/TxtSortingLineRun.cpp'.
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamEi+0x31)[0x7fa8481b76a1]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0xee)[0x7fa8481b53ee]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm3sys15CleanupOnSignalEm+0x100)[0x7fa8481b6a60]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0xd7a1bf)[0x7fa8480e31bf]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12980)[0x7fa85148d980]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(+0xe58ff6)[0x7fa8481c1ff6]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZNK4llvm5Value5printERNS_11raw_ostreamERNS_17ModuleSlotTrackerEb+0x48a)[0x7fa8481c1e0a]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZNK4llvm5Value5printERNS_11raw_ostreamEb+0xc9)[0x7fa8481c1879]
/home/u18new/LLVM_passes/LogPasses-new/messagePublishFunc/instrument.so(+0x2c58)[0x7fa8431d7c58]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x946)[0x7fa8482f27c6]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang17EmitBackendOutputERNS_17DiagnosticsEngineERKNS_19HeaderSearchOptionsERKNS_14CodeGenOptionsERKNS_13TargetOptionsERKNS_11LangOptionsEN4llvm9StringRef$
PNSE_6ModuleENS_13BackendActionESt10unique_ptrINSE_17raw_pwrite_streamESt14default_deleteISK_EE+0x340b)[0x7fa84f4e869b]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(+0x1b89c01)[0x7fa84f80cc01]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang8ParseASTERNS_4SemaEbb+0x244)[0x7fa84e688054]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang13CodeGenAction13ExecuteActionEv+0xb1)[0x7fa84f808f51]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang14FrontendAction7ExecuteEv+0x67)[0x7fa8501aa727]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang16CompilerInstance13ExecuteActionERNS_14FrontendActionE+0x336)[0x7fa850101d86]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang25ExecuteCompilerInvocationEPNS_16CompilerInstanceE+0x29b)[0x7fa850223e8b]
clang++-14(_Z8cc1_mainN4llvm8ArrayRefIPKcEES2_Pv+0x98f)[0x41329f]
clang++-14[0x4114dc]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(+0x20fc392)[0x7fa84fd7f392]
/usr/lib/x86_64-linux-gnu/libLLVM-14.so.1(_ZN4llvm20CrashRecoveryContext9RunSafelyENS_12function_refIFvvEEE+0xdd)[0x7fa8480e2f2d]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang6driver10CC1Command7ExecuteEN4llvm8ArrayRefINS2_8OptionalINS2_9StringRefEEEEEPNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPb+0x140)[0x7fa84f$
7ee80]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang6driver11Compilation14ExecuteCommandERKNS0_7CommandERPS3_+0x3f3)[0x7fa84fd46693]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZNK5clang6driver11Compilation11ExecuteJobsERKNS0_7JobListERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x8a)[0x7fa84fd4691a]
/usr/lib/x86_64-linux-gnu/libclang-cpp.so.14(_ZN5clang6driver6Driver18ExecuteCompilationERNS0_11CompilationERN4llvm15SmallVectorImplISt4pairIiPKNS0_7CommandEEEE+0x1a7)[0x7fa84fd60407]
clang++-14(main+0x2816)[0x410f46]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7fa8465d6c87]
clang++-14(_start+0x2a)[0x40e3da]
clang: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Ubuntu clang version 14.0.6
Target: arm-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang: note: diagnostic msg: /tmp/TxtSortingLineRun-966083.cpp
clang: note: diagnostic msg: /tmp/TxtSortingLineRun-966083.sh
clang: note: diagnostic msg:
********************
Makefile:129: recipe for target 'TxtSmartFactoryLib/Posix_Debug/src/TxtSortingLineRun.o' failed
make: *** [TxtSmartFactoryLib/Posix_Debug/src/TxtSortingLineRun.o] Error 139
In the pass I am just checking if there is any functions containing publish word on it, if it is present then injecting a print call,
if(F.getName().contains("message_arrived") || F.getName().contains("publish")){
Function* msg = &F;
if(msg != nullptr){
auto &BB = msg->getEntryBlock();
errs()<<BB<<"\n";
std::vector<std::string> arguments;
BasicBlock::iterator IP = BB.getFirstInsertionPt();
IRBuilder<> builder(&(*IP));
std::string format("\narguments: ");
std::string s;
raw_string_ostream rso(s);
rso << F.getName() << " ";
errs()<<"rso.str():"<<rso.str()<<"\n";
arguments.push_back(rso.str());
for(auto i = F.arg_begin();i!=F.arg_end();++i){
rso << *i<<"\n";
errs()<<"*i: "<<*i<<"\n";
arguments.push_back(rso.str());
}
for (size_t i = 0; i < arguments.size(); ++i) {
format += " %s\n";
}
Value *str = builder.CreateGlobalStringPtr(format, "");
std::vector<Value *> argsV({str});
for (auto &s : arguments) {
argsV.push_back(builder.CreateGlobalStringPtr(s, ""));
}
builder.CreateCall(printfFunc, argsV, "calltmp");
@sylvestre @akorobeynikov @tobiashieta @smithp35 @tstellar @rpmvig @tedwoodward @jdoerfert, will appreciate any thoughts you have.