zig icon indicating copy to clipboard operation
zig copied to clipboard

zig cc silently ignores `-fuse-ld=` option

Open jiridanek opened this issue 2 years ago • 4 comments

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.

jiridanek avatar Dec 23 '23 15:12 jiridanek

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>

jiridanek avatar Dec 23 '23 17:12 jiridanek

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

kassane avatar Dec 25 '23 20:12 kassane

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.

kubkon avatar Dec 25 '23 20:12 kubkon

Also please note that -fno-lld and -flld are only temporary - once we support more target combinations we will always link using our linkers.

kubkon avatar Dec 25 '23 20:12 kubkon

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

steeve avatar Jan 27 '24 22:01 steeve