rust-lang / hashbrown

Rust port of Google's SwissTable hash map
https://rust-lang.github.io/hashbrown
Apache License 2.0
2.39k stars 276 forks source link

Compiling hashbrown 0.14.2 for aarch64-unknown-linux-gnu with "target-cpu=cortex-a53" generates illegal instructions #485

Closed rohel01 closed 9 months ago

rohel01 commented 9 months ago

Hello,

I am cross compiling a bevy application for a ARMA53 CPU using the aarch64-unknown-linux-gnu target. Since I am only targeting that HW, I tried to refine the build arguments for my specific needs. If I add "target-cpu=cortex-a53" to my cargo config, the resulting executable no longer runs on the target.

root@cortexa53:~# /tmp/toto.exe
Illegal instruction

Looking at the backtrace in GDB, it crashes when executing hashbrown functions. I narrowed it down to this simple program

use hashbrown::HashMap;

fn main() {
    let mut map = HashMap::new();

    map.insert(45879652u128, "Hello world");
    map.insert(5879u128, "Hello Michaël");
    map.insert(666u128, "Hello Hell");
    map.insert(6548674845153135486u128, "Hello you");

    if let Some(val) = map.get(&666) {
        println!("{val}");
    }
}

I do not understand this issue. Can you help?

I am using cargo 1.72.0-nightly (4cebd130e 2023-06-21)

My .cargo/config.toml is:

[target.aarch64-unknown-linux-gnu]
linker = "aarch64-toto-linux-gcc"
rustflags = [
    "-C",
    "target-cpu=cortex-a53",
    "-C",
    "target-feature=+crc",
    "-C",
    "force-frame-pointers",
    "-C",
    "relocation-model=static",
    "-C",
    "link-arg=-mcpu=cortex-a53",
    "-C",
    "link-arg=-march=armv8-a+crc",
    "-C",
    "link-arg=--sysroot=/some/path/sysroots/cortexa53-toto-linux",
]

I am linking with a Yocto generated SDK.

rohel01 commented 9 months ago

I have just found out the GDB disassemble command

The illegal instruction is:

=> 0x0000000000404358 <+104>:   aesd    v1.16b, v2.16b
rohel01 commented 9 months ago

Ok, adding the following to my cargo config file solve the issue. Sorry for the noise!

[target.aarch64-unknown-linux-gnu]
rustflags = [
#...
    "-C",
    "target-feature=-aes",
#...
]