[Scons-users] Adding support for split dwarf info

Andrew C. Morrow andrew.c.morrow at gmail.com
Thu Jul 28 15:45:18 EDT 2016


I'd like to write a SCons Tool to support debug fission:

https://gcc.gnu.org/wiki/DebugFission

The motivation for doing so is to reduce the duplication of DWARF debugging
information in the SCons cache. In a large statically linked codebase, each
binary that is injected into the cache contains its own copy of the DWARF
info for each .o that it linked. Especially for things like unit tests,
this may result in many many copies of the same DWARF info taking up space
in the cache.

If we could use debug fission, then all of the debug information would be
contained only in .dwo files, and not reproduced in each executable.

The effect of adding -gsplit-dwarf to CCFLAGS is that each invocation of
the compiler to generate a .o file from a C or C++ source file also emits a
.dwo file. To achieve the aim of making the cache smaller, but also keep
the debugging information consistent, it is important that this .dwo file
move into and out of the cache in tandem with its associated .o file.

However, I'm having some trouble making this work. My idea was to add an
emitter to the various Object builders that added the .dwo file to the
associated targets. This "works", in the sense that the emitter runs.
However, the .dwo file is never pushed to the Cache.

Additionally, SCons seems not to know how to build the .dwo file: if named
as an explicit target, the build fails. I had assumed, mistakenly it seems,
that the additional emitted target would associate it with the Action, but
this does not seem to be the case.

Here is what I have so far, suggestions on how to take this further are
much appreciated:

import SCons
import itertools

def _dwo_emitter(target, source, env):
    new_targets = []
    for t in target:
        dwo = SCons.Util.splitext(str(t))[0] + ".dwo"
        dwotarget = (t.builder.target_factory or env.File)(dwo)
        print(str(dwotarget))
        new_targets.append(dwotarget)
    targets = target + new_targets
    return (targets, source)

def generate(env):

    env.Append(
        CCFLAGS=[
            "-gsplit-dwarf",
        ],
        LINKFLAGS=[
            "-fuse-ld=gold",
            "-Wl,--gdb-index",
        ]
    )

    # TODO: This should filter for C/C++ language files only
    for object_builder in SCons.Tool.createObjBuilders(env):
        emitterdict = object_builder.builder.emitter
        for suffix in emitterdict.iterkeys():
            base = emitterdict[suffix]
            emitterdict[suffix] = SCons.Builder.ListEmitter([
                base,
                _dwo_emitter,
            ])

def exists(env):
    return true

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


More information about the Scons-users mailing list