Skip to content

alloc-override.c uses wrong type for std::nothrow_t argument in C++ operator new overrides #840

Closed

Description

@sbc100

alloc-override.c overrides operator new, etc, using C functions with C++ mangled names. e.g:

void* _ZnwmRKSt9nothrow_t(size_t n, mi_nothrow_t tag) { MI_UNUSED(tag); return mi_new_nothrow(n); }

The requires signature of this function can be seen via c++filt:

$ c++filt _ZnwmRKSt9nothrow_t
operator new(unsigned long, std::nothrow_t const&)

Note that the second argument here (and everywhere that std::nothrow_t is uses) is passed by reference, but _ZnwmRKSt9nothrow_t is passing mi_nothrow_t by value.

On most platform, especially since all the overrides simply ignore this argument, this is not an issue, but on Wasm C signatures are requires to match between compilation unit.

As it stands, under wasm64, we get a linker warning about the std::nothrow_t argument having a different width in libmimalloc compared to libc++.

See emscripten-core/emscripten#21127 for the proposed downstream fix.

Activity

  1. added a commit that references this issue on Apr 12, 2024
  2. daanx commented on Apr 19, 2024

    @daanx
    Collaborator

    Apologies for the late fix; I pushed a potential fix to dev/dev-slice where I redefine mi_nothrow_t to be a void* -- I guess this will fix the linker error as well?

  3. sbc100 commented on Jul 12, 2024

    @sbc100
    Author

    Yup that should do it. I guess we can close this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions