[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: -Wl,--as-needed considered possibly harmful



On Sun, Dec 09, 2007, Simon Richter wrote:
> If there are broken scripts adding too many libraries then it is time to
> fix those scripts, not employ an evil hack that makes the symptoms go away.

 We met actual cases were --as-needed breaks things; however, for pure C
 program, I think combining it with "-z defs" should be safe:
    LDFLAGS += -Wl,-z,defs -Wl,--as-needed

 Sadly, there are many cases where "-z defs" will actually fail the
 build, for example when creating Python bindings: these may not be
 linked to libpython or to python as they might be loaded from either
 one, and you don't want to load the other one (if you run within
 python, you don't want to load libpython and vice-versa).  In such
 cases, -z defs will fail the build because of missing link flags for
 the Python symbols.

 I heartily agree with other people that fixing the build rules to not
 add superfluous link flags is the best thing to do, but this ain't easy
 in many cases, and --as-needed might allow us to benefit from shorter
 Depends immediately.  If fixing the build is too hard and your build
 passes with -z defs, then you are probably safe with --as-needed.


 NB: -z defs is the same as --no-undefined.
-- 
Loïc Minier



Reply to: