)]}'
{
  "commit": "ce9954c0cfc4bf26b82aef16e6fd8b020c237992",
  "tree": "c24ebfa039fba107ec21ef2eff5aaa5a62922622",
  "parents": [
    "eb6346c659ccb0468a1477c716ca5450a1fa9ba1",
    "56d17c4d191feba4e4a016e1ffa74420f61a2703"
  ],
  "author": {
    "name": "bors",
    "email": "bors@rust-lang.org",
    "time": "Fri Jun 26 18:28:45 2026 +0000"
  },
  "committer": {
    "name": "bors",
    "email": "bors@rust-lang.org",
    "time": "Fri Jun 26 18:28:45 2026 +0000"
  },
  "message": "Auto merge of #155521 - Urgau:runtime-symbols, r\u003ddavidtwco\n\nAdd lint against invalid runtime symbol definitions\n\n\r\n\r\nThis 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.\r\n\r\nWe have had multiple reports of users tripping over `std` symbols (addressed in a future PR):\r\n - [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)\r\n - [Pointer becomes misaligned in test with `no_mangle`](https://users.rust-lang.org/t/pointer-becomes-misaligned-in-test-with-no-mangle/126580)\r\n\r\nThis PR is a second attempt after https://github.com/rust-lang/rust/pull/146505, where T-lang had [some reservations](https://github.com/rust-lang/rust/pull/146505#issuecomment-3492657109) 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). \r\n\r\n## `invalid_runtime_symbol_definitions`\r\n\r\n*(deny-by-default)* \r\n\r\nThe `invalid_runtime_symbol_definitions` lint checks the signature of items whose symbol name is a runtime symbols expected by `core` differs significantly from the expected signature (like mismatch ABI, mismatch C variadics, mismatch argument count, missing return type, ...).\r\n\r\n### Example\r\n\r\n```rust,compile_fail\r\n#[unsafe(no_mangle)]\r\npub fn memcmp() {} // invalid definition of the `memcmp` runtime symbol\r\n```\r\n\r\n```text\r\nerror: invalid definition of the runtime `memcmp` symbol used by the standard library\r\n --\u003e a.rs:2:1\r\n  |\r\n4 | fn memcmp() {}\r\n  | ^^^^^^^^^^^\r\n  |\r\n  \u003d note: expected `unsafe extern \"C\" fn(*const c_void, *const c_void, usize) -\u003e i32`\r\n          found    `fn()`\r\n  \u003d help: either fix the signature or remove any attributes like `#[unsafe(no_mangle)]`, `#[unsafe(export_name \u003d \"memcmp\")]`, or `#[link_name \u003d \"memcmp\"]`\r\n  \u003d note: `#[deny(invalid_runtime_symbol_definitions)]` on by default\r\n```\r\n\r\n### Explanation\r\n\r\nUp-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.\r\n\r\nThe symbols currently checked are `memcpy`, `memmove`, `memset`, `memcmp`, `bcmp` and `strlen`.\r\n\r\n## `suspicious_runtime_symbol_definitions`\r\n\r\n(warn-by-default, asked in [this comment](https://github.com/rust-lang/rust/pull/155521#issuecomment-4696528297))\r\n\r\nThe `suspicious_runtime_symbol_definitions` lint checks the signature of items whose symbol name is a runtime symbol expected by `core`.\r\n\r\n### Example\r\n\r\n```rust\r\n#[unsafe(no_mangle)]\r\npub extern \"C\" fn strlen(ptr: *mut f32) -\u003e usize { 0 }\r\n// suspicious definition of the `strlen` function\r\n// `ptr` should be `*const std::ffi::c_char`\r\n```\r\n\r\n### Explanation\r\n\r\nUp-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.\r\n\r\n[^1]: https://doc.rust-lang.org/core/index.html#how-to-use-the-core-library\r\n\r\n",
  "tree_diff": []
}
