I am using LLVM to compile vsftp to native x86 ELF code.
One of it's object file (sysdeputil) contains inline asm so cannot be compiled by gcc-3.4 frontend.
So I decided to firstly link together the llvm objects and libcrtend and compile it to native .o file and then link it with sysdeputil.o .
The Makefile is sth like this:
gccld -r -native -o vsftpd.o $(OBJS) -L/home/xianai/my_projects/llvm/cfrontend/x86/llvm-gcc/lib/ -lcrtend
gcc -o vsftpd vsftpd.o sysdeputil.o `./vsf_findlibs.sh`
But the gcc/ld still cannot find the reference to __main.
Do I have to compile crtend to native to solve this problem?
gccld -r doesn't work with -native. Also, you do need to link in crtend, which doesn't happen with -r, only "producing an executable mode" links in libraries.
Hi, I have tried another way:
ar rcs libsysdeputil.a sysdeputil.o
gccld seems to recognize the file type. However, it stills find unresoved symbols
which are actually the functions in sysdeputil.o (can be find out with `nm libsysdeputil.a`)
The problem disappears if native gcc/ld tool chain is used.
As another test, main.c:
I agree that this is an ugly issue. You've basically fallen into the "llvmgcc3 doesn't work the way a normal compiler does" problem. If you use llvmgcc4, it is completely transparent, and works just like a native compiler, unless you provide the -emit-llvm switch.
If you'd like for this stuff to work, I'd suggest *not* using the gccld "-native*" switches. They are really only built to work when the whole program is compiled with LLVM (ok, you can have native libraries, but no native .o files). If you'd like to link native .o files together with LLVM .o files, you should run llc/as/ld directly on the LLVM code to do things manually.