From 9660e15264bd68ce4d62b64de2ea08e6b0debf37 Mon Sep 17 00:00:00 2001 From: Martin Kelly Date: Thu, 16 Mar 2017 10:49:10 -0700 Subject: clang: fix the llvm-common wrapper The llvm-common wrapper refers to the LLVM_WANT_RELEASE variable, which is not actually exported, so it fails. In addition, meta-clang does not support multiple side-by-side LLVM versions anyway, so the logic isn't really needed. After fixing these issues, I discovered that llvm-config doesn't cross-compile properly without more extensive wrapping. Specifically, the native llvm-config supplies --libdir, and other arguments relative to its current executable path, so it points into the native sysroot rather than the target sysroot. In addition, it supplies the native rather than the target compile CFLAGS, LDFLAGS, etc. Fix these issues by doing the following: - Alter the llvm-config to intercept certain flags, such as --cflags, while passing on other flags to the native llvm-config. - Patch llvm-config to be able to specify an alternate root location on which to base --libdir, etc. in order to optionally point into the target sysroot when needed. Signed-off-by: Martin Kelly --- .../0004-llvm-allow-env-override-of-exe-path.patch | 36 +++++++++++++++++++ recipes-devtools/clang/clang_git.bb | 7 +--- recipes-devtools/clang/llvm-common/llvm-config | 41 +++++++++++++++++----- 3 files changed, 70 insertions(+), 14 deletions(-) create mode 100644 recipes-devtools/clang/clang/0004-llvm-allow-env-override-of-exe-path.patch diff --git a/recipes-devtools/clang/clang/0004-llvm-allow-env-override-of-exe-path.patch b/recipes-devtools/clang/clang/0004-llvm-allow-env-override-of-exe-path.patch new file mode 100644 index 0000000..739d188 --- /dev/null +++ b/recipes-devtools/clang/clang/0004-llvm-allow-env-override-of-exe-path.patch @@ -0,0 +1,36 @@ +From 60eb14f995e0359aef4ef144338d932cbf9c4531 Mon Sep 17 00:00:00 2001 +From: Martin Kelly +Date: Wed, 15 Mar 2017 10:50:25 -0700 +Subject: [PATCH] allow env override of exe path + +When using a native llvm-config from inside a sysroot, we need llvm-config to +return the libraries, include directories, etc. from inside the sysroot rather +than from the native sysroot. Thus provide an env override for calling +llvm-config from a target sysroot. + +Signed-off-by: Martin Kelly +--- + tools/llvm-config/llvm-config.cpp | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 25344e4..26724c1 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -225,6 +225,13 @@ Typical components:\n\ + + /// \brief Compute the path to the main executable. + std::string GetExecutablePath(const char *Argv0) { ++ // Hack for Yocto: we need to override the root path when we are using ++ // llvm-config from within a target sysroot. ++ const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH"); ++ if (Sysroot != nullptr) { ++ return Sysroot; ++ } ++ + // This just needs to be some symbol in the binary; C++ doesn't + // allow taking the address of ::main however. + void *P = (void *)(intptr_t)GetExecutablePath; +-- +2.1.4 + diff --git a/recipes-devtools/clang/clang_git.bb b/recipes-devtools/clang/clang_git.bb index 67b9597..28baa05 100644 --- a/recipes-devtools/clang/clang_git.bb +++ b/recipes-devtools/clang/clang_git.bb @@ -22,6 +22,7 @@ SRC_URI += "\ file://0001-llvm-Remove-CMAKE_CROSSCOMPILING-so-it-can-cross-com.patch \ file://0002-llvm-Do-not-assume-linux-glibc.patch \ file://0003-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \ + file://0004-llvm-allow-env-override-of-exe-path.patch \ " # Clang patches @@ -96,12 +97,6 @@ DEPENDS_remove_class-nativesdk = "nativesdk-binutils nativesdk-compiler-rt nativ DEPENDS_append_class-nativesdk = " clang-native virtual/${TARGET_PREFIX}binutils-crosssdk virtual/${TARGET_PREFIX}gcc-crosssdk virtual/${TARGET_PREFIX}g++-crosssdk" DEPENDS_append_class-target = " clang-cross-${TARGET_ARCH} ${@bb.utils.contains('TOOLCHAIN', 'gcc', 'virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}g++', '', d)}" -do_configure_prepend() { - # Fix paths in llvm-config - sed -i "s|sys::path::parent_path(CurrentPath))\.str()|sys::path::parent_path(sys::path::parent_path(CurrentPath))).str()|g" ${S}/tools/llvm-config/llvm-config.cpp - sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp -} - do_compile_prepend_class-native () { oe_runmake LLVM-tablegen-host oe_runmake CLANG-tablegen-host diff --git a/recipes-devtools/clang/llvm-common/llvm-config b/recipes-devtools/clang/llvm-common/llvm-config index a9a416d..9fb14cb 100644 --- a/recipes-devtools/clang/llvm-common/llvm-config +++ b/recipes-devtools/clang/llvm-common/llvm-config @@ -1,10 +1,35 @@ -#!/bin/sh -# Wrapper script for real llvm-config. Simply calls +#!/bin/bash +# +# Wrapper script for llvm-config. Supplies the right environment variables +# for the target and delegates to the native llvm-config for anything else. This +# is needed because arguments like --ldflags, --cxxflags, etc. are set by the +# native compile rather than the target compile. +# -if [ $WANT_LLVM_RELEASE ]; then - exec `dirname $0`/${TARGET_PREFIX}llvm-config$WANT_LLVM_RELEASE ${@} -else - echo "The variable WANT_LLVM_RELEASE is not defined and exported" - echo "by your build recipe. Go figure." - exit 1 +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +NEXT_LLVM_CONFIG="$(which -a llvm-config | sed -n 2p)" +export YOCTO_ALTERNATE_EXE_PATH="$(readlink -f "$SCRIPT_DIR/../llvm-config")" + +if [[ $# == 0 ]]; then + exec "$NEXT_LLVM_CONFIG" fi + +for arg in "$@"; do + case "$arg" in + --cppflags) + echo $TARGET_CPPFLAGS + ;; + --cflags) + echo $TARGET_CFLAGS + ;; + --cxxflags) + echo $TARGET_CXXFLAGS + ;; + --ldflags) + echo $TARGET_LDFLAGS + ;; + *) + echo "$("$NEXT_LLVM_CONFIG" "$arg")" + ;; + esac +done -- cgit v1.2.3-54-g00ecf