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

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

Merged
merged 5 commits into from
Nov 2, 2024

Conversation

alexrp
Copy link
Member

@alexrp alexrp commented Oct 6, 2024

Closes #9089.

@alexrp
Copy link
Member Author

alexrp commented Oct 6, 2024

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

@alexrp alexrp force-pushed the target-dyld-stuff branch from 2ef89c5 to 11ffe62 Compare October 7, 2024 06:18
@mikdusan
Copy link
Member

mikdusan commented Oct 7, 2024

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

alexrp commented Oct 7, 2024

Nice, thanks for testing!

@alexrp alexrp requested a review from andrewrk October 8, 2024 10:40
@alexrp
Copy link
Member Author

alexrp commented Oct 13, 2024

@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).

@alexrp alexrp force-pushed the target-dyld-stuff branch from 11ffe62 to 3f88b13 Compare October 15, 2024 17:29
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 ziglang#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 force-pushed the target-dyld-stuff branch from 3f88b13 to 059f188 Compare October 26, 2024 20:00
@alexrp alexrp merged commit e27b464 into ziglang:master Nov 2, 2024
10 checks passed
@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