[LLVMdev] Linking an inmemory module

Armin Steinhoff as at steinhoff-automation.com
Thu Oct 11 06:38:42 PDT 2012


Hi All,

I just started with the API of LLVM and have a beginner's question.

I'm trying to JIT compile the attached C program "getinmemory" to an 
inmemory module by a my attached example LLVM program.
After linking of this inmemory module against libc.so.6 I call the main 
routine of the C program.

Why do I have still malloc as a unresoveld externals ?  Contains the 
module "module_ex" not an fully executable program ?

Here are the printouts ( Linux):

------------------------
compile_to_module-return

clang -fdiagnostics-format=clang getinmemory.c -fsyntax-only -I 
/usr/include -I /usr/lib/gcc/i586-suse-linux/4.6/include -I 
/usr/src/linux/include -I /usr/src/linux/include/linux -v 
-fdollars-in-identifiers -fno-operator-names -ffp-contract=on 
-fobjc-runtime=macosx -triple i386-pc-linux-gnu
clang -cc1 version 3.2 based upon LLVM 3.2svn default target 
i386-pc-linux-gnu
#include "..." search starts here:
#include <...> search starts here:
  /usr/include
  /usr/lib/gcc/i586-suse-linux/4.6/include
  /usr/src/linux/include
  /usr/src/linux/include/linux
End of search list.
[ clip .. warnings]
Main
malloc
curl_global_init
curl_easy_init
curl_easy_setopt
WriteMemoryCallback
curl_easy_perform
curl_easy_cleanup
printf
free
curl_global_cleanup
main
realloc
exit
llvm.memcpy.p0i8.p0i8.i32
LLVM ERROR: Tried to execute an unknown external function: malloc
-----------------------

My target is to JIT compile e.g. the sources of a C/C++ library into 
executable inmemory code
in order to call the individual functions of the library. It's just a 
different kind of late bindings ...

Best Regards

Armin Steinhoff







-------------- next part --------------
A non-text attachment was scrubbed...
Name: compile_to_module-return.cpp
Type: text/x-c++src
Size: 3732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121011/b368244e/attachment.cpp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getinmemory.c
Type: text/x-c++src
Size: 3402 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121011/b368244e/attachment.c>
-------------- next part --------------
INCLUDES=-I /usr/local/include/clang -I/usr/local/include/llvm -I/usr/local/include
LIBS= -L/home/CLING/build/Debug+Asserts/lib/clang/3.2/lib/linux -lclang_rt.full-i386 -lclang_rt.profile-i386 -L/home/CLING/build/Debug+Asserts/lib \
-lclangFrontendTool -lclangFrontend -lclangDriver \
-lclangSerialization -lclangCodeGen -lclangParse -lclangSema \
-lclangStaticAnalyzerFrontend -lclangStaticAnalyzerCheckers \
-lclangStaticAnalyzerCore \
-lclangAnalysis -lclangARCMigrate -lclangRewrite \
-lclangEdit -lclangAST -lclangLex -lclangBasic \
-lLLVMAsmParser -lLLVMTableGen -lLLVMDebugInfo -lLLVMX86AsmParser -lLLVMX86Disassembler -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter \
-lLLVMJIT -lLLVMMCDisassembler -lLLVMMCParser -lLLVMInstrumentation -lLLVMInterpreter \
-lLLVMCodeGen -lLLVMipo -lLLVMVectorize -lLLVMScalarOpts -lLLVMInstCombine -lLLVMLinker -lLLVMTransformUtils -lLLVMipa -lLLVMAnalysis -lLLVMArchive \
-lLLVMBitReader -lLLVMBitWriter -lLLVMMCJIT -lLLVMRuntimeDyld -lLLVMExecutionEngine -lLLVMTarget -lLLVMMC -lLLVMObject -lLLVMCore -lLLVMSupport \
-lLLVMX86Desc -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils 

all : build_executable compile_to_module-return compile_to_module  


#build_executable :
#	g++ `llvm-config --cxxflags` $(INCLUDES)  -o build_executable build_executable.cpp $(LIBS) -ldl -lpthread  #-Wl,-rpath-link /home/CLING/build/Debug+Asserts/lib


#compile_to_module : 
#	g++ `llvm-config --cxxflags` $(INCLUDES)  -o compile_to_module compile_to_module.cpp $(LIBS) -ldl -lpthread 


compile_to_module-return :
	g++ `llvm-config --cxxflags` $(INCLUDES)  -o compile_to_module-return compile_to_module-return.cpp $(LIBS) -ldl -lpthread 



More information about the llvm-dev mailing list