<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/117571>117571</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Suggested _LIBCPP_OVERRIDABLE_FUNC_VIS replacement doesn't work
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          nico
      </td>
    </tr>
</table>

<pre>
    #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 https://github.com/llvm/llvm-project/pull/113139#issuecomment-2483987898 for a repro.

Since these all need changes to the `-fvisibility-global-new-delete=` flag, I suggest we revert #113139 for now.

(See also https://github.com/llvm/llvm-project/pull/113139#issuecomment-2483987898 onwards.)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0Vl1v2zYU_TX0y4UFifLngx_ipgYMFFvRdO2jcUVeSVwpUiApq_73AyU5dtqtyQYMCBKEIu895_DwkOi9qgzRji33bPk4wy7U1u2MEnZWWHnZMZ5nWZ7lW3DU2DNJOH047t99_Hj6_cv7T5-Ojw_7D-9Phz9-e3f6cnwCZaDEs3VgS2CrdF6elVeF0ipc5pW2Beq5oX4uSVMglj-yVZrAvgtvnQzSkjeMrwP01n1LWPrA0ofPNUFJGDpHQN-VDx6CBdTa9lAog07RMKJMICeoDTCWj11tSw6DdWCojw0YP7wYnrqvUkAjwdkuEISamlgv1KQc2N4MvUSc7ydIxwYrZQjQAH0n0QUsdFyIAWr0caUnQA9tV2glwF-awmrP-LuhTajJgK_RkQStCjcy0BYlycjCjpXuKrdKfIOuhVBbT9dyE5aPzhaaGg-9CvVblY5QlAHrJDmwDjydyalwYfnDWDVL4BjAGn0BLEsSYWAF9kwuAvXRAraNsg6ajrVjyTqE1scy_MD4gUgnyjN-EIzvGd9Lh2Vg_FCgVyLxQSTyYrBRIqnIkEMNpbPN0EqjqTqsCFp0IeLta6UpCjbVAklCoyMf9-cHdG8GYqhPJvAJfJ0U_NUhYPnj6YQhOFV0gU4nxjeMb66KRwnjAJdUYqcD45zx7fQzyv4z2IIENjSZ5Ybi1X289hjrxprGhtrZ_q62D3iBWklJBhjf9NF6k9T6AkWntFSmGr1z35Dlj-MqxrcJPCkjXkivgiddgkCtr3a_62kbCqqh0fAvnX554fOX5yeiCSOUSMZ3VUU-kARHrUZBDZnwQ0Sw_AFiPtxV6ZXWo3FrPNMky_xnZeh7a10geXcq_0a_1qkzBrpO8kMs3AIBKgp-cKgaBI0LnYpil9aNLF6wj3UKR_gtih5qZSqfxH35XCsPajxjDSoDwhpBziSMb-HI-F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