[LLVMdev] generating a shared object from a single *.ll (LLVM) source?
Basile STARYNKEVITCH
basile at starynkevitch.net
Sun Jul 20 15:18:07 PDT 2008
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.
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***
More information about the llvm-dev
mailing list