Skip to content

Conversation

nikic
Copy link
Contributor

@nikic nikic commented Sep 19, 2025

Emit #[rustc_allocator] etc. attributes on the functions generated by the #[global_allocator] macro, which will emit LLVM attributes like "alloc-family". If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported.

There is a similar issue when the allocator shim is used, but I've opted not to fix that case in this PR, because doing that cleanly is somewhat gnarly.

Related to #145995.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

// CHECK-LABEL: ; __rustc::__rust_alloc
// CHECK-NEXT: ; Function Attrs: {{.*}}allockind("alloc,uninitialized,aligned") allocsize(0){{.*}}
// CHECK-NEXT: define noalias{{.*}} ptr @{{.*}}__rust_alloc(i64 {{.*}}%size, i64 allocalign{{.*}} %align)
panic!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How the the addition of the attribute change the behaviour here? I.e. what part of the checked stuff would have been missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically all the attributes with alloc in the name (allockind, allocsize, allocalign, etc.) would be missing.

@nnethercote
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Sep 20, 2025

📌 Commit 06b0076 has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 20, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 20, 2025
…cote

Add attributes for #[global_allocator] functions

Emit `#[rustc_allocator]` etc. attributes on the functions generated by the `#[global_allocator]` macro, which will emit LLVM attributes like `"alloc-family"`. If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported.

There is a similar issue when the allocator shim is used, but I've opted not to fix that case in this PR, because doing that cleanly is somewhat gnarly.

Related to rust-lang#145995.
bors added a commit that referenced this pull request Sep 20, 2025
Rollup of 6 pull requests

Successful merges:

 - #144592 (generate list of all variants with `target_spec_enum`)
 - #146762 (Fix and provide instructions for running test suite on Apple simulators)
 - #146766 (Add attributes for #[global_allocator] functions)
 - #146770 (fixes for numerous clippy warnings)
 - #146774 (Allow running `x <cmd> <path>` from a different directory)
 - #146800 (Fix unsupported `std::sys::thread` after move)

r? `@ghost`
`@rustbot` modify labels: rollup
@matthiaskrgr
Copy link
Member

@bors r-

#146807 (comment)

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 20, 2025
@nikic
Copy link
Contributor Author

nikic commented Sep 22, 2025

@bors try jobs=armhf-gnu

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 22, 2025
Add attributes for #[global_allocator] functions

try-job: armhf-gnu
@rust-bors
Copy link

rust-bors bot commented Sep 22, 2025

☀️ Try build successful (CI)
Build commit: 73fa854 (73fa8543bc6dd139d6a6727e1f434b0dda89adb1, parent: 9f32ccf35fb877270bc44a86a126440f04d676d0)

@nikic
Copy link
Contributor Author

nikic commented Sep 22, 2025

@bors r=nnethercote rollup=iffy

@bors
Copy link
Collaborator

bors commented Sep 22, 2025

📌 Commit b6456cd has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 22, 2025
@RalfJung
Copy link
Member

This fixes a regression introduced by #144086 which is on the beta branch (and hasn't been reverted there I think?), so nominating for beta backport.

@RalfJung RalfJung added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Sep 22, 2025
@mati865
Copy link
Member

mati865 commented Sep 22, 2025

An alternative would be to revert the original #144086
It's an optimisation, not a bugfix, so this might be a reasonable solution.

bors added a commit that referenced this pull request Sep 22, 2025
Add attributes for #[global_allocator] functions

Emit `#[rustc_allocator]` etc. attributes on the functions generated by the `#[global_allocator]` macro, which will emit LLVM attributes like `"alloc-family"`. If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported.

There is a similar issue when the allocator shim is used, but I've opted not to fix that case in this PR, because doing that cleanly is somewhat gnarly.

Related to #145995.
@bors
Copy link
Collaborator

bors commented Sep 22, 2025

⌛ Testing commit b6456cd with merge 1932ce3...

@rust-log-analyzer

This comment has been minimized.

Emit `#[rustc_allocator]` etc. attributes on the functions generated
by the `#[global_allocator]` macro, which will emit LLVM attributes
like `"alloc-family"`. If the module with the global allocator
participates in LTO, this ensures that the attributes typically
emitted on the allocator declarations are not lost if the
definition is imported.
@nikic
Copy link
Contributor Author

nikic commented Sep 23, 2025

@bors try jobs=test-various

@rust-bors

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Sep 23, 2025
Add attributes for #[global_allocator] functions

try-job: test-various
@rust-bors
Copy link

rust-bors bot commented Sep 23, 2025

☀️ Try build successful (CI)
Build commit: b7eea9f (b7eea9faff5906b26488eb7bf5ac397d9379749e, parent: f6092f224d2b1774b31033f12d0bee626943b02f)

@clubby789
Copy link
Contributor

@bors r=nnethercote rollup=iffy

@bors
Copy link
Collaborator

bors commented Sep 23, 2025

📌 Commit bc7986e has been approved by nnethercote

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 23, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 24, 2025
…cote

Add attributes for #[global_allocator] functions

Emit `#[rustc_allocator]` etc. attributes on the functions generated by the `#[global_allocator]` macro, which will emit LLVM attributes like `"alloc-family"`. If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported.

There is a similar issue when the allocator shim is used, but I've opted not to fix that case in this PR, because doing that cleanly is somewhat gnarly.

Related to rust-lang#145995.
bors added a commit that referenced this pull request Sep 25, 2025
Rollup of 14 pull requests

Successful merges:

 - #145067 (RawVecInner: add missing `unsafe` to unsafe fns)
 - #145277 (Do not materialise X in [X; 0] when X is unsizing a const)
 - #145973 (Add `std` support for `armv7a-vex-v5`)
 - #146667 (Add an attribute to check the number of lanes in a SIMD vector after monomorphization)
 - #146735 (unstably constify float mul_add methods)
 - #146737 (f16_f128: enable some more tests in Miri)
 - #146766 (Add attributes for #[global_allocator] functions)
 - #146905 (llvm: update remarks support on LLVM 22)
 - #146982 (Remove erroneous normalization step in `tests/run-make/linker-warning`)
 - #147005 (Small string formatting cleanup)
 - #147007 (Explicitly note `&[SocketAddr]` impl of `ToSocketAddrs`)
 - #147008 (bootstrap.py: Respect build.jobs while building bootstrap tool)
 - #147013 (rustdoc: Fix documentation for `--doctest-build-arg`)
 - #147015 (Use `LLVMDisposeTargetMachine`)

r? `@ghost`
`@rustbot` modify labels: rollup
@apiraino
Copy link
Contributor

Beta backport declined as per compiler team on Zulip. As suggested by Nikita, a revert in beta si preferred.

@rustbot label -beta-nominated

@rustbot rustbot removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Sep 25, 2025
@RalfJung
Copy link
Member

@nikic will you handle doing the revert?

@nikic
Copy link
Contributor Author

nikic commented Sep 25, 2025

@RalfJung Sure, I put up a PR at #147030. Not sure what the process for beta reverts is, do I have to beta-nominate that PR?

@bors bors merged commit 46e25aa into rust-lang:master Sep 25, 2025
11 checks passed
@rustbot rustbot added this to the 1.92.0 milestone Sep 25, 2025
rust-timer added a commit that referenced this pull request Sep 25, 2025
Rollup merge of #146766 - nikic:global-alloc-attr, r=nnethercote

Add attributes for #[global_allocator] functions

Emit `#[rustc_allocator]` etc. attributes on the functions generated by the `#[global_allocator]` macro, which will emit LLVM attributes like `"alloc-family"`. If the module with the global allocator participates in LTO, this ensures that the attributes typically emitted on the allocator declarations are not lost if the definition is imported.

There is a similar issue when the allocator shim is used, but I've opted not to fix that case in this PR, because doing that cleanly is somewhat gnarly.

