From 744ddcde54e7572aee51b28c0d279cff79aed3e8 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 10 Jul 2025 15:26:32 +0200 Subject: [PATCH] Updated notes on Mach-O --- docs/macho.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/macho.md b/docs/macho.md index 06dad05..1d5399e 100644 --- a/docs/macho.md +++ b/docs/macho.md @@ -2,11 +2,21 @@ ## Notes -- Headers must be included in the __TEXT segment. +- The start of the file must be loaded in some segment. +- The start of the file must be marked as readable + executable. - Load command size must be divisible by 8. +- Segments must be page-aligned in the file[^1]. + +Due to the page alignment requirement on disk[^1] instead of just memory, +MacOS is the only OS that forces you to write bloated executables on disk. + +Until this check is removed, we cannot produce smaller executables. + +[^1]: https://github.com/apple-oss-distributions/xnu/blob/main/bsd/kern/mach_loader.c#L2021-L2027 ## Links +- https://github.com/apple-oss-distributions/xnu/blob/main/bsd/kern/mach_loader.c - https://github.com/apple-oss-distributions/xnu/blob/main/EXTERNAL_HEADERS/mach-o/loader.h - https://en.wikipedia.org/wiki/Mach-O - https://github.com/aidansteele/osx-abi-macho-file-format-reference