diff options
author | Mike Frysinger <vapier@gentoo.org> | 2015-03-16 21:12:27 +0000 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2015-03-16 21:12:27 +0000 |
commit | 0690b00f733a6588a8e25e2bb74cd9b133e80529 (patch) | |
tree | 409944169800cb6eeb37d021f35bab9d0d4d04aa /eclass | |
parent | fixing download location in 9999 ebuild so it renames safely (diff) | |
download | gentoo-2-0690b00f733a6588a8e25e2bb74cd9b133e80529.tar.gz gentoo-2-0690b00f733a6588a8e25e2bb74cd9b133e80529.tar.bz2 gentoo-2-0690b00f733a6588a8e25e2bb74cd9b133e80529.zip |
tc-ld-is-gold/tc-ld-disable-gold: add helpers for detecting & disabling gold
Diffstat (limited to 'eclass')
-rwxr-xr-x | eclass/tests/toolchain-funcs.sh | 55 | ||||
-rw-r--r-- | eclass/toolchain-funcs.eclass | 69 |
2 files changed, 122 insertions, 2 deletions
diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh index d8fb97e5bc73..af440325990d 100755 --- a/eclass/tests/toolchain-funcs.sh +++ b/eclass/tests/toolchain-funcs.sh @@ -51,9 +51,62 @@ do if [[ ${actual} != ${exp:-${CHOST}} ]] ; then eerror "Failure for CHOST: ${CHOST} Expected: ${exp} != Actual: ${actual}" - ((++ret)) + : $((++ret)) fi done tend ${ret} +# +# TEST: tc-ld-is-gold +# +tbegin "tc-ld-is-gold (bfd selected)" +LD=ld.bfd tc-ld-is-gold && ret=1 || ret=0 +tend ${ret} + +tbegin "tc-ld-is-gold (gold selected)" +LD=ld.gold tc-ld-is-gold +ret=$? +tend ${ret} + +tbegin "tc-ld-is-gold (bfd selected via flags)" +LD=ld.gold LDFLAGS=-fuse-ld=bfd tc-ld-is-gold +ret=$? +tend ${ret} + +tbegin "tc-ld-is-gold (gold selected via flags)" +LD=ld.bfd LDFLAGS=-fuse-ld=gold tc-ld-is-gold +ret=$? +tend ${ret} + +# +# TEST: tc-ld-disable-gold +# +tbegin "tc-ld-disable-gold (bfd selected)" +( +export LD=ld.bfd LDFLAGS= +ewarn() { :; } +tc-ld-disable-gold +[[ ${LD} == "ld.bfd" && -z ${LDFLAGS} ]] +) +tend $? + +tbegin "tc-ld-disable-gold (gold selected)" +( +export LD=ld.gold LDFLAGS= +ewarn() { :; } +tc-ld-disable-gold +[[ ${LD} == "ld.bfd" || ${LDFLAGS} == *"-fuse-ld=bfd"* ]] +) +tend $? + +tbegin "tc-ld-disable-gold (gold selected via flags)" +( +export LD= LDFLAGS="-fuse-ld=gold" +ewarn() { :; } +tc-ld-disable-gold +[[ ${LD} == *"/ld.bfd" || ${LDFLAGS} == "-fuse-ld=gold -fuse-ld=bfd" ]] +) +tend $? + + texit diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass index 80317735f3be..d3c5a67eca29 100644 --- a/eclass/toolchain-funcs.eclass +++ b/eclass/toolchain-funcs.eclass @@ -1,6 +1,6 @@ # Copyright 1999-2015 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.134 2015/03/16 19:26:39 vapier Exp $ +# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v 1.135 2015/03/16 21:12:27 vapier Exp $ # @ECLASS: toolchain-funcs.eclass # @MAINTAINER: @@ -305,6 +305,73 @@ econf_build() { tc-env_build econf --build=${CBUILD} --host=${CBUILD} "$@" } +# @FUNCTION: tc-ld-is-gold +# @USAGE: [toolchain prefix] +# @DESCRIPTION: +# Return true if the current linker is set to gold. +tc-ld-is-gold() { + local out + + # First check the linker directly. + out=$($(tc-getLD "$@") --version 2>&1) + if [[ ${out} == *"GNU gold"* ]] ; then + return 0 + fi + + # Then see if they're selecting gold via compiler flags. + # Note: We're assuming they're using LDFLAGS to hold the + # options and not CFLAGS/CXXFLAGS. + local base="${T}/test-tc-gold" + cat <<-EOF > "${base}.c" + int main() { return 0; } + EOF + out=$($(tc-getCC "$@") ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -Wl,--version "${base}.c" -o "${base}" 2>&1) + rm -f "${base}"* + if [[ ${out} == *"GNU gold"* ]] ; then + return 0 + fi + + # No gold here! + return 1 +} + +# @FUNCTION: tc-ld-disable-gold +# @USAGE: [toolchain prefix] +# @DESCRIPTION: +# If the gold linker is currently selected, configure the compilation +# settings so that we use the older bfd linker instead. +tc-ld-disable-gold() { + if ! tc-ld-is-gold "$@" ; then + # They aren't using gold, so nothing to do! + return + fi + + ewarn "Forcing usage of the BFD linker instead of GOLD" + + # Set up LD to point directly to bfd if it's available. + local bfd_ld="$(tc-getLD "$@").bfd" + local path_ld=$(which "${bfd_ld}" 2>/dev/null) + [[ -e ${path_ld} ]] && export LD=${bfd_ld} + + # Set up LDFLAGS to select gold based on the gcc version. + local major=$(gcc-major-version "$@") + local minor=$(gcc-minor-version "$@") + if [[ ${major} -lt 4 ]] || [[ ${major} -eq 4 && ${minor} -lt 8 ]] ; then + # <=gcc-4.7 requires some coercion. Only works if bfd exists. + if [[ -e ${path_ld} ]] ; then + local d="${T}/bfd-linker" + mkdir -p "${d}" + ln -sf "${path_ld}" "${d}"/ld + export LDFLAGS="${LDFLAGS} -B${d}" + else + die "unable to locate a BFD linker to bypass gold" + fi + else + # gcc-4.8+ supports -fuse-ld directly. + export LDFLAGS="${LDFLAGS} -fuse-ld=bfd" + fi +} + # @FUNCTION: tc-has-openmp # @USAGE: [toolchain prefix] # @DESCRIPTION: |