[LLVMdev] Compile C files to one .bc file

899 views
Skip to first unread message

Vincent De Bruyne

unread,
Mar 2, 2011, 10:44:56 AM3/2/11
to llvmdev
Hi

I'm trying to compile the "bh" C program from the Olden benchmark to one bc file.

# compile source files into an LLVM bitcode file
llvm-gcc -emit-llvm -c args.c -o args.bc -w -DTORONTO
llvm-gcc -emit-llvm -c newbh.c -o newbh.bc -w -DTORONTO
llvm-gcc -emit-llvm -c util.c -o util.bc -w -DTORONTO
llvm-gcc -emit-llvm -c walksub.c -o walksub.bc -w -DTORONTO

# To link files together using llvm-ld
llvm-ld -o bh.bc newbh.bc args.bc util.bc walksub.bc -lm

But when I try to run my pass over bh.bc file or just compile it to native code
llc bh.bc -o bh.s

I get the following error.
llc: bh.bc:1:1: error: expected top-level entity

Do you need to do some special stuff when you want to compile a C program with different files to one bc file.

Thx,
Vincent

Rafael Avila de Espindola

unread,
Mar 2, 2011, 10:57:16 AM3/2/11
to llv...@cs.uiuc.edu
On 11-03-02 10:44 AM, Vincent De Bruyne wrote:
> Hi
>
> I'm trying to compile the "bh" C program from the Olden benchmark to one
> bc file.
>
> # compile source files into an LLVM bitcode file
> llvm-gcc -emit-llvm -c args.c -o args.bc -w -DTORONTO
> llvm-gcc -emit-llvm -c newbh.c -o newbh.bc -w -DTORONTO
> llvm-gcc -emit-llvm -c util.c -o util.bc -w -DTORONTO
> llvm-gcc -emit-llvm -c walksub.c -o walksub.bc -w -DTORONTO
>
> # To link files together using llvm-ld
> llvm-ld -o bh.bc newbh.bc args.bc util.bc walksub.bc -lm

Check what is in bh.bc. If I remember correctly llvm-ld used to create a
shell script that would run lli on the actual IL file.

> But when I try to run my pass over bh.bc file or just compile it to
> native code
> llc bh.bc -o bh.s
>
> I get the following error.

> llc: bh.bc:1:1:*error: expected top-level entity*


>
> Do you need to do some special stuff when you want to compile a C
> program with different files to one bc file.

For large programs you will probably a system linker that supports llvm
(the apple one) or plugin (gold and very recent versions of gnu ld).

For small programs using llvm-link or llvm-ld should be ok.

> Thx,
> Vincent
>

Cheers,
Rafael
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Samuel Crow

unread,
Mar 2, 2011, 11:10:16 AM3/2/11
to LLVM Developers Mailing List
Sorry, forgot to CC the list.


----- Forwarded Message ----
> From: Samuel Crow <samura...@yahoo.com>
> To: Vincent De Bruyne <vincent_...@hotmail.com>
> Sent: Wed, March 2, 2011 10:08:57 AM
> Subject: Re: [LLVMdev] Compile C files to one .bc file
>
> Hi Vincent,
>
> You probably need the C runtime library.
>
> --Sam
>
> >
> >From: Vincent De Bruyne <vincent_...@hotmail.com>
> >To: llvmdev <llv...@cs.uiuc.edu>
> >Sent: Wed, March 2, 2011 9:44:56 AM
> >Subject: [LLVMdev] Compile C files to one .bc file
>
>
> --snip--


>
>
> >
> >Do you need to do some special stuff when you want to compile a C program
>with
>
> >different files to one bc file.
> >
>
>
>
>

Justin Holewinski

unread,
Mar 2, 2011, 11:10:33 AM3/2/11
to Vincent De Bruyne, llvmdev
On Wed, Mar 2, 2011 at 10:44 AM, Vincent De Bruyne <vincent_...@hotmail.com> wrote:
Hi

I'm trying to compile the "bh" C program from the Olden benchmark to one bc file.

# compile source files into an LLVM bitcode file
llvm-gcc -emit-llvm -c args.c -o args.bc -w -DTORONTO
llvm-gcc -emit-llvm -c newbh.c -o newbh.bc -w -DTORONTO
llvm-gcc -emit-llvm -c util.c -o util.bc -w -DTORONTO
llvm-gcc -emit-llvm -c walksub.c -o walksub.bc -w -DTORONTO

# To link files together using llvm-ld
llvm-ld -o bh.bc newbh.bc args.bc util.bc walksub.bc -lm

llvm-link would be better suited for this purpose.  It takes in several byte-code files and combines them into a single byte-code file.  Also, you do not need the -lm flag until you generate the final executable.
 

But when I try to run my pass over bh.bc file or just compile it to native code
llc bh.bc -o bh.s

I get the following error.
llc: bh.bc:1:1: error: expected top-level entity

Do you need to do some special stuff when you want to compile a C program with different files to one bc file.

Thx,
Vincent


_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




--

Thanks,

Justin Holewinski

Reply all
Reply to author
Forward
0 new messages