Skip to content

Improve the DynamicLinker API and fix detectAbiAndDynamicLinker() for non-Linux/Hurd ELF hosts - #21617

Merged
alexrp merged 5 commits into
ziglang:masterfrom
alexrp:target-dyld-stuff
Nov 2, 2024
Merged

alexrp merged 5 commits into
ziglang:masterfrom
alexrp:target-dyld-stuff

Conversation

@alexrp

@alexrp alexrp commented Oct 6, 2024

Copy link
Copy Markdown
Member

Closes #9089.

@alexrp

alexrp commented Oct 6, 2024

Copy link
Copy Markdown
Member Author

@mikdusan ok, I believe this + #21611 should do the trick for ABI detection on BSDs.

@mikdusan

mikdusan commented Oct 7, 2024

Copy link
Copy Markdown
Member

lgtm, zig env | grep target on various BSDs:

"target": "x86_64-freebsd.14.1...14.1-none",
"target": "x86_64-netbsd.10.0...10.0-none",
"target": "x86_64-netbsd.9.4...9.4-none",
"target": "x86_64-openbsd.7.5...7.5-none",
"target": "x86_64-dragonfly.6.4...6.4-none",

@alexrp

alexrp commented Oct 7, 2024

Copy link
Copy Markdown
Member Author

Nice, thanks for testing!

@alexrp
alexrp requested a review from andrewrk October 8, 2024 10:40
@alexrp

alexrp commented Oct 13, 2024

Copy link
Copy Markdown
Member Author

@andrewrk just need your thoughts on the new DynamicLinker.kind() function and the direction of making DynamicLinker.standard() stricter in regards to what triples it's willing to return "standard" paths for (see the commit message).

This helps callers of DynamicLinker.standard() make informed decisions about
the usefulness of the returned value.
hasDynamicLinker() was just kind of lying in the case of Darwin platforms for
the benefit of std.zig.system.detectAbiAndDynamicLinker(). A better name would
have been hasElfDynamicLinker() or something. It also got the answer wrong for a
bunch of platforms that don't actually use ELF. Anyway, this was clearly the
wrong layer to do this at, so remove this function and instead use
DynamicLinker.kind() + an isDarwin() check in detectAbiAndDynamicLinker().
…F hosts.

Since we exclude Abi.none from the list of ABIs to be tested, it means that
Abi.gnu, which happens to be the first in the list, always gets picked for hosts
where the dynamic linker path does not depend on the ABI component of the
triple. Such hosts include all the BSDs, Haiku, Serenity, Solaris, etc.

To fix this, use DynamicLinker.kind() to determine whether this whole exercise
even makes sense. If it doesn't, as is the case on every OS other than Linux and
Hurd, we'll just fall back to Abi.default() which will try to pick a sensible
default based on the arch and OS components. This detection logic still has
plenty of room for improvement, but is at least a notable step up from
confusingly detecting Abi.gnu ~everywhere.

Closes #9089.
Its semantics are now documented in terms of DynamicLinker.kind(os.tag).

The idea here is two-fold:

* The term "standard" actually means something; we shouldn't return a valid
  dynamic linker path for a triple for which it hasn't *actually* been
  standardized. That's just incorrect. For example, previously, this function
  would happily return a path for x86_64-linux-androideabi, csky-macos-gnu, or
  aarch64-hurd-msvc, and other such obvious nonsense.
* Callers that use the return value from this function to do host probing (such
  as std.zig.system.detectAbiAndDynamicLinker()) can now do so with greater
  confidence because DynamicLinker.standard() will eagerly reject nonsensical
  target triples.
@alexrp
alexrp merged commit e27b464 into ziglang:master Nov 2, 2024
@alexrp
alexrp deleted the target-dyld-stuff branch November 2, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve *BSD native ABI detection

2 participants