commit:     7ce7d487acf67d28db2eea56569c6fcb499bf6c9
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Mar 20 18:22:24 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Mar 20 18:22:24 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=7ce7d487

eclass/toolchain-funcs: sync, bug #576680

 eclass/toolchain-funcs.eclass | 125 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 102 insertions(+), 23 deletions(-)

diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
index e6ebd49..4a5c5e1 100644
--- a/eclass/toolchain-funcs.eclass
+++ b/eclass/toolchain-funcs.eclass
@@ -1,6 +1,6 @@
-# Copyright 1999-2014 Gentoo Foundation
+# 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.131 
2014/11/01 05:19:20 vapier Exp $
+# $Id$
 
 # @ECLASS: toolchain-funcs.eclass
 # @MAINTAINER:
@@ -84,6 +84,10 @@ tc-getRANLIB() { tc-getPROG RANLIB ranlib "$@"; }
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the object copier
 tc-getOBJCOPY() { tc-getPROG OBJCOPY objcopy "$@"; }
+# @FUNCTION: tc-getOBJDUMP
+# @USAGE: [toolchain prefix]
+# @RETURN: name of the object dumper
+tc-getOBJDUMP() { tc-getPROG OBJDUMP objdump "$@"; }
 # @FUNCTION: tc-getF77
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the Fortran 77 compiler
@@ -96,6 +100,10 @@ tc-getFC() { tc-getPROG FC gfortran "$@"; }
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the java compiler
 tc-getGCJ() { tc-getPROG GCJ gcj "$@"; }
+# @FUNCTION: tc-getGO
+# @USAGE: [toolchain prefix]
+# @RETURN: name of the Go compiler
+tc-getGO() { tc-getPROG GO gccgo "$@"; }
 # @FUNCTION: tc-getPKG_CONFIG
 # @USAGE: [toolchain prefix]
 # @RETURN: name of the pkg-config tool
@@ -219,10 +227,13 @@ tc-is-static-only() {
 # Export common build related compiler settings.
 tc-export_build_env() {
        tc-export "$@"
+       # Some build envs will initialize vars like:
+       # : ${BUILD_LDFLAGS:-${LDFLAGS}}
+       # So make sure all variables are non-empty. #526734
        : ${BUILD_CFLAGS:=-O1 -pipe}
        : ${BUILD_CXXFLAGS:=-O1 -pipe}
-       : ${BUILD_CPPFLAGS:=}
-       : ${BUILD_LDFLAGS:=}
+       : ${BUILD_CPPFLAGS:= }
+       : ${BUILD_LDFLAGS:= }
        export BUILD_{C,CXX,CPP,LD}FLAGS
 
        # Some packages use XXX_FOR_BUILD.
@@ -297,7 +308,78 @@ tc-env_build() {
 # }
 # @CODE
 econf_build() {
-       tc-env_build econf --build=${CBUILD:-${CHOST}} "$@"
+       local CBUILD=${CBUILD:-${CHOST}}
+       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.
+       # We need to extract the first word in case there are flags appended
+       # to its value (like multilib).  #545218
+       local ld=$(tc-getLD "$@")
+       local bfd_ld="${ld%% *}.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
@@ -397,10 +479,10 @@ ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
                arm*)           echo arm;;
                avr*)           ninj avr32 avr;;
                bfin*)          ninj blackfin bfin;;
-               c6x)            echo c6x;;
+               c6x*)           echo c6x;;
                cris*)          echo cris;;
-               frv)            echo frv;;
-               hexagon)        echo hexagon;;
+               frv*)           echo frv;;
+               hexagon*)       echo hexagon;;
                hppa*)          ninj parisc hppa;;
                i?86*)
                        # Starting with linux-2.6.24, the 'x86_64' and 'i386'
@@ -414,11 +496,12 @@ ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
                        ;;
                ia64*)          echo ia64;;
                m68*)           echo m68k;;
-               metag)          echo metag;;
+               metag*)         echo metag;;
+               microblaze*)    echo microblaze;;
                mips*)          echo mips;;
                nios2*)         echo nios2;;
                nios*)          echo nios;;
