Skip to content

Commit

Permalink
dwp should use post-bolt external debug information
Browse files Browse the repository at this point in the history
Summary: We are passing in pre-bolt dwo files to `llvm-dwp`. This is not a problem if `llvm-bolt` and `llvm-dwp` both run locally, but causes issue when we attempt to run them remotely to cache the binaries.

Reviewed By: keshavdv

Differential Revision: D68116838

fbshipit-source-id: e54b5894c31e68e65bab57b5965244659622c7b6
  • Loading branch information
Christy Lee-Eusman authored and facebook-github-bot committed Jan 14, 2025
1 parent 5845c5d commit 1cc08b9
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
21 changes: 19 additions & 2 deletions prelude/cxx/cxx_bolt.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ load(
)
load(":cxx_context.bzl", "get_cxx_toolchain_info")

CxxBoltOutput = record(
output = field(Artifact),
dwo_output = field(Artifact | None),
)

def cxx_use_bolt(ctx: AnalysisContext) -> bool:
cxx_toolchain_info = get_cxx_toolchain_info(ctx)
return cxx_toolchain_info.bolt_enabled and ctx.attrs.bolt_profile != None

def bolt(ctx: AnalysisContext, prebolt_output: Artifact, external_debug_info: ArtifactTSet, identifier: [str, None]) -> Artifact:
def bolt(ctx: AnalysisContext, prebolt_output: Artifact, external_debug_info: ArtifactTSet, identifier: [str, None], generate_dwp: bool) -> CxxBoltOutput:
output_name = prebolt_output.short_path.removesuffix("-wrapper")
postbolt_output = ctx.actions.declare_output(output_name)
dwo_output = None
bolt_msdk = get_cxx_toolchain_info(ctx).binary_utilities_info.bolt_msdk

if not bolt_msdk or not cxx_use_bolt(ctx):
Expand All @@ -41,6 +47,17 @@ def bolt(ctx: AnalysisContext, prebolt_output: Artifact, external_debug_info: Ar
hidden = materialized_external_debug_info,
)

if generate_dwp:
dwo_output = ctx.actions.declare_output(output_name + ".dwo.d", dir = True)
args.add(cmd_args(dwo_output.as_output(), format = "--dwarf-output-path={}"))
args = cmd_args(
"/bin/sh",
"-c",
cmd_args(dwo_output.as_output(), format = 'mkdir -p {}; "$@"'),
'""',
args,
)

ctx.actions.run(
args,
category = "bolt",
Expand All @@ -67,4 +84,4 @@ def bolt(ctx: AnalysisContext, prebolt_output: Artifact, external_debug_info: Ar
)
output = stripped_postbolt_output

return output
return CxxBoltOutput(output = output, dwo_output = dwo_output)
16 changes: 13 additions & 3 deletions prelude/cxx/dist_lto/dist_lto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,22 @@ def cxx_gnu_dist_link(
],
)

final_output = output if not (executable_link and cxx_use_bolt(ctx)) else bolt(ctx, output, external_debug_info, identifier)
if (executable_link and cxx_use_bolt(ctx)):
bolt_output = bolt(ctx, output, external_debug_info, identifier, generate_dwp)
final_output = bolt_output.output
split_debug_output = bolt_output.dwo_output
else:
final_output = output
split_debug_output = None

dwp_output = ctx.actions.declare_output(output.short_path.removesuffix("-wrapper") + ".dwp") if generate_dwp else None

if generate_dwp:
materialized_external_debug_info = project_artifacts(ctx.actions, [external_debug_info])
referenced_objects = final_link_inputs + materialized_external_debug_info
if split_debug_output:
referenced_objects = final_link_inputs + [split_debug_output]
else:
materialized_external_debug_info = project_artifacts(ctx.actions, [external_debug_info])
referenced_objects = final_link_inputs + materialized_external_debug_info
run_dwp_action(
ctx = ctx,
toolchain = cxx_toolchain,
Expand Down
17 changes: 12 additions & 5 deletions prelude/cxx/link.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,19 @@ def cxx_link_into(
strip_args = opts.strip_args_factory(ctx) if opts.strip_args_factory else cmd_args()
output = strip_object(ctx, cxx_toolchain_info, output, strip_args, opts.category_suffix)

final_output = output if not (is_result_executable and cxx_use_bolt(ctx)) else bolt(ctx, output, external_debug_info, opts.identifier)
use_bolt = (is_result_executable and cxx_use_bolt(ctx))
if use_bolt:
bolt_output = bolt(ctx, output, external_debug_info, opts.identifier, should_generate_dwp)
output = bolt_output.output
split_debug_output = bolt_output.dwo_output

dwp_artifact = None
if should_generate_dwp:
dwp_inputs = cmd_args()
dwp_from_dwo = getattr(ctx.attrs, "separate_debug_info", False) and cxx_toolchain_info.split_debug_mode == SplitDebugMode("split")
if dwp_from_dwo:
if use_bolt:
dwp_inputs.add([split_debug_output])
elif dwp_from_dwo:
dwp_inputs.add(project_identified_artifacts(ctx.actions, [external_debug_info]))
else:
for link in opts.links:
Expand All @@ -347,7 +353,7 @@ def cxx_link_into(
dwp_artifact = dwp(
ctx,
cxx_toolchain_info,
final_output,
output,
identifier = opts.identifier,
category_suffix = opts.category_suffix,
# TODO(T110378142): Ideally, referenced objects are a list of
Expand All @@ -358,10 +364,11 @@ def cxx_link_into(
from_exe = not dwp_from_dwo,
)

final_output = stamp_build_info(ctx, final_output) if is_result_executable else final_output
if is_result_executable:
output = stamp_build_info(ctx, output)

linked_object = LinkedObject(
output = final_output,
output = output,
link_args = opts.links,
bitcode_bundle = bitcode_artifact.artifact if bitcode_artifact else None,
prebolt_output = output,
Expand Down

0 comments on commit 1cc08b9

Please sign in to comment.