[llvm-dev] bug: cross-compile Clang/LLVM for ARM using Clang/LLVM

1,151 views
Skip to first unread message

李阳 via llvm-dev

unread,
Apr 25, 2016, 5:39:47 AM4/25/16
to llvm...@lists.llvm.org

​Hi all,

I'm new to LLVM project and now I need to cross-compile Clang/LLVM for ARM. My host is Ubuntu 14.04 and I could compile Clang/LLVM for X86, however when I cross-compile Clang/LLVM for ARM, I come across a few problems. 

My build structure is in the picture. [llvm-source-code] is from github llvm-mirror; [build4x86] is that I follow the guide  [Clang Getting Started] and build clang/llvm to produce it; [build4arm] is that I try to cross-compile clan/llvm for arm on x86 PC, the problem exist here.

Sorry to finish reading, thanks. My command is as follows:

CC='clang' CXX='clang++' cmake -G Ninja ../llvm-source-code -DCMAKE_CROSSCOMPILING=True 
-DCMAKE_INSTALL_PREFIX=./llvm 
-DLLVM_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/llvm-tblgen 
-DCLANG_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/clang-tblgen 
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf 
-DLLVM_TARGET_ARCH=ARM 
-DLLVM_TARGETS_TO_BUILD=ARM 
-DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9 -I/usr/arm-linux-gnueabihf/include/c++/4.7.3/arm-linux-gnueabihf/ -I/usr/arm-linux-gnueabihf/include/ -I/home/lab/workspace/llvm/llvm-source-code/lib4arm/ -I/home/lab/workspace/llvm/llvm-source-code/lib2ubuntu/ -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.a -mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc' 
-DLLVM_ENABLE_LIBCXX=ON 
-DLLVM_ENABLE_PIC=False

The error is as follows:
1. Host compiler appears to require libatomic, but cannot find it.
2. Host Clang must be able to find libstdc++4.7 or newer!

Could anyone give me some suggestions? Thanks in advance!

Best,
Liyang

Renato Golin via llvm-dev

unread,
Apr 25, 2016, 6:33:49 AM4/25/16
to 李阳, LLVM Dev
On 25 April 2016 at 10:39, 李阳 via llvm-dev <llvm...@lists.llvm.org> wrote:
CC='clang' CXX='clang++' cmake -G Ninja ../llvm-source-code -DCMAKE_CROSSCOMPILING=True 
-DCMAKE_INSTALL_PREFIX=./llvm 
-DLLVM_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/llvm-tblgen 
-DCLANG_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/clang-tblgen 
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf 
-DLLVM_TARGET_ARCH=ARM 
-DLLVM_TARGETS_TO_BUILD=ARM 
-DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9 -I/usr/arm-linux-gnueabihf/include/c++/4.7.3/arm-linux-gnueabihf/ -I/usr/arm-linux-gnueabihf/include/ -I/home/lab/workspace/llvm/llvm-source-code/lib4arm/ -I/home/lab/workspace/llvm/llvm-source-code/lib2ubuntu/ -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.a -mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc' 
-DLLVM_ENABLE_LIBCXX=ON 
-DLLVM_ENABLE_PIC=False

Hi Liyang,

