Hi list, I am making a simple custom pass that inserts print function calls for each instruction, so that compiled programs print out all llvm instructions on the dynamic path. For example, (conceptually) printf(“%s”, “x = x + 1”); // inserted code x = y + 1; // original code But it seems that there are some conflicts with existing optimization paths. When I compile a program with the custom pass and -O2, it causes segmentation faults: 1. <eof> parser at end of file 2. Per-module optimization passes 3. Running pass 'Interprocedural Sparse Conditional Constant Propagation' on module '/src/libfuzzer/FuzzerCrossOver.cpp'. #0 0x0000000001573cfa llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/clang-8+0x1573cfa) #1 0x00000000015721dc llvm::sys::RunSignalHandlers() (/usr/local/bin/clang-8+0x15721dc) #2 0x0000000001572347 SignalHandler(int) (/usr/local/bin/clang-8+0x1572347) #3 0x00007f8d810e7390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390) #4 0x0000000001497e69 (anonymous namespace)::SCCPSolver::getValueState(llvm::Value*) (.constprop.510) (/usr/local/bin/clang-8+0x1497e69) … I have two questions: - Is there any guide line to write a custom pass to avoid such a conflict? - Is there any existing framework to print out dynamic path in LLVM-IR format? I would appreciate if some of you can give comments. Thanks, Kihong
Hi Kihong, On Fri, 28 Jun 2019 at 05:58, Kihong Heo via llvm-dev <llvm-dev at lists.llvm.org> wrote:> - Is there any guide line to write a custom pass to avoid such a conflict?The most likely cause for the error is that the IR you're generating is somehow invalid, and causing issues later. It also looks like you might have an LLVM built without assertions, so if that's the case you should fix that (e.g. CMake a debug build with -DCMAKE_BUILD_TYPE=Debug). That might cause an error immediately when you create the IR, or at should at least give more information about why SCCP is failing.> - Is there any existing framework to print out dynamic path in LLVM-IR format?Not as far as I know. Cheers. Tim.
Hi Tim, Thanks for your suggestion! I built LLVM with Debug and tried this with my custom pass. But it has the following error error: unable to load plugin '../../trace-extractor/build/TracePass.so': '../../trace-extractor/build/TracePass.so: undefined symbol: _ZTIN4llvm10ModulePassE’ Originally I used a builtin Clang in the system and it does not produce this issue. When I search for this issue on Google, it seems to be relevant to “RTTI”. But as I know LLVM is built by default -fno-rtti. I also explicitly turned off it. Here is my cmake command: $ cmake -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_RTTI=OFF -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm Any thought? Best, - Kihong> On Jun 28, 2019, at 5:39 AM, Tim Northover <t.p.northover at gmail.com> wrote: > > Hi Kihong, > > On Fri, 28 Jun 2019 at 05:58, Kihong Heo via llvm-dev > <llvm-dev at lists.llvm.org> wrote: >> - Is there any guide line to write a custom pass to avoid such a conflict? > > The most likely cause for the error is that the IR you're generating > is somehow invalid, and causing issues later. > > It also looks like you might have an LLVM built without assertions, so > if that's the case you should fix that (e.g. CMake a debug build with > -DCMAKE_BUILD_TYPE=Debug). That might cause an error immediately when > you create the IR, or at should at least give more information about > why SCCP is failing. > >> - Is there any existing framework to print out dynamic path in LLVM-IR format? > > Not as far as I know. > > Cheers. > > Tim.