How to build coreutils with LLVM 3.4

1.2k views Asked by At

I am trying to build GNU Coreutils 8.23 using the LLVM 3.4 tool-chain. One very important aspect is that I also need the LLVM bytecode for all the coreutils. Therefore, I need to include -emit-llvm in the CFLAGS. Therefore, I removed the $(CFLAGS) from the LINK variable of the coreutils Makefile. Afterwards, I run the following command:

make CC=/home/user/llvm-3.4.2/build/Release+Asserts/bin/clang 
CCLD=/home/user/llvm-3.4.2/build/Release+Asserts/bin/llvm-link 
IGNORE_UNUSED_LIBRARIES_CFLAGS= CFLAGS="-emit-llvm -S" 
VERBOSE=1 AM_CFLAGS= AM_LDFLAGS= 
AR=/home/user/llvm-3.4.2/build/Release+Asserts/bin/llvm-ar 
RANLIB=/home/user/llvm-3.4.2/build/Release+Asserts/bin/llvm-ranlib

and I get the following error:

/home/user/llvm-3.4.2/build/Release+Asserts/bin/llvm-link: src/libver.a:1:2:    error: expected integer
!<arch>
 ^
/home/user/llvm-3.4.2/build/Release+Asserts/bin/llvm-link: error loading file 'src/libver.a'

Any ideas of how to get this to work?

2

There are 2 answers

1
Abhishek Vasisht On BEST ANSWER

Try this.

export CC="/home/user/llvm-3.4.2/build/Release+Asserts/bin/clang"
export CXX="/home/user/llvm-3.4.2/build/Release+Asserts/bin/clang++" 

Make sure this is where your compiler toolchain is present.

Then in the the coreutils directory, run ./configure (before this run ./bootstrap if you havent already run it). Running ./configure checks if your clang can compile properly and creates a Makefile with the correct configuration.

Then do a make and make install as instructed.

0
Min Gao On

Lib file '.a' here is not readable by llvm-link. A possible informal hack to this probably is to find out the Makefile generating this lib, and let

AR = llvm-link, ar option = -o(i.e. change ar rv to llvm-link -o), 

and disable ranlib command while compling(you don't need ranlib if using llvm-link).

Then the '.a' file generated is a stitched bc file, and this '.a' file should be accpetable by llvm-link command you are calling