-               or32)           echo openrisc;;
+               or32*)          echo openrisc;;
                powerpc*)
                        # Starting with linux-2.6.15, the 'ppc' and 'ppc64' 
trees
                        # have been unified into simply 'powerpc', but until 
2.6.16,
@@ -441,7 +524,7 @@ ninj() { [[ ${type} == "kern" ]] && echo $1 || echo $2 ; }
                        ;;
                riscv*)         echo riscv;;
                s390*)          echo s390;;
-               score)          echo score;;
+               score*)         echo score;;
                sh64*)          ninj sh64 sh;;
                sh*)            echo sh;;
                sparc64*)       ninj sparc64 sparc;;
@@ -674,7 +757,9 @@ gen_usr_ldscript() {
        # Eventually we'd like to get rid of this func completely #417451
        case ${CTARGET:-${CHOST}} in
        *-darwin*) type -P scanmacho > /dev/null || return ;;  # excluded for 
now due to known breakage
-       *linux*|*-freebsd*|*-openbsd*|*-netbsd*|*-solaris*) type -P scanelf > 
/dev/null || return;;  # Prefix
+       *-android*) return 0 ;;
+       *linux*|*-freebsd*|*-openbsd*|*-netbsd*)
+               use prefix && return 0 ;;
        *) return 0 ;;
        esac
 
@@ -719,10 +804,7 @@ gen_usr_ldscript() {
                        else
                                tlib=$(scanmacho -qF'%S#F' 
"${ED}"/${libdir}/${lib})
                        fi
-                       if [[ -z ${tlib} ]] ; then
-                               ewarn "gen_usr_ldscript: unable to read 
install_name from ${lib}"
-                               tlib=${lib}
-                       fi
+                       [[ -z ${tlib} ]] && die "unable to read install_name 
from ${lib}"
                        tlib=${tlib##*/}
 
                        if ${auto} ; then
@@ -731,7 +813,7 @@ gen_usr_ldscript() {
                                if [[ ${tlib} != ${lib%${suffix}}.*${suffix#.} 
]] ; then
                                        mv 
"${ED}"/usr/${libdir}/${tlib%${suffix}}.*${suffix#.} "${ED}"/${libdir}/ || die
                                fi
-                               [[ ${tlib} != ${lib} ]] && rm -f 
"${ED}"/${libdir}/${lib}
+                               rm -f "${ED}"/${libdir}/${lib}
                        fi
 
                        # Mach-O files have an id, which is like a soname, it 
tells how
@@ -778,16 +860,13 @@ gen_usr_ldscript() {
                *)
                        if ${auto} ; then
                                tlib=$(scanelf -qF'%S#F' 
"${ED}"/usr/${libdir}/${lib})
-                               if [[ -z ${tlib} ]] ; then
-                                       ewarn "gen_usr_ldscript: unable to read 
SONAME from ${lib}"
-                                       tlib=${lib}
-                               fi
+                               [[ -z ${tlib} ]] && die "unable to read SONAME 
from ${lib}"
                                mv "${ED}"/usr/${libdir}/${lib}* 
"${ED}"/${libdir}/ || die
                                # some SONAMEs are funky: they encode a version 
before the .so
                                if [[ ${tlib} != ${lib}* ]] ; then
                                        mv "${ED}"/usr/${libdir}/${tlib}* 
"${ED}"/${libdir}/ || die
                                fi
-                               [[ ${tlib} != ${lib} ]] && rm -f 
"${ED}"/${libdir}/${lib}
+                               rm -f "${ED}"/${libdir}/${lib}
                        else
                                tlib=${lib}
                        fi
@@ -799,7 +878,7 @@ gen_usr_ldscript() {
                           redirects the linker to the real lib.  And yes, this 
works in the cross-
                           compiling scenario as the sysroot-ed linker will 
prepend the real path.
 
-                          See bug http://bugs.gentoo.org/4411 for more info.
+                          See bug https://bugs.gentoo.org/4411 for more info.
                         */
                        ${output_format}
                        GROUP ( ${EPREFIX}/${libdir}/${tlib} )

Reply via email to