Skip to content

Rollup of 2 pull requests - #156574

Closed
JonathanBrouwer wants to merge 9 commits into
rust-lang:mainfrom
JonathanBrouwer:rollup-OtmIrGC
Closed

Rollup of 2 pull requests#156574
JonathanBrouwer wants to merge 9 commits into
rust-lang:mainfrom
JonathanBrouwer:rollup-OtmIrGC

Conversation

@JonathanBrouwer

Copy link
Copy Markdown
Member

Successful merges:

r? @ghost

Create a similar rollup

Urgau and others added 9 commits May 14, 2026 12:41
Add lint againts invalid runtime symbol definitions

This PR adds a deny-by-default lint againts invalid runtime symbol definitions, those runtime symbols are assumed and used by `core`[^1] and `rustc` with a specific definition.

We have had multiple reports of users tripping over `std` symbols (addressed in a future PR):
 - [Why does `#[no_mangle] fn open() {}` make `cargo t` hang?](https://users.rust-lang.org/t/why-does-no-mangle-fn-open-make-cargo-t-hang/103423)
 - [Pointer becomes misaligned in test with `no_mangle`](https://users.rust-lang.org/t/pointer-becomes-misaligned-in-test-with-no-mangle/126580)

This PR is a second attempt after rust-lang#146505, where T-lang had [some reservations](rust-lang#146505 (comment)) about a blanket lint that does not check the signature, which is now done with this PR, and about linting of `std` runtime symbols when std is not linked, which this PR omits by not including any std runtime symbols (for now).

## `invalid_runtime_symbol_definitions`

*(deny-by-default)*

The `invalid_runtime_symbol_definitions` lint checks the signature of items whose symbol name is a runtime symbols expected by `core`.

### Example

```rust,compile_fail
#[unsafe(no_mangle)]
pub fn memcmp() {} // invalid definition of the `memcmp` runtime symbol
```

```text
error: invalid definition of the runtime `memcmp` symbol used by the standard library
 --> a.rs:2:1
  |
4 | fn memcmp() {}
  | ^^^^^^^^^^^
  |
  = note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32`
          found    `fn()`
  = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcmp")]`, or `#[link_name = "memcmp"]`
  = note: `#[deny(invalid_runtime_symbol_definitions)]` on by default
```

### Explanation

Up-most care is required when defining runtime symbols assumed and used by the standard library. They must follow the C specification, not use any standard-library facility or undefined behavior may occur.

The symbols currently checked are `memcpy`, `memmove`, `memset`, `memcmp`, `bcmp` and `strlen`.

[^1]: https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library
Disable `main_needs_argc_argv` for Wasm

AFAIU this explains to the "Rust Runtime" that `main()` doesn't need `argc`/`argv`. Newer Wasm targets have explicitly disabled this, this PR changes it so that the base Wasm configuration affecting all Wasm targets disables this now.

This affects the following targets:
- `wasm32-unknown-unknown`
- `wasm32v1-none`
- `wasm64-unknown-unknown`

The only Wasm target where `main_needs_argc_argv` is still enabled is `wasm32-unknown-emscripten`. @hoodmane let me know and I can remove it there as well.

Credit goes to @Spxg for stumbling on this.

r? @alexcrichton
@rust-bors rust-bors Bot added the rollup A PR which is a rollup label May 14, 2026
@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. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 14, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Member Author

@bors r+ rollup=never p=5

@rust-bors

rust-bors Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

📌 Commit b128690 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 May 14, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request May 14, 2026
…uwer

Rollup of 2 pull requests

Successful merges:

 - #155521 (Add lint againts invalid runtime symbol definitions)
 - #156571 (Disable `main_needs_argc_argv` for Wasm)
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job dist-various-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    |
 52 | / macro_rules! intrinsics {
 53 | |     () => ();
...   |
415 | |             unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
    | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
485 | |     );
486 | | }
    | |_- in this expansion of `intrinsics!`
    |
   ::: /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/mem/mod.rs:10:1
    |
 10 | / intrinsics! {
 11 | |     #[mem_builtin]
 12 | |     pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
 13 | |         impls::copy_forward(dest, src, n);
...   |
 50 | | }
    | |_- in this macro invocation
    |
    = note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void`
            found    `unsafe extern "C" fn(*mut u8, *const u8, usize) -> *mut u8`
    = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcpy")]`, or `#[link_name = "memcpy"]`
    = note: `#[deny(invalid_runtime_symbol_definitions)]` on by default

error: invalid definition of the runtime `memmove` symbol used by the standard library
   --> /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/macros.rs:415:13
    |
 52 | / macro_rules! intrinsics {
 53 | |     () => ();
...   |
415 | |             unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
    | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
420 | |         intrinsics!($($rest)*);
    | |         ---------------------- in this macro invocation (#2)
...   |
485 | |     );
486 | | }
    | | -
    | | |
    | |_in this expansion of `intrinsics!` (#1)
    |   in this expansion of `intrinsics!` (#2)
    |
   ::: /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/mem/mod.rs:10:1
    |
 10 | / intrinsics! {
 11 | |     #[mem_builtin]
 12 | |     pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
 13 | |         impls::copy_forward(dest, src, n);
...   |
 50 | | }
    | |_- in this macro invocation (#1)
    |
    = note: expected `unsafe extern "C" fn(*mut c_void, *const c_void, usize) -> *mut c_void`
            found    `unsafe extern "C" fn(*mut u8, *const u8, usize) -> *mut u8`
    = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memmove")]`, or `#[link_name = "memmove"]`

error: invalid definition of the runtime `memset` symbol used by the standard library
   --> /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/macros.rs:415:13
    |
 52 | / macro_rules! intrinsics {
 53 | |     () => ();
...   |
415 | |             unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
    | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
420 | |         intrinsics!($($rest)*);
    | |         ----------------------
    | |         |
    | |         in this macro invocation (#2)
    | |         in this macro invocation (#3)
...   |
---
    |   in this expansion of `intrinsics!` (#3)
    |
   ::: /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/mem/mod.rs:10:1
    |
 10 | / intrinsics! {
 11 | |     #[mem_builtin]
 12 | |     pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
 13 | |         impls::copy_forward(dest, src, n);
...   |
 50 | | }
    | |_- in this macro invocation (#1)
    |
    = note: expected `unsafe extern "C" fn(*mut c_void, i32, usize) -> *mut c_void`
            found    `unsafe extern "C" fn(*mut u8, i32, usize) -> *mut u8`
    = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memset")]`, or `#[link_name = "memset"]`

error: invalid definition of the runtime `memcmp` symbol used by the standard library
   --> /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/macros.rs:415:13
    |
 52 | / macro_rules! intrinsics {
 53 | |     () => ();
...   |
415 | |             unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
    | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
420 | |         intrinsics!($($rest)*);
    | |         ----------------------
    | |         |
    | |         in this macro invocation (#2)
    | |         in this macro invocation (#3)
...   |
---
    |   in this expansion of `intrinsics!` (#3)
    |
   ::: /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/mem/mod.rs:10:1
    |
 10 | / intrinsics! {
 11 | |     #[mem_builtin]
 12 | |     pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
 13 | |         impls::copy_forward(dest, src, n);
...   |
 50 | | }
    | |_- in this macro invocation (#1)
    |
    = note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32`
            found    `unsafe extern "C" fn(*const u8, *const u8, usize) -> i32`
    = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "memcmp")]`, or `#[link_name = "memcmp"]`

error: invalid definition of the runtime `bcmp` symbol used by the standard library
   --> /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/macros.rs:415:13
    |
 52 | / macro_rules! intrinsics {
 53 | |     () => ();
...   |
415 | |             unsafe extern $abi fn $name( $($argname: $ty),* ) $(-> $ret)? {
    | |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...   |
420 | |         intrinsics!($($rest)*);
    | |         ----------------------
    | |         |
    | |         in this macro invocation (#2)
    | |         in this macro invocation (#3)
...   |
---
    |   in this expansion of `intrinsics!` (#3)
    |
   ::: /rustc/77f0eecdc7f0b33434e3c3e20a3bd88865a780bd/library/compiler-builtins/compiler-builtins/src/mem/mod.rs:10:1
    |
 10 | / intrinsics! {
 11 | |     #[mem_builtin]
 12 | |     pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 {
 13 | |         impls::copy_forward(dest, src, n);
...   |
 50 | | }
    | |_- in this macro invocation (#1)
    |
    = note: expected `unsafe extern "C" fn(*const c_void, *const c_void, usize) -> i32`
            found    `unsafe extern "C" fn(*const u8, *const u8, usize) -> i32`
    = help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name = "bcmp")]`, or `#[link_name = "bcmp"]`

[RUSTC-TIMING] compiler_builtins test:false 1.369
error: could not compile `compiler_builtins` (lib) due to 5 previous errors
warning: build failed, waiting for other jobs to finish...
[RUSTC-TIMING] core test:false 16.806

@rust-bors rust-bors Bot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 14, 2026
@rust-bors

rust-bors Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

💔 Test for 77f0eec failed: CI. Failed job:

@rust-bors rust-bors Bot 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-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2026
@rust-bors

rust-bors Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

PR #156571, which is a member of this rollup, was unapproved.

@rust-bors

rust-bors Bot commented May 14, 2026

Copy link
Copy Markdown
Contributor

PR #155521, which is a member of this rollup, was unapproved.

@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 14, 2026
@JonathanBrouwer
JonathanBrouwer deleted the rollup-OtmIrGC branch August 21, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rollup A PR which is a rollup T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants