Skip to content

Build libcxx and libcxxabi from llvm-project#42730

Merged
rschu1ze merged 4 commits intomasterfrom
build-libcxx-and-libcxxabi-from-llvm-project
Nov 30, 2022
Merged

Build libcxx and libcxxabi from llvm-project#42730
rschu1ze merged 4 commits intomasterfrom
build-libcxx-and-libcxxabi-from-llvm-project

Conversation

@rschu1ze
Copy link
Copy Markdown
Member

Resolves #42245

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

@robot-ch-test-poll robot-ch-test-poll added pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR. labels Oct 27, 2022
@kitaisreal kitaisreal self-assigned this Oct 27, 2022
@Algunenano
Copy link
Copy Markdown
Member

❤️

Can the other 2 submodules be removed now then?

@rschu1ze
Copy link
Copy Markdown
Member Author

Actually removing them will break the build of older versions but they can surely be archived (made read-only).

@rschu1ze rschu1ze force-pushed the build-libcxx-and-libcxxabi-from-llvm-project branch from e7c57db to b459bd5 Compare October 27, 2022 09:49
@Algunenano
Copy link
Copy Markdown
Member

I mean removed from the repo, so they are not cloned. Not removed from Github

@rschu1ze
Copy link
Copy Markdown
Member Author

Ah, of course yes ... forgot that, thanks!

@rschu1ze rschu1ze force-pushed the build-libcxx-and-libcxxabi-from-llvm-project branch from b459bd5 to a942788 Compare October 27, 2022 09:55
@rschu1ze
Copy link
Copy Markdown
Member Author

Link error

Oct 30 14:17:21 ld.lld-15: error: undefined symbol: atomic_load
Oct 30 14:17:21 >>> referenced by refcount_c11.c:51 (../contrib/boringssl/crypto/refcount_c11.c:51)
Oct 30 14:17:21 >>>               lto.tmp:(boost::asio::ssl::context::~context())
Oct 30 14:17:21 >>> referenced by refcount_c11.c:51 (../contrib/boringssl/crypto/refcount_c11.c:51)
Oct 30 14:17:21 >>>               lto.tmp:(boost::asio::ssl::detail::engine::~engine())
Oct 30 14:17:21 >>> referenced by refcount_c11.c:51 (../contrib/boringssl/crypto/refcount_c11.c:51)
Oct 30 14:17:21 >>>               lto.tmp:(boost::asio::ssl::detail::stream_core::~stream_core())
Oct 30 14:17:21 >>> referenced 363 more times
Oct 30 14:17:21 
Oct 30 14:17:21 ld.lld-15: error: undefined symbol: atomic_compare_exchange_weak
Oct 30 14:17:21 >>> referenced by refcount_c11.c:60 (../contrib/boringssl/crypto/refcount_c11.c:60)
Oct 30 14:17:21 >>>               lto.tmp:(boost::asio::ssl::context::~context())
Oct 30 14:17:21 >>> referenced by refcount_c11.c:60 (../contrib/boringssl/crypto/refcount_c11.c:60)
Oct 30 14:17:21 >>>               lto.tmp:(boost::asio::ssl::detail::engine::~engine())
Oct 30 14:17:21 >>> referenced by refcount_c11.c:60 (../contrib/boringssl/crypto/refcount_c11.c:60)
Oct 30 14:17:21 >>>               lto.tmp:(boost::asio::ssl::detail::stream_core::~stream_core())
Oct 30 14:17:21 >>> referenced 363 more times
Oct 30 14:17:21 clang: error: linker command failed with exit code 1 (use -v to see invocation)
Oct 30 14:17:21 ninja: build stopped: subcommand failed.

Declarations of C11 functions atomic_load() and atomic_compare_exchange_weak() are visible but no implementation exists. They are defined in "libcxx/include/atomic" and I suppose that compiler intrinsic __c11_atomic_compare_exchange_weak is not defined. Unfortunately, I currently have no idea how to fix that.

What is interesting is that in current master (without this PR), atomic_load() and atomic_compare_exchange_weak()
point to "llvm-project/clang/lib/Headers/stdatomic.h", at least in my IDE, e.g.

#define atomic_compare_exchange_weak(object, expected, desired) __c11_atomic_compare_exchange_weak(object, expected, desired, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)

The alternative is to force-compile BoringSSL w/o atomics by commenting out the stuff after Automatically enable C11 atomics if implemented. in "contrib/boringssl/crypto/internal.h" and I doubt that the result would be any slower. But before doing so, maybe someone else has an idea?

@rschu1ze
Copy link
Copy Markdown
Member Author

rschu1ze commented Nov 8, 2022

@azat @alexey-milovidov Just wondering, perhaps you have an idea or explanation for the link failure libcxx and libcxxabi are build directly from the llvm-project submodule?

@alexey-milovidov
Copy link
Copy Markdown
Member

We are using old glibc without support for C11 (and we have to use the old glibc for compatibility).

Let's check why BoringSSL decided to use C11. It should not, and also we should not have any checks in CMakeLists (all the configuration has to be predefined).

@azat
Copy link
Copy Markdown
Member

azat commented Nov 11, 2022

Oct 30 14:17:21 ld.lld-15: error: undefined symbol: atomic_load

This should be fixed by #43166

We are using old glibc without support for C11 (and we have to use the old glibc for compatibility).

stdatomic.h is not provided by glibc, but by compiler.

TL;DR;

It started to fail because of __config, in particular how _LIBCPP_COMPILER_CLANG_BASED is set.

And because of this it does not include non-c++ version of a header, the fix is obvious, CXX library should not be linked for C (headers and so on).

Also note that there is some trickery in the previous __config - https://github.com/ClickHouse/libcxx/blob/9a457ab3c64a533a06922b386b284215c17ce627/include/__config#L13-L23

P.S. once this will be solved there will be some issues with the problem that std::vector cannot work with opaque structures anymore - #42513 (comment)

azat added a commit to azat/ClickHouse that referenced this pull request Nov 11, 2022
If you will have the same header in both libraries you may have some
tricky failures.

And there is at least one header that exists in both: stdatomic.h

Right now there is a workaround for this header, that allows to use C++
version of this header for C - the workaround is called "set
_LIBCPP_COMPILER_CLANG_BASED not only for CXX" [1] and use include_next
[2].

  [1]: https://github.com/ClickHouse/libcxx/blob/9a457ab3c64a533a06922b386b284215c17ce627/include/__config#L39
  [2]: https://github.com/ClickHouse/libcxx/blob/9a457ab3c64a533a06922b386b284215c17ce627/include/stdatomic.h#L223-L231

However ClickHouse#42730 changes this, and now it fails to compile because of this.

Signed-off-by: Azat Khuzhin <[email protected]>
@rschu1ze
Copy link
Copy Markdown
Member Author

@azat Thanks a lot for checking + the fix.

@kitaisreal This PR is ready, approve? Thanks.

@rschu1ze rschu1ze merged commit 3fc10d5 into master Nov 30, 2022
@rschu1ze rschu1ze deleted the build-libcxx-and-libcxxabi-from-llvm-project branch November 30, 2022 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicated LLVM submodules

6 participants