<div dir="ltr">Hi Peter<div><br></div><div>Thanks for your very clear and detail reply.</div><div><br></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">- You're missing --target=arm-linux-gnueabi , without that clang will</span><br style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">be building an X86 object and will not expect to be cross compiling</span><br></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">=================</span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I use -target arm-linu-gnueabi. I think it should be the same</span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">- --rtlib=compiler-rt will probably not work out of the box. The clang</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">that you download or build on an X86 machine will not have compiler-rt</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">libraries for Arm</span><br></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">==============</span></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I see. I will try it.</span></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">- I don't think that you need to add -L and -l for the llvm library</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">directories unless you are actually using the libraries from them.</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Beware that the libraries in that directory will probably be compiled</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">for X86 so won't be of much use to you on an Arm system.</span><br></span></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">================</span></span></span></div><div><span style="font-size:14px">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.</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Just to make sure you are aware, the arm-linux-gnueabi gcc tooltchain</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">has soft-floating point libraries. If you want hard floating point</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">libraries, such as used on the Raspberry Pi, you'll need the</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">arm-linux-gnueabihf gcc toolchain and to use</span><br style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">--target=arm-linux-gnueabihf.</span><br></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">=============</span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">I see. I don't know before. But I think arm-linux-gnueabi now is enough.</span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Depending on how simple your test.c is I suggest:</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">/home/jmh/Downloads/llvm/</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">build/bin/clang --target=arm-linux-gnueabi</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">--sysroot=/home/jmh/Downloads/</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gcc-linaro-7.3.1-2018.05-x86_</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">64_arm-linux-gnueabi/arm-</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">linux-gnueabi/libc</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">--gcc-toolchain=/home/jmh/</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Downloads/gcc-linaro-7.3.1-</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">2018.05-x86_64_arm-linux-</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gnueabi/lib/gcc/arm-linux-</span><wbr style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">gnueabi/</span><br style="text-decoration-style:initial;text-decoration-color:initial"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">-target arm-linux-gnueabi -fuse-ld=lld -o test test.c</span><br></span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">===============</span></span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Actually, the same exception occurs, which is shown below.</span></span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></span></div><div><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline;font-size:14px"><div>/home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtbegin.o: No such file or directory</div><div>/home/jmh/Downloads/llvm/build/bin/ld.lld: error: unable to find library -lgcc</div><div>/home/jmh/Downloads/llvm/build/bin/ld.lld: error: unable to find library -lgcc</div><div>/home/jmh/Downloads/llvm/build/bin/ld.lld: error: cannot open crtend.o: No such file or directory</div><div>clang-7: error: linker command failed with exit code 1 (use -v to see invocation)</div></span></span></div><div><span style="font-size:14px"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">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.</span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="font-size:14px">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</span></div><div><span style="font-size:14px"><br></span></div><div><span style="font-size:14px">Regards</span></div><div><span style="font-size:14px">Muhui</span></div><div><span style="font-size:14px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-07-02 5:04 GMT-04:00 Peter Smith <span dir="ltr"><<a href="mailto:peter.smith@linaro.org" target="_blank">peter.smith@linaro.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Muhui,<br>
<br>
>From what I can see from your commands I think:<br>
- You're missing --target=arm-linux-gnueabi , without that clang will<br>
be building an X86 object and will not expect to be cross compiling.<br>
- --rtlib=compiler-rt will probably not work out of the box. The clang<br>
that you download or build on an X86 machine will not have compiler-rt<br>
libraries for Arm. You can cross compile these and install them into<br>
the clang/7.0.0/lib/linux directory and there is a document to help<br>
you build the builtins at<br>
<a href="https://llvm.org/docs/HowToCrossCompileBuiltinsOnArm.html" rel="noreferrer" target="_blank">https://llvm.org/docs/<wbr>HowToCrossCompileBuiltinsOnArm<wbr>.html</a>. If you want<br>
to get started quickly I recommend taking out that option.<br>
- You shouldn't need to use sudo to use clang<br>
- I don't think that you need to add -L and -l for the llvm library<br>
directories unless you are actually using the libraries from them.<br>
Beware that the libraries in that directory will probably be compiled<br>
for X86 so won't be of much use to you on an Arm system.<br>
<br>
Just to make sure you are aware, the arm-linux-gnueabi gcc tooltchain<br>
has soft-floating point libraries. If you want hard floating point<br>
libraries, such as used on the Raspberry Pi, you'll need the<br>
arm-linux-gnueabihf gcc toolchain and to use<br>
--target=arm-linux-gnueabihf.<br>
<br>
Depending on how simple your test.c is I suggest:<br>
/home/jmh/Downloads/llvm/<wbr>build/bin/clang --target=arm-linux-gnueabi<br>
--sysroot=/home/jmh/Downloads/<wbr>gcc-linaro-7.3.1-2018.05-x86_<wbr>64_arm-linux-gnueabi/arm-<wbr>linux-gnueabi/libc<br>
--gcc-toolchain=/home/jmh/<wbr>Downloads/gcc-linaro-7.3.1-<wbr>2018.05-x86_64_arm-linux-<wbr>gnueabi/lib/gcc/arm-linux-<wbr>gnueabi/<br>
-target arm-linux-gnueabi -fuse-ld=lld -o test test.c<br>
<br>
Hope this gets you a little bit further.<br>
<span class="HOEnZb"><font color="#888888"><br>
Peter<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On 1 July 2018 at 18:19, Muhui Jiang <<a href="mailto:jiangmuhui@gmail.com">jiangmuhui@gmail.com</a>> wrote:<br>
> Hi Peter<br>
><br>
> I guess this is the document written by you<br>
> <a href="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" rel="noreferrer" target="_blank">https://fosdem.org/2018/<wbr>schedule/event/crosscompile/<wbr>attachments/slides/2107/<wbr>export/events/attachments/<wbr>crosscompile/slides/2107/How_<wbr>to_cross_compile_with_LLVM_<wbr>based_tools.pdf</a><br>
><br>
> I follow it to try to use the clang to do cross compilation. Actually, my<br>
> target binaries is SPECCPU2006 and autotools based binaries.<br>
><br>
> However, I failed on the first step. I write a hello world as test.c.  I<br>
> refer to your document and download the newest version of arm toolchain.<br>
><br>
> I use the following command to try to compile the code to binary.<br>
><br>
> sudo /home/jmh/Downloads/llvm/<wbr>build/bin/clang<br>
> --sysroot=/home/jmh/Downloads/<wbr>gcc-linaro-7.3.1-2018.05-x86_<wbr>64_arm-linux-gnueabi/arm-<wbr>linux-gnueabi/libc<br>
> --gcc-toolchain=/home/jmh/<wbr>Downloads/gcc-linaro-7.3.1-<wbr>2018.05-x86_64_arm-linux-<wbr>gnueabi/lib/gcc/arm-linux-<wbr>gnueabi/<br>
> -target arm-linux-gnueabi -fuse-ld=lld -L /home/jmh/Downloads/llvm/<wbr>build/lib<br>
> -I/home/jmh/Downloads/llvm/<wbr>build/include/ --rtlib=compiler-rt -o test test.c<br>
><br>
> However, I come across the following exception.<br>
><br>
> /home/jmh/Downloads/llvm/<wbr>build/bin/ld.lld: error: cannot open crtbegin.o: No<br>
> such file or directory<br>
> /home/jmh/Downloads/llvm/<wbr>build/bin/ld.lld: error: cannot open<br>
> /home/jmh/Downloads/llvm/<wbr>build/lib/clang/7.0.0/lib/<wbr>linux/libclang_rt.builtins-<wbr>arm.a:<br>
> No such file or directory<br>
> /home/jmh/Downloads/llvm/<wbr>build/bin/ld.lld: error: cannot open<br>
> /home/jmh/Downloads/llvm/<wbr>build/lib/clang/7.0.0/lib/<wbr>linux/libclang_rt.builtins-<wbr>arm.a:<br>
> No such file or directory<br>
> /home/jmh/Downloads/llvm/<wbr>build/bin/ld.lld: error: cannot open crtend.o: No<br>
> such file or directory<br>
> clang-7: error: linker command failed with exit code 1 (use -v to see<br>
> invocation)<br>
><br>
> Do you have any ideas or suggestions. I also cc the problem to llvm<br>
> community. Anyone who has the same experience. Please help me. Many Thanks<br>
><br>
> Regards<br>
> Muhui<br>
><br>
><br>
</div></div></blockquote></div><br></div>