Skip to content

Reimplement crt0 code in Zig for vendored libcs #23875

Closed

Description

@alexrp

SLoC for crt0 code in some of the libcs we vendor:

  • FreeBSD libc: 825
  • MinGW-w64: 524
  • musl: 321
  • NetBSD libc: 467
  • wasi-libc: 56

(glibc is a bit harder to quantify because its organization is incredibly horrible, which results in us having a bunch of probably unnecessary code in lib/libc/glibc. I would be surprised if it's actually more than 2-3k lines of necessary crt0 code after pruning.)

This is really not a lot of code, so rewriting it in Zig would make a lot of sense, and would make progress towards #16270.

A secondary benefit would be finding any areas of the language that make writing this sort of code harder than it should be. In that regard, I can list these upfront:

Activity

  1. added this to the 0.16.0 milestone on May 14, 2025
  2. added
    enhancement
    os-windows
    os-freebsd
    os-netbsd
    os-wasi
    libc
    on May 14, 2025
  3. self-assigned this
    on May 15, 2025
  4. rootbeer commented on May 15, 2025

    @rootbeer
    Contributor

    Once re-written in Zig, how does the Zig crt0 code keep up with changes in the original libraries? Do Zig maintainers just need to look through the diffs in the source C library for changes that should get reflected in the Zig code? Seems fragile to me, but maybe the crt0 code doesn't change very much?

  5. alexrp commented on May 15, 2025

    @alexrp
    MemberAuthor

    Once re-written in Zig, how does the Zig crt0 code keep up with changes in the original libraries? Do Zig maintainers just need to look through the diffs in the source C library for changes that should get reflected in the Zig code?

    That's right.

    Seems fragile to me, but maybe the crt0 code doesn't change very much?

    I don't think so:

    • We can just add a step to the wiki page along the lines of "do a diff between the current and previous release's startup code".
    • You already have to do some manual checks anyway because update_glibc.zig, update_freebsd_libc.zig, etc only update existing files, not new files.
    • And yeah, the startup ABI does not change very often at all. For glibc, I think that's happened exactly once in all the versions we support targeting, as an example.
  6. removed their assignment
    on Jan 22, 2026
  7. modified the milestones: upcoming, 0.16.0 on Mar 17, 2026
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

    enhancementlibcos-freebsdos-linuxos-netbsdos-wasios-windows

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions