[Scons-users] smartlink and reiterating compile flags on the link step

Andrew C. Morrow andrew.c.morrow at gmail.com
Sat Oct 31 13:52:56 EDT 2015


Hi All -

It seems to me that when using smartlink and therefore using the C or C++
compiler to drive the link step for programs and shared libraries, that the
various C and C++ language compile flags should be reiterated on the link
step. In particular, without regard to ordering:

C link for static links should include: $CCFLAGS and $CFLAGS
C link for shared links should include $CCFLAGS, $CFLAGS, $SHCCFLAGS, and
$SHCFLAGS
C++ link for static links should include $CCFLAGS and $CXXFLAGS
C++ link for shared links should include $CCFLAGS, $SHCCFLAGS, $CXXFLAGS
and $SHCXXFLAGS

The rationale is that the presence of certain compile flags may mean that
the effects of other compile flags are deferred until link time. In
particular, if -flto is passed to the compile step, the desired
optimization level should be passed to both the compiler invocation for
objects, and to the linker invocation for programs or shared libraries.
Currently, that latter part doesn't happen with smartlink.

See, for instance the section titled "Be sure you get link-time
optimization flags right" here:
http://hubicka.blogspot.com/2014/04/linktime-optimization-in-gcc-2-firefox.html

I've also verified that building a C++ library (with g++ as the smartlink
selected linker) with

CCFLAGS="-flto -g -O3" LINKFLAGS='-flto -fuse-ld=gold'

vs

CCFLAGS="-flto -g -O3" LINKFLAGS='$CCFLAGS -fuse-ld=gold'

generate different binaries (interestingly, when using clang++ to drive the
link step, there is no difference).

Is there a way to configure smartlink  (which isn't really documented) so
that the appropriate set of compiler flags are reiterated on the link step?
Changing $LINKFLAGS and $SHLINKFLAGS doesn't seem quite right as they don't
differentiate between C and C++ linking. Or is this an improvement that
should be made to smartlink?

Thanks,
Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20151031/0094d652/attachment.html>


More information about the Scons-users mailing list