This is an archive of the discontinued LLVM Phabricator instance.

[lldb][crashlog] Avoid specifying arch for image when a UUID is present
ClosedPublic

Authored by vsk on Sep 17 2021, 4:34 PM.

Details

Summary

When adding an image to a target for crashlog purposes, avoid specifying
the architecture of the image.

This has the effect of making SBTarget::AddModule infer the ArchSpec for
the image based on the SBTarget's architecture, which LLDB puts serious
effort into calculating correctly (in TargetList::CreateTargetInternal).

The status quo is that LLDB randomly guesses the ArchSpec for a module
if its architecture is specified, via:

  SBTarget::AddModule -> Platform::GetAugmentedArchSpec -> Platform::IsCompatibleArchitecture ->
GetSupportedArchitectureAtIndex -> {ARM,x86}GetSupportedArchitectureAtIndex

... which means that the same crashlog can fail to load on an Apple
Silicon Mac (due to the random guess of arm64e-apple-macosx for the
module's ArchSpec not being compatible with the SBTarget's (correct)
ArchSpec), while loading just fine on an Intel Mac.

I'm not sure how to add a test for this (it doesn't look like there's
test coverage of this path in-tree). It seems like it would be pretty
complicated to regression test: the host LLDB would need to be built for
arm64e, we'd need a hand-crafted arm64e iOS crashlog, and we'd need a
binary with an iOS deployment target. I'm open to other / simpler
options.

rdar://82679400

Diff Detail

Event Timeline

vsk created this revision.Sep 17 2021, 4:34 PM
vsk requested review of this revision.Sep 17 2021, 4:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2021, 4:34 PM
jasonmolenda accepted this revision.Sep 17 2021, 11:21 PM

Yeah, on macOS we'll always have a UUID so this is a good change. The only time an arch is really important is if we don't have a UUID and we have a universal binary (aka fat file) & need to select the correct architecture.

This revision is now accepted and ready to land.Sep 17 2021, 11:21 PM

Without having dug into this deeper, do you think not specifying the arch could cause any problems with universal binaries? I guess not, because we still have the UUID, and the UUID is per arch?

vsk added a comment.Sep 21 2021, 3:38 PM

Without having dug into this deeper, do you think not specifying the arch could cause any problems with universal binaries? I guess not, because we still have the UUID, and the UUID is per arch?

Exactly. The bug in question actually did source universal binaries: CreateTargetInternal was able to select the correct slice based on the UUID.

Without having dug into this deeper, do you think not specifying the arch could cause any problems with universal binaries? I guess not, because we still have the UUID, and the UUID is per arch?

Yeah in the no-UUID case we need to depend on a filepath and an arch to uniquely identify a binary (and hope that the filepath is the same binary). In practice we see UUIDs for all binaries on darwin systems in crash reports.