zig cc silently ignores `-fuse-ld=` option
Zig Version
0.11.0
Steps to Reproduce and Observed Behavior
This is a follow-up to
- https://github.com/ziglang/zig/issues/4841#issuecomment-608177171
- https://github.com/ziglang/zig/issues/17480#issuecomment-1816104899
First issue wants to simply opt out from zig cc for linking to workaround a missing linker argument (and that is also my original desire, my issue is https://github.com/ziglang/zig/issues/18356)
The second issue mentions something about cgo, which I admit I don't really understand.
So far, from what I was able to find in GitHub issues, the discussion about the missing/uneffective argument went like this
Quick question: Have you considered adding something like -fuse-ld=/path/to/your/linker, which is supported by clang. This could be useful for using non-standard linkers in case it is needed.
This is a big topic, too big to answer as a quick question
Expected Behavior
I am able to pick my own linker and ignore the zig cc's.
Sneaky workaround, if using CMake when compiling, might be to switch to clang (or gcc with ldd) to run the linker invocation
set(CMAKE_C_LINK_EXECUTABLE "clang <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>")
keeping in mind that the unadulterated CMAKE_C_LINK_EXECUTABLE (on my machine) is
<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>
Currently, Zig allows you to switch between lld or zld (WiP) using the -fno-lld/-flld flags.
- https://github.com/ziglang/zig/issues/8726
However, with zig cc It really doesn't allow you to use the command mentioned below:
- https://github.com/compiler-explorer/compiler-explorer/issues/3682#issuecomment-1529123763
zig: warning: argument unused during compilation: '-fuse-ld=ld' [-Wunused-command-line-argument]
zig: warning: argument unused during compilation: '-stdlib=libstdc++' [-Wunused-command-line-argument]
cc: @kubkon
As a general direction, we do not want to expose -fuse-ld or -B flags to the user. Instead we would appreciate patches and issues submitted on GH.
Also please note that -fno-lld and -flld are only temporary - once we support more target combinations we will always link using our linkers.
Just been bit by this while trying to use the mold linker, would you accept a patch implementing -fuse-ld, -B and --ld-path ?
EDIT: thinking about it, --ld-path might be the easiest and most appropriate anyhow, even arocc deprecated -B and -fuse-ld