Track: zig's Mach-O LTO support (revisit -flto on osx-aarch64/osx-x86_64)

Open
#77 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Quiet
Tech stack
java, shell, zig
Domain
build-system

Research direction

This is a tracking issue with no current action: read issue #70 (the original -flto experiment and JMH results) and scripts/build-zstd.sh to understand the setup. Watch zig release notes for Mach-O LTO or an ld64.lld usable via zig cc -fuse-ld=lld on osx-aarch64/osx-x86_64. Done means: when that lands, re-run the -flto experiment and the JMH benchmarks in benchmark-lto.yml and record whether the Linux compress-regression/decompress-gain pattern holds.

Written by the indexing model from the issue text.

Description

Background

#70 investigated enabling LTO (-flto) in scripts/build-zstd.sh for a compile-time cross-TU inlining win. It works fine on Linux (zig cc links ELF with its bundled real lld), but is currently impossible on macOS:

$ zig cc -target aarch64-macos -O3 -flto -c third_party/zstd/lib/common/xxhash.c -o /tmp/test.o
error: LTO requires using LLD

zig's Mach-O backend is a self-hosted linker, not LLD, so it has no LTO support at all — this reproduces at the -c (compile-only) stage, before any linking. -fuse-ld=lld doesn't help either (no real ld64.lld binary was available to force it).

Separately, even where LTO did work (Linux), the benchmark in #70 showed a net regression on the compress path (zstdJavaBytes -6.2%, zstdJavaSegment -3.7%) versus a smaller decompress gain (+1.9-2.5%) — so LTO was rejected project-wide, not just on macOS. This issue is scoped narrowly to the macOS tooling blocker, in case zig gains Mach-O LTO support and it's ever worth re-benchmarking.

What to watch for
  • zig adding LTO support to its self-hosted Mach-O linker, or shipping a real ld64.lld that zig cc -fuse-ld=lld can target on macOS.
  • Track via zig release notes / changelog for aarch64-macos and x86_64-macos linker work.
Revisit when

If Mach-O LTO becomes available via zig cc:

  1. Re-run the same -flto experiment from #70 on osx-aarch64/osx-x86_64.
  2. Re-benchmark compress/decompress (JMH, benchmark-lto.yml) — the Linux result (compress regression, decompress gain) may or may not hold on ARM/Mach-O codegen, so don't assume the same disposition applies.

No action needed until then; this issue exists purely to remember to check back.

Dominant language
Java
Stars
5
Forks
1
Avg merge
13d 18h
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dfa1/zstd-ffm

All issues in dfa1/zstd-ffm

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.