Related to #145995.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Sep 26, 2025
Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#145067 (RawVecInner: add missing `unsafe` to unsafe fns)
 - rust-lang/rust#145277 (Do not materialise X in [X; 0] when X is unsizing a const)
 - rust-lang/rust#145973 (Add `std` support for `armv7a-vex-v5`)
 - rust-lang/rust#146667 (Add an attribute to check the number of lanes in a SIMD vector after monomorphization)
 - rust-lang/rust#146735 (unstably constify float mul_add methods)
 - rust-lang/rust#146737 (f16_f128: enable some more tests in Miri)
 - rust-lang/rust#146766 (Add attributes for #[global_allocator] functions)
 - rust-lang/rust#146905 (llvm: update remarks support on LLVM 22)
 - rust-lang/rust#146982 (Remove erroneous normalization step in `tests/run-make/linker-warning`)
 - rust-lang/rust#147005 (Small string formatting cleanup)
 - rust-lang/rust#147007 (Explicitly note `&[SocketAddr]` impl of `ToSocketAddrs`)
 - rust-lang/rust#147008 (bootstrap.py: Respect build.jobs while building bootstrap tool)
 - rust-lang/rust#147013 (rustdoc: Fix documentation for `--doctest-build-arg`)
 - rust-lang/rust#147015 (Use `LLVMDisposeTargetMachine`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Sep 27, 2025
Revert "Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic"

This reverts commit 040a98a, reversing changes made to e8a792d.

This reverts #144086 on beta due to #145995. On master the issue will be fixed by #146766.
bors added a commit that referenced this pull request Sep 27, 2025
Revert "Auto merge of #144086 - clubby789:alloc-zeroed, r=nikic"

This reverts commit 040a98a, reversing changes made to e8a792d.

This reverts #144086 on beta due to #145995. On master the issue will be fixed by #146766.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 29, 2025
Emit allocator attributes for allocator shim

This emits the same attributes we place on allocator declarations on the definitions in the allocator shim as well. This complements rust-lang#146766, which added the attribute for `#[global_allocator]` definitions. Emitting the attributes on the definitions ensures that they cannot be lost of the allocator shim participates in LTO.

See rust-lang#145995 for context, though that one was about `#[global_allocator]`. I'm not sure whether this can occur with the allocator shim as well or not, but better safe than sorry.

I'm not sure whether there is any good way to test this, as the allocator shim is not part of `--emit=llvm-ir`. I've verified this locally by inspecting the bitcode produced by `-C save-temps`.

r? `@bjorn3`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 29, 2025
Emit allocator attributes for allocator shim

This emits the same attributes we place on allocator declarations on the definitions in the allocator shim as well. This complements rust-lang#146766, which added the attribute for `#[global_allocator]` definitions. Emitting the attributes on the definitions ensures that they cannot be lost of the allocator shim participates in LTO.

See rust-lang#145995 for context, though that one was about `#[global_allocator]`. I'm not sure whether this can occur with the allocator shim as well or not, but better safe than sorry.

I'm not sure whether there is any good way to test this, as the allocator shim is not part of `--emit=llvm-ir`. I've verified this locally by inspecting the bitcode produced by `-C save-temps`.

r? ``@bjorn3``
rust-timer added a commit that referenced this pull request Sep 30, 2025
Rollup merge of #147150 - nikic:alloc-shim-attributes, r=bjorn3

Emit allocator attributes for allocator shim

This emits the same attributes we place on allocator declarations on the definitions in the allocator shim as well. This complements #146766, which added the attribute for `#[global_allocator]` definitions. Emitting the attributes on the definitions ensures that they cannot be lost of the allocator shim participates in LTO.

See #145995 for context, though that one was about `#[global_allocator]`. I'm not sure whether this can occur with the allocator shim as well or not, but better safe than sorry.

I'm not sure whether there is any good way to test this, as the allocator shim is not part of `--emit=llvm-ir`. I've verified this locally by inspecting the bitcode produced by `-C save-temps`.

r? ``@bjorn3``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants