error: unexpected type in metadata definition
[ 4%] Building CXX object CMakeFiles/MergeBB.dir/MergeBB.o In file included from ____/tutor/lib/MergeBB.cpp:44: _____/tutor/lib/../include/MergeBB.h:13:10: fatal error: llvm/IR/PassManager.h: No such file or directory 13 | #include "llvm/IR/PassManager.h" | ^~~~~~~~~~~~~~~~~~~~~~~
Hacky does not seem to easy to get llvm to point to LLVM release kit using environment variables. Possibly copy llvm/IR/PassManager.h and (all the other .h files you need) into your include directory (note directory structure) or even worse use soft directory link (you may also need llvm-c).
cd ../include/ ln -s $LLVM_DIR/include/llvm ln -s $LLVM_DIR/include/llvm-c
g++ -DOpcodeCounter_EXPORTS -I../include -fPIC -o CMakeFiles/OpcodeCounter.dir/OpcodeCounter.o -c OpcodeCounter.cpp OpcodeCounter.cpp: In lambda function: OpcodeCounter.cpp:124:37: error: ‘llvm::PassBuilder::OptimizationLevel’ has not been declared 124 | llvm::PassBuilder::OptimizationLevel Level) { | ^~~~~~~~~~~~~~~~~ OpcodeCounter.cpp:126:16: error: cannot convert ‘getOpcodeCounterPluginInfo():::: ’ to ‘const std::function &, llvm::OptimizationLevel)>&’ 126 | }); | ^ In file included from OpcodeCounter.cpp:35: llvm/Passes/PassBuilder.h:448:76: note: initializing argument 1 of ‘void llvm::PassBuilder::registerVectorizerStartEPCallback(const std::function &, llvm::OptimizationLevel)>&)’ 448 | const std::function &C) { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ 139 ucacbbl@eden% g++ -DOpcodeCounter_EXPORTS -I../include -fPIC -o CMakeFiles/OpcodeCounter.dir/OpcodeCounter.o -c t.cpp
Remember to restart make to compile and link remaining files
With line 124 removed libOpcodeCounter.so fails with LLVM opt:
$LLVM_DIR/bin/opt -load ../tutor/lib/libOpcodeCounter.so -legacy-opcode-counter -analyze input_for_cc.ll Cannot specify -analyze under new pass manager, either specify '-enable-new-pm=0', or use the corresponding new pass manager pass, e.g. '-passes=print'. For a full list of passes, see the '--print-passes' flag.
$LLVM_DIR/bin/opt -load ../tutor/lib/libOpcodeCounter.so -legacy-opcode-counter -analyze input_for_cc.ll Error opening '../tutor/lib/libOpcodeCounter.so': ../tutor/lib/libOpcodeCounter.so: undefined symbol: _ZTIN4llvm18format_object_baseE
$LLVM_DIR/bin/opt -load ../tutor/lib/libInjectFuncCall.so -legacy-inject-func-call input_for_hello.bc -o instrumented.bin Error opening '../tutor/lib/libInjectFuncCall.so': ../tutor/lib/libInjectFuncCall.so: undefined symbol: _ZTIN4llvm10ModulePassE -load request ignored.
https://stackoverflow.com/questions/17225956/developing-an-llvm-pass-with-cmake-out-of-llvm-source-directory actually suggests -Wall -fno-rtti but only need -fno-rtti Achieved by adding set(CMAKE_CXX_FLAGS "-Wall -fno-rtti") to CMakeLists.txt and running cmake followed by make again.
$LLVM_DIR/bin/opt -enable-new-pm=0 -load ../tutor/lib/libInjectFuncCall.so -legacy-inject-func-call input_for_hello.bc -o instrumented.bin
$LLVM_DIR/bin/opt -enable-new-pm=0 -load ../tutor/lib/libStaticCallCounter.so -legacy-static-cc -analyze input_for_cc.ll Printing analysis 'LegacyStaticCallCounter': ================================================= LLVM-TUTOR: static analysis results ================================================= NAME #N DIRECT CALLS ------------------------------------------------- -------------------------------------------------
Fix recompile input_for_cc.ll without -O1 and re-run.
$LLVM_DIR/bin/clang -S -emit-llvm -c ../tutor/inputs/input_for_cc.c -o input_for_cc.ll $LLVM_DIR/bin/opt -enable-new-pm=0 -load ../tutor/lib/libStaticCallCounter.so -legacy-static-cc -analyze input_for_cc.ll Printing analysis 'LegacyStaticCallCounter': ================================================= LLVM-TUTOR: static analysis results ================================================= NAME #N DIRECT CALLS ------------------------------------------------- foo 3 bar 2 fez 1 -------------------------------------------------
$LLVM_DIR/bin/opt -enable-new-pm=0 -load ../tutor/lib/libMBAAdd.so -legacy-mba-add -mba-ratio=0.3 ../tutor/inputs/input_for_mba.c -o out_obfuscation.ll /cs/sys/software2/llvm/llvm14//bin/opt: ../tutor/inputs/input_for_mba.c:1:1: error: expected top-level entity //============================================================================= ^
$LLVM_DIR/bin/opt -enable-new-pm=0 -load ../tutor/lib/libMBAAdd.so -legacy-mba-add -mba-ratio=0.3 -S input_for_mba.ll -o out_obfuscation.ll
$LLVM_DIR/bin/opt --load-pass-plugin ../tutor/lib/libFindFCmpEq.so --passes="printNo output." -disable-output input_for_fcmp_eq.ll
Note used of -enable-new-pm=0, which is needed for LLVM 14 onwards (see above).
$LLVM_DIR/bin/opt -enable-new-pm=0 -load ../tutor/lib/libFindFCmpEq.so -find-fcmp-eq -analyze input_for_fcmp_eq.ll Printing analysis 'Floating-point equality comparisons locator' for function 'sqrt_impl': Floating-point equality comparisons in "sqrt_impl": %11 = fcmp oeq double %9, %10 Printing analysis 'Floating-point equality comparisons locator' for function 'sqrt': Printing analysis 'Floating-point equality comparisons locator' for function 'main': Floating-point equality comparisons in "main": %9 = fcmp oeq double %8, 1.000000e+00 %13 = fcmp oeq double %11, %12 %19 = fcmp oeq double %17, %18opt's output is not as the example.
Notice %24 = fcmp olt double %22, %23 is not reported (due to being olt rather than a fcmp oeq).
Notice