[cmake-developers] Ubuntu 15.10 and --[no-]-as-needed

Roger Leigh rleigh at codelibre.net
Tue Nov 17 18:51:13 EST 2015


I've just upgraded my work development system to Ubuntu 15.10.  While 
testing the FindBoost work in a separate thread, I noticed that with 
this release the system linker is using --as-needed by default.  This 
means that the system no longer respects the compiler linker arguments, 
and will deliberately fail to link any libraries for which it can't see 
any symbols being used.

While this is possibly useful in trimming unnecessary libraries from 
DT_NEEDED where they are genuinely unused and removal is harmless, it 
completely breaks the case where there is no direct symbol usage but the 
library is still required for correct functioning of the library or 
program, e.g. as a side-effect of ELF constructors for C++ static 
initialisation and destruction.  One case in point: boost_log_setup.  If 
I explicitly request it be linked, it's automatically dropped, against 
my specific wishes.

While previously such behaviour could be explicitly enabled by using 
-Wl,--as-needed, it's now the case that if you want the old correct 
behaviour you need to explictly *disable* with -Wl,--no-as-needed. 
While I can see this was useful for certain reasons, I think this is a 
terrible default.

The reason for bringing this up here is to ask whether this is something 
CMake should expose as a property to allow some measure of control. 
Given that it's a positional parameter which can be turned off and on on 
a per-library basis for each target, I'm not sure how that could be 
done, unless e.g. dummy interface targets could be added to the target 
link libraries to inject the linker options in the correct positions (if 
that's possible).


Regards,
Roger


More information about the cmake-developers mailing list