[Scons-users] How to simultaneously build pie executables and pic shared libraries?

Bill Deegan bill at baddogconsulting.com
Sat Oct 24 00:12:37 EDT 2015


Andrew,

Any reason you couldn't use several different environments with the flags
set as you want and then use the appropriate one for each type of file you
want to build?
Or you can just specify the flags on the builder:

env.Program(target,sources,
    PROGCCFLAGS=["-fpie"],
    SHCCFLAGS=["-fpic"],
    PROGLINKFLAGS=["-pie"])

-Bill

On Fri, Oct 23, 2015 at 8:19 PM, Andrew C. Morrow <andrew.c.morrow at gmail.com
> wrote:

>
> Hi -
>
> I think it is pretty straightforward to get PIE executables with SCons if
> all linking is static:
>
> env.AppendUnique(
>     CCFLAGS=["-fpie"],
>     LINKFLAGS=["-pie"],
> )
>
> How to make it work for a build with both executables and shared libraries
> is not as clear. The problem is that object files destined for the shared
> libraries need to still be built with -fpic and linked as normal, but
> object files destined for the executable need to be built with -fpie and
> then the executable must be linked with -pie:
>
> Doing this:
>
> env.AppendUnique(
>     CCFLAGS=["-fpie"],
>     SHCCFLAGS=["-fpic"],
>     LINKFLAGS=["-pie"],
> )
>
> doesn't work because objects being compiled for shared libraries receive
> both CCFLAGS and SHCCFLAGS. Similarly for linking, where the link step for
> shared libraries gets both LINKFLAGS and SHLINKFLAGS. We definitely don't
> want to pass -pie to our shared library builds, nor do we want both -fpie
> and -fpic on the compile line when building objects for shared libraries.
>
> It feels like there is a need for PROG[C|CC|CXX]FLAGS and PROGLINKFLAGS?
> In other words, compiler and linker flags analogous to the SH prefixed
> variants but that are only used when building objects for an executable or
> linking an executable.
>
> One idea I had was to modify CCCOM, CXXCOM, and LINKCOM to honor
> PROGC*FLAGS and PROGLINKFLAGS, though I'm not very excited about it. Then I
> could do this:
>
> env.AppendUnique(
>     PROGCCFLAGS=["-fpie"],
>     SHCCFLAGS=["-fpic"],
>     PROGLINKFLAGS=["-pie"],
> )
>
> Does this seem like a viable path to achieve PIE executables with PIC
> shared libraries, or am I going to run into surprises? Any thoughts on
> other ways to do this? Has anyone managed to make this work?
>
> Thanks,
> Andrew
>
>
> _______________________________________________
> Scons-users mailing list
> Scons-users at scons.org
> https://pairlist4.pair.net/mailman/listinfo/scons-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20151023/40e774c6/attachment.html>


More information about the Scons-users mailing list