Skip to content

fix incorrect byte count suffix on MSVC - #165458

Open
paradoxicalguy wants to merge 2 commits into
rust-lang:mainfrom
paradoxicalguy:fix-msvc-byte-count-clean
Open

paradoxicalguy wants to merge 2 commits into
rust-lang:mainfrom
paradoxicalguy:fix-msvc-byte-count-clean

Conversation

@paradoxicalguy

@paradoxicalguy paradoxicalguy commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

fixes #165299

this moves the byte count calculation into a shared helper in rustc_codegen_ssa. it now derives the count from the original argument layouts rather than the lowered signature.

the fix is wired up for llvm. symbols are emitted with a \x01 prefix so llvm doesn’t decorate them a second time, and the linker-facing symbol naming path now handles the \x01 and ? prefixes.

testing:

verified fastcall, stdcall and vectorcall on msvc, including cross-crate references.
added a run-make regression test for the linker failure in #165299. unpatched nightly fails with LNK2001; patched compiler links successfully.
added codegen regression tests and updated the existing abi, unwind and assembly tests for the corrected symbol names and byte counts. this also resolves the over-aligned argument FIXME in win32-byte-count-suffix.rs.

cc @folkertdev @workingjubilee

@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs 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 Nov 4, 2026
@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: codegen, compiler
  • codegen, compiler expanded to 77 candidates
  • Random selection from 21 candidates

@rust-log-analyzer

This comment has been minimized.

@paradoxicalguy
paradoxicalguy force-pushed the fix-msvc-byte-count-clean branch from 3536372 to 3ec1e11 Compare November 4, 2026 14:01
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

current CI failure is pointing to this existing FIXME

#[target_feature(enable = "sse2")]
extern "vectorcall" fn four_vectors_vectorcall(_: i32x4, _: i32x4, _: i32x4, _: i32x4) {}
// CHECK-LABEL: eight_vectors_vectorcall@@128:
#[unsafe(no_mangle)]
#[target_feature(enable = "sse2")]
extern "vectorcall" fn eight_vectors_vectorcall(
_: i32x4,
_: i32x4,
_: i32x4,
_: i32x4,
_: i32x4,
_: i32x4,
_: i32x4,
_: i32x4,
) {
}
/// FIXME: the mangled name for this type is incorrect on msvc, where the argument is passed
/// indirectly and a pointer takes up 4 bytes, but clang counts the size of the type and uses
/// @8 there. With GNU the value is passed directly, so the suffix is correct.
#[repr(C, align(8))]

the existing win32-byte-count-suffix.rs test expected @4 for over-aligned arguments on msvc. the patch now emits @8, matching the original argument layout and the existing windows-gnu expectations.
updated that and edited the FIXME.

@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

@bors squash msg = "fix MSVC calling convention symbol byte counts"

@rust-bors

rust-bors Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Unknown value for argument "". Run @bors help or go to https://bors.rust-lang.org/help to see available commands.

@paradoxicalguy

Copy link
Copy Markdown
Contributor Author

is it because of blank space 🤔
@bors squash msg="fix MSVC calling convention symbol byte counts"

@rust-bors

This comment has been minimized.

@rust-bors

rust-bors Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🔨 5 commits were squashed into 71146c7.

@rust-bors
rust-bors Bot force-pushed the fix-msvc-byte-count-clean branch from 19b93cf to 71146c7 Compare November 4, 2026 21:25
@paradoxicalguy paradoxicalguy changed the title Fix msvc byte count clean fix incorrect byte count suffix on MSVC Nov 4, 2026
@paradoxicalguy
paradoxicalguy force-pushed the fix-msvc-byte-count-clean branch from 71146c7 to 16191b5 Compare November 4, 2026 22:15

@folkertdev folkertdev Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A downside of this rmake test is that it only runs on windows msvc. For my local development, I have this setup as a plain UI test.

This works on x86_64-unknown-linux-gnu because it uses lld as the linker, I think it should also work in the msvc CI jobs, but then in most other cases this test is ignored. So, I'm not sure we should add it, but just wanted to share this.

Some notes

  • uses build-pass so it builds and links all the way
  • uses add-minicore so it runs anywhere
  • uses compile-flags: -Clinker=rust-lld, a linker that I actually have, in combination with //@ needs-rust-lld
  • compile-flags: -Clink-arg=/NOENTRY ensures there are no external dependencies, only this file is needed to produce the final link
  • #![crate_type = "cdylib"] make sure there is something to link (this creates a final artifact)
//@ build-pass 
//@ add-minicore
//@ revisions: i686 x86_64
//@[i686] compile-flags: --target i686-pc-windows-msvc
//@[x86_64] compile-flags: --target x86_64-pc-windows-msvc
//@ compile-flags: -Copt-level=3 -Clinker=rust-lld -Clink-arg=/NOENTRY
//@ needs-llvm-components: x86
//@ needs-rust-lld
//@ ignore-backends: gcc

#![feature(no_core, abi_vectorcall)]
#![no_core]
#![crate_type = "cdylib"]

extern crate minicore;

// then test whatever

use minicore::simd::i32x4;

#[unsafe(no_mangle)]
pub extern "vectorcall" fn eight_vectors_vectorcall(
    _: i32x4,
    _: i32x4,
    _: i32x4,
    _: i32x4,
    _: i32x4,
    _: i32x4,
    _: i32x4,
    _: i32x4,
) {
}

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is much nicer tbh!
i ran into the missing target libraries while trying to get the i686 linker regression working locally, so minicore + rust-lld looks like a good way around that.

i'll try moving the existing regression into a build-pass test and check that it still fails on unpatched rustc for the expected linker errors

thanks for sharing this =D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it passed locally after configuring my local setup into this
pushed the portable rust-lld version for ci; kept the run-make test for now until we confirm it runs there. thanks

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-run-make Area: port run-make Makefiles to rmake.rs 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc emits an incorrect byte count suffix on MSVC

6 participants