Morello toolchain compilation

Hi,

I'm trying to compile the Morello (baremetal cross-compilation) toolchains from source. (I know binary releases exist, but I can't use those.)

Initially I tried compiling an LLVM-based toolchain from https://git.morello-project.org/morello/llvm-project (as seems to be most recommended). I managed to get a clang binary that nominally works, but has a few annoying quirks that are annoying to deal with:

  • By default, the compiler wants to use my system linker at /usr/bin/ld, instead of the lld that just got compiled. This can be fixed by adding -DCLANG_DEFAULT_LINKER=lld to the CMake configuration flags, but apparently this is "discouraged".
  • By default, clang wans to link against a libc, crt0 and clang_rt that do not exist, unless -ffreestanding -nostartfiles -nostdlib are supplied (and all other LLVM/clang runtime components seem to rely on a libc being present). Which is understandable, except that:
    • LLVM libc can't really be compiled because it's still to experimental to begin with
    • The binary releases seem to use newlib, but it's unclear  how these got built:

As I am more familiar with these, I then attempted to use the GNU-based one (from https://git.morello-project.org/morello/gnu-toolchain/ and https://git.morello-project.org/morello/newlib ). Compiling binutils and gcc seems to work, but then the newlib build chokes on errors like these:

../../../../../../newlib/newlib/libc/stdlib/mallocr.c:2354:25: error: unknown type name 'capability'; did you mean '__capability'?
 2354 | static Void_t* mem2heap(capability Void_t* mem)
      |                         ^~~~~~~~~~
      |                         __capability
../../../../../../newlib/newlib/libc/stdlib/mallocr.c:2378:13: error: '__cheri_fromcap' undeclared (first use in this function)
 2378 |     return (__cheri_fromcap Void_t *)mem;

Looking at the 'mallocr.c' file, this all seems to happen inside an #ifdef block for CHERI support (so the compiler does support those), but somehow the new magic keywords don't seem to be supported. I did try to use a multilib configuration for GCC and newlib (to compile purecap and hybridcap versions in one go), but I'm not sure if these errors are caused by that, or by something else.

So what's going on here? Are there any 'official' docs on what configuration flags etc. to use to build a cross-compiler?

Thanks.

P.S. here are the configuration flags I've been using:

LLVM: 

cmake ../llvm-project/llvm/ -G Ninja \
        -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:STRING="$INSTALLDIR" \
        -DLLVM_ENABLE_PROJECTS="clang;lld;lldb;clang-tools-extra" \
        -DLLVM_DEFAULT_TARGET_TRIPLE="aarch64-none-elf" -DCLANG_DEFAULT_LINKER=lld \
        -DLLVM_TARGETS_TO_BUILD:STRING="AArch64" \
        -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON \
        -DCMAKE_SKIP_BUILD_RPATH:BOOL=OFF \
        -DCMAKE_INSTALL_RPATH:STRING=\$ORIGIN/../lib \
        -DLLVM_ENABLE_ASSERTIONS:BOOL=ON \
        -DCMAKE_INSTALL_RPATH:STRING=\$ORIGIN/../lib \
        -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON \
        -DLLVM_ENABLE_LIBCXX:BOOL=OFF -DLIBUNWIND_ENABLE_THREADS:BOOL=ON \
        -DLLVM_ENABLE_EH:BOOL=ON -DLLVM_ENABLE_RTTI:BOOL=ON -DLLVM_ENABLE_Z3_SOLVER:BOOL=OFF \
        -DLIBCXX_CXX_ABI:STRING=libcxxabi \
        -DLIBCXX_CXX_ABI_INCLUDE_PATHS:STRING=../llvm-project/libcxxabi/include \
        -DLIBCXXABI_USE_LLVM_UNWINDER:BOOL=ON -DLIBCXX_ENABLE_THREADS:BOOL=ON \
        -DLIBCXXABI_ENABLE_THREADS:BOOL=ON \
        -DBUILD_SHARED_LIBS:BOOL=ON

Binutils: 

../binutils-gdb/configure --target="aarch64-none-elf" \
        --disable-nls --enable-deterministic-archives --enable-ld --enable-multilib \
        --prefix="$INSTDIR" --with-gnu-as --with-gnu-ld \
        --with-sysroot="$INSTDIR/aarch64-none-elf" --with-system-zlib --without-isl

GCC: 

../gcc/configure --target="aarch64-none-elf" \
        --enable-languages=c,c++,lto --enable-multilib \
        --with-multilib-generator='aarch64-ilp32--;morello-hybridcap--;morello+c64-purecap--' \
        \
        --libdir="$INSTDIR/lib" --libexecdir="$INSTDIR/lib" \
        --prefix="$INSTDIR" --with-headers="$INSTDIR/aarch64-none-elf/include" \
        --with-sysroot="$INSTDIR/aarch64-none-elf" \
        --with-native-system-header-dir=/include --with-newlib --with-python-dir=share/gcc-aarch64-none-elf \
        \
        --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap \
        --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls \
        --disable-shared --disable-threads --disable-tls --disable-werror \
        --disable-gcov \
        --enable-__cxa_atexit --enable-c99 --enable-gnu-indirect-functions \
        --enable-long-long --enable-plugins --enable-lto \
        --with-gmp --with-gnu-as --with-gnu-ld --with-host-libstdcxx='-static-libgcc' \
        --without-isl --with-libelf --with-mpc --with-mpfr --with-system-zlib

newlib: 

../newlib/configure --target="aarch64-none-elf" \
        --prefix="$INSTDIR" \
        --with-gnu-as --with-gnu-ld --disable-nls --enable-interwork \
        --disable-newlib-supplied-syscalls --enable-newlib-retargetable-locking \
        --enable-newlib-io-long-long --enable-newlib-register-fini

Parents Reply Children
No data