[libcxx-commits] [PATCH] D121478: [libc++] Add a lightweight overridable assertion handler

Alan Zhao via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 2 16:06:50 PDT 2022


ayzhao added a comment.

In D121478#3730261 <https://reviews.llvm.org/D121478#3730261>, @ayzhao wrote:

> We tried overriding the abort handler in Chromium, and this fails with a linker error when we target Windows, statically link libc++ along with our custom handler (in `base/nodebug_assertion.cc`), enable ThinLTO, and build using `clang-cl`:
>
>   lld-link: error: duplicate symbol: void __cdecl std::Cr::__libcpp_verbose_abort(char const *, ...)
>   >>> defined at ../../base/nodebug_assertion.cc
>   >>>            obj/base/nodebug_assertion/nodebug_assertion.obj
>   >>> defined at ../../buildtools/third_party/libc++/trunk/src/verbose_abort.cpp
>   >>>            obj/buildtools/third_party/libc++/libc++/verbose_abort.obj
>
> I believe this is due to the fact that Windows binaries don't have the concept of weak symbols, so the linker is unable to override the `libc++` version.
>
> Since working with weak symbols can be flaky, would it be possible to implement this using function pointers? E.g. make `__libcpp_verbose_abort(...)` a static function pointer that we call `_LIBCPP_ASSERT(...)`, and add a method `__libcpp_override_abort(...)` that users can call to set and override that function pointer.

It turns out the linker failure we're seeing is caused by `lld` not supporting weak symbols in LLVM bitcode inputs when outputting COFF. D133165 <https://reviews.llvm.org/D133165> should hopefully fix this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121478/new/

https://reviews.llvm.org/D121478



More information about the libcxx-commits mailing list