commit: 64a5154944610c040453e46284a20b9c2bde4d0e Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Sun Oct 16 12:26:44 2022 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Wed Oct 19 11:53:24 2022 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=64a51549
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 <AT> gentoo.org> eclass/llvm.eclass | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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=: