Description
Hello!
I am working on a project that uses Rust's CFFI to expose functions/symbols to Go. It uses musl to compile for AMD64 and musl-cross-make for ARM64. I've enabled static-linkage for both Rust and Go; and I've enabled PIE for Go. Everything works when I build with the Rust 1.58 toolchain. However, when I build with 1.60/nightly, the linker generates this error:
/go/pkg/tool/linux_amd64/link: running /usr/local/bin/aarch64-linux-musl-gcc failed: exit status 1
/usr/local/bin/../lib/gcc/aarch64-linux-musl/9.4.0/../../../../aarch64-linux-musl/bin/ld: read-only segment has dynamic relocations
collect2: error: ld returned 1 exit status
This might not be an issue with Rust. I've tried several combinations of RUSTFLAGS
to fix this, but I am unable to find the right combination. Since the issue isn't present in 1.58, however, I suspect it might be a compiler issue.
Unfortunately, this is difficult to replicate without a project. I've forked rust-plus-golang which is a minimal example of Rust CFFI + Go. My fork includes a docker
subdirectory. The Dockerfile can build the exact environment to replicate the issue. It should also be fairly trivial to switch between 1.58 and 1.60 by modifying that Dockerfile.
To build the environment (from the root of the repository):
# docker build -t crosscompiler docker
To build the executables (also from the root of the repository):
# docker run -v "$(pwd):/project" crosscompiler
Please, let me know if there is anything else that I can provide/change!
Thanks!
Edit:
My apologies, I forgot to mention, that AMD64 builds on both 1.58 and 1.60. It's just ARM64 that is impacted.