[LLVMdev] src to src conversion

John Criswell criswell at cs.uiuc.edu
Tue Apr 25 06:56:06 PDT 2006


Ryan M. Lefever wrote:
> I am trying to use LLVM as a source to source C compiler.  I use 
> llvm-gcc to convert file.c->file.bc.  Then I use opt to run my own 
> compiler passes to convert file.bc->file.opt.bc.  Then I use llc to 
> convert file.opt.bc->file.opt.c.  Now, I want to use normal gcc to 
> compile file.opt.c into an executable.  However, I'm getting the 
> following errors:

Please try the following:

llvm-gcc -o final file.opt.bc -lcrtend
llc -march=c final.bc
gcc -o finalexec final.cbe.c

The first line uses llvm-gcc to link libcrtend.a to your optimized 
bytecode file.  Using llvm-gcc ensures that it picks up the version of 
libcrtend.a located within your llvm-gcc distribution (which should work).

The second and third lines generate the C code and compile it into a 
final executable.

If that doesn't work, please let me know.

> 
> test.opt.c:89: warning: conflicting types for built-in function 'malloc'
> test.opt.o(.text+0xe7): In function `main':
> : undefined reference to `__main'
> collect2: ld returned 1 exit status
> make: *** [test.opt.exe] Error 1
> 
> ------
> 
> I think the problem with main and __main is that I need to link in some 
> LLVM runtime libraries.  So, I tried to link in crtend (which defines 
> __main).  However, I get the following error:
> 
> /home/testbed1/lefever/work/llvm/install/lib/libcrtend.a: could not read 
> symbols: Archive has no index; run ranlib to add one
> collect2: ld returned 1 exit status
> make: *** [test.opt.exe] Error 1
> 
> I tried creating a copy of the libcrtend.a and running ranlib on it and 
> I also separately tried running llvm-ranlib on it.  Neither of those 
> actions worked though.  Am I linking the correct library, i.e., crtend? 
>  Why am I getting the error about the archive having no index?
> 
> -----
> 
> As far as the warning about conflicting types for malloc, it appears 
> that llvm is using the declaration where the output of malloc is a 
> "signed char *" rather than "void *".  Why is that?

My memory is foggy, but it's probably because either the LLVM libraries 
(from llvm/runtime) or the LLVM code you're compiling has a prototype 
for malloc that returns "signed char *," but the header file being 
pulled in by GCC when compiling the .cbe.c file has a prototype for 
"void *."  It's also possible that llc is adding the malloc prototype as 
well.  If you're really curious, some simple experimentation should 
indicate which of the above it is.


> 
> Thanks in advance for any help.
> 
> Regards,
> Ryan
> 

-- John T.

-- 
John T. Criswell
Research Programmer
University of Illinois at Urbana-Champaign
"It's today!" said Piglet. "My favorite day," said Pooh.




More information about the llvm-dev mailing list