Skip to content

Incorrect code behavior on aarch64 #68812

Closed
@berkus

Description

@berkus

The following code compiles and works correctly on x86_64. However, the same code when compiled for aarch64 with opt-level = "s" does not work.

https://github.com/berkus/mre-write_to
The culprit is the function show() in write_to.rs:44

(one-page version here -- this however is not enough for reproduction)

When used from the same module it correctly generates a &str from buffer slice. When used from another module the resulting str is "" (empty).

The original code location, where bug is easily reproducible by running makers test is here

(Disclaimer: custom target file, should match LLVM layout for aarch64 however; custom linker script for OS kernel)

There, marking the function with #[inline] makes it work correctly at call sites other than the same module (for example, from here). Removing inline modifier makes it produce "" (empty) strs. It still works correctly from within the same module (e.g. local unit tests pass).

Changing opt-level from "s" to 2 or 3 also fixes the issue.

Replacing from_utf8_unchecked with from_utf8().unwrap() causes different behavior. Now opt-levels 2 and "s" produce empty strs while opt-level 3 works as intended.

It looks like code generation bug to me.

$ rustc --version
rustc 1.42.0-nightly (cd1ef39 2020-01-31)

Ready to provide more information or test possible fixes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: Code generationC-bugCategory: This is a bug.E-needs-mcveCall for participation: This issue has a repro, but needs a Minimal Complete and Verifiable ExampleI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 stateP-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions