a linking problem of LLVM

Hi Jing,

I am cc ing to LLVMdev (LLVM developer's mailing list). You get more accurate and faster responses that way.


Actually LLVM is well documented and the coding style is very friendly. We have rarely had problems since we started one month ago. Unfortunately, here comes something I am not very clear, but it is critical to our evaluation. I appreciate if you could take a few minutes to look at this, or we could schedule a meeting sometime good for you.

Sure, I'd be happy to help.

The problem is about linking optimization. If I disable link-time optimization, two of Spec2000 integer benchmarks (164.gzip and 256.bzip2) will fail the execution. If I allow default link optimization, all errors are gone. I used out-of-box source code, and did not apply any pass I made. The commands I used are:
llvm-gcc %.c –o %.ll
llvm-as %.ll –o %.bc
gccld -disable-opt [all *.bc] –o $bench.bc
llc $bench.bc.bc –o $bench.s
gcc $bench.s –o $bench

Then I ran $bench on my native Pentium4-linux machine. Do you think the sequence of the commands is correct?

Using the above sequence should give an error in step 2. What you do from step 3 however, is correct.

In general, llvm-gcc x.c -o x
creates an executable shell script 'x' and a byte code file 'x.bc'

In your case, you have 'llvm-gcc x.c -o x.ll'
This creates x.ll (the executable shell script) and a byte code file x.ll.bc
When you use llvm-as on x.ll (a shell script) you should get an error!

llvm-gcc is intended as a replacement for gcc in the Makefiles. You can compile the same way you'd compile with gcc. I recommend doing the following

llvm-gcc -c %.c
llvm-gcc -Wl,-disable-opt *.o -o bench

(-Wl is for passing options to the linker. Alternatively you can use gccld like you did)

This should create a shell script 'bench' and a byte code file 'bench.bc'
Now you can use llc and gcc as in your sequence.

The non-link-optimized gzip can finish execution, but generate an incorrect log file (I diff it with the correct one). The non-link-optimized bzip2 did not finish execution at all. The error message is “(null): Data integrity error when decompressing. Stored CRC = 0x99e8f60, computed CRC = 0xc666c804 Input file = , output file = “.

If you still have the problem above, it could be due to code generation/miscompilation bug in LLVM. Can you try using the C backend? Replace the last two steps by

llc -march=c bench.bc
gcc bench.cbe.c

and let us know the results.

I also want to know how to disable part of the linking-optimization instead of disabling all. I haven’t found a flag that can do this.

gccld does not have a command line option to disable selected optimizations.
You can however do the following. All the optimizations (organized as passes in LLVM) run by gccld are in llvm/tools/gccld/GenerateCode.cpp

If you want to disable a specific pass, comment out that line in the file and recompile.
e.g. //addPass(Passes, createGlobalDCEPass());
disables the GlobalDCE optimization.

Hope it helps