This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] Make __shared_weak_count VTable consistent across all build configurations
ClosedPublic

Authored by ldionne on May 3 2017, 4:39 PM.

Details

Summary

This patch ensures that __shared_weak_count provides a consistent vtable regardless of if RTTI is enabled or if we are targeting a static or shared libc++ build.

This patch is technically ABI breaking, but only for a very specific configuration that neither Apple nor FreeBSD should be shipping.

@dexonsmith @emaste can you confirm that you don't ship builds of libc++ that have both (A) RTTI disabled, and (B) Manually define _LIBCPP_BUILD_STATIC?

Note that _LIBCPP_BUILD_STATIC is not normally defined when building libc++.a, but instead it must be manually provided by the user or the __config_site.

Diff Detail

Event Timeline

EricWF created this revision.May 3 2017, 4:39 PM
dexonsmith edited edge metadata.May 3 2017, 4:58 PM

Breaking the ABI of that configuration SGTM.

src/memory.cpp
126–130 ↗(On Diff #97746)

If this is the right change, seems like the 0/nullptr change can be a separate NFC pre-commit.

However, I wonder if this should call std::terminate or abort or something.

  • Previously, if someone with RTTI accidentally linked against such a library, they'd get a link error in this case.
  • Now, what happens?
EricWF added inline comments.May 3 2017, 5:54 PM
src/memory.cpp
126–130 ↗(On Diff #97746)

Now, what happens?

That's a good question without an easy answer.

Previously, if someone with RTTI accidentally linked against such a library, they'd get a link error in this case.

Yep, that is true.

However if someone compiles a program with -fno-rtti -D_LIBCPP_BUILD_STATIC and links it to a library built w/ RTTI they will run into runtime errors and incorrect codegen since the vtable layout has silently changed. This is the problem I'm trying to fix.

Now, what happens?

After this change it still fails to link when the library is built w/o RTTI but the program is. This is caused by the missing typeinfo definition for __shared_weak_count.

I wonder if this should call std::terminate or abort or something.

This should never actually get called when programs are built with -fno-rtti because all of the call sites should be #ifndef _LIBCPP_NO_RTTI away, so there is no reason to abort or terminate.

dexonsmith resigned from this revision.Oct 19 2020, 2:58 PM
dexonsmith added a reviewer: ldionne.
ldionne commandeered this revision.Oct 20 2020, 5:10 AM
ldionne edited reviewers, added: EricWF; removed: ldionne.
ldionne added a reviewer: Restricted Project.Oct 20 2020, 5:11 AM
ldionne updated this revision to Diff 299342.Oct 20 2020, 5:13 AM

Rebase onto master

Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2020, 5:13 AM
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald Transcript
ldionne updated this revision to Diff 299344.Oct 20 2020, 5:16 AM

Remove uses of _LIBCPP_BUILD_STATIC

Herald added a project: Restricted Project. · View Herald TranscriptOct 20 2020, 5:16 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
Herald added a subscriber: mgorny. · View Herald Transcript
ldionne accepted this revision.Oct 20 2020, 5:19 AM

For libc++: We never manually define _LIBCPP_BUILD_STATIC, so libc++ always contains __shared_weak_count::__get_deleter.
For libc++abi: It could happen that _LIBCPP_BUILD_STATIC is defined through the CMake logic, however libc++abi always builds with RTTI enabled. So !defined(_LIBCPP_NO_RTTI) is always true anyway, and we always get the declaration of __shared_weak_count::__get_deleter.

I think this is a no-op change.

This revision is now accepted and ready to land.Oct 20 2020, 5:19 AM