This is an archive of the discontinued LLVM Phabricator instance.

[libunwind] Minor SJLJ config cleanup. NFCI.
ClosedPublic

Authored by rprichard on Aug 28 2020, 12:51 AM.

Details

Summary

[libunwind] Minor SJLJ config cleanup. NFCI.

Simplify:

defined(__ARM_DWARF_EH__) || !defined(__arm__)

to:

!defined(_LIBUNWIND_ARM_EHABI)

A later patch benefits from the simplicity. This change will result in
the two DWARF macros being defined when USING_SJLJ_EXCEPTIONS is
defined, but:

  • That's already the case with the APPLE and _WIN32 clauses.
  • That's also already the case with other architectures.
  • With USING_SJLJ_EXCEPTIONS, most of the unwinder is #ifdef'ed away.

Generally, when USING_SJLJ_EXCEPTIONS is defined, most of the
libunwind code is removed by the preprocessor. e.g. None of the hpp
files are included, and almost all of the .c and .cpp files are defined
away, except in Unwind-sjlj.c. Unwind_AppleExtras.cpp is an exception
because it includes two hpp files, which it doesn't use. Remove the
unneeded includes for consistency with the general rule.

Diff Detail

Event Timeline

rprichard created this revision.Aug 28 2020, 12:51 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 28 2020, 12:51 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
rprichard requested review of this revision.Aug 28 2020, 12:51 AM

FWIW, I compiled libunwind for Darwin, and I had trouble getting it to compile for armv7. Unwind-sjlj.c needs these things:

  • #include <System/pthread_machdep.h>
  • _pthread_getspecific_direct(__PTK_LIBC_DYLD_Unwind_SjLj_Key)

My iPhoneOS/iPhoneSimulator SDKs lacked the header file and the two identifiers. I compiled the armv7 libunwind by commenting out a few parts of that file.

Sorry for the inconvenience that libunwind is not really buildable for armv7 from iOS SDK. You can build a single threaded version without referring to those interfaces. If this is really troublesome for you, feel free to file a bug report and we can see what can be done here.

This patch is technically not correct from a bigger context. I think, for example, watch armv7k doesn't default to sjlj exception model but it needs to build sjlj model to support some clients.

Sorry for the inconvenience that libunwind is not really buildable for armv7 from iOS SDK. You can build a single threaded version without referring to those interfaces. If this is really troublesome for you, feel free to file a bug report and we can see what can be done here.

Thanks. I think I'm OK as-is.

This patch is technically not correct from a bigger context. I think, for example, watch armv7k doesn't default to sjlj exception model but it needs to build sjlj model to support some clients.

That makes sense. It looks like passing -arch armv7k to clang is enough to switch it to using DWARF and compact unwinding rather than sjlj. I also see a comment in ToolChains/Darwin.cpp:
// Only watchOS uses the new DWARF/Compact unwinding method.

It seems that Darwin/armv7k libunwind doesn't build because config.h enables _LIBUNWIND_SUPPORT_COMPACT_UNWIND, but there is no 32-bit ARM compact unwinder. It looks like setting the flag is the right thing to do, though -- maybe the rest of the code is internal to Apple.

I'll revise or abandon this patch. My main goal was to ensure that if _LIBUNWIND_USE_DL_ITERATE_PHDR was defined, then either of _LIBUNWIND_ARM_EHABI or _LIBUNWIND_SUPPORT_DWARF_UNWIND would also be defined.

rprichard updated this revision to Diff 288740.Aug 28 2020, 5:57 PM

Remove most of the previous change. Add a comment about Apple/armv7k.

rprichard edited the summary of this revision. (Show Details)Aug 28 2020, 5:57 PM
steven_wu accepted this revision.Aug 31 2020, 9:33 AM

Thanks. LGTM.

Do I need an approval from a libunwind group member?

Do I need an approval from a libunwind group member?

I'll add Steven as one of them -- he handles libunwind here at Apple. I think you're good to go, at least from my PoV (but I'm not a code owner for libunwind :)

This revision was not accepted when it landed; it landed in state Needs Review.Sep 3 2020, 4:00 PM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.

Sorry for the inconvenience that libunwind is not really buildable for armv7 from iOS SDK. You can build a single threaded version without referring to those interfaces. If this is really troublesome for you, feel free to file a bug report and we can see what can be done here.

Thanks. I think I'm OK as-is.

This patch is technically not correct from a bigger context. I think, for example, watch armv7k doesn't default to sjlj exception model but it needs to build sjlj model to support some clients.

That makes sense. It looks like passing -arch armv7k to clang is enough to switch it to using DWARF and compact unwinding rather than sjlj. I also see a comment in ToolChains/Darwin.cpp:
// Only watchOS uses the new DWARF/Compact unwinding method.

It seems that Darwin/armv7k libunwind doesn't build because config.h enables _LIBUNWIND_SUPPORT_COMPACT_UNWIND, but there is no 32-bit ARM compact unwinder. It looks like setting the flag is the right thing to do, though -- maybe the rest of the code is internal to Apple.

I'll revise or abandon this patch. My main goal was to ensure that if _LIBUNWIND_USE_DL_ITERATE_PHDR was defined, then either of _LIBUNWIND_ARM_EHABI or _LIBUNWIND_SUPPORT_DWARF_UNWIND would also be defined.

Actually after looking some internal history, armv7k does not need SJLJ APIs for any version. The code was there original for some old compiler version doesn't have __USING_SJLJ_EXCEPTIONS__ set correctly for all the targets we cared about. I guess we can clean it up if needed.