This is an archive of the discontinued LLVM Phabricator instance.

[runtimes] Fix building initial libunwind+libcxxabi+libcxx with compiler implied -lunwind
AbandonedPublic

Authored by mstorsjo on Nov 5 2021, 2:56 AM.

Details

Reviewers
phosek
hvdijk
Group Reviewers
Restricted Project
Restricted Project
Summary

This does mostly the same as D112126, but for the runtimes cmake files.
Most of that is straightforward, but the interdependency between
libcxx and libunwind is tricky:

Libunwind is built at the same time as libcxx, but libunwind is not
installed yet. LIBCXXABI_USE_LLVM_UNWINDER makes libcxx link directly
against the just-built libunwind, but the compiler implicit -lunwind
isn't found. This patch avoids that by adding the intermediate library
output path to link_directories(). I have a separate alternative
patch for the same issue that I'll post in tandem.

(There might be a similar interdependency between libcxxabi and
libunwind too - it doesn't show up in my builds targeting Windows,
as libcxxabi is always built statically though. @hvdijk, can you test
using the new build layout by targeting cmake at llvm-project/runtimes
instead of building libunwind/libcxxabi/libcxx individually in your
environment and see how it behaves?)

Diff Detail

Event Timeline

mstorsjo created this revision.Nov 5 2021, 2:56 AM
mstorsjo requested review of this revision.Nov 5 2021, 2:56 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 5 2021, 2:56 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a reviewer: Restricted Project. · View Herald Transcript

Hmm, the CI failures show that --unwindlib=none does break cases when we're configuring with ASAN/TSAN, because those runtimes (which get implicitly linked everywhere during the cmake tests) do need the unwinder. Should we change the tests to first see if linking works without any flags added, and only try --unwindlib=none if linking otherwise fails?

Secondly, adding --unwindlib=none to CMAKE_REQUIRED_FLAGS does break a lot of other tests within HandleLLVMOptions (is that even needed when building runtimes, which are kinda disconnected from the things done in the main llvm dir?), as those tests check for options with -Werror (to avoid picking up options that do nothing but add warnings), because --unwindlib=none produces warnings when set while compiling (contrary to -nostdlib++ which doesn't cause warnings if set while compiling).

(I guess we could make Clang not warn on unused --unwindlib options, but that doesn't help people building with the currently supported Clang 12 or 13.)

mstorsjo updated this revision to Diff 385064.Nov 5 2021, 7:27 AM

Check if linking works before trying to add --unwindlib=none, this should fix the libcxx CI ASAN/TSAN tests.

Tests within HandleLLVMOptions (add_flag_if_supported and similar) still fail when --unwindlib=none ends up added though, as the option causes warnings, and that function tests with -Werror.

mstorsjo abandoned this revision.Nov 5 2021, 11:17 AM

Preferring D113253 over this one.