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 *BSD native ABI detection #9089

Closed
LemonBoy opened this issue Jun 12, 2021 · 4 comments · Fixed by #21617
Closed

Improve *BSD native ABI detection #9089

LemonBoy opened this issue Jun 12, 2021 · 4 comments · Fixed by #21617
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-freebsd os-openbsd
Milestone

Comments

@LemonBoy
Copy link
Contributor

At the moment zig detects the native ABI as .gnu, that may cause some problems as many *BSD libcs are not fully gnu-compliant (eg. NetBSD has no sincos, a GNU extension, but since we're passing LLVM the wrong triple we end up with some missing symbols).

cc @mikdusan as I guess you'd love some BSD action

@Vexu Vexu added enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. labels Jun 12, 2021
@Vexu Vexu added this to the 0.9.0 milestone Jun 12, 2021
@mikdusan
Copy link
Member

  • the following compares -triple for both zig cc and system clang for compiling empty.c on a freebsd host
"/usr/home/mike/project/zig/work/main/_build/zig" -cc1 -triple x86_64-unknown-freebsd-gnu
"/usr/bin/clang" -cc1 -triple x86_64-unknown-freebsd13.0

zig and llvm model things slightly differently:

  • Target.abi.none vs (Triple.Environment.unknown and .hasEnvironment())
  • currently when Target.abi == none we omit the Environment string component of -triple and it ends up as hasEnvironment() == false

Along those lines we could simply do this:

  • set .abi = .none when detecting target on *bsd hosts (and darwin)
  • bad: this lies to the reader because we in fact have an ABI

But don't we actually want to capture the idea that .abi is optional? We could either do that through using zig optional but it would have higher impact on src/*.zig codebase, or we could add enum .unspecified or similar.

Thoughts?

@LemonBoy
Copy link
Contributor Author

set .abi = .none when detecting target on *bsd hosts (and darwin)

When targeting ARM you still want to specify EABI/EABIHF as ABI, at least for *BSD targets.

or we could add enum .unspecified or similar.

On the LLVM side .none doesn't really mean "no ABI" but more "unspecified, do not make any assumption".

@alexrp
Copy link
Member

alexrp commented Aug 27, 2024

  • currently when Target.abi == none we omit the Environment string component of -triple and it ends up as hasEnvironment() == false

Nowadays we handle Abi.none by emitting unknown as the ABI component. @mikdusan can you confirm whether this issue is still actually relevant?

@mikdusan
Copy link
Member

zig env still detects/sets gnu as the ABI on the BSDs:

"target": "x86_64-freebsd.14.1...14.1-gnu",
"target": "x86_64-netbsd.10.0...10.0-gnu",
"target": "x86_64-openbsd.7.5...7.5-gnu",

alexrp added a commit to alexrp/zig that referenced this issue Oct 6, 2024
alexrp added a commit to alexrp/zig that referenced this issue Oct 6, 2024
…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.
alexrp added a commit to alexrp/zig that referenced this issue Oct 6, 2024
…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.
alexrp added a commit to alexrp/zig that referenced this issue Oct 15, 2024
…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.
@alexrp alexrp closed this as completed in 8818dc6 Nov 2, 2024
@alexrp alexrp modified the milestones: 0.15.0, 0.14.0 Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. os-freebsd os-openbsd
Projects
None yet
5 participants