Safe LDFLAGS
From Gentoo Linux Wiki
Contents |
[edit] Safe LDFLAGS ?
The safe choice is to use "-Wl,-O1":
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 http://lwn.net/Articles/192082/.
To remove unneeded symbol references during linking, use:
LDFLAGS="-Wl,--as-needed"
You can read more about the case for and against --as-needed here.
Please do not include any flags that aren't 100% safe. Just because it works for you doesn't mean it will for everyone else.
We aren't interested in benchmark scores, personal anecdotes, rumors, things your really smart uncle once told you, random flags that made your box dispense root beer, or any other discussion or debate. It will be removed. Take it to the talk page or the appropriate forum. Thanks.
[edit] Other LDFLAGS, not necessarily safe
LDFLAGS="-Wl,--sort-common" LDFLAGS="-Wl,--relax"
Notes:
- -Wl,--relax will break glibc
- -Wl,--export-dynamic will also break glibc (or possibly its combination with -Wl,-O1)
[edit] Per package LDFLAGS
It is possible to set the LDFLAGS on a per-package basis. Just create the following file:
## 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 your local LDFLAGS in the file /etc/portage/package.ldflags, as in the following example:
# 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.