On Wed, Aug 02, 2017 at 05:48:20PM -0600, Jonathan Roelofs wrote:> I strongly recommend against using the host's headers when cross compiling. > You need to either find or build an arm-none-eabi sysroot, and use the > --sysroot= flag. > > > JonOK, that's a start. I found https://www.llvm.org/docs/HowToCrossCompileLLVM.html. Is it enough for --sysroot? In case it is, what should be the value of -DLLVM_DEFAULT_TARGET_TRIPLE if I want to use FreeBSD as host and Cortex-M4 as sysroot? Thanx! Regards, meka -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170803/28cb64bc/attachment.sig>
Jonathan Roelofs via llvm-dev
2017-Aug-03 14:22 UTC
[llvm-dev] Cross compiling C++ program
On 8/2/17 5:57 PM, Goran Mekić wrote:> On Wed, Aug 02, 2017 at 05:48:20PM -0600, Jonathan Roelofs wrote: >> I strongly recommend against using the host's headers when cross compiling. >> You need to either find or build an arm-none-eabi sysroot, and use the >> --sysroot= flag. >> >> >> Jon > OK, that's a start. I found https://www.llvm.org/docs/HowToCrossCompileLLVM.html. Is it enough for --sysroot? In case it is, what should be the value of -DLLVM_DEFAULT_TARGET_TRIPLE if I want to use FreeBSD as host and Cortex-M4 as sysroot? Thanx!IIUC, you don't want to cross compile llvm itself (which is what those instructions are for), but instead you want to *use* llvm to cross compile things. To build your sysroot, you'll need to cross-build: 1) A libc. Good choices for that for baremetal are: newlib or musl. 2) Builtins. In llvm, that's provided in the compiler-rt repo. Otherwise you can use libgcc from an arm-none-eabi-gcc toolchain. 3) If you want c++, you'll also need: 3A) c++ abi library. llvm provides this as libcxxabi. There's also libsupc++, and libcxxrt, depending on what licenses you're comfortable with. 3B) An unwinder. llvm provides libunwind. There's also one packaged in libgcc_s (depending on how it was built), and another from the old HP libunwind project (different codebase, but same name as the llvm one). 3C) A c++ standard library. llvm provides this as libcxx. There's also libstdc++. To start with, I recommend using the cmake cache in: $clang_src/cmake/caches/BaremetalARM.cmake. You'll want the stuff in it that references the armv7em-none-eabi triple. To use it, do something like: $ cmake -G <build system> -DBAREMETAL_ARMV7EM_SYSROOT=path/to/your/v7em/sysroot -C path/to/BaremetalARM.cmake [other CMake Options] Assuming your sysroot has libc headers in it, that should get you a clang that's capable of compiling basic things, which you can use to build all the libraries above. Jon> > Regards, > meka-- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded / Siemens
On Thu, Aug 03, 2017 at 08:22:24AM -0600, Jonathan Roelofs wrote:> IIUC, you don't want to cross compile llvm itself (which is what those > instructions are for), but instead you want to *use* llvm to cross compile > things. > > To build your sysroot, you'll need to cross-build: > > 1) A libc. Good choices for that for baremetal are: newlib or musl. > 2) Builtins. In llvm, that's provided in the compiler-rt repo. Otherwise > you can use libgcc from an arm-none-eabi-gcc toolchain. > 3) If you want c++, you'll also need: > 3A) c++ abi library. llvm provides this as libcxxabi. There's also > libsupc++, and libcxxrt, depending on what licenses you're comfortable with. > 3B) An unwinder. llvm provides libunwind. There's also one packaged in > libgcc_s (depending on how it was built), and another from the old HP > libunwind project (different codebase, but same name as the llvm one). > 3C) A c++ standard library. llvm provides this as libcxx. There's also > libstdc++. > > > To start with, I recommend using the cmake cache in: > $clang_src/cmake/caches/BaremetalARM.cmake. You'll want the stuff in it that > references the armv7em-none-eabi triple. To use it, do something like: > > $ cmake -G <build system> > -DBAREMETAL_ARMV7EM_SYSROOT=path/to/your/v7em/sysroot -C > path/to/BaremetalARM.cmake [other CMake Options] > > Assuming your sysroot has libc headers in it, that should get you a clang > that's capable of compiling basic things, which you can use to build all the > libraries above. > > > JonHello, Your input was very valuable, but I must be too noob so I have to ask. I tried to read as much as I could about musl, compiler-rt and libunwind to understand what are those libs and I decided to go with a "relexed" licenced alternatives. :o) If I got it right, the order of repos I need to compile is: - musl - compiler-rt - libcxxabi - libunwind - libcxx - clang (with the suggestion about baremetal cache) If you know any doc on how to get clang++ compile for any bare metal arm, I'll be glad to RTFM. :o) -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 833 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170804/4748dbba/attachment.sig>