vapier      15/03/16 21:12:27

  Modified:             toolchain-funcs.eclass
  Log:
  tc-ld-is-gold/tc-ld-disable-gold: add helpers for detecting & disabling gold

Revision  Changes    Path
1.135                eclass/toolchain-funcs.eclass

file : 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/toolchain-funcs.eclass?rev=1.135&view=markup
plain: 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/toolchain-funcs.eclass?rev=1.135&content-type=text/plain
diff : 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/eclass/toolchain-funcs.eclass?r1=1.134&r2=1.135

Index: toolchain-funcs.eclass
===================================================================
RCS file: /var/cvsroot/gentoo-x86/eclass/toolchain-funcs.eclass,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- toolchain-funcs.eclass      16 Mar 2015 19:26:39 -0000      1.134
+++ toolchain-funcs.eclass      16 Mar 2015 21:12:27 -0000      1.135
@@ -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 @@
        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:




Reply via email to