Skip to content

Make no_mangle on foreign items explicit instead of implicit #144678

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jdonszelmann
Copy link
Contributor

@jdonszelmann jdonszelmann commented Jul 30, 2025

for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: no_no_mangle or something silly like that but by explicitly putting no_mangle in the codegen fn attrs of foreign items we can default it to no_mangle and then easily remove it when we don't want it.

I guess you'd know about this r? @bjorn3. Shouldn't be too hard to review :)

Builds on #144655 which should merge first.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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 Jul 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 30, 2025

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@bjorn3
Copy link
Member

bjorn3 commented Jul 30, 2025

Can you please squash the last two commits?

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

Can do

@jdonszelmann jdonszelmann force-pushed the no-mangle-extern branch 2 times, most recently from 1790424 to 5240989 Compare July 30, 2025 21:37
@@ -192,6 +192,10 @@ impl CodegenFnAttrs {
/// * `#[export_name(...)]` is present
/// * `#[linkage]` is present
///
/// Note that this returns true for foreign items.
/// However, in some places that care about `contains_extern_indicator`, foreign items
/// (in an `extern` block) should explicitly be ignored.
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to make this not return true for foreign items? Foreign items don't need to be exported and the point of this method is to check if an item needs to be exported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's annoying since we don't have a did or TyCtxt here. We could, but that'd involve adding another flag in the codegen fn attributes. I decided against that but it's perfectly possible.

@bjorn3
Copy link
Member

bjorn3 commented Aug 1, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 1, 2025

📌 Commit 9003a3b has been approved by bjorn3

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 Aug 1, 2025
Zalathar added a commit to Zalathar/rust that referenced this pull request Aug 3, 2025
…jorn3

Make no_mangle on foreign items explicit instead of implicit

for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: `no_no_mangle` or something silly like that but by explicitly putting `no_mangle` in the codegen fn attrs of foreign items we can default it to `no_mangle` and then easily remove it when we don't want it.

I guess you'd know about this r? `@bjorn3.` Shouldn't be too hard to review :)

Builds on rust-lang#144655 which should merge first.
bors added a commit that referenced this pull request Aug 3, 2025
Rollup of 13 pull requests

Successful merges:

 - #143857 (Port #[macro_export] to the new attribute parsing infrastructure)
 - #144070 (Implement `hash_map` macro )
 - #144322 (Add lint against dangling pointers from local variables)
 - #144667 (`AlignmentEnum` should just be `repr(usize)` now)
 - #144678 (Make no_mangle on foreign items explicit instead of implicit)
 - #144790 (Multiple bounds checking elision failures)
 - #144794 (Port `#[coroutine]` to the new attribute system)
 - #144805 (compiletest: Preliminary cleanup of `ProcRes` printing/unwinding)
 - #144808 (`Interner` arg to `EarlyBinder` does not affect auto traits)
 - #144816 (Update E0562 to account for the new impl trait positions)
 - #144822 (Return a struct with named fields from `hash_owner_nodes`)
 - #144824 (Updated test links in compiler)
 - #144829 (Use full flag name in strip command for Darwin)

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

Zalathar commented Aug 3, 2025

Trying to diagnose rollup failure #144846 (comment)

@bors try jobs=test-various

@rust-bors
Copy link

rust-bors bot commented Aug 3, 2025

⌛ Trying commit 9003a3b with merge 50d1271

To cancel the try build, run the command @bors try cancel.

rust-bors bot added a commit that referenced this pull request Aug 3, 2025
Make no_mangle on foreign items explicit instead of implicit

try-job: test-various
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Aug 3, 2025

💔 Test failed (CI). Failed jobs:

@Zalathar
Copy link
Contributor

Zalathar commented Aug 3, 2025

@bors r-

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 3, 2025
@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs T-clippy Relevant to the Clippy team. labels Aug 6, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@jdonszelmann
Copy link
Contributor Author

@bjorn3 well, the CI failure was indeed because I forgot to check for foreign items once. I applied your suggestion for contains_extern_indicator to return false for foreign items. The function has gained some parameters, but I guess this CI failure shows especially the value of having them. The alternative is to move the function to on the TyCtxt, since almost all uses are preceded by a codegen_fn_attrs. i.e. We could make it one operation; give a defid and get a true/false extern indicator + is not foreign item check. However, that may in some cases duplicate a call to codegen_fn_attrs . Another option is to make it a fn on TyCtxt that takes CodegenFnAttrs. Adding the two parameters is by far the simplest solution so that's what I did for now. It will certainly do the job.

@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

I ran the wasm test locally by the way, so I don't think another try build for wasm is strictly necessary if normal CI tests pass. That's up to you, but I know these changes fix the specific thing that caused the earlier rollup to fail.

@jdonszelmann
Copy link
Contributor Author

maybe @bors rollup=iffy

@bjorn3
Copy link
Member

bjorn3 commented Aug 6, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 6, 2025

📌 Commit 0dd2dec has been approved by bjorn3

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 Aug 6, 2025
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann
Copy link
Contributor Author

@bors r-

@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 Aug 6, 2025
@jdonszelmann
Copy link
Contributor Author

ah, something in miri :/

@jdonszelmann
Copy link
Contributor Author

should be ok now

@jdonszelmann
Copy link
Contributor Author

there we go, excuse me for the hiccoughs

@bjorn3
Copy link
Member

bjorn3 commented Aug 7, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 7, 2025

📌 Commit 202d1fd has been approved by bjorn3

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 Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. 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.

8 participants