Gentoo Wiki ArchivesGentoo Wiki

TIP_Safe_LDFLAGS

Contents

Safe LDFLAGS ?

LDFLAGS="-Wl,-O1"

This tells ld to optimize the hash table. As a side effect the hash table gets larger. This optimization is usually safe. For more information see this article

Remove unneeded symbol references during linking

LDFLAGS="-Wl,--as-needed"

The case for and against --as-needed

Other LDFLAGS, not necessarily safe

LDFLAGS="-Wl,--sort-common"
LDFLAGS="-Wl,--relax"

Per package LDFLAGS

It is possible to set the LDFLAGS on a per-package basis. Just create the following file:

File: /etc/portage/bashrc
## Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /etc/portage/bashrc$
# Originally written by Ned Ludd (solar_at_gentoo.org)
# modifications by Ryan McIntosh (thebigslide_at_gmail.com)
# V1.0_rc1
# - /etc/portage/bashrc

loopize()
{
   local file=$1
   local var
   
   # Bail if file does not exist or is not readable.
   [ -r ${ROOT}/etc/portage/package.$file ] || return 0
      
   while read -a target
   do
      unset var
      if [ "${target}" = "${CATEGORY}" -o "${target}" = "${CATEGORY}/${PN}" ]
      then
         unset `echo $file | /usr/bin/tr a-z A-Z`
         # Skip the package part of the line
         target[0]=""
         for i in "${target[@]}"
         do
            case "$i" in
               GLOBALCFLAGS) var="$var $GLOBALCFLAGS" ;;
               GLOBALCXXFLAGS) var="$var $GLOBALCXXFLAGS" ;;
               GLOBALLDFLAGS) var="$var $GLOBALLDFLAGS" ;;
               GLOBALFEATURES) var="$var $GLOBALFEATURES" ;;
               *) var="$var $i"
            esac
         done
         export `echo $file | /usr/bin/tr a-z A-Z`="`echo $var`"
      fi
   done < ${ROOT}/etc/portage/package.$file
}

if [ "$0" = "/usr/lib/portage/bin/ebuild.sh" -o "$0" = "/usr/lib/portage/bin/ebuild-daemon.sh" ]
then
   export GLOBALCFLAGS=$CFLAGS
   export GLOBALCXXFLAGS=$CXXFLAGS
   export GLOBALLDFLAGS=$LDFLAGS
   export GLOBALFEATURES=$FEATURES
   loopize "cflags"
   loopize "cxxflags"
   loopize "ldflags"
   loopize "features"
   unset GLOBALCFLAGS
   unset GLOBALCXXFLAG
   unset GLOBALLDFLAGS
   unset GLOBALFEATURES
else
   echo "This bashrc does not know anything about $0"
fi

and add you local LDFLAGS in the file /etc/portage/package.ldflags as in the following example:

File: /etc/portage/package.ldflags
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

# - /etc/portage/package.ldflags

##############
# Important: #
##############
# >=dev-blah/blah syntax is not supported by this files.
# We can take individual category names
# Or we can take individual ebuild names
# Changes to this file OVERRIDE settings in make.conf

##############
# CATEGORIES #
##############
app-editors -Wl,-O1 -Wl,--as-needed
sys-apps GLOBALLDFLAGS -Wl,-O1

#################
# PACKAGE NAMES #
#################
net-www/mozilla -Wl,-O1

where GLOBALLDFLAGS will be substituted by the LDFLAGS specified in /etc/make.conf. This script can also be used to specify local CFLAGS and CXXFLAGS.

See Also

Retrieved from "http://www.gentoo-wiki.info/Safe_LDFLAGS"

Last modified: Fri, 05 Sep 2008 14:19:00 +1000 Hits: 28,059

Created by NickStallman.net, Luxury Homes Australia
Real estate agents should list their apartments, townhouses and units in Australia.