A completely useless LLVM pass. It's for LLVM 17.
Build:
$ cd llvm-pass-skeleton
$ mkdir build
$ cd build
$ cmake ..
$ make
$ cd ..
Run:
$ clang -fpass-plugin=`echo build/skeleton/SkeletonPass.*` something.c
example LLVM pass
Home Page: http://www.cs.cornell.edu/~asampson/blog/llvm.html
License: MIT License
In case you were interested, I was able to figure this out without having to do the other method of registering the pass following what was done here.
As you can see, trying to run the module pass before the other optimizations causes it generate segmentation faults/assertion faults depending on the method. Also, PassManagerBuilder::EP_ModuleOptimizerEarly
worked as well. I'm assuming the rest of the options should work since they are working within the module. Here is my example that uses your basic framework from your examples.
Important Content:
static RegisterStandardPasses**
RegisterMyPass(PassManagerBuilder::EP_ModuleOptimizerEarly, registerSkeletonPass);
static RegisterStandardPasses
RegisterMyPass0(PassManagerBuilder::EP_EnabledOnOptLevel0, registerSkeletonPass);
Source Code:
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/Debug.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
using namespace llvm;
namespace {
struct SkeletonPass : public ModulePass {
static char ID;
SkeletonPass() : ModulePass(ID) { }
virtual bool runOnModule(Module &M) override;
};
}
char SkeletonPass::ID = 0;
bool SkeletonPass::runOnModule(Module &M) {
errs() << "In module called: " << M.getName() << "!\n";
for (auto &F : M) {
F.dump();
for (auto &B : F) {
B.dump();
for (auto &I : B) {
I.dump();
}
}
}
return false;
}
//Automatically enable the pass.
//http://adriansampson.net/blog/clangpass.html
static void registerSkeletonPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
PM.add(new SkeletonPass());
}
static RegisterStandardPasses
RegisterMyPass(PassManagerBuilder::EP_ModuleOptimizerEarly, registerSkeletonPass);
static RegisterStandardPasses
RegisterMyPass0(PassManagerBuilder::EP_EnabledOnOptLevel0, registerSkeletonPass);
Hi,
am trying to run annotation module code from the link in the tutorial
http://bholt.org/posts/llvm-quick-tricks.html
`
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/IR/Module.h"
#include
using namespace llvm;
namespace {
struct SkeletonPass : public ModulePass {
static char ID;
SkeletonPass() : ModulePass(ID) {}
virtual bool runOnModule(Module &M) override;
};
}
char SkeletonPass::ID = 0;
std::set<Function*> async_fns;
bool SkeletonPass::runOnModule(Module &M) {
// Get the function to call from our runtime library.
auto global_annos = M.getNamedGlobal("llvm.global.annotations");
if (global_annos) {
auto a = cast<ConstantArray>(global_annos->getOperand(0));
for (int i=0; i<a->getNumOperands(); i++) {
auto e = cast<ConstantStruct>(a->getOperand(i));
if (auto fn = dyn_cast<Function>(e->getOperand(0)->getOperand(0))) {
auto anno = cast<ConstantDataArray>(cast<GlobalVariable>(e->getOperand(1)->getOperand(0))->getOperand(0))->getAsCString();
if (anno == "async") { async_fns.insert(fn); } }
}
}
}
// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
static void registerSkeletonPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
PM.add(new SkeletonPass());
}
static RegisterStandardPasses
MyPassRegistration(PassManagerBuilder::EP_EarlyAsPossible,
registerSkeletonPass);
static RegisterStandardPasses
RegisterMyPass0(PassManagerBuilder::EP_EnabledOnOptLevel0, registerSkeletonPass);`
and something.c
`#include <stdio.h>
attribute((annotate("async"))) int foo() {
printf("foo does nothing\n");
}
int main(int argc, const char** argv) {
int num;
int x = foo();
scanf("%i", &num);
printf("%i\n", x + num + 2);
return 0;
}`
am getting these errors:
0. Program arguments: /usr/local/bin/clang-5.0 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name something.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /home/atamli/StaticAnalysis/llvm-pass-skeleton/build/example/something.gcno -resource-dir /usr/local/lib/clang/5.0.0 -internal-isystem /usr/local/include -internal-isystem /usr/local/lib/clang/5.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/atamli/StaticAnalysis/llvm-pass-skeleton/build/example -ferror-limit 19 -fmessage-length 111 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -load ../skeleton/libSkeletonPass.so -o something.o -x c something.c
Any idea how to fix this ?
Hello,
I would like to thank you very much for your code, I'm new to LLVM so this might seem like a silly question but each time I try to build your code it gives me this error:
"Skeleton.cpp:30:32: error: ‘class llvm::BinaryOperator’ has no member named ‘uses’
for (auto &U : op->uses()) {"
I'm using llvm-3.4 could please let me know how to fix this error.
Best regards.
YN
Hi, Adrian
Thank you for your great post about writing LLVM pass. It really helps me a lot!
When I was trying to build the rtlib branch, It failed to compile and fired the following error message:
[ 50%] Building CXX object skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o
In file included from /opt/llvm/include/llvm/IR/IRBuilder.h:37:0,
from /home/pan/project/LLVM/llvm-pass/llvm-pass-skeleton/skeleton/Skeleton.cpp:7:
/opt/llvm/include/llvm/IR/Module.h: In instantiation of ‘llvm::Constant* llvm::Module::getOrInsertFunction(llvm::StringRef, llvm::AttributeList, llvm::Type*, ArgsTy ...) [with ArgsTy = {llvm::IntegerType*, long int}]’:
/opt/llvm/include/llvm/IR/Module.h:353:69: required from ‘llvm::Constant* llvm::Module::getOrInsertFunction(llvm::StringRef, llvm::Type*, ArgsTy ...) [with ArgsTy = {llvm::IntegerType*, long int}]’
/home/pan/project/LLVM/llvm-pass/llvm-pass-skeleton/skeleton/Skeleton.cpp:22:7: required from here
/opt/llvm/include/llvm/IR/Module.h:344:57: error: call of overloaded ‘SmallVector(<brace-enclosed initializer list>)’ is ambiguous
SmallVector<Type*, sizeof...(ArgsTy)> ArgTys{Args...};
^
/opt/llvm/include/llvm/IR/Module.h:344:57: note: candidates are:
In file included from /opt/llvm/include/llvm/PassAnalysisSupport.h:22:0,
from /opt/llvm/include/llvm/Pass.h:387,
from /home/pan/project/LLVM/llvm-pass/llvm-pass-skeleton/skeleton/Skeleton.cpp:1:
/opt/llvm/include/llvm/ADT/SmallVector.h:871:12: note: llvm::SmallVector<T, N>::SmallVector(size_t, const T&) [with T = llvm::Type*; unsigned int N = 2u; size_t = long unsigned int] <near match>
explicit SmallVector(size_t Size, const T &Value = T())
^
/opt/llvm/include/llvm/ADT/SmallVector.h:871:12: note: no known conversion for argument 2 from ‘long int’ to ‘llvm::Type* const&’
/opt/llvm/include/llvm/ADT/SmallVector.h:890:3: note: llvm::SmallVector<T, N>::SmallVector(std::initializer_list<_Tp>) [with T = llvm::Type*; unsigned int N = 2u] <near match>
SmallVector(std::initializer_list<T> IL) : SmallVectorImpl<T>(N) {
^
/opt/llvm/include/llvm/ADT/SmallVector.h:890:3: note: no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::initializer_list<llvm::Type*>’
skeleton/CMakeFiles/SkeletonPass.dir/build.make:62: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o' failed
make[2]: *** [skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o] Error 1
CMakeFiles/Makefile2:117: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/all' failed
make[1]: *** [skeleton/CMakeFiles/SkeletonPass.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I'm using LLVM 6.0 and it seems that the syntax for getOrInsertFunction
was changed since then. Do you consider updating it?
I have the following packages:
ii cmake 3.2.2-2 amd64 cross-platform, open-source make system
ii llvm 1:3.5-26 amd64 Low-Level Virtual Machine (LLVM)
ii llvm-3.5 1:3.5.2-1 amd64 Modular compiler and toolchain technologies
Error happens when executing cmake ..
in the build directory :
CMake Error at /usr/share/llvm-3.5/cmake/LLVMConfig.cmake:50 (include):
include could not find load file:
/usr/lib/llvm-3.5/share/llvm/cmake/LLVMExports.cmake
Call Stack (most recent call first):
CMakeLists.txt:3 (find_package)
CMake Error at /usr/share/llvm-3.5/cmake/LLVMConfig.cmake:53 (include):
include could not find load file:
/usr/lib/llvm-3.5/share/llvm/cmake/LLVM-Config.cmake
Call Stack (most recent call first):
CMakeLists.txt:3 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/mdl/Repos/Github/llvm-pass-skeleton/CMakeFiles/CMakeOutput.log".
What should I do ?
I am getting the following:
/Users/abidmalik/Programming/LLVM/JLLVM/install/include/llvm/ADT/STLExtras.h:555:49: error: no template named
'index_sequence' in namespace 'std'
template <size_t... Ns> value_type deref(std::index_sequence<Ns...>) const {
~~~~~^
/Users/abidmalik/Programming/LLVM/JLLVM/install/include/llvm/ADT/STLExtras.h:560:36: error: no template named
'index_sequence' in namespace 'std'
decltype(iterators) tup_inc(std::index_sequence<Ns...>) const {
~~~~~^
I am using LLVM-9.0
Does this have something to do with the version?
Hi
I am trying to build llvm-pass-skeleton using cmake .. command. I installed llvm 3.8 package on ubuntu 16.04 using apt-get install llvm command from terminal. I also changed paths to my LLVM include and Lib folders as described in find_package error in CMakeLists.txt #2 issue. But still I am getting the following error when running cmake .. command from build folder.
CMake Error at /usr/share/llvm-3.8/cmake/LLVMExports.cmake:1034 (message):
The imported target "LLVMSupport" references the file
"/usr/lib/libLLVMSupport.a"
but this file does not exist. Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
"/usr/share/llvm-3.8/cmake/LLVMExports.cmake"
but not all the files it references.
Call Stack (most recent call first):
/usr/share/llvm-3.8/cmake/LLVMConfig.cmake:178 (include)
CMakeLists.txt:3 (find_package)
-- Configuring incomplete, errors occurred!
See also "/home/hammad/llvm-pass-skeleton/build/CMakeFiles/CMakeOutput.log".
Anyone please help.
I'm trying out your skeleton project and I get the following error when building in Ubuntu with LLVM 3.4 and Cmake 2.8.12.2:
CMake Error at skeleton/CMakeLists.txt:7 (target_compile_features):
Unknown CMake command "target_compile_features"
Is there some other package needed by CMake?
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.
Hi when I try to run the pass I got this error, do you know why? I am working on a Mac with a hombbrew installed LLVM.
error: unable to load plugin 'build/skeleton/libSkeletonPass.so': 'dlopen(build/skeleton/libSkeletonPass.so, 9): Symbol not found:
__ZN4llvm12FunctionPass17assignPassManagerERNS_7PMStackENS_15PassManagerTypeE
Referenced from: build/skeleton/libSkeletonPass.so
Expected in: flat namespace
in build/skeleton/libSkeletonPass.so'
I tried to run the following code
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
using namespace llvm;
namespace {
struct SkeletonPass : public FunctionPass {
static char ID;
SkeletonPass() : FunctionPass(ID) {}
virtual bool runOnFunction(Function &F) {
errs() << "In a function called " << F.getName() << "!\n";
errs() << "Function body:\n";
F.dump();
for (auto &B : F) {
errs() << "Basic block:\n";
B.dump();
for (auto &I : B) {
errs() << "Instruction: ";
I.dump();
}
}
return false;
}
};
}
char SkeletonPass::ID = 0;
// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
static void registerSkeletonPass(const PassManagerBuilder &,
legacy::PassManagerBase &PM) {
PM.add(new SkeletonPass());
}
static RegisterStandardPasses
RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible,
registerSkeletonPass);
and I received the following error
In a function called __cxx_global_var_init!
Function body:
~/Softwares/LLVM7/bin/clang-7.0: symbol lookup error: ./libSkeletonPass.so: undefined symbol: _ZNK4llvm5Value4dumpEv
clang-7.0: error: unable to execute command: No such file or directory
clang-7.0: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 7.0.0 (https://llvm.org/git/clang.git e77fed96933e0fa11bd4cd8dc8a198a34649c6ea) (https://llvm.org/git/llvm.git 96102045c0f3090e8ce16bb1fc20cc0a50c236ca)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/pradeep/Softwares/LLVM7/bin
clang-7.0: note: diagnostic msg: PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
clang-7.0: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-7.0: note: diagnostic msg: /tmp/test-e972d6.cpp
clang-7.0: note: diagnostic msg: /tmp/test-e972d6.sh
clang-7.0: note: diagnostic msg:
********************
clang version 7.0
llvm version 7.0
Operating System Ubuntu 16.04.3 LTS
Should I need to install a different version of clang?
hi, sir, lucky to see your course and I wonder if we can use llvm for instrumentation for inline assembly of c code. Look forward to your reply.
Hi,
I'm getting this error
$ opt -load /home/nidhin/LLVM/build/build/lib/LLVMMyHello.so -myhe input.ll
Error opening '/home/nidhin/LLVM/build/build/lib/LLVMMyHello.so': /home/nidhin/LLVM/build/build/lib/LLVMMyHello.so: undefined symbol: _ZN4llvm23EnableABIBreakingChecksE
-load request ignored.
opt: Unknown command line argument '-myhe'. Try: 'opt --help'
opt: Did you mean '--adce'?
LLVM version is 10
I'm using clang-11
Hi, I read the blog and use the code, with my compiled clang 14.0.5 on ubuntu 20.04, when execute:
$CC -flegacy-pass-manager -Xclang -load -Xclang build/skeleton/libSkeletonPass.so example.c
Got error msg
clang-15: error: unable to execute command: Aborted (core dumped)
clang-15: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 14.0.5 (https://github.com/llvm/llvm-project c12386ae247c0d46e1d513942e322e3a0510b126)
It seems a bug of LLVM (correct me if I'm wrong), so I create a issue at llvm/llvm-project#56148 .
Hope this helps people.
Hello,
I would like to thank you very much for your code, I'm new to LLVM so this might seem like a silly question but each time I try to build your code it gives me this error:
"Skeleton.cpp:30:32: error: ‘class llvm::BinaryOperator’ has no member named ‘uses’
for (auto &U : op->uses()) {"
I'm using llvm-3.4 could please let me know how to fix this error.
Best regards.
YN
It is a moving target I know, but I cannot get the skeleton to work with llvm and clang version 15.
Any hints?
I success to run some basic pass methods according to this repo, but in some situations, it seems not to work.
such as when I use some method in Basic Block,
for(BasicBlock::iterator i = B.begin(); i!= B.end(); i++){
if(i->getOpcode() == Instruction::Load){
LoadInst *ld = dyn_cast<LoadInst>(i);
GetElementPtrInst* gep = dyn_cast<GetElementPtrInst>(ld->getPointerOperand());
gep->getSourceElementType();
errs()<<"end here\n";
}
}
Every thing works well until "gep->getSourceElementType();" then it output
Stack dump:
0.Program arguments: clang -Xclang -load -Xclang ../build/DSPass/libDSPass.so -c test.c
1. parser at end of file
2.Per-function optimization
3.Running pass 'Unnamed pass: implement Pass::getPassName()' on function '@main'
#0 0x00007f3e76c1306a llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/usr/local/bin/../lib/libLLVMSupport.so.10+0x17806a)
...
clang-10: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 10.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
...
and when I use #7 , it corrupt early in "ld->getPointerOperand()"
The LLVM and Clang version is 10
Hi,
I ran into an error when I tried to run "make" on the rtlib example. The output is below. Do you have any suggestions on how to fix this error?
Scanning dependencies of target SkeletonPass
[ 50%] Building CXX object skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o
/llvm-pass-skeleton/skeleton/Skeleton.cpp: In member function ‘virtual bool {anonymous}::SkeletonPass::runOnFunction(llvm::Function&)’:
/llvm-pass-skeleton/skeleton/Skeleton.cpp:23:84: error: cannot convert ‘llvm::FunctionCallee’ to ‘llvm::Constant*’ in initialization
Constant *logFunc = F.getParent()->getOrInsertFunction("logop", logFuncType);
^
skeleton/CMakeFiles/SkeletonPass.dir/build.make:62: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o' failed
make[2]: *** [skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o] Error 1
CMakeFiles/Makefile2:117: recipe for target 'skeleton/CMakeFiles/SkeletonPass.dir/all' failed
make[1]: *** [skeleton/CMakeFiles/SkeletonPass.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Thank you!
Did you ever attempt to use C++ for calling a runtime library, or was the mangling too big of an issue to overcome?
I checkouted to the branch rtlib
, but the instrumention failed.
Here are my commands.
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ mkdir build
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ cd build
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/fdse/luorong/LLVM/test/llvm-pass-skeleton/build
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton/build$ make
[ 50%] Building CXX object skeleton/CMakeFiles/SkeletonPass.dir/Skeleton.cpp.o
[100%] Linking CXX shared module libSkeletonPass.so
[100%] Built target SkeletonPass
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton/build$ cd ..
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ cc -c rtlib.c
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ clang -Xclang -load -Xclanc build/skeleton/libSkeletonPass.so -c example.c
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ cc example.o rtlib.o
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ ./a.out
12
14
When I run the a.out
, llvm pass show nothing. It should be:
$ cc -c rtlib.c
$ clang -Xclang -load -Xclang build/skeleton/libSkeletonPass.so -c example.c
$ cc example.o rtlib.o
$ ./a.out
12
computed: 14
14
I don't know why. I followed the instructions in the readme. But when finally I use the command clang -flegacy-pass-manager -Xclang -load -Xclang build/skeleton/libSkeletonPass.* something.c
and get the a.out
and run it, what I get is the same as the result produced by a simple command gcc something.c
.
and here is my code structure:
/skeleton/CMakefile.txt:
add_library(SkeletonPass MODULE
# List your source files here.
Skeleton.cpp
)
# Use C++11 to compile our pass (i.e., supply -std=c++11).
# target_compile_features(SkeletonPass PRIVATE cxx_range_for cxx_auto_type)
# LLVM is (typically) built with no C++ RTTI. We need to match that;
# otherwise, we'll get linker errors about missing RTTI data.
set_target_properties(SkeletonPass PROPERTIES
COMPILE_FLAGS "-fno-rtti"
)
# Get proper shared-library behavior (where symbols are not necessarily
# resolved when the shared library is linked) on OS X.
if(APPLE)
set_target_properties(SkeletonPass PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup"
)
endif(APPLE)
/skeleton/Skeleton.cpp
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
using namespace llvm;
namespace {
struct SkeletonPass : public FunctionPass {
static char ID;
SkeletonPass() : FunctionPass(ID) {}
virtual bool runOnFunction(Function &F) {
errs() << "I saw a function called " << F.getName() << "!\n";
return false;
}
};
}
char SkeletonPass::ID = 0;
// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
// static void registerSkeletonPass(const PassManagerBuilder &,
// legacy::PassManagerBase &PM) {
// PM.add(new SkeletonPass());
// }
// static RegisterStandardPasses
// RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible,
// registerSkeletonPass);
// Register the pass so `opt -skeleton` runs it.
static RegisterPass<SkeletonPass> X("skeleton", "a useless pass"); //注册Pass
/CMakeLists.txt
cmake_minimum_required(VERSION 3.1)
project(Skeleton)
# support C++14 features used by LLVM 10.0.0
set(CMAKE_CXX_STANDARD 14)
find_package(LLVM REQUIRED CONFIG)
add_definitions(${LLVM_DEFINITIONS})
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_subdirectory(skeleton) # Use your pass name here.
/src/demo.cpp
#include <stdio.h>
void func2(){
printf("hello world");
}
void func(){
func2();
}
int main(){
func();
return 0;
}
Actually, when I run make
in /build
, I then run opt -load ./libSkeletonPass.so -help | grep skeleton
to show information of pass. BUT, I get NOTHING. It means that I don't have any pass.
So, I would like to ask for help. SO MUCH THANKS!
I see the usage of function, basickblock, instruction in your repo, I try to use ModulePass as the same way with FunctionPass.
for (auto &F : M) {
for (auto &B : F) {
for (auto &I : B) {
But it gets error reports. I don't know why?
hi,
when I make
the program , I met the error - fatal error: llvm/IR/Attributes.gen: No such file or directory
and I did not find Attributes.gen
in my llvm-4.0.1. I've tried llvm-3.2 , but I failed too. So dose this program require a special version of llvm?
Thank you very much!
Hey, I am trying to get the skeleton work on iOS platform and I followed your README and got the Pass working on MacOS. However, when I want to set it up on iOS project in XCODE and set "Other C Flags" to "-Xclang -load -Xclang libSkeletonPass.so" on iOS project I get the following error:
error: unable to load plugin 'libSkeletonPass.so': 'dlopen(libSkeletonPass.so, 9):
Symbol not found: __ZN4llvm24DisableABIBreakingChecksE
Referenced from:libSkeletonPass.so
Expected in: flat namespace
in /libSkeletonPass.so'
Command CompileC failed with a nonzero exit code
Do you have any idea how to fix this? Have you tried using it with iOS?
On macOS, llvm 13.
I was making my way through the tutorial and had a build error in the "mutate branch", beginning with:
/opt/homebrew/opt/llvm/include/llvm/Support/SwapByteOrder.h:152:13: error: no template named 'enable_if_t' in namespace 'std'; did you mean 'enable_if'?
inline std::enable_if_t<std::is_enum::value, T> getSwappedBytes(T C) {
~~~~~^~~~~~~~~~~
enable_if
Turns out this construct is only supported from C++ 14. So I added this to the Cmake file:
set(CMAKE_CXX_STANDARD 14)
and fixed the build error.
Hope this helps.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.