MACH-O(5)
π MACH-O β Mach-O assembler and link editor output β¨
okay bestie, gather round, because we're about to talk about the iconic mach-o(5) page β yes, it's section 5, yes, it's a file format, and yes it's lowkey the blueprint for everything the assembler and link editor spit out π
πΈ SYNOPSIS πΈ
like, literally just include these headers and you're in:
#include <mach-o/loader.h>
#include <mach-o/nlist.h>
#include <mach-o/stab.h>
#include <mach-o/reloc.h>
π DESCRIPTION π
so the object files that the assembler and link editor produce? they're in Mach-O (Mach object) file format. no cap. π«Ά
and listen β the file name a.out is the default output file name of the assembler as(1) and the link editor ld(1). but here's the tea: the format of the object file is not 4.3BSD a.out format, even though the name is giving that vibe. it's actually Mach-O format. the name is lying to you, fr fr π
the link editor will make a.out executable if the resulting format is an executable type and there were no errors and no unresolved external references. so like, all the stars have to align β¨
the complete description of a Mach-O file is given in a number of include files:
<mach-o/loader.h>describes the headers<mach-o/nlist.h>describes the symbol table entries, with<mach-o/stab.h>supplementing it<mach-o/reloc.h>describes the relocation entries
the actual instructions and data used by the program represented by a Mach-O file are the contents of its sections. sections are grouped together in segments β think of segments as the main character energy and sections as the supporting cast π
each section carries with it, in its header, the information as to which segment it belongs in. when a file type that is executable is created, the sections are placed in their proper segment and all the segment headers are created and the segments themselves are padded out to the segment alignment (typically the target pagesize). obsessed with that attention to detail π
for the object file type produced by an assembler (or by the link editor for further linking) all the sections are placed in one segment for compactness. cute and efficient, we love to see it π
when the kernel executes a Mach-O file it maps in the object file's segments, the dynamic link editor (if used) and creates the thread(s) for execution. any part of the object file that is not part of a segment is not mapped in for execution. periodt. π₯
for executable using the dynamic link editor, the headers and other link edit information is needed to execute the file. these parts include:
- the relocation entries
- the symbol table
- the string table
these parts are mapped in with the use of the link editor's -seglinkedit option which creates a segment that contains these parts. and if you're feeling minimalist? these parts can be stripped down with the -S option to ld(1) or various options to strip(1). slay π¦
π¦ SEE ALSO π¦
as(1), ld(1), nm(1), gdb(1), stab(5), strip(1)
bestie reminder: the name a.out is giving 4.3BSD but it is not that format β it's Mach-O. don't let the filename catfish you π
kisses and good vibes from Apple Computer, Inc. π this lil page was dated October 22, 2001 β iconic vintage energy, and it's filed under MACH-O(5) in the File Formats Manual. mwah πβ
π¦ where this page comes from
- nixpkgs unstable: cctools 1010.6
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms