A relocatable object (MH_OBJECT) has no __LINKEDIT segment; clang places its link-edit data after the sections, outside any segment. The placement check counted every such table as outside __LINKEDIT, so a complete data-in-code table in a valid object reported partial coverage. Only file types that have the segment now count a table outside it. in_linkedit stays false as an observation.
5.9 KiB
Mach-O function starts and data in code
Use inspect_macho_function_starts to read LC_FUNCTION_STARTS and
LC_DATA_IN_CODE from one thin Mach-O, or from one slice of a universal file.
LC_FUNCTION_STARTS is the linker's ULEB128 delta list of function starts.
Images that carry LC_DATA_IN_CODE mark jump tables and literal data inside
__TEXT. The reader does not disassemble and does not execute the image.
rea inspect-macho-function-starts /absolute/path/to/program --limit 0 --json
rea inspect-macho-function-starts /absolute/path/to/program --architecture arm64 --kind starts --json
MCP accepts { "path": "/absolute/path/to/program" }. A universal file also
needs architecture. CLI paths may be relative to the current directory; MCP
paths must be absolute.
What it reports
function_startsanddata_in_codegive each command'sdataoff,datasize, containerfile_offset, and whether that range sits in__LINKEDIT.statusispresentorabsent. A relocatable object (MH_OBJECT) has no__LINKEDITsegment, so its tables reportin_linkedit: falsewithout counting as misplaced.- Start addresses are absolute VM addresses. The first delta is added to the
vmaddrof the first declared__TEXTsegment, which need not have file bytes, asllvm-objdump --function-startsdoes. A zero delta ends the list. Zero bytes after that terminator are padding. A sum past the image's 32- or 64-bit address space is a wrapped start. dyld adds the deltas to themach_headeraddress instead. The two agree when__TEXTmaps file offset 0. When it doesn't,coverage.text_not_at_headeris 1 and coverage ispartial, because the base is disputed. - On 32-bit ARM, ld64 sets bit 0 of a Thumb start and takes the next delta
from that tagged value.
vmaddrclears that bit, as LLDB does, andthumbrecords whether it was set. Other architectures omitthumb. - Each start names the section that contains it, such as
__text. - Each data-in-code entry has its
data_in_code_entryoffset, its VM address,length, andkind. ld64 writes the offset as the entry's address minus themach_headeraddress, and dyld documents it as a delta from themach_header, so the VM address is that header address plus the offset. A relocatable object (MH_OBJECT) does not map its header, so its offset is the address itself. An entry whose header address is unknown or ambiguous, or whose address is outside every segment, has no VM address and counts as unmapped. The kinds are:DICE_KIND_DATAJUMP_TABLE8JUMP_TABLE16JUMP_TABLE32ABS_JUMP_TABLE32- Any other kind stays the numeric
uint16.
owneris the greatest decoded start at or before that VM address, with that start's index.coveragecounts every start and every complete 8-byte data entry. It also counts duplicate commands, commands whosecmdsizeis not 16, tables outside__LINKEDIT, commands that extend past the file, truncated or overflowing ULEB128, wrapped addresses, addresses outside every executable segment, a missing__TEXTanchor, amach_headernot mapped at the__TEXTvmaddr, a list that ends without its zero terminator, nonzero bytes after the terminator, a data tail shorter than 8 bytes, entries that leave their section, offsets that are not strictly increasing, offsets outside every segment, and zero lengths. Any of those counters makescoverage.statuspartial.pagerecordskind(all,starts, ordata),offset,limit, and the next offset of each selected table. The same offset and limit apply to each selected table.limit: 0returns counts only. Every entry is checked and counted, but only the returned page is built, so a small page of a large table stays small in memory.- The Evidence file ranges of the two tables stay inside the selected slice.
A table declared past the slice's end keeps its declared
dataoffandfile_offset, but contributes no range in another slice's bytes.
Reading the result
The starts are the addresses the linker recorded. A stripped image can still
carry the list. A missing command is absent, and the standing limitations
say what that absence leaves unknown. Compare a provider procedure address
with starts[].vmaddr. A data-in-code entry names the start that owns its
address, so a jump table or literal pool inside a function stays attached to
that start.
When a command is declared more than once, the first one is decoded. Decoding stops at the first wrapped or out-of-text start, and that address stays in the list.
Failures
A file that is not Mach-O, such as an ELF or PE image, is a target failure
of kind unrecognized: this operation reads only Mach-O. A Mach-O whose
header or load commands are broken, or a universal slice that cannot be read,
is a target failure of kind malformed or truncated. architecture on a thin image is refused. A universal file
without architecture is refused.
max_entries (default 2,097,152, at most 16,777,216; CLI --max-entries)
bounds decoded starts plus complete data-in-code entries, and bounds the
decoding work as well as the result. A data table larger than the allowance
is refused from its byte count before any entry is examined, and the start
walk stops once the combined count would pass it. When the image has no
function starts to decode, the data count is the whole total and the refusal
reports it as required_value. Otherwise decoding stopped before the total
was measured, so details.limit omits required_value. The call returns no partial report.
The default read allowance
is 64 MiB (max_file_bytes, floor 64 bytes, ceiling 512 MiB). The identity
pass stops at 4 GiB minus one byte, because dataoff and FAT32 slice offsets
are 32-bit. max_file_bytes does not raise that ceiling.
max_structure_bytes bounds the load-command table read.