This is an archive of the discontinued LLVM Phabricator instance.

[Support] Implement findModulesAndOffsets on Apple 64-bit platforms
ClosedPublic

Authored by luismarques on Jan 21 2023, 7:11 AM.

Details

Summary

To have file name and line information in stack traces (per stack frame) it's necessary to implement findModulesAndOffsets.

With this implementation, stack traces can show source location information on macOS (64-bit, for now). To make it work I used the cmake option LLVM_EXTERNALIZE_DEBUGINFO=True to generate the .dSYM directories and changed the calls to llvm-symbolizer to pass --dsym-hint arguments with the generated .dSYM directories (see follow-up patch D142283). Tested on macOS 13.1.

Diff Detail

Event Timeline

luismarques created this revision.Jan 21 2023, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2023, 7:11 AM
luismarques requested review of this revision.Jan 21 2023, 7:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2023, 7:11 AM
luismarques edited the summary of this revision. (Show Details)Jan 21 2023, 7:16 AM

Is this something we can test for?

luismarques added a comment.EditedJan 29 2023, 9:23 AM

Is this something we can test for?

It seems it is.

I'll submit a separate patch to add a unit test for symbolized stack traces. To enable that new test for Darwin/macOS will require both this patch and D142283 (or another alternative), so this patch can't be tested in isolation by that test.

mehdi_amini accepted this revision.Jan 29 2023, 10:21 AM
This revision is now accepted and ready to land.Jan 29 2023, 10:21 AM
This revision now requires review to proceed.Jan 29 2023, 10:22 AM

I'll submit a separate patch to add a unit test for symbolized stack traces.

D143607.

I can't speak to the correctness of the implementation of findModulesAndOffsets here, but I'd love to see this make progress.

@luismarques @mehdi_amini @dblaikie are there any updates here?

I have some reservations about this, given the reservations about https://reviews.llvm.org/D142283 - but I guess this part of the work's relatively neutral, even if a more robust implementation of debug-info finding for MachO is implemented rather than the dsym hints direction.

Though some of the discussion there sounds like the more robust direction might be too much work/invasive/not very standalone, and maybe folks would be better off using the apple tool atos insetad?

Oh I forgot I reviewed this, and got frustrated by this just a couple of days ago and implemented https://reviews.llvm.org/D144839

Note that you're only supporting 64 bits platforms here while I added support for 32 bits as well.

mehdi_amini accepted this revision.Feb 28 2023, 10:53 AM

LG to me!

I have some reservations about this, given the reservations about https://reviews.llvm.org/D142283 - but I guess this part of the work's relatively neutral, even if a more robust implementation of debug-info finding for MachO is implemented rather than the dsym hints direction.

This patch is just the part about finding the offset, it is orthogonal to D142283 in that with just the patch we have here we will correctly symbolize traces if we run separately dsymutil on the binary.

Having llvm-symbolizer be able to do the work of dsymutil automatically would be nice as well of course :)

Though some of the discussion there sounds like the more robust direction might be too much work/invasive/not very standalone, and maybe folks would be better off using the apple tool atos insetad?

Any direction would be based on top of this patch anyway I think?

llvm/lib/Support/Unix/Signals.inc
544

The variable style isn't LLVM right now it seems, can you fix it?

This revision is now accepted and ready to land.Feb 28 2023, 10:53 AM

Yes, this can land independently of the other work. Since D144839 was abandoned I'll update and land this.
I'll also work on the unit test and llvm-symbolizer improvement, I've just been busy with childcare and other work.

llvm/lib/Support/Unix/Signals.inc
544

I'll fix the style before landing it.

dblaikie accepted this revision.Feb 28 2023, 1:24 PM

Though some of the discussion there sounds like the more robust direction might be too much work/invasive/not very standalone, and maybe folks would be better off using the apple tool atos insetad?

Any direction would be based on top of this patch anyway I think?

Ah, right, fair enough.

This revision was landed with ongoing or failed builds.Mar 2 2023, 2:59 AM
This revision was automatically updated to reflect the committed changes.
stefanp added a subscriber: stefanp.Mar 2 2023, 7:06 AM

@luismarques
Hi,
It looks like your patch broke our build bot on AIX:
https://lab.llvm.org/buildbot/#/builders/214/builds/6115

On AIX we end up without a definition for findModulesAndOffsets so very likely the combination of #if, #elif, #else, #endif is excluding AIX from all of the definitions and it did not do that before..

Could you please take a look?

Thanks!

hubert.reinterpretcast added inline comments.
llvm/lib/Support/Unix/Signals.inc
511–512

This comment was wrong: the fallback definition was also provided when backtraces are not requested.

On AIX we end up without a definition for findModulesAndOffsets so very likely the combination of #if, #elif, #else, #endif is excluding AIX from all of the definitions and it did not do that before..

Sorry, I only noticed your message now. I just reverted this instead of fixing forward. I'll take the time tomorrow to check how to best fix this, potentially not just messing with the preprocessor conditions. Thanks @hubert.reinterpretcast for the review tip about the old code comment being wrong.

Update with the re-landed patch.