This is an archive of the discontinued LLVM Phabricator instance.

[ExecutionEngine] Check for libunwind before calling __register_frame
ClosedPublic

Authored by hvdijk on Jul 15 2021, 11:33 PM.

Details

Summary

libgcc and libunwind have different flavours of register_frame. Both flavours are already correctly handled, except that the code to handle the libunwind flavour is guarded by APPLE. This change uses the presence of unw_add_dynamic_fde in libunwind instead to detect whether libunwind is used, rather than hardcoding it as Apple vs. non-Apple.

Fixes PR44074.

Thanks to Albert Jin <albert.jin@gmail.com> and Chris Schafmeister <chris.schaf@verizon.net> for identifying the problem.

Diff Detail

Event Timeline

hvdijk created this revision.Jul 15 2021, 11:33 PM
hvdijk requested review of this revision.Jul 15 2021, 11:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2021, 11:33 PM
hvdijk edited the summary of this revision. (Show Details)Jul 15 2021, 11:33 PM
lhames accepted this revision.Aug 14 2021, 6:27 PM

LGTM -- Thanks Harald. Do you have commit access? If not please let me know and I can commit this on your behalf.

Side note: I think we should revisit the dynamic registration APIs in libunwind to see if we can come up with something universal, but this seems like a good interim solution. I'll mention this on PR44074 too.

This revision is now accepted and ready to land.Aug 14 2021, 6:27 PM

Thanks, I do have commit access, I'll push this once I can re-test against current main just to be sure.

I agree that it would be good to change libunwind's __register_frame to accept the same arguments that libgcc's version accepts, but I think we would need something like this patch regardless for the short term, as LLVM may be linked against older versions of libunwind that we will still want to support for now.

This revision was landed with ongoing or failed builds.Aug 15 2021, 5:36 AM
This revision was automatically updated to reflect the committed changes.
tstellar added inline comments.
llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
72

Should this be a runtime check and not a compile time check?

Herald added a project: Restricted Project. · View Herald TranscriptMar 9 2023, 12:09 PM
hvdijk added inline comments.Mar 9 2023, 2:45 PM
llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
72

It only makes a difference if we build against libgcc and then change it at runtime to use libunwind, or vice versa. In general, I think that if __register_frame behaves differently between the two versions, we cannot support that anyway. We could make it work specifically in the case of LLVM as a special exception, but if we want to make that work in general, it would be more useful to modify libunwind to be compatible with libgcc rather than making changes here.

tstellar added inline comments.Mar 9 2023, 8:28 PM
llvm/lib/ExecutionEngine/RuntimeDyld/RTDyldMemoryManager.cpp
72

OK, thanks.