Skip to content

Suggested _LIBCPP_OVERRIDABLE_FUNC_VIS replacement doesn't work #117571

Open
@nico

Description

@nico

#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:

  1. 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.

  2. _LIBCPP_OVERRIDABLE_FUNC_VIS allows applying dllexport / dllimport on Windows; -fvisibility-global-new-delete doesn't. (This doesn't affect us, but it might affect others.)

  3. -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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions