banach-space / llvm-tutor Goto Github PK
View Code? Open in Web Editor NEWA collection of out-of-tree LLVM passes for teaching and learning
License: MIT License
A collection of out-of-tree LLVM passes for teaching and learning
License: MIT License
Hi! Thank you for creating such a useful resource to learn about LLVM!
I have some questions about LLVM out-of-source development that you can probably answer
Thank you in advance!
my opt version is
opt --version
LLVM (http://llvm.org/):
LLVM version 9.0.0
Optimized build.
Default target: x86_64-apple-darwin19.0.0
Host CPU: broadwell
when i run opt
, it seem the command line flags is not right
opt -load-pass-plugin libHelloWorld.dylib -hello-world -disable-output ../input_for_hello.ll
OVERVIEW: llvm .bc -> .bc modular optimizer and analysis printer
USAGE: opt [options] <input bitcode file>
OPTIONS:
Color Options:
--color - Use colors in output (default=autodetect)
General options:
--O0 - Optimization level 0. Similar to clang -O0
--O1 - Optimization level 1. Similar to clang -O1
--O2 - Optimization level 2. Similar to clang -O2
--O3 - Optimization level 3. Similar to clang -O3
--Os - Like -O2 with extra optimizations for size. Similar to clang -Os
--Oz - Like -Os but reduces code size further. Similar to clang -Oz
-S - Write output as LLVM assembly
--aarch64-neon-syntax=<value> - Choose style of NEON code to emit from AArch64 backend:
......
Hello, i build LLVM on windows under Visual Studio 2019 with the config like this:
cmake -S llvm\llvm -B build -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;lld" -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=On -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=X86 -Thost=x64
C:\passes\december\HelloWorld>llvm-config --version
14.0.0git
now i download this tutor and want to compile it, i do:
C:\passes\december\HelloWorld>cmake -Bbuild -DLT_LLVM_INSTALL_DIR="C:\Program Files (x86)\LLVM"
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.29.30137.0
-- The CXX compiler identification is MSVC 19.29.30137.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - 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: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
CMake Error in CMakeLists.txt:
IMPORTED_IMPLIB not set for imported target "opt" configuration "Debug".
CMake Error in CMakeLists.txt:
IMPORTED_IMPLIB not set for imported target "opt" configuration "Release".
CMake Error in CMakeLists.txt:
IMPORTED_IMPLIB not set for imported target "opt" configuration
"MinSizeRel".
CMake Error in CMakeLists.txt:
IMPORTED_IMPLIB not set for imported target "opt" configuration
"RelWithDebInfo".
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
As you can see it produces weird result, i looked solution in this repository and found one suggestion to change CMakeLists.txt
:
add_llvm_library( HelloWorld SHARED BUILDTREE_ONLY
HelloWorld.cpp
DEPENDS
intrinsics_gen
PLUGIN_TOOL
opt
)
Changed MODULE
to SHARED
works it produced build files
cd build
cmake --build . --config Release --target ALL_BUILD
this produced HelloWorld.dll
.
Now i want to use this and do:
opt -load-pass-plugin="C:\passes\december\HelloWorld\build\Release\HelloWorld.dll" -passes="hello-world" -disable-output Source.bc
And get output
C:\passes\hello>opt -load-pass-plugin="C:\passes\december\HelloWorld\build\Release\HelloWorld.dll" -passes="hello-world" -disable-output Source.bc
Failed to load passes from 'C:\passes\december\HelloWorld\build\Release\HelloWorld.dll'. Request ignored.
Expected<T> must be checked before access or destruction.
Unchecked Expected<T> contained error:
Plugin entry point not found in 'C:\passes\december\HelloWorld\build\Release\HelloWorld.dll'. Is this a legacy plugin?PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: opt -load-pass-plugin=C:\\passes\\december\\HelloWorld\\build\\Release\\HelloWorld.dll -passes=hello-world -disable-output Source.bc
#0 0x00007ff71ae82935 C:\Program Files (x86)\LLVM\bin\opt.exe 0x1442935 (C:\Program Files (x86)\LLVM\bin\opt.exe+0x1442935)
#1 0x00007ff71ae82935
#2 0x00007ff71ae82935 (C:\Program Files (x86)\LLVM\bin\opt.exe+0x1442935)
#3 0x00007ff884fc1881 C:\Program Files (x86)\LLVM\bin\opt.exe 0x78b21 C:\Program Files (x86)\LLVM\bin\opt.exe 0x7dd5c
#4 0x00007ff884fc1881 C:\Program Files (x86)\LLVM\bin\opt.exe 0x8a7f0 C:\Program Files (x86)\LLVM\bin\opt.exe 0x1e0a600
#5 0x00007ff884fc1881 (C:\Windows\System32\ucrtbase.dll+0x71881)
#6 0x00007ff884fc2851 (C:\Windows\System32\ucrtbase.dll+0x72851)
0x00007FF71AE82935 (0x00007974991A16CF 0x0000000000000076 0x0000000000000016 0x00007FF71AE82930), HandleAbort() + 0x5 bytes(s)
0x00007FF884FC1881 (0x000001C9DC584301 0x0000000000000000 0x0000000000000000 0x000000500C58CEC0), raise() + 0x1E1 bytes(s)
0x00007FF884FC2851 (0x0000005000000003 0x0000005000000003 0x0000000000000000 0x000001C9DC5A2DB0), abort() + 0x31 bytes(s)
0x00007FF719AB8B21 (0x000001C9DC5A2DB0 0x000000500C58CFF0 0x0000000000000000 0x000001C9DC5A2DB0), ?erase@?$SmallPtrSetImpl@PEAVLiveInterval@llvm@@@llvm@@QEAA_NPEAVLiveInterval@2@@Z() + 0x111 bytes(s)
0x00007FF719ABDD5C (0x0000000000000000 0x0000000000000000 0x000000500C58E920 0x0000000000000000), ?run@?$AnalysisPassModel@VFunction@llvm@@VAAManager@2@VPreservedAnalyses@2@VInvalidator@?$AnalysisManager@VFunction@llvm@@$$V@2@$$V@detail@llvm@@UEAA?AV?$unique_ptr@U?$AnalysisResultConcept@VFunction@llvm@@VPreservedAnalyses@2@VInvalidator@?$AnalysisManager@VFunction@llvm@@$$V@2@@detail@llvm@@U?$default_delete@U?$AnalysisResultConcept@VFunction@llvm@@VPreservedAnalyses@2@VInvalidator@?$AnalysisManager@VFunction@llvm@@$$V@2@@detail@llvm@@@std@@@std@@AEAVFunction@3@AEAV?$Analys() + 0x28FC bytes(s)
0x00007FF719ACA7F0 (0x0000000000000000 0x0000000000000000 0x000001C9DC554DA0 0x0000000000000000), ?assign@?$SmallVectorImpl@PEBVValue@llvm@@@llvm@@QEAAX_KPEBVValue@2@@Z() + 0x4780 bytes(s)
0x00007FF71B84A600 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), ?identify_magic@llvm@@YA?AVerror_code@std@@AEBVTwine@1@AEAUfile_magic@1@@Z() + 0x1360 bytes(s)
0x00007FF887597034 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), BaseThreadInitThunk() + 0x14 bytes(s)
0x00007FF887882651 (0x0000000000000000 0x0000000000000000 0x0000000000000000 0x0000000000000000), RtlUserThreadStart() + 0x21 bytes(s)
I checked HelloWord.dll and main entry point is DllEntryPoint
i assume i need llvmGetPassPluginInfo
as exported function?? How do you get this to work
I want to instrument a call to a function every time a program calls a function.
I've started from the lib/InjectFuncCall.cpp
example, but my custom function has type int32 func (int32)
.
I've managed to make it all compile, but I'm getting a segfault. This is my patch:
diff --git a/lib/InjectFuncCall.cpp b/lib/InjectFuncCall.cpp
index 72dde08..8d6c0b7 100644
--- a/lib/InjectFuncCall.cpp
+++ b/lib/InjectFuncCall.cpp
@@ -47,39 +47,27 @@ bool InjectFuncCall::runOnModule(Module &M) {
bool InsertedAtLeastOnePrintf = false;
auto &CTX = M.getContext();
- PointerType *PrintfArgTy = PointerType::getUnqual(Type::getInt8Ty(CTX));
// STEP 1: Inject the declaration of printf
// ----------------------------------------
// Create (or _get_ in cases where it's already available) the following
// declaration in the IR module:
- // declare i32 @printf(i8*, ...)
+ // declare i32 @func(i32)
// It corresponds to the following C declaration:
- // int printf(char *, ...)
+ // int func(int)
FunctionType *PrintfTy = FunctionType::get(
IntegerType::getInt32Ty(CTX),
- PrintfArgTy,
- /*IsVarArgs=*/true);
+ IntegerType::getInt32Ty(CTX),
+ /*IsVarArgs=*/false);
- FunctionCallee Printf = M.getOrInsertFunction("printf", PrintfTy);
+ FunctionCallee Printf = M.getOrInsertFunction("func", PrintfTy);
// Set attributes as per inferLibFuncAttributes in BuildLibCalls.cpp
Function *PrintfF = dyn_cast<Function>(Printf.getCallee());
PrintfF->setDoesNotThrow();
- PrintfF->addParamAttr(0, Attribute::NoCapture);
- PrintfF->addParamAttr(0, Attribute::ReadOnly);
-
-
- // STEP 2: Inject a global variable that will hold the printf format string
- // ------------------------------------------------------------------------
- llvm::Constant *PrintfFormatStr = llvm::ConstantDataArray::getString(
- CTX, "(llvm-tutor) Hello from: %s\n(llvm-tutor) number of arguments: %d\n");
- Constant *PrintfFormatStrVar =
- M.getOrInsertGlobal("PrintfFormatStr", PrintfFormatStr->getType());
- dyn_cast<GlobalVariable>(PrintfFormatStrVar)->setInitializer(PrintfFormatStr);
- // STEP 3: For each function in the module, inject a call to printf
+ // STEP 2: For each function in the module, inject a call to func
// ----------------------------------------------------------------
for (auto &F : M) {
if (F.isDeclaration())
@@ -88,22 +76,13 @@ bool InjectFuncCall::runOnModule(Module &M) {
// Get an IR builder. Sets the insertion point to the top of the function
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
- // Inject a global variable that contains the function name
- auto FuncName = Builder.CreateGlobalStringPtr(F.getName());
-
- // Printf requires i8*, but PrintfFormatStrVar is an array: [n x i8]. Add
- // a cast: [n x i8] -> i8*
- llvm::Value *FormatStrPtr =
- Builder.CreatePointerCast(PrintfFormatStrVar, PrintfArgTy, "formatStr");
-
// The following is visible only if you pass -debug on the command line
// *and* you have an assert build.
- LLVM_DEBUG(dbgs() << " Injecting call to printf inside " << F.getName()
+ LLVM_DEBUG(dbgs() << " Injecting call to func inside " << F.getName()
<< "\n");
- // Finally, inject a call to printf
- Builder.CreateCall(
- Printf, {FormatStrPtr, FuncName, Builder.getInt32(F.arg_size())});
+ // Finally, inject a call to func
+ Builder.CreateCall(Printf, {Builder.getInt32(F.arg_size())});
InsertedAtLeastOnePrintf = true;
}
At present, func
just does a printf
, but, ideally, I'd want it to call a function defined in an auxiliary library linked with some flag -laux
.
I noticed that the instruction for "Run the pass through opt - New PM" in section InjectFuncCall is missing. And I tried as following, it worked. So I suggested to add this instruction to README.md
$LLVM_DIR/bin/opt -load-pass-plugin <build_dir>/lib/libInjectFuncCall.so --passes="inject-func-call" input_for_hello.bc -o instrumented.bin
for new PM, I run $LLVM_DIR/bin/opt -load-pass-plugin <build_dir>/lib/libStaticCallCounter.so --passes='print<static-cc>' -disable-output input_for_cc.bc
successfully
but '-analyze' is a unknown command line argument when i run $LLVM_DIR/bin/opt -enable-new-pm=0 -load <build_dir>/lib/libStaticCallCounter.so -legacy-static-cc -analyze input_for_cc.bc
my llvm version is 15.0.7
for SLP tests, File check commands have lacked. If add it, tests failed. So it might be better to update them.
like
; RUN: opt -passes=slp-vectorizer,dce -mtriple=x86_64-unknown-linuxgnu -S %s | FileCheck %s
If this is intentional for some reasons, close this silently :)
https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/slp_x86.ll
https://github.com/banach-space/llvm-tutor/blob/main/test/llvm/slp_aarch64.ll
Shall we continue our discussion from Homebrew/discussions#3666 here?
Here's a summary of alternatives discussed so far:
LLVM_ENABLE_LTO=ON
on macOS.libLLVM
shared library instead.C[XX]FLAGS
)2 and 3 seem like the most attractive alternatives now, but it may still be possible to do 1 (depending on how other users receive the changes wrt LTO), or even 4 if there is a neat enough way to do it.
Hello Andrzej,
I tried HelloWorld
on macOS, and it works fine. But RIV doesn't show anything.
The commands I used:
export LLVM_DIR=/usr/local/opt/llvm
git clone https://github.com/banach-space/llvm-tutor
cd llvm-tutor
export TUTOR_DIR=$(pwd)
mkdir build
cd build
cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../
make
$LLVM_DIR/bin/clang -emit-llvm -S -O1 $TUTOR_DIR/inputs/input_for_riv.c -o input_for_riv.ll
$LLVM_DIR/bin/opt -load ./lib/libRIV.dylib -legacy-riv input_for_riv.ll
I got this:
WARNING: You're attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the `-f' option.
Then I used -disable-output
, but got nothing on stdout.
$LLVM_DIR/bin/opt -load ./lib/libRIV.dylib -legacy-riv -disable-output input_for_riv.ll
I guess there are some problems with pass registration because when I changed the code (using scaffolding codes for pass registration in HelloWorld
) I was able to make it work.
Thanks.
After building the project on Ubuntu with LLVM-10, updated yesterday, I see the following:
cades@kharazi-cades-dev:~/llvm-tutor$ $LLVM_DIR/bin/opt -load-pass-plugin libHelloWorld.dylib -passes=hello-world -disable-output input_for_hello.ll
/home/cades/.llvm/bin/opt: input_for_hello.ll:1:2: error: expected top-level entity
.text
^
When I tried
$LLVM_DIR/bin/opt -S -load-pass-plugin <build_dir>/lib/libMBAAdd.so -passes=mba-add input_for_mba.ll -debug-only=mba-add -stats -o out.ll
It gives
opt-12: Unknown command line argument '-debug-only=mba-add'. Try: 'opt-12 --help'
opt-12: Did you mean '--debug-pass=mba-add'?
But both
$LLVM_DIR/bin/opt -S -load-pass-plugin <build_dir>/lib/libMBAAdd.so -passes=mba-add input_for_mba.ll --debug-pass=Structure -stats -o out1.ll
and
$LLVM_DIR/bin/opt -S -load-pass-plugin <build_dir>/lib/libMBAAdd.so -passes=mba-add input_for_mba.ll -o out2.ll
generate the exactly same output files when comparing them by diff out1.ll out2.ll
. I have no idea what goes wrong here.
$opt-12 --version
LLVM (http://llvm.org/):
LLVM version 12.0.1
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: broadwell
input_for_mba_sub.ll
; ModuleID = '../inputs/input_for_mba_sub.c'
source_filename = "../inputs/input_for_mba_sub.c"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx13.0.0"
; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main(i32 %0, i8** %1) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i32, align 4
%7 = alloca i32, align 4
%8 = alloca i32, align 4
%9 = alloca i32, align 4
%10 = alloca i32, align 4
%11 = alloca i32, align 4
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
%12 = load i8**, i8*** %5, align 8
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13, align 8
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6, align 4
%16 = load i8**, i8*** %5, align 8
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17, align 8
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7, align 4
%20 = load i8**, i8*** %5, align 8
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21, align 8
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8, align 4
%24 = load i8**, i8*** %5, align 8
%25 = getelementptr inbounds i8*, i8** %24, i64 4
%26 = load i8*, i8** %25, align 8
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9, align 4
%28 = load i32, i32* %6, align 4
%29 = load i32, i32* %7, align 4
%30 = sub nsw i32 %28, %29
store i32 %30, i32* %10, align 4
%31 = load i32, i32* %8, align 4
%32 = load i32, i32* %9, align 4
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %11, align 4
%34 = load i32, i32* %10, align 4
%35 = load i32, i32* %11, align 4
%36 = sub nsw i32 %34, %35
ret i32 %36
}
declare i32 @atoi(i8*) #1
attributes #0 = { noinline nounwind optnone ssp uwtable "darwin-stkchk-strong-link" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "probe-stack"="___chkstk_darwin" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
attributes #1 = { "darwin-stkchk-strong-link" "frame-pointer"="all" "no-trapping-math"="true" "probe-stack"="___chkstk_darwin" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 13, i32 1]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"PIC Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 1}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"Apple clang version 14.0.0 (clang-1400.0.29.202)"}
out.ll
; ModuleID = 'input_for_mba_sub.ll'
source_filename = "../inputs/input_for_mba_sub.c"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx13.0.0"
; Function Attrs: noinline nounwind optnone ssp uwtable
define i32 @main(i32 %0, i8** %1) #0 {
%3 = alloca i32, align 4
%4 = alloca i32, align 4
%5 = alloca i8**, align 8
%6 = alloca i32, align 4
%7 = alloca i32, align 4
%8 = alloca i32, align 4
%9 = alloca i32, align 4
%10 = alloca i32, align 4
%11 = alloca i32, align 4
store i32 0, i32* %3, align 4
store i32 %0, i32* %4, align 4
store i8** %1, i8*** %5, align 8
%12 = load i8**, i8*** %5, align 8
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13, align 8
%15 = call i32 @atoi(i8* %14)
store i32 %15, i32* %6, align 4
%16 = load i8**, i8*** %5, align 8
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17, align 8
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7, align 4
%20 = load i8**, i8*** %5, align 8
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21, align 8
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8, align 4
%24 = load i8**, i8*** %5, align 8
%25 = getelementptr inbounds i8*, i8** %24, i64 4
%26 = load i8*, i8** %25, align 8
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %9, align 4
%28 = load i32, i32* %6, align 4
%29 = load i32, i32* %7, align 4
%30 = sub nsw i32 %28, %29
store i32 %30, i32* %10, align 4
%31 = load i32, i32* %8, align 4
%32 = load i32, i32* %9, align 4
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %11, align 4
%34 = load i32, i32* %10, align 4
%35 = load i32, i32* %11, align 4
%36 = sub nsw i32 %34, %35
ret i32 %36
}
declare i32 @atoi(i8*) #1
attributes #0 = { noinline nounwind optnone ssp uwtable "darwin-stkchk-strong-link" "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "probe-stack"="___chkstk_darwin" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
attributes #1 = { "darwin-stkchk-strong-link" "frame-pointer"="all" "no-trapping-math"="true" "probe-stack"="___chkstk_darwin" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+cx8,+fxsr,+mmx,+sahf,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "tune-cpu"="generic" }
!llvm.module.flags = !{!0, !1, !2, !3, !4}
!llvm.ident = !{!5}
!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 13, i32 1]}
!1 = !{i32 1, !"wchar_size", i32 4}
!2 = !{i32 7, !"PIC Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 1}
!4 = !{i32 7, !"frame-pointer", i32 2}
!5 = !{!"Apple clang version 14.0.0 (clang-1400.0.29.202)"}
Identical!
Hello
Thank you for your useful repository.
I have a question about generating .ll files, you used this command:
$LLVM_DIR/bin/clang -S -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll
The question is how to generate this for all source files of a project, also each file has some included header files.
for example how to generate LLVM IR for all of the source files in Libgd?
I have tried this way but the result was almost empty:
$LLVM_DIR/clang -emit-llvm -S -O0 src/gd_tiff.c -o src/gd_tiff.ll
Thank you very much.
Hello Andrzej,
I have some questions about StaticMain.cpp:
countStaticCalls
, you added an instance of StaticWrapper
to the ModulePassManager
. It seems that the tool is an analysis tool (in the sense that it doesn't transform any units of IR), so why we are wrapping our analysis pass (i.e., StaticCallCounter
) inside StaticWrapper
(which is derived from PassInfoMixin
)?StaticCallCounter
(which is derived from AnalysisInfoMixin
) to ModuleAnalysisManager
is not enough?MAM.getResult<StaticCallCounter>(M)
, why we didn't call it inside of a pass derived from AnalysisInfoMixin
(instead we are calling it from StaticWrapper
which is derived from PassInfoMixin
)Thank you very much.
Cheers,
Amir
This may not be a bug, but I am curious about how to link multiple modules.
I found the linker reports duplicate symbols (like some global variables ResultFormatStrIR
, printf_wrapper
) when I was trying to link two c files together.
The file foo.c
#include <stdio.h>
void bar();
void foo(){
bar();
printf("foo\n");
}
int main(){
foo();
}
The file bar.c
#include <stdio.h>
void bar(){
printf("bar\n");
}
and generate the LLVM IR
clang -emit-llvm -S foo.c -o foo.ll
clang -emit-llvm -S bar.c -o bar.ll
opt -enable-new-pm=0 -S -load libDynamicCallCounter.dylib -legacy-dynamic-cc foo.ll -o foo_opt.ll
opt -enable-new-pm=0 -S -load libDynamicCallCounter.dylib -legacy-dynamic-cc bar.ll -o bar_opt.ll
llc foo_opt.ll
llc bar_opt.ll
clang bar_opt.s foo_opt.s -o foo
and the error
duplicate symbol '_printf_wrapper' in:
/var/folders/c8/q41g17kj78j1t6_4wrf0py2w0000gn/T/bar_opt-eb2385.o
/var/folders/c8/q41g17kj78j1t6_4wrf0py2w0000gn/T/foo_opt-8688fa.o
duplicate symbol '_ResultFormatStrIR' in:
/var/folders/c8/q41g17kj78j1t6_4wrf0py2w0000gn/T/bar_opt-eb2385.o
/var/folders/c8/q41g17kj78j1t6_4wrf0py2w0000gn/T/foo_opt-8688fa.o
duplicate symbol '_ResultHeaderStrIR' in:
/var/folders/c8/q41g17kj78j1t6_4wrf0py2w0000gn/T/bar_opt-eb2385.o
/var/folders/c8/q41g17kj78j1t6_4wrf0py2w0000gn/T/foo_opt-8688fa.o
ld: 3 duplicate symbols for architecture x86_64
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
Currently the version is set to 16 (required).
Tried to compile with fresh llvm 17 and failed (can't match).
I'm working on a patch, if acceptable.
in LLVM 16 the Add extension points for MachinePass should be availible,
i couldn't find a way to write a plugin in LLVM that can change the function prologue and epilogue that the MachinePass creates..
do you have such example ?
I use the macOS Catalina (10.15.2)
After running:
$LLVM_DIR/bin/opt -load-pass-plugin libHelloWorld.dylib -passes=hello-world -disable-output input_for_hello.ll
I got this:
(llvm-tutor) Hello from: foo
(llvm-tutor) number of arguments: 1
(llvm-tutor) Hello from: bar
(llvm-tutor) number of arguments: 2
(llvm-tutor) Hello from: fez
(llvm-tutor) number of arguments: 3
(llvm-tutor) Hello from: main
(llvm-tutor) number of arguments: 2
Stack dump:
0. Program arguments: /usr/local/opt/llvm/bin/opt -load-pass-plugin libHelloWorld.dylib -passes=hello-world -disable-output input_for_hello.ll
0 opt 0x000000010d2629c6 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1 opt 0x000000010d262db8 SignalHandler(int) + 180
2 libsystem_platform.dylib 0x00007fff63a9b42d _sigtramp + 29
3 libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603338844097520
4 opt 0x000000010cf31d05 llvm::object_deleter<llvm::SmallVector<std::__1::pair<llvm::PassManagerBuilder::ExtensionPointTy, std::__1::function<void (llvm::PassManagerBuilder const&, llvm::legacy::PassManagerBase&)> >, 8u> >::call(void*) + 19
5 opt 0x000000010d223805 llvm::llvm_shutdown() + 53
6 opt 0x000000010d20bb41 llvm::InitLLVM::~InitLLVM() + 15
7 opt 0x000000010c0afc5a main + 10025
8 libdyld.dylib 0x00007fff638a27fd start + 1
Segmentation fault: 11
Do you know why I get the segfault?
BTW, thanks a lot for this great tutorial!
Description:
I'm running into an error when trying to use the opt command. All the passes in the repo work fine. But when I wrote and ran my own pass code using MBASub.cpp as a template and this error produced.
I've checked my command line arguments to make sure I'm not specifying -load multiple times and my code only change the name and runOnBasicBlock function in MBASub.cpp , so I'm not sure what's causing this error. Can anyone help me troubleshoot this issue?
Steps to reproduce:
Run the opt command with opt-14 -load-pass-plugin ./lib/libIndirectJmp.so -passes=indirect-jmp -S ./inputs/input_for_mba_sub.ll -o out.ll
Observe the "Option 'load' registered more than once!" error message
Expected result:
The opt command should run successfully with the specified options.
Actual result:
opt-14: CommandLine Error: Option 'load' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: opt-14 -load-pass-plugin ./lib/libIndirectJmp.so -passes=indirect-jmp -S ./inputs/input_for_mba_sub.ll -o out.ll
#0 0x00007fae6c81aa71 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xea5a71)
#1 0x00007fae6c8187be llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xea37be)
#2 0x00007fae6c81afa6 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xea5fa6)
#3 0x00007fae6b4aff90 (/lib/x86_64-linux-gnu/libc.so.6+0x3bf90)
#4 0x00007fae6b4feccc __pthread_kill_implementation ./nptl/./nptl/pthread_kill.c:44:76
#5 0x00007fae6b4afef2 raise ./signal/../sysdeps/posix/raise.c:27:6
#6 0x00007fae6b49a472 abort ./stdlib/./stdlib/abort.c:81:7
#7 0x00007fae6c74f668 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xdda668)
#8 0x00007fae6c74f486 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xdda486)
#9 0x00007fae6c73a4e0 (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xdc54e0)
#10 0x00007fae6c72be5b llvm::cl::Option::addArgument() (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xdb6e5b)
#11 0x00007fae67bc0ec0 llvm::cl::opt<llvm::PluginLoader, false, llvm::cl::parser<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > >::done() /usr/include/llvm-14/llvm/Support/CommandLine.h:1489:22
#12 0x00007fae67bc0046 llvm::cl::opt<llvm::PluginLoader, false, llvm::cl::parser<std::__cxx11::basic_string<char, std::char_traits, std::allocator > > >::opt<char [5], llvm::cl::NumOccurrencesFlag, llvm::cl::value_desc, llvm::cl::desc>(char const (&) [5], llvm::cl::NumOccurrencesFlag const&, llvm::cl::value_desc const&, llvm::cl::desc const&) /usr/include/llvm-14/llvm/Support/CommandLine.h:1513:3
#13 0x00007fae67bbd188 __static_initialization_and_destruction_0(int, int) /usr/include/llvm-14/llvm/Support/PluginLoader.h:35:5
#14 0x00007fae67bbd248 _GLOBAL__sub_I_IndirectJmp.cpp /home/kali/learnllvm/my-pass/lib/IndirectJmp.cpp:145:59
#15 0x00007fae722f4abe call_init ./elf/./elf/dl-init.c:69:21
#16 0x00007fae722f4abe call_init ./elf/./elf/dl-init.c:26:1
#17 0x00007fae722f4ba4 _dl_init ./elf/./elf/dl-init.c:116:14
#18 0x00007fae6b5c2e44 _dl_catch_exception ./elf/./elf/dl-error-skeleton.c:184:18
#19 0x00007fae722fb30e dl_open_worker ./elf/./elf/dl-open.c:812:6
#20 0x00007fae6b5c2dea _dl_catch_exception ./elf/./elf/dl-error-skeleton.c:209:18
#21 0x00007fae722fb6a8 _dl_open ./elf/./elf/dl-open.c:884:17
#22 0x00007fae6b4f92d8 dlopen_doit ./dlfcn/./dlfcn/dlopen.c:56:13
#23 0x00007fae6b5c2dea _dl_catch_exception ./elf/./elf/dl-error-skeleton.c:209:18
#24 0x00007fae6b5c2e9f _dl_catch_error ./elf/./elf/dl-error-skeleton.c:228:12
#25 0x00007fae6b4f8dc7 _dlerror_run ./dlfcn/./dlfcn/dlerror.c:145:17
#26 0x00007fae6b4f9389 dlopen_implementation ./dlfcn/./dlfcn/dlopen.c:71:51
#27 0x00007fae6b4f9389 dlopen ./dlfcn/./dlfcn/dlopen.c:81:12
#28 0x00007fae6c8052f9 llvm::sys::DynamicLibrary::getPermanentLibrary(char const*, std::__cxx11::basic_string<char, std::char_traits, std::allocator >) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0xe902f9)
#29 0x00007fae6f39326f llvm::PassPlugin::Load(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&) (/lib/x86_64-linux-gnu/libLLVM-14.so.1+0x3a1e26f)
#30 0x0000000000420088 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRefllvm::StringRef, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool) (/usr/lib/llvm-14/bin/opt+0x420088)
#31 0x0000000000435fb7 main (/usr/lib/llvm-14/bin/opt+0x435fb7)
#32 0x00007fae6b49b18a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#33 0x00007fae6b49b245 call_init ./csu/../csu/libc-start.c:128:20
#34 0x00007fae6b49b245 __libc_start_main ./csu/../csu/libc-start.c:368:5
#35 0x000000000041bd8a _start (/usr/lib/llvm-14/bin/opt+0x41bd8a)
zsh: IOT instruction opt-14 -load-pass-plugin ./lib/libIndirectJmp.so -passes="indirect-jmp" -S -
Environment details:
Operating system: kali
LLVM/Clang version: 14.0.6-2
here is my source code
indirectjmp.txt
Thank you for your help!
Hi Andrzej,
I'm on macOS Big Sur (Intel, not M1). I've worked through the "HelloWorld: Your First Pass" section, up to running the pass.
When I run $LLVM_DIR/bin/opt -load-pass-plugin ./libHelloWorld.dylib -passes=hello-world -disable-output input_for_hello.ll
, nothing appears and it immediately returns to a prompt. No error, nothing at all. Obviously I'm expecting messages showing the numbers of arguments, like in your readme.
I've tried using my own build of LLVM, LLVM 12 installed via brew
, and with the prebuilt LLVM 12 release from GitHub.
My own build was done today, directly from the main branch of the llvm-project repository on GitHub. It claims to be version 13.0.0.
I'm new to both LLVM and macOS, so very possible this is user error.
Finally, a big thank you for creating this project. I found this repo from one of your talks on YouTube. The talk helped me a lot in understanding what's going on.
It's rare to find resources specifically meant to guide beginners through learning about open-source projects. As a noob accustomed to being told to rtfm, your work here is hugely appreciated.
I want to write a pass which replaces float datatype with int.To achieve this ,How can I replace a datatype in .cpp file.
Thank You
It is expected :
main
What is happening:
I think main should print all instructions opcodes.
$LLVM_DIR/bin/opt --version
LLVM (http://llvm.org/):
LLVM version 12.0.0
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: bdver4
Hi @banach-space, this is my question, I think it is not really a bug.
I would like to know why GlobalValue::CommonLinkage
is used insead of GlobalValue::ExternalLinkage
when creating a global variable. It seems work well if I use GlobalValue::ExternalLinkage
.
I made some changes to the input_for_cc.c
and here is my code. It has an indirect function call.
void foo() { }
void bar() {foo(); }
void fez() {bar(); }
int main() {
foo();
bar();
fez();
void (*p) () = &foo;
p();
int ii = 0;
for (ii = 0; ii < 10; ii++)
foo();
return 0;
}
I found that the pass DynamicCounterCall.cpp
would fail in this scenario.
And here is the report generated by LLVM
Assertion failed: (!isZeroFill() && "Adding edge to zero-fill block?"), function addEdge, file JITLink.h, line 301.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: lli instrument_bin
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):
0 lli 0x000000010a1151dd llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 61
1 lli 0x000000010a11571b PrintStackTraceSignalHandler(void*) + 27
2 lli 0x000000010a11357f llvm::sys::RunSignalHandlers() + 127
3 lli 0x000000010a11729f SignalHandler(int) + 223
4 libsystem_platform.dylib 0x00007ff81be79e2d _sigtramp + 29
5 libsystem_platform.dylib 0x00007fc0c605f830 _sigtramp + 18446743836045498912
6 libsystem_c.dylib 0x00007ff81bdb0d10 abort + 123
7 libsystem_c.dylib 0x00007ff81bdb00be err + 0
8 lli 0x0000000109804325 llvm::jitlink::Block::addEdge(unsigned char, unsigned int, llvm::jitlink::Symbol&, long long) + 117
9 lli 0x00000001092c89da llvm::jitlink::EHFrameEdgeFixer::processFDE(llvm::jitlink::EHFrameEdgeFixer::ParseContext&, llvm::jitlink::Block&, unsigned long, unsigned long, unsigned long, unsigned int, llvm::DenseMap<unsigned int, llvm::jitlink::EHFrameEdgeFixer::EdgeTarget, llvm::DenseMapInfo<unsigned int, void>, llvm::detail::DenseMapPair<unsigned int, llvm::jitlink::EHFrameEdgeFixer::EdgeTarget> >&) + 3882
10 lli 0x00000001092c6876 llvm::jitlink::EHFrameEdgeFixer::processBlock(llvm::jitlink::EHFrameEdgeFixer::ParseContext&, llvm::jitlink::Block&) + 2550
11 lli 0x00000001092c5953 llvm::jitlink::EHFrameEdgeFixer::operator()(llvm::jitlink::LinkGraph&) + 1171
12 lli 0x00000001093ad365 decltype(std::__1::forward<llvm::jitlink::EHFrameEdgeFixer&>(fp)(std::__1::forward<llvm::jitlink::LinkGraph&>(fp0))) std::__1::__invoke<llvm::jitlink::EHFrameEdgeFixer&, llvm::jitlink::LinkGraph&>(llvm::jitlink::EHFrameEdgeFixer&, llvm::jitlink::LinkGraph&) + 69
13 lli 0x00000001093ad2f5 llvm::Error std::__1::__invoke_void_return_wrapper<llvm::Error, false>::__call<llvm::jitlink::EHFrameEdgeFixer&, llvm::jitlink::LinkGraph&>(llvm::jitlink::EHFrameEdgeFixer&, llvm::jitlink::LinkGraph&) + 69
14 lli 0x00000001093ad2a5 std::__1::__function::__alloc_func<llvm::jitlink::EHFrameEdgeFixer, std::__1::allocator<llvm::jitlink::EHFrameEdgeFixer>, llvm::Error (llvm::jitlink::LinkGraph&)>::operator()(llvm::jitlink::LinkGraph&) + 69
15 lli 0x00000001093ac084 std::__1::__function::__func<llvm::jitlink::EHFrameEdgeFixer, std::__1::allocator<llvm::jitlink::EHFrameEdgeFixer>, llvm::Error (llvm::jitlink::LinkGraph&)>::operator()(llvm::jitlink::LinkGraph&) + 68
16 lli 0x00000001092fc93d std::__1::__function::__value_func<llvm::Error (llvm::jitlink::LinkGraph&)>::operator()(llvm::jitlink::LinkGraph&) const + 93
17 lli 0x00000001092f7510 std::__1::function<llvm::Error (llvm::jitlink::LinkGraph&)>::operator()(llvm::jitlink::LinkGraph&) const + 64
18 lli 0x00000001092f4f49 llvm::jitlink::JITLinkerBase::runPasses(std::__1::vector<std::__1::function<llvm::Error (llvm::jitlink::LinkGraph&)>, std::__1::allocator<std::__1::function<llvm::Error (llvm::jitlink::LinkGraph&)> > >&) + 153
19 lli 0x00000001092f4b45 llvm::jitlink::JITLinkerBase::linkPhase1(std::__1::unique_ptr<llvm::jitlink::JITLinkerBase, std::__1::default_delete<llvm::jitlink::JITLinkerBase> >) + 165
20 lli 0x0000000109337842 void llvm::jitlink::JITLinker<llvm::jitlink::MachOJITLinker_x86_64>::link<std::__1::unique_ptr<llvm::jitlink::JITLinkContext, std::__1::default_delete<llvm::jitlink::JITLinkContext> >, std::__1::unique_ptr<llvm::jitlink::LinkGraph, std::__1::default_delete<llvm::jitlink::LinkGraph> >, llvm::jitlink::PassConfiguration>(std::__1::unique_ptr<llvm::jitlink::JITLinkContext, std::__1::default_delete<llvm::jitlink::JITLinkContext> >&&, std::__1::unique_ptr<llvm::jitlink::LinkGraph, std::__1::default_delete<llvm::jitlink::LinkGraph> >&&, llvm::jitlink::PassConfiguration&&) + 130
21 lli 0x00000001093374f8 llvm::jitlink::link_MachO_x86_64(std::__1::unique_ptr<llvm::jitlink::LinkGraph, std::__1::default_delete<llvm::jitlink::LinkGraph> >, std::__1::unique_ptr<llvm::jitlink::JITLinkContext, std::__1::default_delete<llvm::jitlink::JITLinkContext> >) + 968
22 lli 0x000000010931c10e llvm::jitlink::link_MachO(std::__1::unique_ptr<llvm::jitlink::LinkGraph, std::__1::default_delete<llvm::jitlink::LinkGraph> >, std::__1::unique_ptr<llvm::jitlink::JITLinkContext, std::__1::default_delete<llvm::jitlink::JITLinkContext> >) + 206
23 lli 0x00000001092e3ff0 llvm::jitlink::link(std::__1::unique_ptr<llvm::jitlink::LinkGraph, std::__1::default_delete<llvm::jitlink::LinkGraph> >, std::__1::unique_ptr<llvm::jitlink::JITLinkContext, std::__1::default_delete<llvm::jitlink::JITLinkContext> >) + 128
24 lli 0x000000010991794f llvm::orc::ObjectLinkingLayer::emit(std::__1::unique_ptr<llvm::orc::MaterializationResponsibility, std::__1::default_delete<llvm::orc::MaterializationResponsibility> >, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer> >) + 463
25 lli 0x000000010994fed4 llvm::orc::ObjectTransformLayer::emit(std::__1::unique_ptr<llvm::orc::MaterializationResponsibility, std::__1::default_delete<llvm::orc::MaterializationResponsibility> >, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer> >) + 484
26 lli 0x00000001098447d7 llvm::orc::IRCompileLayer::emit(std::__1::unique_ptr<llvm::orc::MaterializationResponsibility, std::__1::default_delete<llvm::orc::MaterializationResponsibility> >, llvm::orc::ThreadSafeModule) + 503
27 lli 0x0000000109847120 llvm::orc::IRTransformLayer::emit(std::__1::unique_ptr<llvm::orc::MaterializationResponsibility, std::__1::default_delete<llvm::orc::MaterializationResponsibility> >, llvm::orc::ThreadSafeModule) + 352
28 lli 0x0000000109847120 llvm::orc::IRTransformLayer::emit(std::__1::unique_ptr<llvm::orc::MaterializationResponsibility, std::__1::default_delete<llvm::orc::MaterializationResponsibility> >, llvm::orc::ThreadSafeModule) + 352
29 lli 0x000000010986b6e7 llvm::orc::BasicIRLayerMaterializationUnit::materialize(std::__1::unique_ptr<llvm::orc::MaterializationResponsibility, std::__1::default_delete<llvm::orc::MaterializationResponsibility> >) + 471
30 lli 0x0000000109719c88 llvm::orc::MaterializationTask::run() + 72
31 lli 0x0000000109719ee2 llvm::orc::ExecutionSession::runOnCurrentThread(std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> >) + 18
32 lli 0x0000000109757be2 void llvm::detail::UniqueFunctionBase<void, std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> > >::CallImpl<void (*)(std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> >)>(void*, std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> >&) + 66
33 lli 0x00000001097222a7 llvm::unique_function<void (std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> >)>::operator()(std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> >) + 55
34 lli 0x0000000109709ee5 llvm::orc::ExecutionSession::dispatchTask(std::__1::unique_ptr<llvm::orc::Task, std::__1::default_delete<llvm::orc::Task> >) + 245
35 lli 0x000000010971b576 llvm::orc::ExecutionSession::dispatchOutstandingMUs() + 566
36 lli 0x000000010971ea9c llvm::orc::ExecutionSession::OL_completeLookup(std::__1::unique_ptr<llvm::orc::InProgressLookupState, std::__1::default_delete<llvm::orc::InProgressLookupState> >, std::__1::shared_ptr<llvm::orc::AsynchronousSymbolQuery>, std::__1::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > const&)>) + 956
37 lli 0x0000000109779e74 llvm::orc::InProgressFullLookupState::complete(std::__1::unique_ptr<llvm::orc::InProgressLookupState, std::__1::default_delete<llvm::orc::InProgressLookupState> >) + 228
38 lli 0x000000010971090d llvm::orc::ExecutionSession::OL_applyQueryPhase1(std::__1::unique_ptr<llvm::orc::InProgressLookupState, std::__1::default_delete<llvm::orc::InProgressLookupState> >, llvm::Error) + 3901
39 lli 0x000000010970da5d llvm::orc::ExecutionSession::lookup(llvm::orc::LookupKind, std::__1::vector<std::__1::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags>, std::__1::allocator<std::__1::pair<llvm::orc::JITDylib*, llvm::orc::JITDylibLookupFlags> > > const&, llvm::orc::SymbolLookupSet, llvm::orc::SymbolState, llvm::unique_function<void (llvm::Expected<llvm::DenseMap<llvm::orc::SymbolStringPtr, llvm::JITEvaluatedSymbol, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void>, llvm::detail::DenseMapPair<llvm::orc::SymbolStringPtr, llvm::JITEvaluatedSymbol> > >)>, std::__1::function<void (llvm::DenseMap<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> >, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::orc::SymbolStringPtr, void> > > > const&)>) + 381
40 lli 0x0000000109718fb8 llvm::orc::Platform::lookupInitSymbols(llvm::orc::ExecutionSession&, llvm::DenseMap<llvm::orc::JITDylib*, llvm::orc::SymbolLookupSet, llvm::DenseMapInfo<llvm::orc::JITDylib*, void>, llvm::detail::DenseMapPair<llvm::orc::JITDylib*, llvm::orc::SymbolLookupSet> > const&) + 952
41 lli 0x00000001098a2821 (anonymous namespace)::GenericLLVMIRPlatformSupport::issueInitLookups(llvm::orc::JITDylib&) + 305
42 lli 0x00000001098a1eae (anonymous namespace)::GenericLLVMIRPlatformSupport::getInitializers(llvm::orc::JITDylib&) + 78
43 lli 0x0000000109895bc7 (anonymous namespace)::GenericLLVMIRPlatformSupport::initialize(llvm::orc::JITDylib&) + 151
44 lli 0x00000001082fd965 llvm::orc::LLJIT::initialize(llvm::orc::JITDylib&) + 277
45 lli 0x00000001082f849f runOrcJIT(char const*) + 5359
46 lli 0x00000001082f4d96 main + 438
47 dyld 0x0000000118b5a4fe start + 462
[1] 44361 abort lli instrument_bin
If I replace the GlobalValue::CommonLinkage
with GlobalValue::ExternalLinkage
, then DynamicCounterCall works well.
Here is the result returned by the program.
=================================================
LLVM-TUTOR: dynamic analysis results
=================================================
NAME #N DIRECT CALLS
-------------------------------------------------
foo 14
bar 2
fez 1
main 1
I'm using llvm 13.0.1
After being instrumented by dynamic-cc, running the program in lli prints nothing.
But when I run the same program in lli 15.0.0, it prints as expected.
Anybody experienced same issue?
Hi, sir, follow the instructions you mentioned in the document, I got nothing in the screen:
2314 echo "export LLVM_DIR=/usr/local/opt/llvm@12" >> ~/.zshrc
...
2321 cd build
2322 cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../HelloWorld/
2323 make
2324 $LLVM_DIR/bin/clang -S -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll
2325 $LLVM_DIR/bin/opt -load-pass-plugin ./libHelloWorld.dylib -disable-output input_for_hello.ll
I wanna store infomation in a file. But I don't know how to add redirection codes in IR.
> log.txt
is not a satisfactory solution.
I follow your guide about how to debug using gdb on ubuntu. But my gdb cannot see the source file.
I using following command:
clang -emit-llvm -S -O1 input_for_mba.c -o input_for_mba.ll
gdb --args opt -S -load-pass-plugin ../build/lib/libMBAAdd.so -passes=mba-add input_for_mba.ll
b ../lib/MBAAdd.cpp:MBAAdd::run
gdb said: No source file named ../lib/MBAAdd.cpp.
(gdb) info source
No current source file.
Please help me. thanks a lot
Hi there!
I'm trying to write a legacy pass which can be used like:
clang -O3 -Xclang -load -Xclang libMyPass.so test.c -o test
And I also noticed that by setting the parameter llvm::PassManagerBuilder::ExtensionPointTy I can control the loading order of the pass at a degree.
However, I have been wondering how I can explore the exact execution order of the passes used in the whole compilation process? (Including those are used by O3 or other operations)
@banach-space I followed the instructions in the README and proceeded with the operation.
First,wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main" sudo apt-get update sudo apt-get install -y llvm-16 llvm-16-dev llvm-16-tools clang-16Second,
cd /root/llvm-tutor/build/ cmake -DLT_LLVM_INSTALL_DIR=/usr/lib/llvm-16 /root/llvm-tutor make
Third
root@LAPTOP-OJLO0M82:~/llvm-tutor/build# ls CMakeCache.txt CMakeFiles Makefile cmake_install.cmake input_for_hello.ll root@LAPTOP-OJLO0M82:~/llvm-tutor/build# lit --version lit 16.0.6 root@LAPTOP-OJLO0M82:~/llvm-tutor/build# lit ../test lit: /usr/local/lib/python3.10/dist-packages/lit/TestingConfig.py:140: fatal: unable to parse config file '/root/llvm-tutor/test/lit.cfg.py', traceback: Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/lit/TestingConfig.py", line 129, in load_from_path exec(compile(data, path, 'exec'), cfg_globals, None) File "/root/llvm-tutor/test/lit.cfg.py", line 22, in <module> config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell) AttributeError: 'NoneType' object has no attribute 'use_lit_shell'
Hi
I have tried the recommended command line from #12 but I am still not able to load the .so file. The command line I used was
$LLVM_DIR/bin/opt -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_helloworld.ll
I am running on Ubuntu 2004 LTS in VirtualBox.
$LLVM_DIR/bin/opt --version
LLVM version 12.0.0-test
Optimized build
Default target: x86_64-unknown-linux-gnu
Host CPU: haswell
The MBAAdd pass has a custom command line option specified (-mba-ratio
), which you show how to use with the legacy pass manager, but you don't show an example of how this is done with the new pass manager. I haven't been able to figure out how to use custom command line options with the new pass manager. Can you provide an example of this?
Recently I've started seeing this in my CI jobs on Ubuntu Bionic:
Could not find a configuration file for package "LLVM" that is compatible
with requested version "11.0.0"
It turns out that the package for LLVM 11 for Ubuntu Bionic started claiming to be version 11.1.0
rather than 11.0.1
or 11.0.0
.
As LLVM 11.1.0
has not been released yet (rc1 has just been tagged: llvm-dev thread), I assume that this is a bug in the packaging. I reported it here.
Although LLVM 11.1.0 and LLVM 11.0.0 will be ABI incompatible, I doubt that this will affect llvm-tutor. But it does confuse the CMake scripts.
hello,
I have a question.
runOnFunction
) on a specific function that gets the function name from the user? I mean can I pass some input to runOnFunction
?Thanks a lot
I'm using LLVM compiled from branch release/13.x
with the new Pass Manager.
After following the steps at the InjectFuncCall section when i run
$LLVM_DIR/bin/lli instrumented_hello.bin
I only get the following output
(llvm-tutor) Hello from: main
(llvm-tutor) number of arguments: 2
I tried by removing -O1
option when compiling with clang-13 and it shows the correct output.
I'd open a pr but since I'm a beginner with compilers and llvm I'm not sure if there could be other reasons I got this behavior.
Related
I am trying to instrument all function calls in an existing codebase.
I don't want to have to modify existing makefile scripts too extensively.
The solution is to use the legacy pass manager.
clang++ -flegacy-pass-manager -Xclang -load -Xclang ./libmypass.so input.cpp
It seems that the new pass manager doesn't allow this yet.
You must take care to choose the correct extension point. See here are the extension points. See [here] (https://github.com/rdadolf/clangtool/blob/353b80061ce30c3062bbe4752dbaa2a1c84cc9c8/clangtool.cpp#L42-L49) for an explanation of which ones to use.
This information should be added to the readme.md.
Only one change necessary.
Change: https://reviews.llvm.org/D107025
https://github.com/banach-space/llvm-tutor/blob/main/lib/OpcodeCounter.cpp#L124
- llvm::PassBuilder::OptimizationLevel
+ llvm::OptimizationLevel
When you call opt directly you use --passes and the list of desired passes, but in some older code I've seen you could call from clang with -mllvm followed by some additional options added directly to PassManagerBuilder in the form of cl::opt items. This was also how you could then pass along additional options to the pass. This code was using the legacy pass manager. What is the current way to specify the passes and options when using clang?
Hello, I just started to learn llvm pass. You must be very professional in llvm pass, so I want to ask a practical question, as the title says.
For example, this is a very simple program.
#include <stdlib.h>
int main(){
int a=0;
for(int i=0;i<5;i++){
a++;
}
return 0;
}
Can I dynamically obtain the value of local variable a in llvm pass? My purpose is to observe its value change When it changes. So I have to obtain the value of the local variable a firstly.
If it's a global variable, it should be very simple to obtain its value, but I don't have any ideas about local variables.
I have checked the official documents and don't know whether this can be realized. If so, can you provide some ideas?
Hello Andrzej,
I built HelloWorld
pass on macOS, and it worked fine, but I had a problem on Linux.
The command I used:
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout release/10.x
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 ../llvm
cmake --build .
export LLVM_DIR=$(pwd)
git clone https://github.com/banach-space/llvm-tutor
cd llvm-tutor
export TUTOR_DIR=$(pwd)
cd HelloWorld/
mkdir build
cd build
cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../
make
$LLVM_DIR/bin/clang -S -emit-llvm $TUTOR_DIR/inputs/input_for_hello.c -o input_for_hello.ll
$LLVM_DIR/bin/opt -load-pass-plugin libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll
The error from opt
:
Failed to load passes from 'libHelloWorld.so'. Request ignored.
/home/amir/llvm-project/build/bin/opt: unknown pass name 'hello-world'
Thanks,
Amir
I find that the examples here are used for middle-end pass at IR level, does our framework can be used on backend pass ?
Currently all testing is run on either Ubuntu or MacOS. It would be great to cover more OSes! Fedora should be relatively easy to set-up.
This is a direct follow-up from #31.
I'm using macOS, and I install LLVM with brew
.
$ llvm-config --version
10.0.0
In debugging:
Without -debug-only=mba-add -stats
:
opt -load-pass-plugin build/lib/libMBAAdd.dylib -passes=mba-add input_for_mba.ll -S -o input_for_mba.transformed.ll
It generates input_for_mba.transformed.ll
with no error/warning.
However, with -debug-only=mba-add -stats
:
opt -load-pass-plugin build/lib/libMBAAdd.dylib -passes=mba-add -debug-only=mba-add -stats input_for_mba.ll -S -o input_for_mba.transformed.ll
Output:
opt: Unknown command line argument '-debug-only=mba-add'. Try: 'opt --help'
opt: Did you mean '--debug-pass=mba-add'?
When I used --debug-pass=mba-add
:
opt -load-pass-plugin build/lib/libMBAAdd.dylib -passes=mba-add input_for_mba.ll --debug-pass=mba-add -stats -S -o input_for_mba.transformed.ll
Output:
opt: for the --debug-pass option: Cannot find option named 'mba-add'!
Hello !
To begin, thanks for your super repo !
I have some troubles with running the HelloWorld example pass... By following your tutorial I am doing this :
(orc) root[0]/r/testzone > cd llvm-tutor/
(orc) root[0]/r/t/llvm-tutor > export LLVM_DIR=/root/orchestra/root/lib64/llvm/llvm
(orc) root[0]/r/t/llvm-tutor > mkdir build
cd build
cmake -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ../HelloWorld/
make
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /root/orchestra/root/link-only/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: /root/orchestra/root/link-only/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: /root/orchestra/root/lib64/libz.so (found version "1.2.11")
-- Configuring done
-- Generating done
-- Build files have been written to: /root/testzone/llvm-tutor/build
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cpp.o
[100%] Linking CXX shared library libHelloWorld.so
[100%] Built target HelloWorld
(orc) root[0]/r/t/l/build > $LLVM_DIR/bin/clang -O1 -S -emit-llvm ../inputs/input_for_hello.c -o input_for_hello.ll
(orc) root[0]/r/t/l/build >
(orc) root[134]/r/t/l/build > $LLVM_DIR/bin/opt -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output
input_for_hello.ll
Failed to load passes from './libHelloWorld.so'. Request ignored.
Expected<T> must be checked before access or destruction.
Unchecked Expected<T> contained error:
Could not load library './libHelloWorld.so': ./libHelloWorld.so: undefined symbol: _ZNK4llvm12FunctionPass17createPrinterPassERNS_11raw_ostreamERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /root/orchestra/root/lib64/llvm/llvm/bin/opt -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll
#0 0x00007f42457c4a5e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:570:13
#1 0x00007f42457c2dc4 llvm::sys::RunSignalHandlers() /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/Signals.cpp:105:18
#2 0x00007f42457c4fcd SignalHandler(int) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:415:1
#3 0x00007f4245205520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007f4245259a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007f4245259a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007f4245259a7c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007f4245205476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007f42451eb7f3 abort ./stdlib/abort.c:81:7
#9 0x000055c33f5d4c11 llvm::raw_ostream::operator<<(llvm::StringRef) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/raw_ostream.h:220:7
#10 0x000055c33f5d4c11 llvm::raw_ostream::operator<<(char const*) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/raw_ostream.h:244:18
#11 0x000055c33f5d4c11 llvm::Expected<llvm::PassPlugin>::fatalUncheckedExpected() const /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/Error.h:704:14
#12 0x000055c33f5d0d98 (/root/orchestra/root/lib64/llvm/llvm/bin/opt+0x2ad98)
#13 0x000055c33f5d2bfb std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__is_long[abi:v160001]() const /builds/gitlab/revng/orchestra/orchestra/root/lib64/llvm/clang-release/bin/../include/c++/v1/string:1682:16
#14 0x000055c33f5d2bfb std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string() /builds/gitlab/revng/orchestra/orchestra/root/lib64/llvm/clang-release/bin/../include/c++/v1/string:2361:9
#15 0x000055c33f5d2bfb llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::handleOccurrence(unsigned int, llvm::StringRef, llvm::StringRef) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/CommandLine.h:1673:3
#16 0x00007f42456da45d ProvideOption(llvm::cl::Option*, llvm::StringRef, llvm::StringRef, int, char const* const*, int&) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/CommandLine.cpp:708:1
#17 0x00007f42456de4ef (anonymous namespace)::CommandLineParser::ParseCommandLineOptions(int, char const* const*, llvm::StringRef, llvm::raw_ostream*, bool) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/CommandLine.cpp:1714:23
#18 0x00007f42456de4ef llvm::cl::ParseCommandLineOptions(int, char const* const*, llvm::StringRef, llvm::raw_ostream*, char const*, bool) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/CommandLine.cpp:1470:24
#19 0x000055c33f5ce47a main /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/tools/opt/opt.cpp:0:3
#20 0x00007f42451ecd90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#21 0x00007f42451ece40 call_init ./csu/../csu/libc-start.c:128:20
#22 0x00007f42451ece40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#23 0x000055c33f5bf379 _start (/root/orchestra/root/lib64/llvm/llvm/bin/opt+0x19379)
fish: Job 1, '$LLVM_DIR/bin/opt -load-pass-pl…' terminated by signal SIGABRT (Abort)
I saw this problem in a stackoverflow post. It was an ABI match problem. The user had solve it by inserting the _GLIBCXX_USE_CXX11_ABI=0
compilation option...In my case doing that let me fall in another symbol problem :
(orc) root[0]/r/t/l/build > $LLVM_DIR/bin/opt -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output i
nput_for_hello.ll
Failed to load passes from './libHelloWorld.so'. Request ignored.
Expected<T> must be checked before access or destruction.
Unchecked Expected<T> contained error:
Could not load library './libHelloWorld.so': ./libHelloWorld.so: undefined symbol: _ZNK4llvm12FunctionPass17createPrinterPassERNS_11raw_ostreamERKSsPLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /root/orchestra/root/lib64/llvm/llvm/bin/opt -load-pass-plugin ./libHelloWorld.so -passes=hello-world -disable-output input_for_hello.ll
#0 0x00007fd15505ea5e llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:570:13
#1 0x00007fd15505cdc4 llvm::sys::RunSignalHandlers() /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/Signals.cpp:105:18
#2 0x00007fd15505efcd SignalHandler(int) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/Unix/Signals.inc:415:1
#3 0x00007fd154a9f520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x00007fd154af3a7c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007fd154af3a7c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007fd154af3a7c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007fd154a9f476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007fd154a857f3 abort ./stdlib/abort.c:81:7
#9 0x000055e011ed3c11 llvm::raw_ostream::operator<<(llvm::StringRef) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/raw_ostream.h:220:7
#10 0x000055e011ed3c11 llvm::raw_ostream::operator<<(char const*) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/raw_ostream.h:244:18
#11 0x000055e011ed3c11 llvm::Expected<llvm::PassPlugin>::fatalUncheckedExpected() const /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/Error.h:704:14
#12 0x000055e011ecfd98 (/root/orchestra/root/lib64/llvm/llvm/bin/opt+0x2ad98)
#13 0x000055e011ed1bfb std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::__is_long[abi:v160001]() const /builds/gitlab/revng/orchestra/orchestra/root/lib64/llvm/clang-release/bin/../include/c++/v1/string:1682:16
#14 0x000055e011ed1bfb std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>::~basic_string() /builds/gitlab/revng/orchestra/orchestra/root/lib64/llvm/clang-release/bin/../include/c++/v1/string:2361:9
#15 0x000055e011ed1bfb llvm::cl::list<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, llvm::cl::parser<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>>::handleOccurrence(unsigned int, llvm::StringRef, llvm::StringRef) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/include/llvm/Support/CommandLine.h:1673:3
#16 0x00007fd154f7445d ProvideOption(llvm::cl::Option*, llvm::StringRef, llvm::StringRef, int, char const* const*, int&) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/CommandLine.cpp:708:1
#17 0x00007fd154f784ef (anonymous namespace)::CommandLineParser::ParseCommandLineOptions(int, char const* const*, llvm::StringRef, llvm::raw_ostream*, bool) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/CommandLine.cpp:1714:23
#18 0x00007fd154f784ef llvm::cl::ParseCommandLineOptions(int, char const* const*, llvm::StringRef, llvm::raw_ostream*, char const*, bool) /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/lib/Support/CommandLine.cpp:1470:24
#19 0x000055e011ecd47a main /builds/gitlab/revng/orchestra/orchestra/sources/llvm-project/llvm/tools/opt/opt.cpp:0:3
#20 0x00007fd154a86d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#21 0x00007fd154a86e40 call_init ./csu/../csu/libc-start.c:128:20
#22 0x00007fd154a86e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#23 0x000055e011ebe379 _start (/root/orchestra/root/lib64/llvm/llvm/bin/opt+0x19379)
fish: Job 1, '$LLVM_DIR/bin/opt -load-pass-pl…' terminated by signal SIGABRT (Abort)
Some other issues in other projects (sampsyo/llvm-pass-skeleton#12) give some solutions...which are not working for me.
My setup is :
(orc) root[0]/r/t/l/build > $LLVM_DIR/bin/opt --version
LLVM (http://llvm.org/):
LLVM version 16.0.1
Optimized build with assertions.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake
If you have any suggestions, I take 😄
Have a nice day.
when I try to build HelloWorld project with VS2019, I got LINK error( my cmake command is: cmake -G "Visual Studio 16 2019" -A x64 -Thost=x64 ../
):
if I modify add_llvm_library
MODULE
to SHARED
, VS2019 can successfully compile the HelloWolrd
but got the following warning:
and then opt.exe failed to load passes
In addition, the cmake invocation for llvm is:
cmake -DLLVM_ENABLE_PROJECTS="clang;lld;libcxx;llvm" -DLLVM_EXPORT_SYMOBLS_FOR_PLUGINS=On -G "Visual Studio 16 2019" -A x64 -Thost=x64 ..\
In DuplicateBB.cpp, the run method of the DuplicateBB struct return none() when Targets is empty and return all() when Targets is not empty.
Should the return value be reversed?
Because when Targets is empty the pass dose not modify the LLVM program, the run method should return all()
And I also referenced documention on official website, it doesn't work neither, is legacy plugin still supported by LLVM 15?
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.