llvmc doesn't work for compilation nor linking

Is llvmc meant for compilation?

$ llvmc -c a.c -o a.o
/usr/src/llvm/dist/etc/llvm/c:55: Error: Expecting output type value
/usr/src/llvm/dist/etc/llvm/c had 1 errors. Terminating.

The offending line contains:

optimizer.output = bytecode

which doesn't seem to be understood by llvmc. If I uncomment this
line, I get another error message:

$ llvmc -c a.c -o a.o
llvmc: Can't find program '%llvmcc1%'

However, I can use it for linking:

$ llvm-gcc --emit-llvm -c a.c -o a.o
$ llvm-gcc -c main.c -o main.o
$ llvmc a.o main.o -o main

Wow, nice. Unfortunately, the result doesn't run:

$ ./main
'main' function not found in module.

That seems true, because llvm-dis doesn't find a main either:

$ llvm-dis main.bc -o -
; ModuleID = 'main.bc'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i686-pc-linux-gnu"
@i.b = internal global i1 false ; <i1*> [#uses=2]

define void @foo2() {
entry:
        store i1 true, i1* @i.b, align 1
        ret void
}

declare void @foo4()

define i32 @foo1() {
entry:
        %tmp1.b = load i1* @i.b, align 1 ; <i1> [#uses=1]
        br i1 %tmp1.b, label %cond_true, label %return

cond_true: ; preds = %entry
        call void @foo4( )
        ret i32 52

return: ; preds = %entry
        ret i32 42
}

Is llvmc meant for compilation?

I'm not sure what the status of llvmc is (is anyone working on it?), but I don't believe it was ready for real use or was finished.

If you would like to work on it, patches are welcomed!

Thanks,
Tanya

If you would like to work on it, patches are welcomed!

I think this problem space matched my capabilities, below is a
patch. With this patch applied, the following worked:

$ llvmc -verbose -native -lstdc++ -o hellocpp hello.cpp
g++ -E hello.cpp -o /tmp/llvm_30nlL0/hello.E
/usr/src/llvm/dist/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1plus -quiet -emit-llvm /tmp/llvm_30nlL0/hello.E -o /tmp/llvm_30nlL0/hello.trans -O1
llvm-as /tmp/llvm_30nlL0/hello.trans -o /tmp/llvm_30nlL0/hello.trans.bc
/usr/src/llvm/dist/bin/opt /tmp/llvm_30nlL0/hello.trans.bc -std-compile-opts -f -o /tmp/llvm_30nlL0/hello.opt
llvm-ld -O1 /tmp/llvm_30nlL0/hello.opt -lstdc++ -L%llvmgccdir%/lib -L%llvmgccdir%/lib -L/usr/local/lib/ -L/usr/X11R6/lib/ -L/usr/lib/ -L/lib/ -native -v -o hellocpp
  Linking bitcode file '/tmp/llvm_30nlL0/hello.opt'
  Linked in file '/tmp/llvm_30nlL0/hello.opt'
  Linking archive file '/usr/src/llvm/dist/lib/libstdc++.a'
Generating Bitcode To hellocpp.bc
Generating Assembly With:
'/usr/src/llvm/dist/bin/llc' '-f' '-o' 'hellocpp.s' 'hellocpp.bc'
Generating Native Executable With:
'/usr/bin/gcc' '-fno-strict-aliasing' '-O3' '-o' 'hellocpp' 'hellocpp.s' '-L' '%llvmgccdir%/lib' '-L' '%llvmgccdir%/lib' '-L' '/usr/local/lib/' '-L' '/usr/X11R6/lib/' '-L' '/usr/lib/' '-L' '/lib/' '-lstdc++'

$ llvmc -verbose -native -o helloc hello.c
gcc -E hello.c -o /tmp/llvm_XpaR7m/hello.E
/usr/src/llvm/dist/libexec/gcc/i686-pc-linux-gnu/4.0.1/cc1 -quiet -emit-llvm /tmp/llvm_XpaR7m/hello.E -o /tmp/llvm_XpaR7m/hello.trans -O1
llvm-as /tmp/llvm_XpaR7m/hello.trans -o /tmp/llvm_XpaR7m/hello.trans.bc
/usr/src/llvm/dist/bin/opt /tmp/llvm_XpaR7m/hello.trans.bc -std-compile-opts -f -o /tmp/llvm_XpaR7m/hello.opt
llvm-ld -O1 /tmp/llvm_XpaR7m/hello.opt -L%llvmgccdir%/lib -L%llvmgccdir%/lib -L/usr/local/lib/ -L/usr/X11R6/lib/ -L/usr/lib/ -L/lib/ -native -v -o helloc
  Linking bitcode file '/tmp/llvm_XpaR7m/hello.opt'
  Linked in file '/tmp/llvm_XpaR7m/hello.opt'
Generating Bitcode To helloc.bc
Generating Assembly With:
'/usr/src/llvm/dist/bin/llc' '-f' '-o' 'helloc.s' 'helloc.bc'
Generating Native Executable With:
'/usr/bin/gcc' '-fno-strict-aliasing' '-O3' '-o' 'helloc' 'helloc.s' '-L' '%llvmgccdir%/lib' '-L' '%llvmgccdir%/lib' '-L' '/usr/local/lib/' '-L' '/usr/X11R6/lib/' '-L' '/usr/lib/' '-L' '/lib/'

$ size helloc hellocpp
   text data bss dec hex filename
    911 260 4 1175 497 helloc
   1427 288 148 1863 747 hellocpp

I'll look after the strange '-L' '%llvmgccdir%/lib' in a
separate patch, but I guess that this has something to do with
the configure call I made for LLVM.

Now the patch: