Skip to content

Commit 2e6bfc3

Browse files
[ObjWriter] Emit the MH_SUBSECTIONS_VIA_SYMBOLS header flag for Mach-O (#471) (#472)
The flag tells the linker that there are no functions with overlapping code and thus the code sections can be divided into subsections based on the symbols. This is similar in effect to how `-ffunction-sections` behaves on ELF. Notably, this enables optimization such as dead code stripping and identical code folding, if requested through linker switches. Old ld64 linker tends to run into deep stack loop without this switch if `-dead_strip` is used (encountered in Xamarin, not used by regular NativeAOT), and often ends up stack overflowing. New Xcode 15+ linker completely fails to produce correct unwind tables without this flag, which results in the NativeAOT executables crashing during GC or on first stack walk. Co-authored-by: Filip Navara <filip.navara@gmail.com>
1 parent 08a449c commit 2e6bfc3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

llvm/tools/objwriter/objwriter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ bool ObjectWriter::Init(llvm::StringRef ObjectFilePath, const char* tripleName)
155155

156156
CFIsPerOffset.truncate(0);
157157

158+
if (OutContext->getObjectFileType() == MCContext::IsMachO) {
159+
Streamer->emitAssemblerFlag(MCAF_SubsectionsViaSymbols);
160+
}
161+
158162
return true;
159163
}
160164

0 commit comments

Comments
 (0)