Jimi Damon
2013-Jul-29 18:28 UTC
[LLVMdev] llvm-g++ 4.6.4 unable to compile simple shared library on Ubuntu 12.04 x86_64
Hi, I am trying to release a Makefile for building my company's software that will be flexible enough to use the llvm suite of compilers to build shared libraries for talking to USB peripherals. The problem that I am having is that while I am able to build a shared library using llvm-gcc , the llvm-g++ compiler is giving me error messages saying " relocation R_X86_64_PC32 against undefined symbol `__morestack' can not be used when making a shared object; recompile with -fPIC Here's my configuration on my local machine: cat /etc/issue Ubuntu-12.04 uname -a Linux localhost 3.2.0-48-generic #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux dpkg -l | grep llvm ii libllvm2.7 2.7-0ubuntu1 Low-Level Virtual Machine (LLVM) (runtime library) ii libllvm2.9 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM), runtime library ii libllvm3.0 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), runtime library ii libllvm3.0:i386 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), runtime library ii llvm 2.9-7 Low-Level Virtual Machine (LLVM) ii llvm-2.9 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM) ii llvm-2.9-dev 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM), libraries and headers ii llvm-2.9-runtime 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM), bytecode interpreter ii llvm-3.0 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM) ii llvm-3.0-dev 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), libraries and headers ii llvm-3.0-runtime 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), bytecode interpreter ii llvm-dev 2.9-7 Low-Level Virtual Machine (LLVM), libraries and headers ii llvm-gcc-4.6 3.0-3 C front end for LLVM C/C++ compiler ii llvm-runtime 2.9-7 Low-Level Virtual Machine (LLVM), bytecode interpreter I have a very simple example that appears to illustrate this problem /******** squared.h BEGIN *****/ int squared(int val); /********* END *****/ /******* squared.c BEGIN ****/ int squared(int val) { return val*val; } /********* END ****/ /**** main.c BEGIN *****/ #include <stdio.h> int main(int argc,char *argv[] ) { int i = 0; for( i = 0; i < 10 ; i ++ ) { printf("%d\n",squared(i)); } } /**** END *******/ Using llvm-gcc works just fine: llvm-gcc -fPIC -c -o squared.o squared.c llvm-gcc -shared -o libsquared.so squared.o llvm-gcc -L. -o main main.c -lsquared LD_LIBRARY_PATH=. ./main 0 1 4 9 16 25 36 49 64 81 The creation of the shared library fails when using llvm-g++ llvm-g++ -fPIC -c -o squared.o squared.c llvm-g++ -shared -o libsquared.so squared.o /usr/bin/ld: squared.o: relocation R_X86_64_PC32 against undefined symbol `__morestack' can not be used when making a shared object; recompile with -fPIC This exact compile works on a 32 bit version of Ubuntu 12.04 , i686 cat /etc/issue Ubuntu 12.04.2 LTS \n \l uname -a Linux gdbserver 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:15:33 UTC 2013 i686 i686 i386 GNU/Linux llvm-g++ -fPIC -c -o squared.o squared.c llvm-g++ -shared -o libsquared.so squared.o This succeeds and I am able to use the shared library to compile the main program. Any ideas for how to get passed this problem with llvm-g++ ? Thanks -Jimi
Duncan Sands
2013-Aug-01 15:45 UTC
[LLVMdev] llvm-g++ 4.6.4 unable to compile simple shared library on Ubuntu 12.04 x86_64
Hi, I can't reproduce this on x86-64 ubuntu 13.04 with version 3.2-1~exp1ubuntu2 of the llvm-gcc-4.6 package. > I am trying to release a Makefile for building my company's software that will> be flexible enough to use the llvm suite of compilers to build shared libraries > for talking to USB peripherals. The problem that I am having is that while I am > able to build a shared library using llvm-gcc , the llvm-g++ compiler is giving > me error messages saying " > > relocation R_X86_64_PC32 against undefined symbol `__morestack' can not be used > when making a shared object; recompile with -fPICIf you do: llvm-g++ -fPIC -S -o squared.ll squared.c -flto what is in squared.ll? Anyway, this issue smells like a Debian packaging problem to me. It's the kind of thing you get when the plugin was built against a different version of gcc to the one it is being loaded into. For example, if it was built against a basic gcc with no C++ support but is being loaded into g++. (The original plugin will refuse to load in this situation but I think the Debian package turns this check off). Does it happen if you build LLVM and the dragonegg plugin yourself? Ciao, Duncan.> > > Here's my configuration on my local machine: > > cat /etc/issue > Ubuntu-12.04 > > uname -a > Linux localhost 3.2.0-48-generic #74-Ubuntu SMP Thu Jun 6 19:43:26 UTC 2013 > x86_64 x86_64 x86_64 GNU/Linux > > dpkg -l | grep llvm > > ii libllvm2.7 2.7-0ubuntu1 Low-Level Virtual Machine (LLVM) (runtime library) > ii libllvm2.9 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM), runtime library > ii libllvm3.0 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), runtime library > ii libllvm3.0:i386 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), runtime library > ii llvm 2.9-7 Low-Level Virtual > Machine (LLVM) > ii llvm-2.9 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM) > ii llvm-2.9-dev 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM), libraries > and headers > ii llvm-2.9-runtime 2.9+dfsg-3ubuntu4 Low-Level Virtual Machine (LLVM), > bytecode interpreter > ii llvm-3.0 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM) > ii llvm-3.0-dev 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), libraries and > headers > ii llvm-3.0-runtime 3.0-4ubuntu1 Low-Level Virtual Machine (LLVM), bytecode > interpreter > ii llvm-dev 2.9-7 Low-Level Virtual Machine (LLVM), libraries and headers > ii llvm-gcc-4.6 3.0-3 C front end > for LLVM C/C++ compiler > ii llvm-runtime 2.9-7 Low-Level Virtual Machine (LLVM), bytecode interpreter > > > > I have a very simple example that appears to illustrate this problem > > /******** squared.h BEGIN *****/ > int squared(int val); > /********* END *****/ > > > /******* squared.c BEGIN ****/ > int squared(int val) { > return val*val; > } > /********* END ****/ > > /**** main.c BEGIN *****/ > #include <stdio.h> > int > main(int argc,char *argv[] ) { > int i = 0; > for( i = 0; i < 10 ; i ++ ) { > printf("%d\n",squared(i)); > } > } > /**** END *******/ > > Using llvm-gcc works just fine: > > llvm-gcc -fPIC -c -o squared.o squared.c > llvm-gcc -shared -o libsquared.so squared.o > llvm-gcc -L. -o main main.c -lsquared > > LD_LIBRARY_PATH=. ./main > 0 > 1 > 4 > 9 > 16 > 25 > 36 > 49 > 64 > 81 > > > The creation of the shared library fails when using llvm-g++ > > llvm-g++ -fPIC -c -o squared.o squared.c > llvm-g++ -shared -o libsquared.so squared.o > /usr/bin/ld: squared.o: relocation R_X86_64_PC32 against undefined symbol > `__morestack' can not be used when making a shared object; recompile with -fPIC > > > > This exact compile works on a 32 bit version of Ubuntu 12.04 , i686 > cat /etc/issue > Ubuntu 12.04.2 LTS \n \l > > uname -a > Linux gdbserver 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:15:33 UTC > 2013 i686 i686 i386 GNU/Linux > > llvm-g++ -fPIC -c -o squared.o squared.c > llvm-g++ -shared -o libsquared.so squared.o > > This succeeds and I am able to use the shared library to compile the main program. > > > Any ideas for how to get passed this problem with llvm-g++ ? > > Thanks > > -Jimi > > > > > > > > > > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev