My understanding is that --fission is supposed to be a cross-platform way to generate separate debug info files for C/C++ rules (this is definitely stretching it a bit; I think --fission is intended to be .dwo/.dwp specific – that is, it's not supposed to generate .dSYMs on macOS and .pdbs on Windows).
In practice, --fission=yes alone does not generate non-empty .dwp files; --features=per_object_debug_info must also be specified.
This is because unix_cc_toolchain_config.bzl's cc_toolchain_config does not enable the per_object_debug_info feature by default.
Passing in --features=per_object_debug_info to enable it manually (i.e. in a .bazelrc) is sub-optimal because this breaks compilation on other platforms like macOS where -gsplit-dwarf has different behavior and will not produce .dwo files (on macOS debug info lives in the .o files – as in there is no .dwo equivalent – and running with -gsplit-dwarf when producing a binary will produce a .dSYM file, the .dwp equivalent).
It seems better to have the toolchain – which knows the platform it targets and has enough information to choose to enable this feature – handle this rather than to foist this onto users (afaik there isn't a create way to deal with this outside of the toolchain anyways; best I can come up with is build:linux --features=per_object_debug_info and then requiring --config=linux when building for Linux, etc.).
I think it's actually safe for us to enable the per_object_debug_info feature by default on Linux because it's effectively gated on fission:
steps
While we're still using unix_cc_toolchain_config.bzl there's not much we can do about this. These are notes for what to do when we eventually vendor in a version of unix_cc_toolchain_config.bzl (and potentially macOS and Windows host counterparts as well).
It's not clear yet whether this is doable/sensible but it'd be nice to have --fission (or some flag like it) cause rules_cc to generate split debug info for all the targets that support it. This would mean:
- generating
dSYM files on macOS (but only on the final link step)
- no idea what the story is for Windows
- there's
generate_pdb_file which seems to work similarly enough to .dwp files except that it's output_group based instead of a separate target (it'd have been nice to just have a debug_info output group for all these files...) and the logic seems to live inside of bazel instead of in the toolchain features
All in all, probably not pursuing. We should do the first thing though.
open questions
My understanding is that
--fissionis supposed to be a cross-platform way to generate separate debug info files for C/C++ rules (this is definitely stretching it a bit; I think--fissionis intended to be.dwo/.dwpspecific – that is, it's not supposed to generate.dSYMs on macOS and.pdbs on Windows).In practice,
--fission=yesalone does not generate non-empty.dwpfiles;--features=per_object_debug_infomust also be specified.This is because
unix_cc_toolchain_config.bzl'scc_toolchain_configdoes not enable theper_object_debug_infofeature by default.Passing in
--features=per_object_debug_infoto enable it manually (i.e. in a.bazelrc) is sub-optimal because this breaks compilation on other platforms like macOS where-gsplit-dwarfhas different behavior and will not produce.dwofiles (on macOS debug info lives in the.ofiles – as in there is no.dwoequivalent – and running with-gsplit-dwarfwhen producing a binary will produce a.dSYMfile, the.dwpequivalent).It seems better to have the toolchain – which knows the platform it targets and has enough information to choose to enable this feature – handle this rather than to foist this onto users (afaik there isn't a create way to deal with this outside of the toolchain anyways; best I can come up with is
build:linux --features=per_object_debug_infoand then requiring--config=linuxwhen building for Linux, etc.).I think it's actually safe for us to enable the
per_object_debug_infofeature by default on Linux because it's effectively gated onfission:per_object_debug_infofeature (which we cans see introduces the-gsplit-dwarfflag) lives hereper_object_debug_info_fileper_object_debug_info_filecomes from here in Bazel and is ultimately set by this bit inCompileBuildVariables.setupSpecificVariableswhen given a realdwoFileCcCompilationHelper.setupCompileBuildVariableswhich just threads through thedwoFileit's called withCcCompilationHelper.createSourceActionwhich provide adwoFileto ^ if they are passedgenerateDwo = trueCcCompilationHelper.createCcCompileActionswhich ultimately ask the currentccToolchain(CcToolchainProvider.shouldCreatePerObjectDebugInfo) if generating per object debug info is enabled for the current feature configurationCcToolchainProvider.shouldCreatePerObjectDebugInforeturns true only iffissionis enabled and if theper_object_debug_infofeature is enabledsteps
While we're still using
unix_cc_toolchain_config.bzlthere's not much we can do about this. These are notes for what to do when we eventually vendor in a version ofunix_cc_toolchain_config.bzl(and potentially macOS and Windows host counterparts as well).per_object_debug_infoby defaultper_object_debug_infoflag explicitly; passing in--fission=yesshould be sufficient--features=per_object_debug_infosets the debug level high enough to generate.dwofilesper_object_debug_infofor Clang 12 and GCC 11 bazelbuild/rules_cc#115 has a fixper_object_debug_infofor Clang 12 and GCC 11 bazelbuild/rules_cc#115 doesn't get merged we should do something like it when we switch to using our ownunix_cc_toolchain_config.bzl-c dbgtransition workaround that was added in Include the symlinked dwp/objcopy/strip files in the toolchain #108 when we do thisIt's not clear yet whether this is doable/sensible but it'd be nice to have
--fission(or some flag like it) causerules_ccto generate split debug info for all the targets that support it. This would mean:dSYMfiles on macOS (but only on the final link step)--features=apple_generate_dsym) but I don't think that helpsrules_ccto give us top-level exposed.dSYMtargetsgenerate_pdb_filewhich seems to work similarly enough to.dwpfiles except that it'soutput_groupbased instead of a separate target (it'd have been nice to just have adebug_infooutput group for all these files...) and the logic seems to live inside ofbazelinstead of in the toolchain featuresAll in all, probably not pursuing. We should do the first thing though.
open questions
cc_toolchainactually do.per_object_debug_infofeature is not associated with the toolchainsunix_cc_toolchain_config.bzlproduces for macOS but if I enable the feature manually with--features=per_object_debug_infoI can see that feature's flags being added to the commands executed)cc_common.create_cc_toolchain_config_infoultimately is backed byccToolchainConfigInfoFromStarlarkbut other than getting stored here I haven't really been able to tell what the features that are passed in get used for. I'll look into this more later.