Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot link Rust (1.60+, ARM64) generated static-object with Go #97117

Closed
bnpfeife opened this issue May 17, 2022 · 7 comments
Closed

Cannot link Rust (1.60+, ARM64) generated static-object with Go #97117

bnpfeife opened this issue May 17, 2022 · 7 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bnpfeife
Copy link

bnpfeife commented May 17, 2022

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.

@bnpfeife bnpfeife added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 17, 2022
@petrochenkov
Copy link
Contributor

This looks very similar to #95926 which happened due to switching the linking default from -static to -static-pie in 1.59 or 1.60.

2 similar comments
@petrochenkov
Copy link
Contributor

This looks very similar to #95926 which happened due to switching the linking default from -static to -static-pie in 1.59 or 1.60.

@petrochenkov
Copy link
Contributor

This looks very similar to #95926 which happened due to switching the linking default from -static to -static-pie in 1.59 or 1.60.

@Titaniumtown
Copy link

You could say that 3 times!

@wllenyj
Copy link

wllenyj commented Jun 24, 2022

The important things to say 3 times.

@wolffcm
Copy link

wolffcm commented Aug 12, 2022

I just tried reproducing this from the Dockerfile in the linked fork of rust-plus-golang with Go 1.19 and Rust 1.63, and I still get the same error.

@bnpfeife
Copy link
Author

bnpfeife commented Aug 19, 2022

Hello @wolffcm @petrochenkov @Titaniumtown @wllenyj,

My apologies for the radio silence on this issue. I found that the root cause was musl-cross-make. musl still requires a patch to enable "static-pie". However, when I cross-compile musl (+patch) for x86_64 and aarch64, I can build and link a "static-pie" executable. I believe this can be closed as #95926 summaries the original issue.

If anyone comes across this issue, follow the original build instructions, but on this branch for a demo of the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants