mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
fca3f6f62e
MachO has a mechanism where symbols can introduce "subsections", which (as I understand it) allows a linker to garbage-collect parts of sections without pulling in the heavy machinery of `-fdata-sections` and `-ffunction-sections`. Essentially, symbols can be considered to partition a section, and these boundaries are not allowed to be crossed by memory accesses, so the linker can detect symbols which are unused and drop the corresponding input section regions. However, the symbol flag `N_ALT_ENTRY` indicates that a symbol should not participate in this "splitting", and is instead an "alternate entry point" to the previous subsection, which should continue through this symbol. The Mach-O linker was failing to ignore `N_ALT_ENTRY` symbols when creating subsections, which meant that for certain link inputs, it would create additional subsection splits, and then garbage collect the extra sections (due to the `N_ALT_ENTRY` symbol being unused). Naturally, this silent dropping of parts of input sections led to miscompilations.