[llvm-dev] Cross Compilation Problem

Muhui Jiang via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 2 04:25:54 PDT 2018


Hi Peter

Thanks for your very clear and detail reply.

- You're missing --target=arm-linux-gnueabi , without that clang will
be building an X86 object and will not expect to be cross compiling
=================
I use -target arm-linu-gnueabi. I think it should be the same

- --rtlib=compiler-rt will probably not work out of the box. The clang
that you download or build on an X86 machine will not have compiler-rt
libraries for Arm
==============
I see. I will try it.

- I don't think that you need to add -L and -l for the llvm library
directories unless you are actually using the libraries from them.
Beware that the libraries in that directory will probably be compiled
for X86 so won't be of much use to you on an Arm system.
================
Here I am a little bit confusing. In my test.c, I need to include some .h
files like stdio.h. I think I need to use the -L or -I to tell clang where
to find these headers.


Just to make sure you are aware, the arm-linux-gnueabi gcc tooltchain
has soft-floating point libraries. If you want hard floating point
libraries, such as used on the Raspberry Pi, you'll need the
arm-linux-gnueabihf gcc toolchain and to use
--target=arm-linux-gnueabihf.
=============
I see. I don't know before. But I think arm-linux-gnueabi now is enough.

Depending on how simple your test.c is I suggest:
/home/jmh/Downloads/llvm/build/bin/clang --target=arm-linux-gnueabi
--sysroot=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_
64_arm-linux-gnueabi/arm-linux-gnueabi/libc
--gcc-toolchain=/home/jmh/Downloads/gcc-linaro-7.3.1-
2018.05-x86_64_arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/
-target arm-linux-gnueabi -fuse-ld=lld -o test test.c
===============
Actually, the same exception occurs, which is shown below.

/home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtbegin.o:
No such file or directory
/home/jmh/Downloads/llvm/build/bin/ld.lld: error: unable to find library
-lgcc
/home/jmh/Downloads/llvm/build/bin/ld.lld: error: unable to find library
-lgcc
/home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtend.o: No
such file or directory
clang-7: error: linker command failed with exit code 1 (use -v to see
invocation)

I use clang -emit-llvm -c to generate the LLVM bitcode. It works. I think
this problem is related to the llvm linkers, lld. Do you have any ideas.

The last, but might be more important to me. Do you have any experience to
cross compile the arm binaries with autotools(configure, make, make
install) and save the LLVM IR at the same time. Many Thanks

Regards
Muhui


2018-07-02 5:04 GMT-04:00 Peter Smith <peter.smith at linaro.org>:

> Hello Muhui,
>
> From what I can see from your commands I think:
> - You're missing --target=arm-linux-gnueabi , without that clang will
> be building an X86 object and will not expect to be cross compiling.
> - --rtlib=compiler-rt will probably not work out of the box. The clang
> that you download or build on an X86 machine will not have compiler-rt
> libraries for Arm. You can cross compile these and install them into
> the clang/7.0.0/lib/linux directory and there is a document to help
> you build the builtins at
> https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html. If you want
> to get started quickly I recommend taking out that option.
> - You shouldn't need to use sudo to use clang
> - I don't think that you need to add -L and -l for the llvm library
> directories unless you are actually using the libraries from them.
> Beware that the libraries in that directory will probably be compiled
> for X86 so won't be of much use to you on an Arm system.
>
> Just to make sure you are aware, the arm-linux-gnueabi gcc tooltchain
> has soft-floating point libraries. If you want hard floating point
> libraries, such as used on the Raspberry Pi, you'll need the
> arm-linux-gnueabihf gcc toolchain and to use
> --target=arm-linux-gnueabihf.
>
> Depending on how simple your test.c is I suggest:
> /home/jmh/Downloads/llvm/build/bin/clang --target=arm-linux-gnueabi
> --sysroot=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_
> 64_arm-linux-gnueabi/arm-linux-gnueabi/libc
> --gcc-toolchain=/home/jmh/Downloads/gcc-linaro-7.3.1-
> 2018.05-x86_64_arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/
> -target arm-linux-gnueabi -fuse-ld=lld -o test test.c
>
> Hope this gets you a little bit further.
>
> Peter
>
> On 1 July 2018 at 18:19, Muhui Jiang <jiangmuhui at gmail.com> wrote:
> > Hi Peter
> >
> > I guess this is the document written by you
> > https://fosdem.org/2018/schedule/event/crosscompile/
> attachments/slides/2107/export/events/attachments/
> crosscompile/slides/2107/How_to_cross_compile_with_LLVM_based_tools.pdf
> >
> > I follow it to try to use the clang to do cross compilation. Actually, my
> > target binaries is SPECCPU2006 and autotools based binaries.
> >
> > However, I failed on the first step. I write a hello world as test.c.  I
> > refer to your document and download the newest version of arm toolchain.
> >
> > I use the following command to try to compile the code to binary.
> >
> > sudo /home/jmh/Downloads/llvm/build/bin/clang
> > --sysroot=/home/jmh/Downloads/gcc-linaro-7.3.1-2018.05-x86_
> 64_arm-linux-gnueabi/arm-linux-gnueabi/libc
> > --gcc-toolchain=/home/jmh/Downloads/gcc-linaro-7.3.1-
> 2018.05-x86_64_arm-linux-gnueabi/lib/gcc/arm-linux-gnueabi/
> > -target arm-linux-gnueabi -fuse-ld=lld -L /home/jmh/Downloads/llvm/
> build/lib
> > -I/home/jmh/Downloads/llvm/build/include/ --rtlib=compiler-rt -o test
> test.c
> >
> > However, I come across the following exception.
> >
> > /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open
> crtbegin.o: No
> > such file or directory
> > /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open
> > /home/jmh/Downloads/llvm/build/lib/clang/7.0.0/lib/
> linux/libclang_rt.builtins-arm.a:
> > No such file or directory
> > /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open
> > /home/jmh/Downloads/llvm/build/lib/clang/7.0.0/lib/
> linux/libclang_rt.builtins-arm.a:
> > No such file or directory
> > /home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtend.o:
> No
> > such file or directory
> > clang-7: error: linker command failed with exit code 1 (use -v to see
> > invocation)
> >
> > Do you have any ideas or suggestions. I also cc the problem to llvm
> > community. Anyone who has the same experience. Please help me. Many
> Thanks
> >
> > Regards
> > Muhui
> >
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180702/b50141f7/attachment.html>


More information about the llvm-dev mailing list