[RFC] Possible ABI break for libc++ built with -fno-rtti and -D_LIBCPP_BUILD_STATIC

Hi All,

Libc++ currently has an ABI incompatibility when built as a static library with no RTTI. Specifically some std::shared_ptr internals have different vtable layouts in this configuration.

I would like to fix this by making the vtable definition consistent across all configurations, but that requires breaking the ABI of a very rare configuration of libc++. I suspect all users of this configuration can take the ABI break immediately, but I would like to confirm this before proceeding.

The configuration in question is a static libc++ library built with -DLIBCXX_ENABLE_RTTI=OFF and -D_LIBCPP_BUILD_STATIC,

Is anybody using this configuration and can’t take an ABI break?

Note that _LIBCPP_BUILD_STATIC must be manually defined by the user at both when building and using libc++, and it is not supported by the CMake build system. This should mean that almost nobody is defining it.

The proposed changes can be found here: https://reviews.llvm.org/D32838

/Eric

SGTM.

Hi Eric,

In the email I sent on the 27th April (“[LibC++] Bug in implementation of ‘std::shared_ptr’”), the problem I was seeing was:

o LibC++ library built with -DLIBCXX_ENABLE_RTTI=ON and -D_LIBCPP_BUILD_STATIC.

o User code compiled with ‘-fno-rtti -D_LIBCPP_BUILD_STATIC’.

Having ‘_LIBCPP_BUILD_STATIC’ defined by both the library builder and the library user was where it broke. I removed ‘-D_LIBCPP_BUILD_STATIC’ from the user and it worked. But I wasn’t building the static library with RTTI disabled because it is stated as an unsupported configuration.

So are you advising that with the proposed fix, that I should revert to defining ‘_LIBCPP_BUILD_STATIC’ as the user?

Thanks,

MartinO

Hi Eric,

In the email I sent on the 27th April (“[LibC++] Bug in implementation of
'std::shared_ptr'”), the problem I was seeing was:

  o LibC++ library built with -DLIBCXX_ENABLE_RTTI=ON and
-D_LIBCPP_BUILD_STATIC.

  o User code compiled with ‘-fno-rtti -D_LIBCPP_BUILD_STATIC’.

Having ‘_LIBCPP_BUILD_STATIC’ defined by both the library builder and the
library user was where it broke. I removed ‘-D_LIBCPP_BUILD_STATIC’ from
the user and it worked. But I wasn’t building the static library with RTTI
disabled because it is stated as an unsupported configuration.

So are you advising that with the proposed fix, that I should revert to
defining ‘_LIBCPP_BUILD_STATIC’ as the user?

`_LIBCPP_BUILD_STATIC` has been removed entirely by the change. It fixes
your bug by making the vtable consistent across all configurations.

/Eric

Sounds like the perfect solution - no opportunity for error :slight_smile:

Thanks Eric,

MartinO