[LLVMdev] How to Cross Compile libcompiler_rt Static Library?

705 views
Skip to first unread message

Chao Yan

unread,
Mar 29, 2015, 4:18:15 AM3/29/15
to LLVM Developers Mailing List
Hi,

I've cross-compiled musl-libc to arm binaries with clang. It needs functions from static runtime library "libcompiler_rt.a". I tried to build compile_rt outside the llvm source tree. Using command like "make clang_linux", I can easily build "libcompiler_rt.a" for my host machine, which is X86_64. But how can I *cross-compile* the compiler_rt runtime libraries?

According to the following websites:


It seems that the makefile does not support non-X86 targets. Someone tried cmake failed as well. Any suggestions?

Thanks,
Chao 

Ed Schouten

unread,
Mar 29, 2015, 4:36:50 AM3/29/15
to Chao Yan, LLVM Developers Mailing List
Hi there,

2015-03-29 10:14 GMT+02:00 Chao Yan <yanch...@gmail.com>:
> I've cross-compiled musl-libc to arm binaries with clang. It needs functions
> from static runtime library "libcompiler_rt.a". I tried to build compile_rt
> outside the llvm source tree. Using command like "make clang_linux", I can
> easily build "libcompiler_rt.a" for my host machine, which is X86_64. But
> how can I *cross-compile* the compiler_rt runtime libraries?

I am cross-compiling compiler-rt for my specific use-case. That said,
I'm cross-compiling from x86-64 to x86-64, but for a different ABI.
This is what I use:

https://github.com/NuxiNL/cloudlibc/wiki/Building-runtime-libraries#user-content-compiler-rt

As you can see, I'm using CMake. Works pretty well so far. Hopefully
something like this will work for you as well?

--
Ed Schouten <e...@80386.nl>
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Chao Yan

unread,
Mar 29, 2015, 12:30:33 PM3/29/15
to Ed Schouten, LLVM Developers Mailing List
2015-03-29 3:33 GMT-05:00 Ed Schouten <e...@80386.nl>:
I am cross-compiling compiler-rt for my specific use-case. That said,
I'm cross-compiling from x86-64 to x86-64, but for a different ABI.
This is what I use:

https://github.com/NuxiNL/cloudlibc/wiki/Building-runtime-libraries#user-content-compiler-rt
-DCMAKE_CROSSCOMPILING=True
As you can see, I'm using CMake. Works pretty well so far. Hopefully
something like this will work for you as well?

I tried "cmake ../compiler-rt -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++  -DLLVM_NATIVE_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DTARGET_TRIPLE=armv-none-linux-gnueabi  -DCMAKE_CROSSCOMPILING=True". It will still build X86_64 version.

I also tried "cmake ../compiler-rt -DCMAKE_C_COMPILER=/usr/local/arm-2009q3/bin/arm-none-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=/usr/local/arm-2009q3/bin/arm-none-linux-gnueabi-g++  -DLLVM_NATIVE_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DTARGET_TRIPLE=armv-none-linux-gnueabi  -DCMAKE_CROSSCOMPILING=True
". the configure process generate errors: 
 
CMake Error at cmake/config-ix.cmake:111 (message):
Cannot compile for x86_64:

It seems that the cmake only works for X86 target?

Thanks,
Chao

Daniel Dilts

unread,
Mar 29, 2015, 3:55:07 PM3/29/15
to Chao Yan, LLVM Developers Mailing List
I asked about this same question in the past (month or three ago).  It is not possible to cross compile compiler-rt on Windows.  If you want to cross compile you should use the make build system, not the CMake build system.

Daniel Dilts

unread,
Mar 29, 2015, 4:14:00 PM3/29/15
to Chao Yan, LLVM Developers Mailing List
I need to correct myself.  It is possible to cross compile it on Windows, but not using the provided build systems.

Chao Yan

unread,
Mar 29, 2015, 4:31:52 PM3/29/15
to Daniel Dilts, LLVM Developers Mailing List

2015-03-29 15:11 GMT-05:00 Daniel Dilts <dilt...@gmail.com>:
I need to correct myself.  It is possible to cross compile it on Windows, but not using the provided build systems.

Hi Daniel,

