Cross-compiling Rust for aarch64 from amd64

Hi there,

I am trying to setup RUST cross compilation and building on AMD64/FreeBSD 14.rc3 for aarch64/FreeBSD 14.rc3. I am very new to cross compilation so not sure what details are needed, please let me know if something is missing.

SO I have a project on Rust that I am trying to build for aarch64 architecture and I googled many things and got as far as being able to compile but not being able to link. SO I assume the linker is the problem.

The linker I downloaded is devel/freebsd-gcc12

I also downloaded sysroot from devel/freebsd-sysroot

I set up environment with sysroot as follows export PKG_CONFIG_SYSROOT_DIR=/usr/local/freebsd-sysroot/aarch64

Then I setup .cargo/config
Code:
[target.aarch64-unknown-freebsd]
linker="aarch64-unknown-freebsd14.0-gcc12"

Then I'm adding nightly toolchain rustup +nightly component add rust-src

And then I execute cargo +nightly build -Z build-std --target aarch64-unknown-freebsd

Where I am seeing that all dependencies compiled but then linker is throwing error
Code:
error: linking with `aarch64-unknown-freebsd14.0-gcc12` failed: exit status: 1
...

note: /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: Relocations in generic ELF (EM: 62)


          /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: Relocations in generic ELF (EM: 62)


          /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: Relocations in generic ELF (EM: 62)


          /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: Relocations in generic ELF (EM: 62)


          /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: Relocations in generic ELF (EM: 62)


          /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: Relocations in generic ELF (EM: 62)


          /usr/local/bin/aarch64-unknown-freebsd14.0-ld: /usr/lib/Scrt1.o: error adding symbols: file in wrong format


          collect2: error: ld returned 1 exit status

And that is pretty much where I am at. Any help is greatly appreciated, thank you.
 
Last edited:
plexinvise
Quite old post, but did you get far with this?
Not really, got sidetracked and left it in "another day" bucket. I'm pretty sure the right way to think about it is to setup qemu environment for the rust compiler. Not sure how to do that yet though. Let me know if you get anywhere with this. Thanks
 
It actually worked for me, to a point.
As long as pure rust code was compiled everything was okay.
But then it needed to link to a shared library, so I needed to somehow put it in the right place, etc/
That's where I gave up and decided to build directly on a small arm64 system that I have.
 
In my context: "work" means I can install, run and upgrade FreeBSD on it (command line is fine, desktop not needed). The goal is to explore working with FreeBSD ports and other areas of interest on arm64.
 
It's not fast, but it works.
Using an eMMC module instead of SD card helps a little bit too.
I haven't compared performance to running under qemu on a modern amd64 CPU (like some Ryzen).
I probably should, just to enlighten myself, at least.
 
I have experimented a bit with arm64 laptops (Samsung Snapdragon, Mac M2), but they do not work for FreeBSD yet. ("Do not work" -> I haven't managed to install FreeBSD on them).
And from what I read on these forums and elsewhere, Raspberry Pi 5 isn't so easy either.
 
Back
Top