Hello
(my machine is a Debian/Sid/x86-64/Core2)
Assuming I have one C source file chello.c, to compile it into a dynamically loadable thru dlopen shared object, I can run
gcc -fPIC -shared -O chello.c -o chello.so
I thought that, assuming I have one llvm source ehello.ll, the equivalent would be
llvmc2 -opt ehello.ll -o ehello.so
but it is not that simple.
Any clues ?
May I also suggest to document it in the man pages or the --help output?
Hello all,
In a previous email, I asked:
Basile STARYNKEVITCH wrote:
(my machine is a Debian/Sid/x86-64/Core2)
Assuming I have one C source file chello.c, to compile it into a dynamically loadable thru dlopen shared object, I can run
gcc -fPIC -shared -O chello.c -o chello.so
I thought that, assuming I have one llvm source ehello.ll, the equivalent would be
llvmc2 -opt ehello.ll -o ehello.so
but it is not that simple.
Apparently the following script should work; $1 is supposed to be a source file -either *.c or *.cc or *.ll and $2 is the generated output dynamically loadable shared object *.so
#! /bin/sh
src=$1
obj=$2
objbase=$(basename $obj .so)
case $src in
*.c) gcc -O -g -fPIC -shared $src -o $obj;;
*.cc) g++ -O -g -fPIC -shared $src -o $obj;;
*.ll) /usr/local/bin/llvm-as -f $src -o $objbase.bc
/usr/local/bin/opt -std-compile-opts -f $objbase.bc -o $objbase.opt.bc
/usr/local/bin/llc -f -relocation-model=pic -march=x86-64 -tailcallopt $objbase.opt.bc > $objbase.s
as $objbase.s -o $objbase.pic.o
ld -shared $objbase.pic.o -o $obj
rm $objbase.s $objbase.pic.o $objbase.opt.bc $objbase.bc;;
*) echo unknown file $src; exit 1;;
esac
Thanks for reading.
Regards.