This is an archive of the discontinued LLVM Phabricator instance.

Handle NetBSD specific _Unwind_Ptr
AbandonedPublic

Authored by krytarowski on Jun 4 2017, 8:27 AM.

Details

Summary

NetBSD declares _Unwind_Ptr as void* which is not compatible
without explicit cast with the compiler-rt version uintptr_t.

Sponsored by <The NetBSD Foundation>

Diff Detail

Repository
rL LLVM

Event Timeline

krytarowski created this revision.Jun 4 2017, 8:27 AM

@kcc this is first step to upstream NetBSD support for sanitizers - to cleanup build issues in compiler-rt.

kcc edited edge metadata.Jun 8 2017, 10:07 AM

@kcc this is first step to upstream NetBSD support for sanitizers - to cleanup build issues in compiler-rt.

Sorry, I don't know this code.

krytarowski added inline comments.
lib/builtins/gcc_personality_v0.c
27

This line must be defined(__NetBSD__) && !defined(__clang__) as the failure is GCC specific. Clang uses custom unwind.h header.

fjricci resigned from this revision.Aug 21 2017, 7:54 AM
fjricci edited reviewers, added: abdulras; removed: fjricci.
compnerd edited reviewers, added: compnerd; removed: abdulras.Aug 21 2017, 9:15 AM
compnerd requested changes to this revision.Aug 21 2017, 9:27 AM
compnerd added inline comments.
lib/builtins/gcc_personality_v0.c
27

clang doesn't really use a custom unwind.h per se. It is one of the compiler vended headers, and unless you specifically setup the build, the compiler vended header can be used over the external unwinder. That said, this macro should only be needed at one site, so we should just inline the difference.

215–216

Interesting that this has never been an issue, but the explicit cast here is fine.

248

_Unwind_SetGR is declared as: void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Word);

So this cast should not be needed.

250

Yes, _Unwind_SetIP is declared as void _Unwind_SetIP(struct _Unwind_Context *, _Unwind_Ptr);, and if NetBSD declares it as void *, then the explicit cast is reasonable.

Didn't NetBSD use GCC at one point? It seems that GCC too defines _Unwind_Ptr as unsigned int __attribute__((__mode__(__pointer__))), making it effectively the same as uintptr_t.

I'm tempted to say that this is a bug in the unwinder in NetBSD. However, adding a condition here for NetBSD and a cast is not too terrible.

This revision now requires changes to proceed.Aug 21 2017, 9:27 AM
joerg edited edge metadata.Aug 21 2017, 9:35 AM

Kamil, which unwind.h are you using? The outdated copy in libexecinfo.h or the modern one used by libunwind? I see little reason to cater to the bugs in the former...

krytarowski added a comment.EditedAug 21 2017, 9:37 AM

https://github.com/NetBSD/src/blob/trunk/lib/libexecinfo/unwind.h here is the referenced header used by GCC.

For Clang/LLVM if I understand correctly the used header is (it overshadows the libexecinfo one):
https://github.com/NetBSD/src/blob/trunk/external/bsd/llvm/dist/clang/lib/Headers/unwind.h

Kamil, which unwind.h are you using? The outdated copy in libexecinfo.h or the modern one used by libunwind? I see little reason to cater to the bugs in the former...

So, can we get rid of the libexecinfo one?

Well, the libexecinfo one exists as fallback because gcc doesn't provide one.

Well, the libexecinfo one exists as fallback because gcc doesn't provide one.

What's the preferred solution to this issue? There is also an option to upfront decide that compiler-rt isn't buildable with GCC.

krytarowski planned changes to this revision.Sep 11 2017, 5:21 AM

Suspended till getting functional elementary support of LLDB/NetBSD aboard.

krytarowski requested review of this revision.Nov 4 2018, 7:51 AM
krytarowski added inline comments.
lib/builtins/gcc_personality_v0.c
248

Pity on NetBSD this is:

void _Unwind_SetGR(struct _Unwind_Context *, int, _Unwind_Ptr);

So the 3rd argument differs.

krytarowski added inline comments.Nov 4 2018, 7:53 AM
lib/builtins/gcc_personality_v0.c
248

Maybe NetBSD should change the type to _Unwind_Word here? @joerg ?

250

How about _Unwind_SetIP(context, (_Unwind_Ptr)(funcStart + landingPad));?

joerg added inline comments.Nov 4 2018, 2:39 PM
lib/builtins/gcc_personality_v0.c
248

It is plain uintptr_t. _Unwind_Word isn't part of the IA64 specification, GNU seems to have created it because they didn't want to use uint64_t and somehow didn't think of uintptr_t it seems. I don't really see a point in introducing it.

krytarowski abandoned this revision.Nov 16 2018, 2:22 PM

Committed non-controversial chunks of this. The rest is rescheduled for future in separate review.