-emit-llvm on ubuntu is broken

I try to generate a human readable .ll file on Linux. I installed llvm-gcc
but as I see it can generate only assembly code (-S option). Is there any
way to get something like what is generated by llvm online compiler?

That's what I get with llvm-gcc -S -emit-llvm hello.c on Ubuntu 10.10:

    .file "hello.c"

    .ident "GCC: (Ubuntu/Linaro 4.5.1-7ubuntu2) 4.5.1 LLVM: "

    .text
    .globl main
    .align 16, 0x90
    .type main,@function
main:
    pushl %ebp
    movl %esp, %ebp
    subl $8, %esp
    movl $.L.str, 4(%esp)
    movl $1, (%esp)
    call __printf_chk
    xorl %eax, %eax
    addl $8, %esp
    popl %ebp
    ret
.Ltmp0:
    .size main, .Ltmp0-main

    .type .L.str,@object
    .section .rodata.str1.1,"aMS",@progbits,1
.L.str:
    .asciz "hello world\n"
    .size .L.str, 13

    .section .note.GNU-stack,"",@progbits

That's what I am trying to get:

; ModuleID = '/tmp/webcompile/_7829_0.bc'
target datalayout =
"e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-linux-gnu"

@.str = private constant [12 x i8] c"hello world\00", align 1 ; <[12 x i8]*>
[#uses=1]

define i32 @main() nounwind {
entry:
  %0 = tail call i32 @puts(i8* getelementptr inbounds ([12 x i8]* @.str, i64
0, i64 0)) nounwind ; <i32> [#uses=0]
  ret i32 0
}

declare i32 @puts(i8* nocapture) nounwind

On windows I successfully get this file with the same command: llvm-gcc -S
-emit-llvm hello.c.
llvm

llvm-gcc -v ?

-eric

Hi Eric,

here is my -emit-llvm -S -v output:

Using built-in specs.
COLLECT_GCC=gcc-4.5
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.5.1/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.5.1-7ubuntu2' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.5 --enable-shared --enable-multiarch
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-gold
--with-plugin-ld=ld.gold --enable-objc-gc --enable-targets=all
--disable-werror --with-arch-32=i686 --with-tune=generic
--enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu
--target=i686-linux-gnu
Thread model: posix
gcc version 4.5.1 (Ubuntu/Linaro 4.5.1-7ubuntu2)
COLLECT_GCC_OPTIONS='-fplugin=/usr/lib/gcc/i686-linux-gnu/4.5/plugin/dragonegg.so'
'-emit-llvm' '-S' '-v' '-mtune=generic' '-march=i686'
/usr/lib/gcc/i686-linux-gnu/4.5.1/cc1 -quiet -v
-iplugindir=/usr/lib/gcc/i686-linux-gnu/4.5.1/plugin hello.c
-D_FORTIFY_SOURCE=2 -iplugindir=/usr/lib/gcc/i686-linux-gnu/4.5.1/plugin
-quiet -dumpbase hello.c -mtune=generic -march=i686 -auxbase hello -version
-fplugin=/usr/lib/gcc/i686-linux-gnu/4.5/plugin/dragonegg.so -o hello.s
-fstack-protector
GNU C (Ubuntu/Linaro 4.5.1-7ubuntu2) version 4.5.1 (i686-linux-gnu)
  compiled by GNU C version 4.5.1, GMP version 4.3.2, MPFR version 3.0.0-p3,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Versions of loaded plugins:
dragonegg:
ignoring nonexistent directory "/usr/local/include/i686-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i686-linux-gnu/4.5.1/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i686-linux-gnu/4.5.1/include
/usr/lib/gcc/i686-linux-gnu/4.5.1/include-fixed
/usr/include/i686-linux-gnu
/usr/include
End of search list.
GNU C (Ubuntu/Linaro 4.5.1-7ubuntu2) version 4.5.1 (i686-linux-gnu)
  compiled by GNU C version 4.5.1, GMP version 4.3.2, MPFR version 3.0.0-p3,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Versions of loaded plugins:
dragonegg:
Compiler executable checksum: ee807c30bb3adc8f3aa917a64443d0ec
COMPILER_PATH=/usr/lib/gcc/i686-linux-gnu/4.5.1/:/usr/lib/gcc/i686-linux-gnu/4.5.1/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.5.1/:/usr/lib/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i686-linux-gnu/4.5.1/:/usr/lib/gcc/i686-linux-gnu/4.5.1/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.5.1/../../../:/lib/:/usr/lib/:/usr/lib/i686-linux-gnu/
COLLECT_GCC_OPTIONS='-fplugin=/usr/lib/gcc/i686-linux-gnu/4.5/plugin/dragonegg.so'
'-emit-llvm' '-S' '-v' '-mtune=generic' '-march=i686'

Eric Christopher-2 wrote:

Looks like something wonky with DragonEgg.

Duncan?

-eric

I am new to LLVM, what do you mean by Duncan?

Btw, I installed llvm from the repository: sudo apt-get install llvm
llvm-gcc

Eric Christopher-2 wrote:

I am new to LLVM, what do you mean by Duncan?

The guy I cc'd on the last email.

Btw, I installed llvm from the repository: sudo apt-get install llvm
llvm-gcc

I have no idea how ubuntu packages anything.

-eric

Hi Eric,

Looks like something wonky with DragonEgg.

you need to use -fplugin-arg-dragonegg-emit-ir or -flto with dragonegg,
not -emit-llvm. Also, you currently have to use -S (getting human readable
IR) rather than -c because with -c gcc will run cc1 with -S (getting human
readable IR) then pass the result to the system assembler which of course
barfs. This is documented on the web-page and in the README.

Ciao, Duncan.

Interesting. Makes complete sense.

-eric

PS: I assume this is with debian's dragonegg package which has a script called
"llvm-gcc" which runs gcc-4.5+dragonegg. It would be neat if the script
intercepted -emit-llvm and turned it into the right thing, but last time I look
this wasn't implemented.

It is. I haven't played with it at all so I wasn't sure what the correct thing
would be. Apparently there's an open bug on it in the ubuntu system.

-eric

Thanks, it works

Duncan Sands wrote: