Skip to content

Change the macho linker gc_sections option to respect rdynamic flag - #25501

Closed
TeddyRandby wants to merge 1 commit into
ziglang:masterfrom
TeddyRandby:UpdateMachOLinkGCRespectRDynamic
Closed

TeddyRandby wants to merge 1 commit into
ziglang:masterfrom
TeddyRandby:UpdateMachOLinkGCRespectRDynamic

Conversation

@TeddyRandby

Copy link
Copy Markdown

Fix #17554

When initializing the gc_sections flag in the MachO linker, check the config's rdynamic setting. Don't eliminate dead code in non-debug builds when rdynamic is set (Unless gc_sections itself is explicitly set).

I tested locally on a c file such as this:

int example(int a, int b) { return a + b; }

int main() { return 0; }

Cross-compiling for macos like so:

~/repos/zig/stage3/bin/zig cc -O3 -rdynamic main.c -o main --target=aarch64-macos-none

Using llvm-objdump -S main, I can confirm that:

  • the example function is eliminated in -O3
  • the example function is present in -O3 -rdynamic.

This is my first open source contribution, let me know if anything needs to be fixed!

@alexrp

alexrp commented Sep 26, 2026

Copy link
Copy Markdown
Member

Closing because:

  1. I'm not entirely convinced this logic is right. I don't think -rdynamic should block GC wholesale.
  2. We're starting work on a new Mach-O linker: https://codeberg.org/ziglang/zig/pulls/36942

@alexrp alexrp closed this Sep 26, 2026
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.

rdynamic = true has no effect on Mach-O ld linker

2 participants