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

orenaud at coventor.com orenaud at coventor.com
Mon May 25 13:11:20 EDT 2020


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://pairlist4.pair.net/pipermail/scons-users/attachments/20200525/7157e1d6/attachment.html>


More information about the Scons-users mailing list