[Scons-users] Using a Decider to prevent shared lib relinks

Bill Deegan bill at baddogconsulting.com
Mon May 25 17:26:19 EDT 2020


Olivier,

You're not the first to head down this path as it would be useful to
(configurably) avoid such unnecessary relinks.
I think MongoDB has implemented something like this.

Please keep in mind that dep and tgt are not strings, the are File() nodes,
which have access to information stored in .sconsign with regards to the
signature of the file from the previous build.
This is (currently) a md5sum of the full contents of the file.
So to adequately do what you're thinking you'd need a way to store the ABI
info (or a hash thereof) as the content signature (also known as csig) for
the node(s) in question.

So it's going to be a pretty deep dive into the code.

Perhaps someone from MongoDB will chime in here with a pointer to their
code/experience.

-Bill

On Mon, May 25, 2020 at 10:11 AM <orenaud at coventor.com> wrote:

> Hi,
>
> I want to prevent unnecessary re-links against my shared libraries. By
> "unnecessary", I mean the re-links that happen even when the list of
> exported symbols did not change.
>
> In practice, I would like to use the output of `nm --extern-only` on Linux
> or `dumpbin /exports` on Windows as the content to use for the signature of
> the shared library.
>
> I was able to approximate this on a simple example, by explicitly
> specifying the dependency of a target (myExe) that links against a specific
> shared library (myLib.lib):
>
> def dumpLibSymbols(target, source, env):
>     with open(str(target[0]), 'w') as dumpFile:
>         nm = WhereIs('nm', env['ENV']['PATH'])
>         subprocess.call([nm, '--extern-only', str(source[0])], stdout=dumpFile)
>
> dumpLibSymbolsAction = Action(dumpLibSymbols,
>                               "Dumping Symbols for $SOURCE into $TARGET")
> dumpLibSymbolsBuilder = Builder(action=dumpLibSymbolsAction,
>                                 src_suffix="$LIBSUFFIX",
>                                 suffix=".lib.exports")
> env.Append(BUILDERS= {'DumpLibSymbols': dumpLibSymbolsBuilder})
>
> Ignore(myExe, 'myLib.lib')
> Depends(myExe, 'myLib.lib.exports')
>
> Basically, it changes the dependency chain [myExe -> myLib.lib] to [myExe
> -> myLib.lib.exports -> myLib.lib], without changing the link command
> itself.
>
> While this example works, I am unable to generalize it: the calls to
> Ignore and Depends must be explicit for all the pairs exe/lib (or lib/lib).
> What I want is for it to be automatic for anything that depends on a shared
> library.
>
> It seems to me that the Decider function (
> https://scons.org/doc/production/HTML/scons-user/ch06.html#idm962) is
> exactly what I need. Indeed, I want to decide a target is out of date based
> on the output of nm/dumpbin. The problem is that I don't understand how I
> can do that in practice. The example in the docs uses an unspecified
> `specific_part_of_file_has_changed(dep, tgt)` function, but I don't see how
> this function can do its job given its inputs. To me, this function needs
> an additional information: the previous content of the dependency file (or
> a hash of only the part it is interested in). Similarly, my custom Decider
> would also need to know the previous content of nm/dumpbin in addition to
> its current content.
>
> Can someone points me to a real world usage of the Decider function? Is it
> the right tool I need, or did I overlook a better way to achieve my goal?
>
> Thanks,
>
> Olivier Renaud
> _______________________________________________
> 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/20200525/4919a823/attachment-0001.html>


More information about the Scons-users mailing list