Add a native LLVM Morello cross compiler and a native LLVM that will build it. Add class to be inherited by users of LLVM Morello compiler, this class is required as the inital commit does not provide a proper Yocto Morello toolchain.
Signed-off-by: Pawel Zalewski pzalewski@thegoodpenguin.co.uk --- COPYING.MIT | 17 +++ classes/llvm-morello-native.bbclass | 49 +++++++ recipes-devtools/llvm/llvm-13.0.1-native.bb | 31 ++++ .../llvm/llvm-morello-native_13.0.bb | 13 ++ recipes-devtools/llvm/llvm-morello.inc | 136 ++++++++++++++++++ 5 files changed, 246 insertions(+) create mode 100644 COPYING.MIT create mode 100644 classes/llvm-morello-native.bbclass create mode 100644 recipes-devtools/llvm/llvm-13.0.1-native.bb create mode 100644 recipes-devtools/llvm/llvm-morello-native_13.0.bb create mode 100644 recipes-devtools/llvm/llvm-morello.inc
diff --git a/COPYING.MIT b/COPYING.MIT new file mode 100644 index 0000000..e14c371 --- /dev/null +++ b/COPYING.MIT @@ -0,0 +1,17 @@ +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/classes/llvm-morello-native.bbclass b/classes/llvm-morello-native.bbclass new file mode 100644 index 0000000..b944052 --- /dev/null +++ b/classes/llvm-morello-native.bbclass @@ -0,0 +1,49 @@ +MORELLO_COMPILER = "llvm-morello-native" + +LLVM_VERSION = "13.0.0" + +LLVM_PATH = "${STAGING_DIR_NATIVE}/usr/bin" + +ELF_PATCHER = "${STAGING_BINDIR_NATIVE}/elf-patcher" + +INHIBIT_DEFAULT_DEPS = "1" + +DEPENDS += "virtual/llvm-morello-native" +DEPENDS:append:morello-linux-glibc:class-target = " virtual/musl-morello-libs-native virtual/elf-patcher-native" +DEPENDS:append:morello-linux-musl:class-target = " virtual/musl-morello-libs-native virtual/elf-patcher-native" + +# rough hack to deal with llvm-morello not being a proper toolchain in its own meta yet +DEPENDS:remove = "libgcc" + +do_configure[depends] += " ${@get_depends(d)}" + +LIBCPLUSPLUS = "-stdlib-libc++" + +export CC = "${LLVM_PATH}/clang" +export CXX = "${LLVM_PATH}/clang++" +export CPP = "${LLVM_PATH}/clang" +export CCLD = "${LLVM_PATH}/clang" +export RANLIB = "${LLVM_PATH}/llvm-ranlib" +export AR = "${LLVM_PATH}/llvm-ar" +export AS = "${LLVM_PATH}/llvm-as" +export NM = "${LLVM_PATH}/llvm-nm" +export OBJDUMP = "${LLVM_PATH}/llvm-objdump" +export OBJCOPY = "${LLVM_PATH}/llvm-objcopy" +export STRIP = "${LLVM_PATH}/llvm-strip" +export STRINGS = "${LLVM_PATH}/llvm-strings" +export READELF = "${LLVM_PATH}/llvm-readelf" +export LD = "${LLVM_PATH}/ld.lld" +export LTO = "-fuse-ld=lld" +export HOSTCC = "${LLVM_PATH}/clang" +export LLVM_CONFIG = "${LLVM_PATH}/llvm-config" + +def get_depends(d): + if d.getVar('DEPENDENCIES'): + return "llvm-morello-native:do_populate_sysroot" + else: + return "llvm-morello-native:do_populate_sysroot virtual/musl-morello:do_populate_sysroot" + +DEPENDENCIES:kernel = "1" +DEPENDENCIES:musl = "1" +DEPENDENCIES:musl-morello-native = "1" +DEPENDENCIES ?= "0" \ No newline at end of file diff --git a/recipes-devtools/llvm/llvm-13.0.1-native.bb b/recipes-devtools/llvm/llvm-13.0.1-native.bb new file mode 100644 index 0000000..37140ce --- /dev/null +++ b/recipes-devtools/llvm/llvm-13.0.1-native.bb @@ -0,0 +1,31 @@ +inherit native nopackages + +SUMMARY = "LLVM 13.01" +DESCRIPTION = "LLVM used purely for compiling llvm-morello" +HOMEPAGE = "http://llvm.org" +LICENSE = "Apache-2.0-with-LLVM-exception" +OUTPUTS_NAME = "llvm-13.0.1" + +PROVIDES = "virtual/${OUTPUTS_NAME}-native ${OUTPUTS_NAME}-native" + +SRC_URI = "https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/clang+..." + +SRC_URI[md5sum] = "041e3a5c735d5f956668254b1ffd35d1" +LIC_FILES_CHKSUM = "file://include/llvm/Support/LICENSE.TXT;md5=986c03435151a0086b8aaac964939cdd" + +S = "${WORKDIR}/clang+llvm-13.0.1-x86_64-linux-gnu-ubuntu-18.04" +FILES:${PN} = "/${OUTPUTS_NAME}" + +SYSROOT_DIRS_NATIVE += "/${OUTPUTS_NAME}" + +do_install() { + install -d ${D}${libdir}/${OUTPUTS_NAME} + cp -rf ${S}/* ${D}${libdir}/${OUTPUTS_NAME} +} + +INSANE_SKIP_${PN} = "already-stripped libdir staticdev file-rdeps arch dev-so rpaths useless-rpaths" +INHIBIT_SYSROOT_STRIP = "1" +INHIBIT_PACKAGE_STRIP = "1" +INHIBIT_PACKAGE_DEBUG_SPLIT = "1" +INHIBIT_DEFAULT_DEPS = "1" +EXCLUDE_FROM_SHLIBS = "1" \ No newline at end of file diff --git a/recipes-devtools/llvm/llvm-morello-native_13.0.bb b/recipes-devtools/llvm/llvm-morello-native_13.0.bb new file mode 100644 index 0000000..3b7653b --- /dev/null +++ b/recipes-devtools/llvm/llvm-morello-native_13.0.bb @@ -0,0 +1,13 @@ +inherit cmake pkgconfig python3native native +require llvm-morello.inc +DESCRIPTION = "The Morello LLVM Compiler Infrastructure native" + +PROVIDES = "virtual/${OUTPUTS_NAME}-native" +PN = "${OUTPUTS_NAME}-native" + +FILES:${PN} += "${prefix}" + +do_install:append() { + install -d ${D}${prefix} + cp -rvf ${LLVM_INSTALL_DIR}/* ${D}${prefix} +} \ No newline at end of file diff --git a/recipes-devtools/llvm/llvm-morello.inc b/recipes-devtools/llvm/llvm-morello.inc new file mode 100644 index 0000000..8291017 --- /dev/null +++ b/recipes-devtools/llvm/llvm-morello.inc @@ -0,0 +1,136 @@ + + +SUMMARY = "CHERI enabled Linux kernel" +HOMEPAGE = "http://llvm.org" +LICENSE = "Apache-2.0-with-LLVM-exception" +OUTPUTS_NAME = "llvm-morello" + +DEPENDS = "zlib-native ninja-native ${COMPILER}-native" + +SRC_URI = "git://git.morello-project.org/morello/llvm-project;protocol=https;branch=${SRCBRANCH}" +SRCREV = "cac045cbb70a9c8161f2f32fa5ef056242eb28f3" + +SRCBRANCH = "morello/release-1.5" +LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=8a15a0759ef07f2682d2ba4b893c9afe" + +S = "${WORKDIR}/git/llvm" +S_git = "${WORKDIR}/git" + +FILES:${PN} = "/${OUTPUTS_NAME}" +SYSROOT_DIRS_NATIVE += "/${OUTPUTS_NAME}" + +COMPILER = "llvm-13.0.1" + +LLVM_TARGETS_TO_BUILD = "X86;AArch64" +LLVM_PROJECTS = "libcxx;libcxxabi;compiler-rt;libunwind;llvm;clang;lld;lldb" +LLVM_BUILD_DIR = "${WORKDIR}/${OUTPUTS_NAME}-build" +LLVM_INSTALL_DIR = "${D}/${OUTPUTS_NAME}" + +NATIVE_LLVM_PATH = "${STAGING_LIBDIR_NATIVE}/${COMPILER}/bin" +LIB_PATH = "${STAGING_LIBDIR_NATIVE}/${COMPILER}/lib" +LIB_PATH_RT = "${STAGING_LIBDIR_NATIVE}/${COMPILER}/lib/clang/13.0.1/lib/linux" + +EXTRA_OECMAKE += "-Wno-dev -G Ninja \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=${LLVM_INSTALL_DIR} \ + -DCMAKE_C_COMPILER='${NATIVE_LLVM_PATH}/clang' \ + -DCMAKE_CXX_COMPILER='${NATIVE_LLVM_PATH}/clang++' \ + -DCMAKE_ASM_COMPILER='${NATIVE_LLVM_PATH}/clang' \ + -DCMAKE_AR='${NATIVE_LLVM_PATH}/llvm-ar' \ + -DCMAKE_RANLIB='${NATIVE_LLVM_PATH}/llvm-ranlib' \ + -DCMAKE_NM='${NATIVE_LLVM_PATH}/llvm-nm' \ + -DCMAKE_OBJDUMP='${NATIVE_LLVM_PATH}/llvm-objdump' \ + -DCMAKE_OBJCOPY='${NATIVE_LLVM_PATH}/llvm-objcopy' \ + -DCMAKE_LINKER='${NATIVE_LLVM_PATH}/ld.lld' \ + -DCMAKE_C_FLAGS_RELEASE='${CFLAGS}' \ + -DCLANG_DEFAULT_LINKER='lld' \ + -DCMAKE_EXE_LINKER_FLAGS='-fuse-ld=lld' \ + -DCMAKE_SHARED_LINKER_FLAGS='-fuse-ld=lld' \ + -DCMAKE_SKIP_BUILD_RPATH=OFF \ + -DCMAKE_INSTALL_RPATH='$ORIGIN/../lib:${LIB_PATH}' \ + -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \ + -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \ + -DLLVM_CCACHE_BUILD=FALSE \ + -DLLVM_ENABLE_ASSERTIONS=OFF \ + -DLLVM_ENABLE_EH=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_ENABLE_LLD=ON \ + -DLLVM_ENABLE_LIBCXX=ON \ + -DBUILD_SHARED_LIBS=ON \ + -DCOMPILER_RT_BUILD_BUILTINS=ON \ + -DCOMPILER_RT_BUILD_XRAY=OFF \ + -DCOMPILER_RT_BUILD_LIBFUZZER=OFF \ + -DCOMPILER_RT_BUILD_PROFILE=OFF \ + -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS_TO_BUILD}' \ + -DLLVM_ENABLE_PROJECTS='${LLVM_PROJECTS}' \ + -DLIBCXX_CXX_ABI='libcxxabi' \ + -DLIBCXX_CXX_ABI_INCLUDE_PATHS='${WORKDIR}/git/libcxxabi/include' \ + -DLIBCXXABI_USE_LLVM_UNWINDER=ON \ + -DLIBCXXABI_USE_COMPILER_RT=ON \ + -DLIBUNWIND_ENABLE_THREADS=ON \ + -DCLANG_DEFAULT_RTLIB='compiler-rt' \ + -DCLANG_DEFAULT_CXX_STDLIB='libc++' \ + -DCLANG_DEFAULT_OBJCOPY='llvm-objcopy'\ + '-DLLVM_LIT_ARGS=--max-time 3600 --timeout 300 -s -vv' \ + -DLLVM_USE_SPLIT_DWARF=TRUE \ + -DLLVM_ENABLE_OCAMLDOC=FALSE \ + -DLLVM_ENABLE_BINDINGS=FALSE \ + -DLLVM_INCLUDE_EXAMPLES=FALSE \ + -DLLVM_INCLUDE_DOCS=FALSE \ + -DLLVM_INCLUDE_BENCHMARKS=FALSE \ + -DCLANG_ENABLE_STATIC_ANALYZER=FALSE \ + -DCLANG_ENABLE_ARCMT=FALSE \ + -DLLVM_ENABLE_Z3_SOLVER=FALSE \ + -DLLVM_TOOL_LLVM_MCA_BUILD=FALSE \ + -DLLVM_TOOL_LLVM_EXEGESIS_BUILD=FALSE \ + -DLLVM_TOOL_LLVM_RC_BUILD=FALSE \ + -DLLVM_OPTIMIZED_TABLEGEN=FALSE \ + -DLLVM_ENABLE_ZLIB=FORCE_ON \ + -DLLVM_ENABLE_LIBXML2=FALSE \ +" + +INSANE_SKIP_${PN} = "already-stripped" +INHIBIT_SYSROOT_STRIP = "1" +INHIBIT_PACKAGE_STRIP = "1" +INHIBIT_PACKAGE_DEBUG_SPLIT = "1" +INHIBIT_DEFAULT_DEPS = "1" + +do_unpack[depends] += "${COMPILER}-native:do_populate_sysroot" + +do_configure() { + mkdir -p ${LLVM_BUILD_DIR} + cd ${LLVM_BUILD_DIR} + cmake -S ${S} -B ${LLVM_BUILD_DIR} ${EXTRA_OECMAKE} +} + +do_compile() { + export CC="${NATIVE_LLVM_PATH}/clang" + export NM="${NATIVE_LLVM_PATH}/llvm-nm" + export CXX="${NATIVE_LLVM_PATH}/clang++" + export LD="${NATIVE_LLVM_PATH}/ld.lld" + cd ${LLVM_BUILD_DIR} + cmake --build . --target all -- -j20 +} + +do_install() { + cd ${LLVM_BUILD_DIR} + cmake --build . --target install + install -d ${LLVM_SHARED_SOURCE} +} + +python do_symlink() { + s = d.getVar("S_git") + if s[-1] == '/': + # drop trailing slash, so that os.symlink(src, s) doesn't use s as directory name and fail + s=s[:-1] + src = d.getVar("LLVM_SHARED_SOURCE") + if s != src: + bb.utils.mkdirhier(src) + bb.utils.remove(src, recurse=True) + os.symlink(s, src) + else: + import shutil + shutil.move(s, src) + os.symlink(src, s) +} +addtask do_symlink after do_install before do_build \ No newline at end of file