Why is rust calling GCC with an option it doesn't support? (Cross-compilation, linking to C++)

Hey! So I'm working on a C++ executable that statically links to a Rust library. When building for my development platform, it works fine. But when I build it for Nintendo Switch, it throws this error:

note: aarch64-none-elf-gcc: error: unrecognized command-line option '--script'

GCC doesn't seem to support "--script" specifically as an option. But when I looked at the Rust source code, it seems to pass "--script" regardless of the linker. (https://github.com/rust-lang/rust/blob/644e8068cbffef6428d1970fe50a4a863079ee54/compiler/rustc_codegen_ssa/src/back/link.rs#L1799)

I'm very hesitant to point fingers at Rust for this, because I'm not yet super fluent in Rust and I also expect this code has been thoroughly tested throughout the years. But honestly I'm just confused. Any help would be appreciated!

(Not knowledgeable about this topic specifically, just clicked around GitHub out of curiosity.)

Looks like Rust Switch support requires a linker script. (Or see the whole PR.) The assumption in the code you linked seems to be that "gnu flavored" linkers support --script.

Perhaps you can provide more details about your build invocation.

2 Likes

And it seems for the switch target we expect to directly call the linker rather than a linker wrapper like gcc or clang. By default we use the lld version shipped with rustc itself.

Alright so its specifically an issue with the switch target making that assumption?

Yeah, seems so.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.