This is an archive of the discontinued LLVM Phabricator instance.

AArch64: disable asynchronous unwind by default for MachO.
ClosedPublic

Authored by t.p.northover on Aug 4 2022, 2:50 AM.

Details

Reviewers
MaskRay
Summary

AArch64 MachO has a compact unwind format where most functions' unwind info can be represented in just 4 bytes. But this cannot represent any asynchronous CFI function, so it's essentially disabled when that's used. This is a large code-size hit that we'd rather not take unless explicitly requested.

So this patch adds a new callback to switch the default on ARM64 MachO to synchronous. Command-line options can still turn it on if anyone wants to take the hit.

Diff Detail

Event Timeline

t.p.northover created this revision.Aug 4 2022, 2:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 2:50 AM
t.p.northover requested review of this revision.Aug 4 2022, 2:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 4 2022, 2:50 AM
Herald added a subscriber: MaskRay. · View Herald Transcript

I just discovered this and was about to post on Discourse about it. Glad you're already on it :)

I don't think this is quite correct though? It'll turn off unwind tables for AArch64 entirely, whereas we want to keep sync unwind tables. If we want to minimize changes to the existing logic, maybe we could add IsSyncUnwindTablesDefault instead and have SyncUnwindTables default to that and AsyncUnwindTables default to ! that?

clang/include/clang/Driver/ToolChain.h
509

I believe the option is spelled -fasynchronous-unwind-tables.

clang/lib/Driver/ToolChains/Darwin.cpp
2942

This comment is a bit confusing. I thought Darwin supported compact unwind for all architectures. Is it that compact unwind can't handle async unwind on arm64 but can on other architectures?

rmaz added a subscriber: rmaz.Aug 30 2022, 11:02 AM
MaskRay added inline comments.Aug 30 2022, 1:03 PM
clang/include/clang/Driver/ToolChain.h
509

Changing IsUnwindTablesDefault to unwindTablesDefaultLevel may be cleaner.

I don't think this is quite correct though? It'll turn off unwind tables for AArch64 entirely, whereas we want to keep sync unwind tables.

You're right, sorry about that. Hopefully this refactoring with MaskRay's suggestion gets it right.

clang/include/clang/Driver/ToolChain.h
509

I prefer it, though the Clang.cpp logic is unavoidably weird.

Quick rename of new method to flow better.

Herald added a project: Restricted Project. · View Herald TranscriptSep 7 2022, 6:59 AM
MaskRay accepted this revision.Sep 8 2022, 8:46 PM

You may want to split the patch, with refactoring as the first, and the Mach-O specific change as the second one.

clang/include/clang/Driver/ToolChain.h
111

I'd prefer enum class without the UTL_ prefix. That will be more readable. UTL isn't very clear (RM_Enabled is kinda a bad name as without RTTIMode it's clear what's enabled; UNW_CompilerRT is fine as from CompilerRT/Libgcc we know it refers to the unwind or builtin library; Asynchrounous/Synchronous is not very clear).

This revision is now accepted and ready to land.Sep 8 2022, 8:46 PM
t.p.northover marked an inline comment as done.

Switched to enum class.

You may want to split the patch, with refactoring as the first, and the Mach-O specific change as the second one.

I've got it split into two commits locally now. It's pretty much as you'd expect: first one NFC with no test changes, the second adds the test change and changes the return statement in MachO::getDefaultUnwindTableLevel from an unconditional Asynchronous.

t.p.northover closed this revision.Sep 20 2022, 2:48 AM

Just noticed it'd already been approved with those suggestions, so pushed the revised version: 4388b56d and 58f9abaed4aa.

clang/include/clang/Driver/ToolChain.h
111

Makes sense now that we have classes.