Skip to content

refactor: link Zig objects directly with cc_common.link - #717

Open
cerisier wants to merge 2 commits into
cerisier/zig-cc-link-setupfrom
cerisier/zig-cc-link-direct-objects
Open

cerisier wants to merge 2 commits into
cerisier/zig-cc-link-setupfrom
cerisier/zig-cc-link-direct-objects

Conversation

@cerisier

@cerisier cerisier commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Before

With cc_common.link, Zig compiled binaries and shared libraries to intermediate archives. Tests already emitted an object with test-obj, then ran build-lib to package it with compiler-rt. The final C/C++ link consumed an archive in all three cases.

After

Binaries and shared libraries use build-obj, and tests use test-obj. The shared C/C++ link from #716 takes those objects directly, removing the archive step.

When compiler-rt is enabled, the same Zig SDK emits it as a separate object for all three rule kinds.

We need to compile compile-rt as a separate action because of 2 bugs zig when using -fcompiler-rt.

  • In both: `test-obj -fcompiler-rt doesn't emit compiler-rt symbols. Zig issue #37735
  • Zig 0.16: build-obj -fcompiler-rt -fstack-protector triggers an assertion in LLVM’s StackProtector pass when it encounters the runtime’s __stack_chk_fail alias. Zig issue #31702

Use the same object handoff for binaries, tests, and shared libraries. Build Zig compiler-rt separately when enabled so Zig 0.16 and 0.17 share one path.
@cerisier
cerisier added this pull request to stack #714 November 22, 2026 11:51
@cerisier
cerisier requested a review from aherrmann November 22, 2026 18:34
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.

1 participant