Bug 236905 - LLVM's implementation of __gcc_personality_v0 does not correctly initialise the context
Summary: LLVM's implementation of __gcc_personality_v0 does not correctly initialise t...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: CURRENT
Hardware: arm Any
: --- Affects Many People
Assignee: freebsd-arm (Nobody)
Depends on:
Reported: 2019-03-30 19:51 UTC by David Chisnall
Modified: 2019-04-01 16:38 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description David Chisnall freebsd_committer 2019-03-30 19:51:34 UTC
When __gcc_personality_v0 is invoked (when exceptions unwind through C code that needs to run cleanups), it calls _Unwind_GetLanguageSpecificData:


This is completely fine on most architectures, but on ARM this tries to map from the context to the exception structure.  The GNU extension to the APCS requires that the personality function stores this pointer in the context in register 12 (reserved as a linker scratch register, so never actually used in unwinding).  

The abstraction layer used in libcxxrt does this automatically:


It appears that the LLVM implementation of the personality routine does not do this.  This can be fixed by adding:

_Unwind_SetGR(context, 12, reinterpret_cast<unsigned long>(exceptionObject));

on entry to the personality routine.  This will want to be done upstream, but we should carry a local patch to compiler-rt (and possibly issue an EN) because at present any program that tries to throw an exception through C stack frames crashes on ARM.
Comment 1 Ed Maste freebsd_committer 2019-04-01 14:16:08 UTC
David would you be willing to submit an upstream patch for compiler-rt? If so I'll cherry-pick that into FreeBSD and merge to stable branches.
Comment 2 David Chisnall freebsd_committer 2019-04-01 15:29:42 UTC
Is there an ARM ref machine that I can test it on?  I was borrowing access to someone else's BBB to test this and it isn't anywhere near powerful enough to build LLVM.

I suspect that, since Apple ships this code for iOS, their unwinder (LLVM's libUnwind?) doesn't depend on this behaviour, so I don't know if the change makes sense upstream.
Comment 3 Ed Maste freebsd_committer 2019-04-01 16:36:14 UTC
(In reply to David Chisnall from comment #2)
I have a Jetson TK1 here (quad-core A15, 2GB) which might be just barely sufficient for building LLVM, I can make it available to you if that will be helpful.
Comment 4 David Chisnall freebsd_committer 2019-04-01 16:38:27 UTC
Yes please, that ought to be able to handle release builds, at least...