Skip to content

Improve *BSD native ABI detection #9089

Closed

Description

@LemonBoy

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

Activity

  1. added
    enhancement
    frontend
    on Jun 12, 2021
  2. added this to the 0.9.0 milestone on Jun 12, 2021
  3. mikdusan commented on Jun 12, 2021

    @mikdusan
    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?

  4. LemonBoy commented on Jun 12, 2021

    @LemonBoy
    ContributorAuthor

    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".

  5. modified the milestones: 0.9.0, 0.10.0 on Nov 22, 2021
  6. modified the milestones: 0.10.0, 0.11.0 on Apr 17, 2022
  7. modified the milestones: 0.11.0, 0.12.0 on Apr 9, 2023
  8. alexrp commented on Aug 27, 2024

    @alexrp
    Member
    • 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?

  9. mikdusan commented on Aug 27, 2024

    @mikdusan
    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",
  10. modified the milestones: 0.15.0, 0.14.0 on Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrontendos-freebsdos-openbsd

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions