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-summarySo 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! 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 -------------- 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/20170805/d256baa8/attachment.sig>
Richard Pennington via llvm-dev
2017-Aug-05 14:19 UTC
[llvm-dev] Cross compiling C++ program
On 08/05/2017 08:41 AM, Goran Mekić via llvm-dev wrote:> > 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/ff3248f08ddc99361dcc009e9f4c1020It is slightly tricky to compile compile musl and compiler-rt. The bits directory is populated when you install musl, but musl needs compiler-rt built if you want to build libc.so. The solution that works is to first do a "make install-headers" on musl, then build compiler-rt, then build musl. If you look at the ELLCC make-libraries and build-musl scripts, you'll see how ELLCC does it. Or you can disable building the musl shared library. The other problem you'll run into is that musl is nowhere near bare metal. It's whole purpose in life is to turn the C standard library calls into Linux system calls. While a baremetal version of musl would be very nice to have, it is a non-trivial project. Baremetal is what something like NuttX's C library provides. -Rich
On Sat, Aug 05, 2017 at 09:19:57AM -0500, Richard Pennington via llvm-dev wrote:> On 08/05/2017 08:41 AM, Goran Mekić via llvm-dev wrote: > > > > > 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 > It is slightly tricky to compile compile musl and compiler-rt. The bits > directory is populated when you install musl, but musl needs compiler-rt > built if you want to build libc.so. > The solution that works is to first do a "make install-headers" on musl, > then build compiler-rt, then build musl. If you look at the ELLCC > make-libraries and build-musl scripts, you'll see how ELLCC does it. Or > you can disable building the musl shared library.Thanx for this. I got to libunwind (libcxxabi expects it as dependency) and this is the error I get: # set -xg CC /tmp/barearm-sysroot/bin/clang-6.0 # set -xg CXX /tmp/barearm-sysroot/bin/clang-6.0 # 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/libunwind # make -j4 VERBOSE=1 https://gist.github.com/anonymous/b3a211e90808058a2c0b083154ddf5c7> The other problem you'll run into is that musl is nowhere near bare > metal. It's whole purpose in life is to turn the C standard library > calls into Linux system calls. While a baremetal version of musl would > be very nice to have, it is a non-trivial project. Baremetal is what > something like NuttX's C library provides.I know, but I though that this is how ELLCC is built, too. Baremetal clang build with musl not having much to with libc that NuttX uses. Also, I though this is a way to create sysroot. Am I wrong? -------------- 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/20170805/81dbc7bb/attachment.sig>
Jonathan Roelofs via llvm-dev
2017-Aug-07 15:37 UTC
[llvm-dev] Cross compiling C++ program
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