This is an archive of the discontinued LLVM Phabricator instance.

[libcxxabi] [test] Depend on unwind only if available
ClosedPublic

Authored by mgorny on Feb 11 2022, 3:51 AM.

Details

Reviewers
ldionne
Group Reviewers
Restricted Project
Commits
rG5244ef0faf55: [libcxxabi] [test] Depend on unwind only if available
Summary

When building libcxxabi via LLVM_ENABLE_RUNTIMES=libcxxabi the CMake
invocation fails because of missing "unwind" target. However,
if the extraneous dependency is removed, the library builds just fine
against installed libunwind and tests work fine. To fix this,
add the dependency only if the target actually exists.

Diff Detail

Event Timeline

mgorny requested review of this revision.Feb 11 2022, 3:51 AM
mgorny created this revision.
ldionne added inline comments.Feb 14 2022, 3:17 PM
libcxxabi/test/CMakeLists.txt
66

Do I understand correctly that you're passing LIBCXXABI_USE_LLVM_UNWINDER but not including libunwind in LLVM_ENABLE_RUNTIMES? Is there a reason for doing that?

mgorny added inline comments.Feb 14 2022, 3:40 PM
libcxxabi/test/CMakeLists.txt
66

Yes, I'm linking to system-installed libunwind.

ldionne added inline comments.Feb 15 2022, 9:01 AM
libcxxabi/test/CMakeLists.txt
66

Why are you specifying LIBCXXABI_USE_LLVM_UNWINDER then? That's the part I don't understand:

option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder.")

You specifically don't want to do that, right?

mgorny added inline comments.Feb 15 2022, 10:18 AM
libcxxabi/test/CMakeLists.txt
66

Well, the option enables some conditional code that I presume should be enabled when linking to LLVM libunwind, doesn't it?

emaste added a subscriber: emaste.Feb 15 2022, 12:07 PM
emaste added inline comments.
libcxxabi/test/CMakeLists.txt
66

It enables cases like

#if !defined(LIBCXXABI_USE_LLVM_UNWINDER)
    // Copy the address of _Unwind_Control_Block to r12 so that
    // _Unwind_GetLanguageSpecificData() and _Unwind_GetRegionStart() can
    // return correct address.
    _Unwind_SetGR(context, REG_UCB, reinterpret_cast<uint32_t>(unwind_exception));
#endif

In FreeBSD we have the same case @mgorny mentions, there is a system-provided built-in llvm libunwind. I haven't looked into the implication of not defining LIBCXXABI_USE_LLVM_UNWINDER but using llvm libunwind.

ldionne accepted this revision.Feb 16 2022, 7:49 AM
ldionne added inline comments.
libcxxabi/test/CMakeLists.txt
66

I see, thanks for the explanation. So IIUC this means you're also building against a LLVM-provided unwind.h header, right? In the longer term, what would you think if libunwind provided a _LIBUNWIND_VERSION macro in its header that you can query for (like we do for libc++ and libc++abi)?

This revision is now accepted and ready to land.Feb 16 2022, 7:49 AM
mgorny added inline comments.Feb 16 2022, 10:13 AM
libcxxabi/test/CMakeLists.txt
66

Our systems do have unwind.h from llvm-libunwind or "nongnu" libunwind but at this point I'm not really sure whether it is picked up by the compiler vs the one supplied along with the compiler.

I don't really mind some extra macro but I don't really see why that would be a question for me. I'm merely packaging it, not writing software against libunwind.

This revision was landed with ongoing or failed builds.Feb 16 2022, 10:30 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 16 2022, 10:30 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
emaste added inline comments.Feb 16 2022, 10:35 AM
libcxxabi/test/CMakeLists.txt
66

It was a bit of a mess in FreeBSD; we do now install LLVM's unwind.h as of https://reviews.freebsd.org/D34065. Prior to this change we had a copy of HP libunwind unwind.h in the tree but it wasn't installed.

Also agree with @mgorny, I think a _LIBUNWIND_VERSION is reasonable but it doesn't really matter to me per se.

ldionne added inline comments.Feb 17 2022, 6:38 AM
libcxxabi/test/CMakeLists.txt
66

Sorry, I didn't explain properly. My point is that if you install the correct unwind.h header and it has a _LIBUNWIND_VERSION macro defined in it, this code in libc++abi could simply query if defined(_LIBUNWIND_VERSION) instead of having to be told that it's using the LLVM libunwind by means of setting LIBCXXABI_USE_LLVM_UNWINDER. That would solve the problem that this patch tries to solve in a cleaner way IMO.

emaste added inline comments.Feb 17 2022, 6:41 AM
libcxxabi/test/CMakeLists.txt
66

Ah, yes.

ldionne added inline comments.Mar 4 2022, 11:37 AM
libcxxabi/test/CMakeLists.txt
66
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 11:37 AM