llvm-pass-skeleton
llvm-pass-skeleton copied to clipboard
Unable to run the program
I git cloned this repo and followed here to build my LLVM 4.0.0.
And use this c program under folder llvm-pass-skeleton/program/test.c to test:
/*
* C Program to Check whether the given Integer has an Alternate
* Pattern
*/
#include <stdio.h>
void main()
{
int num, x, y, count = 0;
printf("enter the number:");
scanf("%d", &num);
x = num << 1;
y = x ^ num;
y = y + 1;
/* Checks if the number is in powers of 2 */
while ((y / 2) != 0)
{
if (y % 2 != 0)
{
count++;
break;
}
else
{
y = y / 2;
}
}
if (count)
{
printf("false");
}
else
{
printf("true");
}
}
Then I got this error:
clang -Xclang -load -Xclang build/skeleton/libSkeletonPass.so program/test.c
error: unable to load plugin 'build/skeleton/libSkeletonPass.so': 'build/skeleton/libSkeletonPass.so:
undefined symbol: _ZN4llvm23EnableABIBreakingChecksE'
Similar to #4, but the default path is used when building and compiling my LLVM. This problem may be caused by LLVM version difference with reference to #11
I could use my LLVM version to run other .bc program without problem.
Indeed, as in #11, we haven't tested this with more recent versions of LLVM. As I recommended there, please look into using the LLVM version that was current when the code was written. Or, if you find the necessary changes to work with 4.0, please submit a pull request!
I had similar error when loading the plugin.
error: unable to load plugin 'skeleton/libSkeletonPass.so': 'skeleton/libSkeletonPass.so: undefined symbol: _ZNK4llvm12FunctionPass17createPrinterPassERNS_11raw_ostreamERKSs'
I found this thread https://stackoverflow.com/questions/37366291/undefined-symbol-for-self-built-llvm-opt. It works for me by adding compiler flag in llvm-pass-skeleton/skeleton/CMakeLists.txt:
set_target_properties(SkeletonPass PROPERTIES COMPILE_FLAGS "-D__GLIBCXX_USE_CXX11_ABI=0 -fno-rtti" )
Hope it helps.
add set(CMAKE_CXX_COMPILER "clang-9") into skeleton/CMakeList.txt solved my problem.
If remove this line, then default compiler is g++ in my case, which will cause this problem.
Hope it helps.