diff options
author | Martin Kelly <mkelly@xevo.com> | 2017-03-16 10:49:10 -0700 |
---|---|---|
committer | Khem Raj <raj.khem@gmail.com> | 2017-03-21 11:46:51 -0700 |
commit | 9660e15264bd68ce4d62b64de2ea08e6b0debf37 (patch) | |
tree | 630a18c3400243517b54b557b071b2161ffdd550 | |
parent | 589360bcdaa337a125d08ad4ca66e2a19aef0aca (diff) | |
download | meta-clang-9660e15264bd68ce4d62b64de2ea08e6b0debf37.tar.gz |
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 <mkelly@xevo.com>
-rw-r--r-- | recipes-devtools/clang/clang/0004-llvm-allow-env-override-of-exe-path.patch | 36 | ||||
-rw-r--r-- | recipes-devtools/clang/clang_git.bb | 7 | ||||
-rw-r--r-- | recipes-devtools/clang/llvm-common/llvm-config | 41 |
3 files changed, 70 insertions, 14 deletions
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 @@ | |||
1 | From 60eb14f995e0359aef4ef144338d932cbf9c4531 Mon Sep 17 00:00:00 2001 | ||
2 | From: Martin Kelly <mkelly@xevo.com> | ||
3 | Date: Wed, 15 Mar 2017 10:50:25 -0700 | ||
4 | Subject: [PATCH] allow env override of exe path | ||
5 | |||
6 | When using a native llvm-config from inside a sysroot, we need llvm-config to | ||
7 | return the libraries, include directories, etc. from inside the sysroot rather | ||
8 | than from the native sysroot. Thus provide an env override for calling | ||
9 | llvm-config from a target sysroot. | ||
10 | |||
11 | Signed-off-by: Martin Kelly <mkelly@xevo.com> | ||
12 | --- | ||
13 | tools/llvm-config/llvm-config.cpp | 7 +++++++ | ||
14 | 1 file changed, 7 insertions(+) | ||
15 | |||
16 | diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp | ||
17 | index 25344e4..26724c1 100644 | ||
18 | --- a/tools/llvm-config/llvm-config.cpp | ||
19 | +++ b/tools/llvm-config/llvm-config.cpp | ||
20 | @@ -225,6 +225,13 @@ Typical components:\n\ | ||
21 | |||
22 | /// \brief Compute the path to the main executable. | ||
23 | std::string GetExecutablePath(const char *Argv0) { | ||
24 | + // Hack for Yocto: we need to override the root path when we are using | ||
25 | + // llvm-config from within a target sysroot. | ||
26 | + const char *Sysroot = std::getenv("YOCTO_ALTERNATE_EXE_PATH"); | ||
27 | + if (Sysroot != nullptr) { | ||
28 | + return Sysroot; | ||
29 | + } | ||
30 | + | ||
31 | // This just needs to be some symbol in the binary; C++ doesn't | ||
32 | // allow taking the address of ::main however. | ||
33 | void *P = (void *)(intptr_t)GetExecutablePath; | ||
34 | -- | ||
35 | 2.1.4 | ||
36 | |||
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 += "\ | |||
22 | file://0001-llvm-Remove-CMAKE_CROSSCOMPILING-so-it-can-cross-com.patch \ | 22 | file://0001-llvm-Remove-CMAKE_CROSSCOMPILING-so-it-can-cross-com.patch \ |
23 | file://0002-llvm-Do-not-assume-linux-glibc.patch \ | 23 | file://0002-llvm-Do-not-assume-linux-glibc.patch \ |
24 | file://0003-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \ | 24 | file://0003-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \ |
25 | file://0004-llvm-allow-env-override-of-exe-path.patch \ | ||
25 | " | 26 | " |
26 | 27 | ||
27 | # Clang patches | 28 | # Clang patches |
@@ -96,12 +97,6 @@ DEPENDS_remove_class-nativesdk = "nativesdk-binutils nativesdk-compiler-rt nativ | |||
96 | DEPENDS_append_class-nativesdk = " clang-native virtual/${TARGET_PREFIX}binutils-crosssdk virtual/${TARGET_PREFIX}gcc-crosssdk virtual/${TARGET_PREFIX}g++-crosssdk" | 97 | DEPENDS_append_class-nativesdk = " clang-native virtual/${TARGET_PREFIX}binutils-crosssdk virtual/${TARGET_PREFIX}gcc-crosssdk virtual/${TARGET_PREFIX}g++-crosssdk" |
97 | DEPENDS_append_class-target = " clang-cross-${TARGET_ARCH} ${@bb.utils.contains('TOOLCHAIN', 'gcc', 'virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}g++', '', d)}" | 98 | DEPENDS_append_class-target = " clang-cross-${TARGET_ARCH} ${@bb.utils.contains('TOOLCHAIN', 'gcc', 'virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}g++', '', d)}" |
98 | 99 | ||
99 | do_configure_prepend() { | ||
100 | # Fix paths in llvm-config | ||
101 | 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 | ||
102 | sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp | ||
103 | } | ||
104 | |||
105 | do_compile_prepend_class-native () { | 100 | do_compile_prepend_class-native () { |
106 | oe_runmake LLVM-tablegen-host | 101 | oe_runmake LLVM-tablegen-host |
107 | oe_runmake CLANG-tablegen-host | 102 | 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 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/bash |
2 | # Wrapper script for real llvm-config. Simply calls | 2 | # |
3 | # Wrapper script for llvm-config. Supplies the right environment variables | ||
4 | # for the target and delegates to the native llvm-config for anything else. This | ||
5 | # is needed because arguments like --ldflags, --cxxflags, etc. are set by the | ||
6 | # native compile rather than the target compile. | ||
7 | # | ||
3 | 8 | ||
4 | if [ $WANT_LLVM_RELEASE ]; then | 9 | SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" |
5 | exec `dirname $0`/${TARGET_PREFIX}llvm-config$WANT_LLVM_RELEASE ${@} | 10 | NEXT_LLVM_CONFIG="$(which -a llvm-config | sed -n 2p)" |
6 | else | 11 | export YOCTO_ALTERNATE_EXE_PATH="$(readlink -f "$SCRIPT_DIR/../llvm-config")" |
7 | echo "The variable WANT_LLVM_RELEASE is not defined and exported" | 12 | |
8 | echo "by your build recipe. Go figure." | 13 | if [[ $# == 0 ]]; then |
9 | exit 1 | 14 | exec "$NEXT_LLVM_CONFIG" |
10 | fi | 15 | fi |
16 | |||
17 | for arg in "$@"; do | ||
18 | case "$arg" in | ||
19 | --cppflags) | ||
20 | echo $TARGET_CPPFLAGS | ||
21 | ;; | ||
22 | --cflags) | ||
23 | echo $TARGET_CFLAGS | ||
24 | ;; | ||
25 | --cxxflags) | ||
26 | echo $TARGET_CXXFLAGS | ||
27 | ;; | ||
28 | --ldflags) | ||
29 | echo $TARGET_LDFLAGS | ||
30 | ;; | ||
31 | *) | ||
32 | echo "$("$NEXT_LLVM_CONFIG" "$arg")" | ||
33 | ;; | ||
34 | esac | ||
35 | done | ||