diff options
author | Michał Górny <mgorny@gentoo.org> | 2022-10-16 14:26:44 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2022-10-19 13:53:24 +0200 |
commit | 64a5154944610c040453e46284a20b9c2bde4d0e (patch) | |
tree | e02ae23c3c400820991186135ebd44810863d680 /eclass/llvm.eclass | |
parent | llvm.eclass: Fix CC/CXX version to prevent the eclass overriding it (diff) | |
download | gentoo-64a5154944610c040453e46284a20b9c2bde4d0e.tar.gz gentoo-64a5154944610c040453e46284a20b9c2bde4d0e.tar.bz2 gentoo-64a5154944610c040453e46284a20b9c2bde4d0e.zip |
llvm.eclass: Fix LLVM tool paths to prevent overriding them
Fix the LLVM tool path in variables such as AR, LD, etc. to their
current locations prior to manipulating PATH, in order to prevent
llvm.eclass from overriding them. Otherwise, a package requiring older
LLVM libraries could force older tool versions, possibly incompatible
with the object files produced by a newer clang version.
Closes: https://github.com/gentoo/gentoo/pull/27803
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/llvm.eclass')
-rw-r--r-- | eclass/llvm.eclass | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/eclass/llvm.eclass b/eclass/llvm.eclass index 39299d06dbe9..16596ec2ea66 100644 --- a/eclass/llvm.eclass +++ b/eclass/llvm.eclass @@ -214,6 +214,30 @@ llvm_fix_clang_version() { ${shopt_save} } +# @FUNCTION: llvm_fix_tool_path +# @USAGE: <variable-name>... +# @DESCRIPTION: +# Fix the LLVM tools referenced in the specified variables to their +# current location, to prevent PATH alterations from forcing older +# versions being used. +llvm_fix_tool_path() { + debug-print-function ${FUNCNAME} "${@}" + + local shopt_save=$(shopt -p -o noglob) + set -f + local var + for var; do + local split=( ${!var} ) + local path=$(type -P ${split[0]} 2>/dev/null) + # if it resides in one of the LLVM prefixes, it's an LLVM tool! + if [[ ${path} == "${BROOT}/usr/lib/llvm"* ]]; then + split[0]=${path} + declare -g "${var}=${split[*]}" + fi + done + ${shopt_save} +} + # @FUNCTION: llvm_pkg_setup # @DESCRIPTION: # Prepend the appropriate executable directory for the newest @@ -233,6 +257,9 @@ llvm_pkg_setup() { if [[ ${MERGE_TYPE} != binary ]]; then llvm_fix_clang_version CC CPP CXX + # keep in sync with profiles/features/llvm/make.defaults! + llvm_fix_tool_path ADDR2LINE AR AS LD NM OBJCOPY OBJDUMP RANLIB + llvm_fix_tool_path READELF STRINGS STRIP local llvm_path=$(get_llvm_prefix "${LLVM_MAX_SLOT}")/bin local IFS=: |