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>
Jonathan Roelofs via llvm-dev
2017-Aug-04 19:54 UTC
[llvm-dev] Cross compiling C++ program
On 8/4/17 1:14 PM, Goran Mekić via llvm-dev wrote:> 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. >> >> >> Jon > > Hello, > > 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)Not quite. You'll need clang built in order to build the other things. (I guess you could use your existing toolchain to do that, but IIUC, you want to use clang for all of it & bootstrap a full clang-based toolchain). For that, the usual order is to: 1) Pick a directory as your sysroot 2) Install the libc headers there (without having built it) 3) Build clang w/ baremetal cache, pointing it at the partially built sysroot. 4) Build your libc. 4A) Test your libc. 4B) Install your libc in your sysroot. 5) Build libcxxabi. (it's build needs to know where the source for libcxx lives) 5A) Test libcxxabi. (testing it requires knowing where source for libcxx lives. use remote executors & linker scripts to run on your board, or in qemu) 5B) Install libcxxabi in your sysroot. 6) Build libunwind. 6A) Test libunwind. (testing it requires knowing where source for libcxx lives. use remote executors & linker scripts to run on your board, or in qemu) 6B) Install libunwind in your sysroot. 7) Build libcxx. 7A) Test libcxx. (use remote executors & linker scripts to run on your board, or in qemu) 7B) Install libcxx in your sysroot. A note on linker scripts: support for them in lld is still a bit rough around the edges, so you may want to use the linker that comes with your board (presumably binutils ld).> > If you know any doc on how to get clang++ compile for any bare metal arm, I'll be glad to RTFM. :o)Sorry, I don't have a doc for that. We're getting closer to making it work "out of the tin", but it's not there yet. We (wearing my CodeSourcery hat) are working on it, but it's going to take some time before it "just works" upstream. Jon> > > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-- Jon Roelofs jonathan at codesourcery.com CodeSourcery / Mentor Embedded / Siemens
You may also take a look at the ELLCC project (www.ellcc.org <http://www.ellcc.org/>). As far as I understand it they produce and package cross toolchains for a number of popular targets. - Matthias> On Aug 4, 2017, at 12:54 PM, Jonathan Roelofs via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > > > On 8/4/17 1:14 PM, Goran Mekić via llvm-dev wrote: >> 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. >>> >>> >>> Jon >> Hello, >> 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) > > > Not quite. You'll need clang built in order to build the other things. (I guess you could use your existing toolchain to do that, but IIUC, you want to use clang for all of it & bootstrap a full clang-based toolchain). For that, the usual order is to: > > 1) Pick a directory as your sysroot > 2) Install the libc headers there (without having built it) > 3) Build clang w/ baremetal cache, pointing it at the partially built sysroot. > 4) Build your libc. > 4A) Test your libc. > 4B) Install your libc in your sysroot. > 5) Build libcxxabi. (it's build needs to know where the source for libcxx lives) > 5A) Test libcxxabi. (testing it requires knowing where source for libcxx lives. use remote executors & linker scripts to run on your board, or in qemu) > 5B) Install libcxxabi in your sysroot. > 6) Build libunwind. > 6A) Test libunwind. (testing it requires knowing where source for libcxx lives. use remote executors & linker scripts to run on your board, or in qemu) > 6B) Install libunwind in your sysroot. > 7) Build libcxx. > 7A) Test libcxx. (use remote executors & linker scripts to run on your board, or in qemu) > 7B) Install libcxx in your sysroot. > > > A note on linker scripts: support for them in lld is still a bit rough around the edges, so you may want to use the linker that comes with your board (presumably binutils ld). > >> If you know any doc on how to get clang++ compile for any bare metal arm, I'll be glad to RTFM. :o) > > Sorry, I don't have a doc for that. We're getting closer to making it work "out of the tin", but it's not there yet. We (wearing my CodeSourcery hat) are working on it, but it's going to take some time before it "just works" upstream. > > > Jon > >> _______________________________________________ >> LLVM Developers mailing list >> llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev> > > -- > Jon Roelofs > jonathan at codesourcery.com <mailto:jonathan at codesourcery.com> > CodeSourcery / Mentor Embedded / Siemens > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org> > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170804/9f9a06ff/attachment.html>
On Fri, Aug 04, 2017 at 01:54:33PM -0600, Jonathan Roelofs wrote:> > > On 8/4/17 1:14 PM, Goran Mekić via llvm-dev wrote: > > 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. > > > > > > > > > Jon > > > > Hello, > > > > 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) > > > Not quite. You'll need clang built in order to build the other things. (I > guess you could use your existing toolchain to do that, but IIUC, you want > to use clang for all of it & bootstrap a full clang-based toolchain). For > that, the usual order is to: > > 1) Pick a directory as your sysroot~/arm-sysroot> 2) Install the libc headers there (without having built it)What I did was mv musl-*/include ~/arm-sysroot/usr/include.> 3) Build clang w/ baremetal cache, pointing it at the partially built > sysroot.cmake -G 'Unix Makefiles' -DBAREMETAL_ARMV7EM_SYSROOT=~/arm-sysroot -C ../../code/clang/cmake/caches/BaremetalARM.cmake ../../code/clang loading initial cache file ../../code/clang/cmake/caches/BaremetalARM.cmake -- Found LLVM_CONFIG as /usr/local/bin/llvm-config -- Building with -fPIC -- Could NOT find Z3 (missing: Z3_LIBRARIES Z3_INCLUDE_DIR) (Required is at least version "4.5") -- Clang version: 4.0.1 CMake Error at /usr/local/llvm40/lib/cmake/llvm/LLVM-Config.cmake:203 (message): Library `BinaryFormat' not found in list of llvm libraries. Call Stack (most recent call first): /usr/local/llvm40/lib/cmake/llvm/AddLLVM.cmake:508 (llvm_map_components_to_libnames) cmake/modules/AddClang.cmake:86 (llvm_add_library) lib/AST/CMakeLists.txt:6 (add_clang_library) -- Configuring incomplete, errors occurred! See also "/usr/home/meka/repos/clang/build/clang/CMakeFiles/CMakeOutput.log".> A note on linker scripts: support for them in lld is still a bit rough > around the edges, so you may want to use the linker that comes with your > board (presumably binutils ld).Thank you!> Sorry, I don't have a doc for that. We're getting closer to making it work > "out of the tin", but it's not there yet. We (wearing my CodeSourcery hat) > are working on it, but it's going to take some time before it "just works" > upstream.I will test what ever you throw my way regarding this (or write a doc). -------------- 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/b9dd1ea6/attachment.sig>