Skip to content

test_stable_hash fails on s390x (big-endian) #15265

@cuviper

Description

@cuviper

Problem

Since 1.85.0, s390x-unknown-linux-gnu fails on cargo's test_stable_hash. Here's the result on master as of commit c14c1c0:

---- core::source_id::tests::test_stable_hash stdout ----

thread 'core::source_id::tests::test_stable_hash' panicked at src/cargo/core/source_id.rs:823:9:

---- expected: src/cargo/core/source_id.rs:823:46
++++ actual:   In-memory
   1      - 7062945687441624357∅
        1 + 2724068093996237922∅

assert_data_eq!(gen_hash(source_id), str!["7062945687441624357"].raw());

The actual is byte-swapped from the expected value, even though stable-hashing is meant to be platform-agnostic.

Steps

In cargo's own repo: cargo test --lib test_stable_hash

Possible Solution(s)

No response

Notes

I found that rustc-stable-hash adds a .to_le() in its Hasher::finish, which seems suspect:
https://github.com/rust-lang/rustc-stable-hash/blob/24e9848c89917abca155c8f854118e6d00ad4a30/src/sip128.rs#L532

When cargo's test calls .to_string(), that will treat the u64 as native-endian, so it doesn't match the string that a little-endian host would produce.

Similarly, the next line in the test calls short_hash -> to_hex -> to_le_bytes, which will byte-swap it again before hex-printing it.

Version


Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions