Page MenuHomePhabricator

libc++abi: build with -fvisibility=hidden

Authored by compnerd on May 14 2016, 2:39 PM.



This enables building libc++abi with -fvisibility=hidden if the compiler supports it. This is required to ensure that only public interfaces are made available from the library. Currently, the ABI difference between the default and hidden versions is:

  • __cxa_new_handler
  • __cxa_terminate_handler
  • __cxa_unexpected_handler

On Darwin, the difference between the version shipped in 10.11 and the hidden visibility is a bit more interesting as follows:

  • __cxa_new_handler
  • __cxa_terminate_handler
  • cxa_unexpected_handler + cxa_throw_bad_array_new_length + __cxa_uncaught_exceptions

Linux is even more interesting with the following diffs:

  • __cxa_new_handler
  • __cxa_terminate_handler
  • __cxa_unexpected_handler
  • _ZNKSt3120vector_base_commonILb1EE20__throw_length_errorEv
  • _ZNKSt3121basic_string_commonILb1EE20__throw_length_errorEv
  • _ZNKSt3121basic_string_commonILb1EE20__throw_out_of_rangeEv

The last three removed on Linux is more of a bug fix as they are supposed to be provided either by libc++ or inlined.

Its unclear whether the diffs are part of the public ABI or not.

Diff Detail

Event Timeline

compnerd updated this revision to Diff 57285.May 14 2016, 2:39 PM
compnerd retitled this revision from to libc++abi: build with -fvisibility=default.
compnerd updated this object.
compnerd added a reviewer: EricWF.
compnerd set the repository for this revision to rL LLVM.
compnerd added subscribers: llvm-commits, mclow.lists.
compnerd updated this object.May 14 2016, 2:42 PM
compnerd updated this object.May 14 2016, 2:44 PM

Okay, so the differences are caused by the data definitions which hold the current allocator (std::set_new_handler), terminator (std::set_terminate), and unexpected exception handler (std::set_unexpected). We could either move those three functions in libc++abi (ABI break) or export the data symbols :-(. Doing so however means that users can directly (and therefore unsafely!) access the pointer in a multithreaded environment. The accessors in the std namespace are just atomic accessors to the pointers. Ill upload a new version of the patch which marks the data symbols for export for now.

Hmm, actually, investigating this further, it seems that libc++abi already has an implementation of std::set_terminate, std::set_unexpected, std::set_new_handler, std::get_new_handler. Why not add std::get_terminate, std::get_unexpected and not expose the storage? Im not sure how the bindings for these currently works.

I don't believe OS X defaults to two-level namespaces, so the binding there should still resolve if we were to move these. ELF doesn't support two-level namespaces, so again, we should be safe there. That leaves COFF, which I don't believe has a stable ABI, so we should be able to get away with this for now.

Furthermore, to support this move, there is prior art supporting this model. libcxxrt and libsupc++ both provide these interfaces.

EricWF edited edge metadata.May 23 2016, 9:36 PM

So the first three symbols mentioned need to be reexported. See for a related bug.
They are listed as part of the spec in "spec.html" and we shouldn't change that now.
Better safe than sorry especially when managing the ABI.

You noted that __cxa_throw_bad_array_new_length and __cxa_uncaught_exceptions are added on OS X, but that is true before this change as well (when comparing to the system library).

I'm not really concerned with the basic_string methods that go away. The symbols are also exported by and so they should always be present anyway.

Also the title of this revision is the opposite of what it does.

EricWF retitled this revision from libc++abi: build with -fvisibility=default to libc++abi: build with -fvisibility=hidden.May 23 2016, 11:57 PM
EricWF edited edge metadata.
EricWF added a subscriber: cfe-commits.

Added cfe-commits.

compnerd accepted this revision.May 25 2016, 7:19 PM
compnerd added a reviewer: compnerd.
This revision is now accepted and ready to land.May 25 2016, 7:19 PM
compnerd closed this revision.May 25 2016, 7:19 PM

SVN r270816 with the changes.