Skip to content

Make je_malloc_conf weak on MSVC - #2689

Open
roblabla wants to merge 1 commit into
jemalloc:devfrom
roblabla:msvc-allow-overriding-malloc-conf
Open

roblabla wants to merge 1 commit into
jemalloc:devfrom
roblabla:msvc-allow-overriding-malloc-conf

Conversation

@roblabla

@roblabla roblabla commented Aug 12, 2024

Copy link
Copy Markdown
Contributor

Currently, the malloc_conf attribute isn't "weak" in the same way as on other toolchain. While it is possible to override it in an OBJ file, and the linker will favor the one from the obj file over the symbol from the lib, it isn't possible to override it from another lib file. This makes it impossible to override it from Rust, for instance, as it always generates libs and links them together.

While the weak attribute is not supported by MSVC, it can be emulated using the /alternatename linker flag. This flag takes two symbols, and aliases the first symbol to the second if it isn't defined during linking. This ensures that the default value provided by jemalloc can be overridden from all contexts, whether the override comes from an obj or a lib.

This is supported by MSVC link.exe since time immemorial, and by lld-link since 3.7.0.

@roblabla
roblabla force-pushed the msvc-allow-overriding-malloc-conf branch from 49dd323 to ebf0b39 Compare August 12, 2024 13:18
@roblabla
roblabla force-pushed the msvc-allow-overriding-malloc-conf branch 3 times, most recently from d4c2bb8 to 94ccfef Compare August 20, 2024 09:15
Previously, the malloc_conf attribute wasn't as "weak" on MSVC as on
other toolchain. While it is possible to override it in an OBJ file -
in MSVC, every symbol coming from a LIB file can be overriden from an
OBJ file - it isn't possible to override it from another lib file. This
makes it impossible to override it from Rust, for instance, as it always
generates libs and links them together, instead of linking the obj files
directly.

While the weak attribute is not supported by MSVC, it can be emulated
using the /alternatename linker flag. This flag takes two symbols, and
aliases the first symbol to the second if it isn't defined during
linking. This ensures that the default value provided by jemalloc can be
overridden from all contexts, whether the override comes from an obj or
a lib, matching the behavior of gcc's weak attribute.

This is supported by MSVC link.exe since time immemorial, and by
lld-link since 3.7.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant