briansmith / ring

Safe, fast, small crypto using Rust
Other
3.77k stars 708 forks source link

Failed to link lib ring when trying to build binary files in aarch64-unknown-* #2141

Open xlouis027 opened 2 months ago

xlouis027 commented 2 months ago

I'm trying to build bins file of kuksa-databroker:

git clone https://github.com/eclipse-kuksa/kuksa-databroker.git cargo build --bins --release --target aarch64-unknown-linux-gnu // or aarch64-unknown-nto-qnx710

I configured and build lib ring successfully but I got these errors when creating binary files, the last steps:

/home/nd/qnx710/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: /tmp/rustcvdXfHX/libring-af233445ca34a4b5.rlib(0b57cc7e47bb3e90-curve25519.o): Relocations in generic ELF (EM: 62)
 /home/nd/qnx710/host/linux/x86_64/usr/bin/aarch64-unknown-nto-qnx7.1.0-ld: /tmp/rustcvdXfHX/libring-af233445ca34a4b5.rlib: error adding symbols: file in wrong format

I did successfully in x86_64 arch but I failed when I configured in aarch64-unknown-* arch.

andrewdavidmackenzie commented 2 months ago

I have a similar error. When I searched the web for it, some entries suggest it is due to having some object files compiled for the wrong architecture (x86 vs aarch64), although I am not 100% convinced.

Example: https://github.com/ninja-build/ninja/issues/2112#issuecomment-1510989125

andrewdavidmackenzie commented 2 months ago

I also have issues reported against ring, but for armv7, aarch64 seems to work fine for me :shrug:

bjorn3 commented 2 months ago

If you are cross-compiling you need to tell it where to find a C compiler that can cross-compile. See https://docs.rs/cc/latest/cc/#external-configuration-via-environment-variables for the env vars you can use to configure this.

andrewdavidmackenzie commented 2 months ago

I have tried setting CC="aarch64-elf-gcc" when trying to compile for target=aarch64-unknown-linux-gnu, but now realize that the problem (I think) is cross-compiling to linux from mac, not so much the arch. I guess I would need to setup a sysroot and all that stuff to get it to work, so I might reconsider and just use cross for linux builds.

The following warnings were emitted during compilation:

warning: ring@0.17.8: In file included from include/ring-core/base.h:64,
warning: ring@0.17.8:                  from include/ring-core/mem.h:60,
warning: ring@0.17.8:                  from crypto/curve25519/curve25519.c:22:
warning: ring@0.17.8: /opt/homebrew/Cellar/aarch64-elf-gcc/14.2.0/lib/gcc/aarch64-elf/14.2.0/include/stdint.h:9:16: fatal error: stdint.h: No such file or directory
warning: ring@0.17.8:     9 | # include_next <stdint.h>
warning: ring@0.17.8:       |                ^~~~~~~~~~
warning: ring@0.17.8: compilation terminated.