Description
#113139 removed _LIBCPP_OVERRIDABLE_FUNC_VIS in favor of -fvisibility-global-new-delete=
. But -fvisibility-global-new-delete=
doesn't work.
The feature exists to allow binaries to intercept global operator new
/ operator delete
and route them to their own allocators.
Imagine an executable that has these as public symbols, and then shared libraries loaded into that executable pick up those symbols.
Problems with -fvisibility-global-new-delete=
, in order or severity:
-
It only affects the overloads of op new / delete in https://eel.is/c++draft/basic.stc.dynamic.general from the language part, while libc++ declares all the overloads in https://eel.is/c++draft/new.delete . With
_LIBCPP_OVERRIDABLE_FUNC_VIS=__attribute__((visibiliity("default")))
, all the overloads became public. With-fvisibility-global-new-delete=default
, the nothrow overloads stay hidden (when generally building with -fvisibility=hidden). Since libc++ itself calls these overloads sometimes, a shared library loaded into an executable built with the suggested replacement doesn't work: The executable will only have the no-nothrow overloads exported, and the nothrow overloads private, and so the allocator gets partially overriden for the shared library, breaking things. (This is the main concern.) I'll attach a minimal repro for this, but I hope the description here is pretty clear. -
_LIBCPP_OVERRIDABLE_FUNC_VIS
allows applyingdllexport
/dllimport
on Windows;-fvisibility-global-new-delete
doesn't. (This doesn't affect us, but it might affect others.) -
-fvisibility-global-new-delete=
doesn't override visibility on op new / delete, it only adds additional declarations. So if the declarations from that flag don't match the attribute from (now-libc++-internal)_LIBCPP_OVERRIDABLE_FUNC_VIS
, you get a build error. See [libc++] Remove workaround which allows setting _LIBCPP_OVERRIDABLE_FUNC_VIS externally #113139 (comment) for a repro.
Since these all need changes to the -fvisibility-global-new-delete=
flag, I suggest we revert #113139 for now.
(See also #113139 (comment) onwards.)