-
Notifications
You must be signed in to change notification settings - Fork 68
Add #[used] static to always override
#146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9e5d00a to
e35c0d2
Compare
This was referenced Sep 16, 2025
Collaborator
|
Also great stuff 💯 When you're ready with this we can merge |
At least when the final linker invocation is driven by `rustc`.
e35c0d2 to
9650cee
Compare
Contributor
Author
|
Rebased, I think this is ready now. |
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Nov 11, 2025
…zelmann Simplify `jemalloc` setup In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang#95604, and more recently for Mach-O in rust-lang#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`. Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day). Test with: ```sh ./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true # macOS lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b _rjem_je_zone_register (lldb) run # Should breakpoint, this means that the allocator was properly linked # Linux lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b malloc (lldb) run # Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc` ``` try-job: `aarch64-gnu` try-job: `dist-aarch64-linux` try-job: `dist-x86_64-musl` try-job: `dist-x86_64-apple` try-job: `dist-aarch64-apple`
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Nov 11, 2025
…zelmann Simplify `jemalloc` setup In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang#95604, and more recently for Mach-O in rust-lang#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`. Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day). Test with: ```sh ./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true # macOS lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b _rjem_je_zone_register (lldb) run # Should breakpoint, this means that the allocator was properly linked # Linux lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b malloc (lldb) run # Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc` ``` try-job: `aarch64-gnu` try-job: `dist-aarch64-linux` try-job: `dist-x86_64-musl` try-job: `dist-x86_64-apple` try-job: `dist-aarch64-apple`
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Nov 12, 2025
…zelmann Simplify `jemalloc` setup In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang#95604, and more recently for Mach-O in rust-lang#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`. Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day). Test with: ```sh ./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true # macOS lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b _rjem_je_zone_register (lldb) run # Should breakpoint, this means that the allocator was properly linked # Linux lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b malloc (lldb) run # Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc` ``` try-job: `aarch64-gnu` try-job: `dist-aarch64-linux` try-job: `dist-x86_64-musl` try-job: `dist-x86_64-apple` try-job: `dist-aarch64-apple`
Zalathar
added a commit
to Zalathar/rust
that referenced
this pull request
Nov 12, 2025
…zelmann Simplify `jemalloc` setup In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang#95604, and more recently for Mach-O in rust-lang#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`. Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day). Test with: ```sh ./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true # macOS lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b _rjem_je_zone_register (lldb) run # Should breakpoint, this means that the allocator was properly linked # Linux lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b malloc (lldb) run # Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc` ``` try-job: `aarch64-gnu` try-job: `dist-aarch64-linux` try-job: `dist-x86_64-musl` try-job: `dist-x86_64-apple` try-job: `dist-aarch64-apple`
rust-timer
added a commit
to rust-lang/rust
that referenced
this pull request
Nov 12, 2025
Rollup merge of #146627 - madsmtm:jemalloc-simplify, r=jdonszelmann Simplify `jemalloc` setup In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in #95604, and more recently for Mach-O in #133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`. Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day). Test with: ```sh ./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true # macOS lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b _rjem_je_zone_register (lldb) run # Should breakpoint, this means that the allocator was properly linked # Linux lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b malloc (lldb) run # Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc` ``` try-job: `aarch64-gnu` try-job: `dist-aarch64-linux` try-job: `dist-x86_64-musl` try-job: `dist-x86_64-apple` try-job: `dist-aarch64-apple`
github-actions bot
pushed a commit
to rust-lang/miri
that referenced
this pull request
Nov 12, 2025
Simplify `jemalloc` setup In the past, `#[used]` had to appear in the top-level crate to have a consistent effect on the linker. This has been fixed a while ago for ELF with the introduction of the `symbols.o` file in rust-lang/rust#95604, and more recently for Mach-O in rust-lang/rust#133832, which means that libraries can now implement the required workarounds themselves. This allows moving these `#[used]` declarations out of our `main.rs`. Specifically, I have moved them into `tikv-jemalloc-sys` where they belong in tikv/jemallocator#109 and done the same for `mimalloc` in purpleprotocol/mimalloc_rust#146 (in case we want to experiment with switching to that one day). Test with: ```sh ./x build library src/tools/rustdoc src/tools/clippy --set rust.jemalloc=true # macOS lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b _rjem_je_zone_register (lldb) run # Should breakpoint, this means that the allocator was properly linked # Linux lldb -- ./build/host/stage1/bin/rustc -vV (lldb) b malloc (lldb) run # Should breakpoint, inspect that the `malloc` symbol comes from the `rustc` binary and not from `libc` ``` try-job: `aarch64-gnu` try-job: `dist-aarch64-linux` try-job: `dist-x86_64-musl` try-job: `dist-x86_64-apple` try-job: `dist-aarch64-apple`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At least when the linker is driven by
rustc. See the comments inlibmimalloc-sys/src/lib.rsfor details.Finally fixes #41, see https://github.com/madsmtm/test-malloc-overriding for the tests I've performed.
Builds upon #145, hence why this is marked as a draft.