How -Clinker and -Clinker-flavor interact if both set?

Is there any difference if I use this on Windows
-Clinker=rust-lld.exe -Clinker-flavor=link-lld

In the docs, there are description of behaviour if only one of them set (e.g. if I set -Clinker=rust-lld.exe or if I set -Clinker-flavor=link-lld) but no description of how they interact if both set.

Is linker-flavor ignored if I set linker? Or it somehow affects the linker specified?

If you look at an up-to-date version of the rustc documentation, you see:

If a linker is given with the -C linker flag, then the linker flavor is inferred from the value provided. If no linker is given then the linker flavor is used to determine the linker to use. Every rustc target defaults to some linker flavor.

Which implies that -C linker has priority over -C linker-flavor.

1 Like

As I understood, -C linker-flavor=flavor leads to adding addition -flavor=mapped_flavor to linker invokation.
E.g., if I specify -Clinker=rust-lld.exe -Clinker-flavor=ld.lld, it results as calling rust-lld.exe -flavor=gnu <other link args> during linkage.

Yes, it is confirmed.
Here is code in rustc: rust/ at 50f2c292007f9364908e4b8344886797f0144648 · rust-lang/rust · GitHub
And rust/ at 50f2c292007f9364908e4b8344886797f0144648 · rust-lang/rust · GitHub

So, process is following.
If -Clinker is specified but it is not rust-lld or lld, it used as is.
If -Clinker is specfied and it is rust-lld or lld, and no flavor specified, it uses default lld-flavor for toolchain, e.g. -flavor=gnu for x86_64-pc-windows-gnu or -flavor=link if it is x86_64-pc-windows-msvc.
If both -Clinker and -Clinker-flavor specified, this flavor passed to linker (even if linker is not lld). This way, it is possible to use gnu linkage on msvc target.

From practical POV, there is no need to specify -Clinker-flavor if -Clinker=rust-lld because there is default flavor already.

1 Like

Hmm, sounds like the rustc documentation is not quite accurate then.

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.