[llvm-dev] Cross compiling C++ program

Jonathan Roelofs via llvm-dev llvm-dev at lists.llvm.org
Mon Aug 7 08:37:38 PDT 2017



On 8/5/17 7:41 AM, Goran Mekić wrote:
> On Fri, Aug 04, 2017 at 04:40:44PM -0600, Jonathan Roelofs wrote:
>> Might be a helpful exercise for you to try building vanilla clang with
>> runtimes for the host, before worrying about how to build everything for
>> your baremetal case:
>> http://llvm.org/docs/GettingStarted.html#getting-started-quickly-a-summary
> So I did. :o) It was fun realizing how much Release type reduces LD memory usage :o)
>
> Anyway, just to be clear what "I did" means:
> - llvm sources from trunk and projects/tools repos checkout under llvm
> - clang-6.0 compiles "Hello World"
> - make check-all fails (not sure I'm not causing it)
> - make install creates everything under PREFIX
>
> # cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_INSTALL_PREFIX=/tmp/x86-sysroot ../../source/llvm
> # make -j4
> # make install
>
> It was fun learning how to manualy compile compiler for the first time. Now how to cross compile for bare? Given that I have musl-1.1.16 directory and that I'm preseeding sysroot with:
>
> # rm -rf /tmp/barearm-sysroot
> # mkdir -p /tmp/barearm-sysroot
> # cp -r musl-1.1.16/include /tmp/barearm-sysroot/ # Thanx for the tip!

Your sysroot needs to be laid out like:

$sysroot/usr/include/<libc headers here>
$sysroot/usr/include/c++/v1/<libcxx headers here>
$sysroot/usr/lib/<all target *.a's here, except for the builtins>

with the builtins placed in:

$PREFIX/lib/clang/$version/lib/baremetal/libclang_rt.builtins-armv7em.a
$BUILD/lib/clang/$version/lib/baremetal/libclang_rt.builtins-armv7em.a


Jon

>
> So I tried to use it, and clang/llvm build, but compiler-rt fails:
>
> # cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Release -DBAREMETAL_ARMV7EM_SYSROOT=/tmp/barearm-sysroot -DCMAKE_INSTALL_PREFIX=/tmp/barearm-sysroot -C ../../source/llvm/cmake/caches/BaremetalARM.cmake ../../source/llvm
> # make -j4
> https://gist.github.com/anonymous/85cd5081a6d46a63731d970ee95b20b4
>
> This is the BaremetalARM.cmake:
> https://gist.github.com/anonymous/ff3248f08ddc99361dcc009e9f4c1020

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded / Siemens



More information about the llvm-dev mailing list