You have "LLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf"  and "CMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf" which are different, and may confuse Clang when finding tools and libraries. Use whatever is the ARM triple in your system (looks like it's "arm-linux-gnueabihf") and make both target triple and "-target" to be that exact same string.

Also, you're including x86_64 libraries (ex. -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so) to an ARM compilation job, that won't work. You have to find the ARM version (maybe /usr/lib/gcc/arm-linux-gnueabihf/ ?).

Finally, the include paths with -I are only necessary if Clang cannot find it. The first three should be ok, but using -I on a DSO object (libatomic.so) makes no sense.

cheers,
--renato

李阳 via llvm-dev

unread,
Apr 25, 2016, 7:26:29 AM4/25/16
to Renato Golin, LLVM Dev, Duo Liu
Hi renato,

1. The command above is followed by the guide[ HowToCrossCompileLLVM.rst ] and I specify some path(ex. <path-to-host-bin>).

2. The including x86_64 libraries is added because of  some missing libraries(ex. "error:  Host compiler appears to require libatomic, but cannot find it"). As I have found that the bugs needed to dealt with is some ARM-dependent libraries, I cannot download them on Ubuntu14, could you share them or some available links?

Thanks very much!

Best,
Liyang

James Molloy via llvm-dev

unread,
Apr 25, 2016, 7:49:02 AM4/25/16
to 李阳, Renato Golin, LLVM Dev, Duo Liu
Hi Liyang,

The including x86_64 libraries is added because of  some missing libraries

This will never work. The reason the libatomic check is failing is almost certainly because a path to the C++ headers/libraries is missing. You've manually added them all:

-I/usr/arm-linux-gnueabihf/include/c++/4.7.3/arm-linux-gnueabihf/ -I/usr/arm-linux-gnueabihf/include/ -I/home/lab/workspace/llvm/llvm-source-code/lib4arm/ -I/home/lab/workspace/llvm/llvm-source-code/lib2ubuntu/ -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -I/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.so -L/usr/lib/gcc/x86_64-linux-gnu/4.8/libatomic.a

But a much more robust way to do this is just to use a sysroot:

-DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9 --sysroot=/usr/arm-linux-gnueabihf/'

Cheers,

James


_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

李阳 via llvm-dev

unread,
Apr 25, 2016, 11:40:10 AM4/25/16
to James Molloy, LLVM Dev, Duo Liu
Hi James, renato,

So how do I download the missing ARM libraries on Ubuntu14.04? I cannot find any available libraries.

Best,
Liyang

James Molloy via llvm-dev

unread,
Apr 25, 2016, 11:42:16 AM4/25/16
to 李阳, LLVM Dev, Duo Liu
You shouldn't need any. Did you attempt my suggestion ?

李阳 via llvm-dev

unread,
Apr 25, 2016, 11:56:32 AM4/25/16
to James Molloy, LLVM Dev, Duo Liu
Hi James,

1. I have tried with your suggestion, the command is as follows:

CC='clang' CXX='clang++' cmake -G Ninja ../llvm-source-code 
-DCMAKE_CROSSCOMPILING=True 
-DCMAKE_INSTALL_PREFIX=./llvm 
-DLLVM_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/llvm-tblgen 
-DCLANG_TABLEGEN=/home/lab/workspace/llvm/build4x86/bin/clang-tblgen 
-DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabihf 
-DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM 
-DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9 --sysroot=/usr/arm-linux-gnueabihf/ -mfloat-abi=hard -ccc-gcc-name arm-linux-gnueabihf-gcc' 
-DLLVM_ENABLE_LIBCXX=ON -DLLVM_ENABLE_PIC=False

But it still produce error, like this:

CMake Error at /home/lab/workspace/cmake-3.2.0-Linux-x86_64/share/cmake-3.2/Modules/CMakeTestCXXCompiler.cmake:54 (message):
  The C++ compiler "/home/lab/workspace/llvm/build4x86/bin/clang++" is not
  able to compile a simple test program.

/usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi

  Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 i386linux elf_l1om
  elf_k1om i386pep i386pe

  clang-3.9: error: linker command failed with exit code 1 (use -v to see
  invocation)

  ninja: build stopped: subcommand failed.

2. If I maually add all the libraries/headers, it don't produce the errors above.

So I think I still need to download some necessary libraries.

Thanks for your reply!

Best,
Liyang

Renato Golin via llvm-dev

unread,
Apr 25, 2016, 1:03:43 PM4/25/16
to 李阳, LLVM Dev, Duo Liu
On 25 April 2016 at 16:56, 李阳 <yangl...@gmail.com> wrote:
> -DCMAKE_CXX_FLAGS='-target armv7a-linux-gnueabihf -mcpu=cortex-a9
> --sysroot=/usr/arm-linux-gnueabihf/ -mfloat-abi=hard -ccc-gcc-name
> arm-linux-gnueabihf-gcc'

Try to change the triple to "arm-linux-gnueabihf" as I mentioned
earlier. Clang is getting confused.


> /usr/bin/ld: unrecognised emulation mode: armelf_linux_eabi

This is certainly not the ARM linker. :)


> 2. If I maually add all the libraries/headers, it don't produce the errors
> above.

If you're using --sysroot, the only library path you may have to use
is /usr/lib/gcc/arm-linux-gnueabihf/VERSION/ due to GCC run-time
libraries.

Reply all
Reply to author
Forward
0 new messages