src to src conversion

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

src to src conversion

Ryan M. Lefever
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:

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?

Thanks in advance for any help.

Regards,
Ryan

--
Ryan M. Lefever  [217.333.7231]  [http://www.ews.uiuc.edu/~lefever]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: src to src conversion

John Criswell
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.

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: src to src conversion

Patrick Meredith

On Apr 25, 2006, at 8:56 AM, John Criswell wrote:

> 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.
>

My guess is that it is because void* is always converted to sbyte* in  
llvm.  Since both char* and void* get mapped to sbyte*
the mapping back is difficult, and perhaps impossible.  (Maybe I'm  
wrong?)

>
>> 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.
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: src to src conversion

Chris Lattner
On Tue, 25 Apr 2006, Patrick Meredith wrote:
> My guess is that it is because void* is always converted to sbyte* in llvm.
> Since both char* and void* get mapped to sbyte*
> the mapping back is difficult, and perhaps impossible.  (Maybe I'm wrong?)

Yup, that's right.

-Chris

--
http://nondot.org/sabre/
http://llvm.org/

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: src to src conversion

Ryan M. Lefever
In reply to this post by John Criswell
This seems to work.  Thank you for the help!

John Criswell wrote:

> 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.
>

--
Ryan M. Lefever  [217.333.7231]  [http://www.ews.uiuc.edu/~lefever]

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

LLVM Java front-end

ac-6
In reply to this post by Patrick Meredith
Hello,
I have just downloaded the source from CVS.
Does exist a LLVM Java front-end?
If yes, where can I find documentations about it?
If no, is anyway somebody working on it? Where can I find the source code
related?

Thanks,
Alessandro

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Reply | Threaded
Open this post in threaded view
|

Re: LLVM Java front-end

Reid Spencer
Hi Alessandro,

There is a partial implementation of a Java front end in the llvm-java
CVS repository. Here's some info on front-end language support:

http://llvm.org/docs/FAQ.html#felangs

Reid.

On Wed, 2006-04-26 at 08:37 +0000, [hidden email] wrote:

> Hello,
> I have just downloaded the source from CVS.
> Does exist a LLVM Java front-end?
> If yes, where can I find documentations about it?
> If no, is anyway somebody working on it? Where can I find the source code
> related?
>
> Thanks,
> Alessandro
>
> _______________________________________________
> LLVM Developers mailing list
> [hidden email]         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: LLVM Java front-end

Sebastien Lafond
In reply to this post by ac-6
Hello Alessandro,

You can get the source code for the existing Java front-end by doing this:

cvs -d :pserver:[hidden email]:/var/cvs/llvm login
Hit the return key when prompted for the password.
cvs -z3 -d :pserver:[hidden email]:/var/cvs/llvm co llvm-java

You will need the GNU classpath libraries to compile llvm-java, and the
GNU classpath libraries need GTK+

llvm-java needs a "flat" classpath structure so you will need to unzip
the file GNU_classpath_dir/share/classpath/glibj.zip

Then in llvm-java directory just do
./configure --prefix=install_dir --with-classpathdir=My_GNU_classpath_dir

I was able to compile and install the llvm-java front-end without any
erros, but i get a ugly error as soon I execute the front-end...:

class2llvm: Constants.cpp:228: llvm::ConstantSInt::ConstantSInt(const
llvm::Type*, int64_t): Assertion `Ty->isInteger() && Ty->isSigned() &&
"Illegal type for signed integer constant!"' failed.
Aborted

I didn't have the time yet to look at the problem, but I will....

Sebastien


[hidden email] wrote:
> Hello,
> I have just downloaded the source from CVS.
> Does exist a LLVM Java front-end?
> If yes, where can I find documentations about it?
> If no, is anyway somebody working on it? Where can I find the source code
> related?
>
> Thanks,
> Alessandro

_______________________________________________
LLVM Developers mailing list
[hidden email]         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev