Safe LDFLAGS

Safe LDFLAGS?
Default LDFLAGS choice in Gentoo is:

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

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/.

You can read more about the case for and against --as-needed here.

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)

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

and add your local LDFLAGS in the file, as in the following example:

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