This is an archive of the discontinued LLVM Phabricator instance.

[MC] Don't emit redundant compact unwind entries
AbandonedPublic

Authored by int3 on Sep 26 2022, 7:09 PM.

Details

Summary

If there's no DWARF instructions, personality, or LSDA, I don't think
there's a need to emit a CU entry either. This canonicalization of
unwind info allows link-time code folding to fold more functions (since
functions with trivial unwind info are now obviously identical to
functions with the same code but with no unwind info).

Diff Detail

Event Timeline

int3 created this revision.Sep 26 2022, 7:09 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 26 2022, 7:09 PM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
int3 requested review of this revision.Sep 26 2022, 7:09 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 26 2022, 7:09 PM
int3 removed a reviewer: Restricted Project.Sep 26 2022, 7:18 PM
int3 added a subscriber: Restricted Project.
steven_wu requested changes to this revision.EditedSep 27 2022, 9:38 AM

If a function do not have unwind info, you cannot throw anything across the frame. That will be a very harsh behavior for any programmer who does not think about exception for all the code they use.

For example:

func call_back_throw() <--- with unwind info
func library_code() <--- no dwarf, no LSDA
func catch_site() <--- nope, cant catch anything

If you want to avoid unwind table, just have something like -fno-unwind-tables so they are nounwind in IR in the first place.

This revision now requires changes to proceed.Sep 27 2022, 9:38 AM
int3 added a comment.Sep 27 2022, 11:09 AM

Oh, thanks for your example, I wasn't aware of that. Just to make sure I understand, if a function has an encoding of 0x0 in the final binary's __unwind_info, that means you cannot throw anything across the frame?

Also, the x86_64 MC backend is a lot more aggressive about omitting unwind info (https://discourse.llvm.org/t/does-it-make-sense-for-a-function-to-have-a-personality-lsda-if-it-has-no-other-unwind-info-mach-o/65490). Curious if you have thoughts on that. Is that a bug in x86_64, or does the arm64 unwinder work differently?

Oh, thanks for your example, I wasn't aware of that. Just to make sure I understand, if a function has an encoding of 0x0 in the final binary's __unwind_info, that means you cannot throw anything across the frame?

I am not an expert in the area but I would believe that is the case. You can dig through libunwind in llvm to see the implementation over there.

Also, the x86_64 MC backend is a lot more aggressive about omitting unwind info (https://discourse.llvm.org/t/does-it-make-sense-for-a-function-to-have-a-personality-lsda-if-it-has-no-other-unwind-info-mach-o/65490). Curious if you have thoughts on that. Is that a bug in x86_64, or does the arm64 unwinder work differently?

Looks like x86 backend emit __eh_frame instead?

kyulee added a subscriber: kyulee.Sep 27 2022, 4:24 PM
int3 abandoned this revision.Oct 5 2022, 4:09 PM

Looks like x86 backend emit __eh_frame instead?

Yep, you're right, thanks!