Thanks for helping. I'm using ubuntu 14.04 x86_64 system. I've tried cmake for couple of days until I give up. You are right, using make build system seems more feasible. I've combined the compiler_rt/make/platform/clang_linux.mk and the compiler_rt/make/platform/clang_macho_embedded.mk. So far it could cross-compile all of the files in "compiler-rt/lib/builtins/" (*.c files). However, the libcompiler_rt.a still missing functions such as "__aeabi_memset", "__aeabi_memcpy". These functions were in "compiler_rt/lib/biltins/arm/" (*.S) files. They are not included in any of the *.mk files. Do you have any idea on how to add these assembly sources to the build list? BTW, did you build the complete libcompiler_rt.a at the end?

Thanks,
Chao

Daniel Dilts

unread,
Mar 29, 2015, 5:14:43 PM3/29/15
to Chao Yan, LLVM Developers Mailing List
I was attempting to cross compile on Windows.  I ended up having to find the list in the CMake build system (not very hard) and manually creating a makefile to compile them.  Took maybe 2 hours total.

Richard Pennington

unread,
Mar 29, 2015, 8:46:29 PM3/29/15
to llv...@cs.uiuc.edu
On 03/29/2015 04:11 PM, Daniel Dilts wrote:
> I was attempting to cross compile on Windows. I ended up having to
> find the list in the CMake build system (not very hard) and manually
> creating a makefile to compile them. Took maybe 2 hours total.
>
I also use my own Makefiles to build compiler-rt for ELLCC. I build for
ARM, Mips, Microblaze, PowerPC, and x86. This is the list of files I
came up with:
http://ellcc.org/viewvc/svn/ellcc/trunk/libecc/src/compiler-rt/sources.mk?view=markup

More info at http://ellcc.org

-Rich

Chao Yan

unread,
Mar 30, 2015, 12:28:23 PM3/30/15
to Richard Pennington, LLVM Developers Mailing List

2015-03-29 19:41 GMT-05:00 Richard Pennington <ri...@pennware.com>:
I also use my own Makefiles to build compiler-rt for ELLCC. I build for ARM, Mips, Microblaze, PowerPC, and x86. This is the list of files I came up with: http://ellcc.org/viewvc/svn/ellcc/trunk/libecc/src/compiler-rt/sources.mk?view=markup

More info at http://ellcc.org

I've check the compiler-rt source code and try to run  "make arm-linux-engeabi" in ellcc/libecc directory. I got the following errors:

Making libcompiler-rt for arm-linux-engeabi in compiler-rt-build
arm-linux-engeabi
cp: cannot stat ‘Makefile.lib’: No such file or directory

I've searched through the directory but there is no "Makefile.lib". Run "locate Makefile.lib" I find:

/usr/src/linux-headers-3.13.0-45/scripts/Makefile.lib
/usr/src/linux-headers-3.13.0-45/scripts/dtc/libfdt/Makefile.libfdt
/usr/src/linux-headers-3.13.0-45-generic/scripts/Makefile.lib
/usr/src/linux-headers-3.13.0-46/scripts/Makefile.lib
/usr/src/linux-headers-3.13.0-46/scripts/dtc/libfdt/Makefile.libfdt
/usr/src/linux-headers-3.13.0-46-generic/scripts/Makefile.lib
/usr/src/linux-headers-3.13.0-48/scripts/Makefile.lib
/usr/src/linux-headers-3.13.0-48/scripts/dtc/libfdt/Makefile.libfdt
/usr/src/linux-headers-3.13.0-48-generic/scripts/Makefile.lib

I've tried to use these Makefile.lib but they are not working properly:
arm-linux-engeabi
make[1]: *** No rule to make target `install'.  Stop.

Am I missing something? BTW in your makefile line 49:

$(OUT)cp -p Makefile.lib compiler-rt-build/$@/Makefile

The $(OUT) stuff at the beginning seems not useful?

Thanks,
Chao


Richard Pennington

unread,
Mar 30, 2015, 7:58:44 PM3/30/15
to Chao Yan, LLVM Developers Mailing List
Hi Chao,

I don't want to bring noise to the mailing list. I'll respond privately.

-Rich
Reply all
Reply to author
Forward
0 new messages