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

zig cc silently ignores -fuse-ld= option #18357

Open
jiridanek opened this issue Dec 23, 2023 · 6 comments
Open

zig cc silently ignores -fuse-ld= option #18357

jiridanek opened this issue Dec 23, 2023 · 6 comments
Labels
bug Observed behavior contradicts documented or intended behavior

Comments

@jiridanek
Copy link

Zig Version

0.11.0

Steps to Reproduce and Observed Behavior

This is a follow-up to

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 #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 jiridanek added the bug Observed behavior contradicts documented or intended behavior label Dec 23, 2023
@jiridanek
Copy link
Author

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>

@kassane
Copy link
Contributor

kassane commented Dec 25, 2023

Currently, Zig allows you to switch between lld or zld (WiP) using the -fno-lld/-flld flags.

However, with zig cc It really doesn't allow you to use the command mentioned below:

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

@kubkon
Copy link
Member

kubkon commented Dec 25, 2023

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
Copy link
Member

kubkon commented Dec 25, 2023

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

@steeve
Copy link

steeve commented Jan 27, 2024

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

@polarathene
Copy link

Also please note that -fno-lld and -flld are only temporary

Is ZLD meant to be compatible with zig cc?

On Fedora I often have to explicitly provide -L /usr/lib64 if I use Zig to build libraries that belong there on Fedora, yet I wouldn't normally have to provide that (such as with cargo build instead of cargo zigbuild).


I am curious why static linking doesn't work (seems potentially similar to this comment for mold ). If all dependencies from ldd are provided via static libs (*.a) to zig cc and ldd shows that there is nothing dynamically linked, the binary segfaults when run because it still has the system interpreter configured when it shouldn't need that. The equivalent hello world built with gcc / clang and -static works fine.

I tried both the fedora package of zig and a version from the Zig downloads page where readelf -p .comment mentions both times Clang and LLD used (slightly different version reported between the two 0.13.0 zigs), but I assume are all part of the zig binary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

5 participants