Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build 32-bit with 64-bit llvm-gcc

I have a 64-bit version of llvm-gcc, but I want to be able to build both 32-bit and 64-bit binaries. Is there a flag for this? I tried passing -m32 (which works on the regular gcc), but I get an error message like this:

[jay@andesite]$ llvm-gcc -m32 test.c -o test
Warning: Generation of 64-bit code for a 32-bit processor requested.
Warning: 64-bit processors all have at least SSE2.
/tmp/cchzYo9t.s: Assembler messages:
/tmp/cchzYo9t.s:8: Error: bad register name `%rbp'
/tmp/cchzYo9t.s:9: Error: bad register name `%rsp'
...

This is backwards; I want to generate 32-bit code for a 64-bit processor!

I'm running llvm-gcc 4.2, the one that comes with Ubuntu 9.04 x86-64.


EDIT: Here is the relevant part of the output when I run llvm-gcc with the -v flag:

[jay@andesite]$ llvm-gcc -v -m32 test.c -o test.bc
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../llvm-gcc4.2-2.2.source/configure --host=x86_64-linux-gnu --build=x86_64-linux-gnu --prefix=/usr/lib/llvm/gcc-4.2 --enable-languages=c,c++ --program-prefix=llvm- --enable-llvm=/usr/lib/llvm --enable-threads --disable-nls --disable-shared --disable-multilib --disable-bootstrap
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5546) (LLVM build)
 /usr/lib/llvm/gcc-4.2/libexec/gcc/x86_64-linux-gnu/4.2.1/cc1 -quiet -v -imultilib . test.c -quiet -dumpbase test.c -m32 -mtune=generic -auxbase test -version -o /tmp/ccw6TZY6.s

I looked in /usr/lib/llvm/gcc-4.2/libexec/gcc hoping to find another binary, but the only directory there is x86_64-linux-gnu. I will probably look at compiling llvm-gcc from source with appropriate options next.

like image 908
Jay Conrod Avatar asked Sep 24 '09 21:09

Jay Conrod


People also ask

Is GCC 32 or 64-bit?

Mostly compiler(gcc or clang) of C and C++, nowadays come with default 64-bit version.

Can GCC compile LLVM?

The llvm-gcc command is the LLVM C front end. It is a modified version of gcc that compiles C/ObjC programs into native objects, LLVM bitcode or LLVM assembly language, depending upon the options. By default, llvm-gcc compiles to native objects just like GCC does.

What is GCC m32?

The -m32 flag tells GCC to compile in 32-bit mode. The -march=i686 option further defines what kind of optimizations to use (refer to info gcc for a list of options). The -L flag sets the path to the libraries you want GCC to link to.

Is GCC better than LLVM?

While LLVM and GCC both support a wide variety languages and libraries, they are licensed and developed differently. LLVM libraries are licensed more liberally and GCC has more restrictions for its reuse. When it comes to performance differences, GCC has been considered superior in the past.


1 Answers

Try setting:

export CFLAGS="-m32"
export LDFLAGS="-m32"

before compiling...

like image 94
ChristopheD Avatar answered Sep 24 '22 03:09

ChristopheD