[LLVMdev] Documentation error in http://llvm.org/docs/LinkTimeOptimization.html

Holger Schurig hs4233 at mail.mn-solutions.de
Fri Aug 24 14:58:46 PDT 2007


> > $ llvm-gcc --emit-llvm -c a.c -o a.o
> > $ llvm-gcc -c main.c -o main.o
> > $ llvm-gcc a.o main.o -o main
> > a.o: file not recognized: File format not recognized
> > collect2: ld returned 1 exit status
> >
> > Okay, that did not really work :-/
> 
> This document describes interface between llvm and linker. You need  
> system linker that implements this interface. LLVM tool kit does not  
> supply system linker.

I'm not sure this is right. I still think that this is a documentation
error.

The "a.o" file is really a LLVM bitcode file:

$ file *.o
a.o:    data
main.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped

libmagic doesn't know about LLVM bitcode, but rest assured that a.o
*IS* indeed an llvm bitcode file. E.g. "llvm-dis a.o -o -" works.

However, when you call llvm-gcc without --emit-llvm it behaves like a plain
gcc. So it calls the system linker, ld, with this file.

$ strace -oa -efile -ff llvm-gcc a.o main.o -o main
$ grep -h execve a.*
execve("/usr/src/llvm/dist/bin/llvm-gcc", ["llvm-gcc", "a.o", "main.o", "-o", "main"], [/* 38 vars */]) = 0
execve("/usr/src/llvm/dist/libexec/gcc/i686-pc-linux-gnu/4.0.1/collect2", ["/usr/src/llvm/dist/libexec/gcc/i"..., "--eh-frame-hdr", "-m", "elf_i386", "-dynamic-linker", "/lib/ld-linux.so.2", "-o", "main", "/usr/lib/crt1.o", "/usr/lib/crti.o", "/usr/src/llvm/dist/lib/gcc/i686-"..., "-L/usr/src/llvm/dist/lib/gcc/i68"..., "-L/usr/src/llvm/dist/lib/gcc/i68"..., "a.o", "main.o", "-lgcc", ...], [/* 42 vars */]) = 0
execve("/usr/bin/ld", ["/usr/bin/ld", "--eh-frame-hdr", "-m", "elf_i386", "-dynamic-linker", "/lib/ld-linux.so.2", "-o", "main", "/usr/lib/crt1.o", "/usr/lib/crti.o", "/usr/src/llvm/dist/lib/gcc/i686-"..., "-L/usr/src/llvm/dist/lib/gcc/i68"..., "-L/usr/src/llvm/dist/lib/gcc/i68"..., "a.o", "main.o", "-lgcc", ...], [/* 43 vars */]) = 0

See the last line, llvm-gcc calls /usr/bin/ld with "a.o" ...

And it's obvious that the system linker cannot handle LLVM bitcode files,
this linker is for ELF files. Can you tell me ONE system linker that
can load and handle LLVM files?  If not, then the documentation still
describes something that doesn't work in real life.

If llvm-gcc in this case was NOT supposed to call the system-linker
with an bitcode a.o file, then llvm-gcc-4.0 in SVN trunk contains a bug.


However, if I'm supposed to run not "llvm-gcc" in step 3 to get a main
program but, say, llvm-ld, then the documentation is wrong again.



More information about the llvm-dev mailing list