rust-lang / rust-lang/rust

x86-64 assembler silently truncates 64-bit address

Open
#118,223 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-inline-assembly A-LLVM C-bug I-miscompile I-unsound llvm-fixed-upstream O-x86_64 P-high T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

When using a 64-bit address with the mov instruction on x86-64, the assembler truncates the 64-bit address to 32-bit without notifying the user. It seems to expect an abs suffix on the mov instruction (movabs) to correctly use the 64-bit address, which I could not find in the Intel specification. See godbolt snippet:

asm!(
    "mov    [0x1234567890], al",
    "movabs [0x1234567890], al"
);

becomes:

mov BYTE PTR ds:0x34567890,   al ; 88 04 25 90 78 56 34
movabs       ds:0x1234567890, al ; a2       90 78 56 34 12 00 00 00

I would expect some form of feedback from the compiler, preferably a compilation failure, instead of the silent truncation.

Meta

rustc --version --verbose:

Stable:

rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4

Nightly:

rustc 1.76.0-nightly (2f8d81f9d 2023-11-21)
binary: rustc
commit-hash: 2f8d81f9dbac6b8df982199f69da04a4c8357227
commit-date: 2023-11-21
host: x86_64-unknown-linux-gnu
release: 1.76.0-nightly
LLVM version: 17.0.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the x86-64 behavior with the inline asm! entry point and the two mov forms from the report. Trace how the assembler handles the 64-bit address and compare the generated bytes; done means the truncating form produces a compilation failure or other clear diagnostic instead of silently generating a 32-bit address.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.