These tables are reached through linkedit_data_commands: each is a file
offset and a size in __LINKEDIT.
Function starts
LC_FUNCTION_STARTS points at a stream of ULEB128 numbers: the address of
each function in __TEXT, as differences from the one before. The first
is the offset of the first function from the start of __TEXT. A zero, or
the end of the data, ends the list; the rest of the data is padding.
Unlike the symbol table it also covers static functions, so a stripped program still
shows where its functions begin. The explorer names a function without a symbol
sub_ and its address.
Data in code
LC_DATA_IN_CODE points at 8-byte records naming ranges of a code
section that are data rather than instructions, such as jump tables:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | offset | Offset of the range from the Mach header. |
| 4 | 2 | length | Its length in bytes. |
| 6 | 2 | kind | 1 data, 2 8-bit jump table, 3 16-bit jump table, 4 32-bit jump table, 5 32-bit absolute jump table. |
Segment split information
LC_SEGMENT_SPLIT_INFO lists every place in one segment that holds an
address in another, so that a builder of the dyld shared cache can move the segments
apart and still fix each reference. Layout from the dyld project
(mach_o/SplitSeg.cpp). Every number is a ULEB128. The data is empty in a
file that only carries the marker.
Version 2 starts with the byte 0x7F, then:
| Part | Holds |
|---|---|
| count | The number of pairs of sections. |
| for each pair | from section index, to section index, the number of target offsets. |
| for each target offset | its difference from the one before (the first is from 0), the number of kinds. |
| for each kind | the kind, the number of references, then each reference’s offset in the from section as a difference from the one before. |
The kinds are 1 POINTER_32, 2 POINTER_64, 3 DELTA_32, 4 DELTA_64, 5 ARM64_ADRP,
6 ARM64_OFF12, 7 ARM64_BR26, 8 ARM_MOVW_MOVT, 9 ARM_BR24, 10 THUMB_MOVW_MOVT,
11 THUMB_BR22, 12 IMAGE_OFF_32 and 13 THREADED_POINTER_64 (the
DYLD_CACHE_ADJ_V2_ names). Anything else in the first byte is the older
version 1: a kind byte, then ULEB128 differences between the addresses of the
references of that kind, ended by a zero; a zero kind byte ends the list. The explorer
reads both. On this Mac the reference count of version 2 matches
dyld_info -shared_region exactly (572 references in
libsystem_platform).
Linker optimisation hints
LC_LINKER_OPTIMIZATION_HINT is in object files and some linked ones for
64-bit ARM. It is a stream of ULEB128 numbers: a kind, a count, then that many
addresses of instructions. The kinds name the sequences the linker may rewrite once it
knows where things end up: 1 ADRP ADRP, 2 ADRP LDR, 3 ADRP ADD LDR, 4 ADRP LDR(GOT)
LDR, 5 ADRP ADD STR, 6 ADRP LDR(GOT) STR, 7 ADRP ADD, 8 ADRP LDR(GOT) (the
LOH_ARM64_ names of the older linker; Apple’s newer linker library lists
kinds 1 to 8 as no longer used). A kind of zero ends the hints, and the rest of the
data is padding.
Function variants
Newer systems let a library ship several implementations of one function and pick one
when it loads, by CPU feature or system setting. LC_FUNCTION_VARIANTS
holds the tables (dyld mach_o/FunctionVariants.h), in the file’s byte
order:
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 4 | tableCount | The number of tables. |
| 4 | 4 × count | tableOffsets | Where each table starts in the blob. |
| each table: | |||
| 0 | 4 | kind | 1 per-process, 2 system-wide, 3 arm64, 4 x86_64. |
| 4 | 4 | count | Number of entries. |
| 8 | 8 × count | entries | Each: a 32-bit word (the low 31 bits impl, the top bit anotherTable), then four bytes of flag bit numbers. |
impl is the function’s offset from the image, or, with the top bit set, the
number of another table. The flag bytes say which feature bits must be set for the entry
to apply; a zero ends the list, and the last entry of a table, with none, is the
default. LC_FUNCTION_VARIANT_FIXUPS is an array of 8-byte records for
variants that are not exported: a segment offset (4 bytes), then a 32-bit word with the
segment index (4 bits), the variant table (8 bits), whether the pointer is signed
(1 bit), whether its address is mixed in (1), the key (2 bits: IA, IB, DA, DB) and the
diversity (16 bits). On this Mac libdispatch (introspection) holds one table of two
entries, which dyld_info -function_variants lists the same way.
Lazily loaded libraries
LC_LAZY_LOAD_DYLIB_INFO (dyld mach_o/LazyLoadDylib.h)
starts with 24 bytes: the offset in the blob of the library’s path (4), the offset
from the image’s header of the flag that says the library is loaded (4), flags (2,
bit 0 for a weakly linked library), the chained-fixup pointer format (2), the offset
from the header of the first pointer of the chain (4), the number of symbol names (4)
and the offset of the array of offsets to them (4). The path and the names are
zero-terminated strings after it. None of the files checked on this Mac has this command,
so the explorer reads it from the source alone.
The other tables
| Command | Holds | In the explorer |
|---|---|---|
| LC_DYLIB_CODE_SIGN_DRS | Designated requirements of linked libraries. | Listed as bytes |
| LC_ATOM_INFO | Information about the file’s atoms. | Listed as bytes |
| LC_NOTE | A note whose layout depends on its owner name. | The owner and the bytes |
Apple’s public headers name these commands but do not give the layouts, and none of the files checked on this Mac has them, so the explorer only shows where they are.