Documentation
¶
Index ¶
- Constants
- type RelocationBuilder
- type RelocationInfo
- type RelocationLength
- type RelocationType
- type Section64Builder
- func (builder Section64Builder) Build(ctx *context.CommandContext) Section64Header
- func (builder Section64Builder) DataLen() uint64
- func (builder Section64Builder) DataWriteTo(writer io.Writer) (int64, error)
- func (builder Section64Builder) HeaderLen() uint64
- func (builder Section64Builder) HeaderWriteTo(writer io.Writer, ctx *context.CommandContext) (int64, error)
- type Section64Flags
- type Section64Header
Constants ¶
const ( RelocationSymbolNumMask uint32 = 0xFFFFFF RelocationPcRelative uint32 = 1 << 24 RelocationExtern uint32 = 1 << 27 )
const RelocationInfoSize uint64 = 8
const Section64HeaderSize uint64 = 0x50
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RelocationBuilder ¶
type RelocationBuilder struct {
Address uint32
SymbolIndex uint32
IsRelocationPcRelative bool
Length RelocationLength
IsRelocationExtern bool
Type RelocationType
}
func (RelocationBuilder) Build ¶
func (builder RelocationBuilder) Build() RelocationInfo
type RelocationInfo ¶
Sources: https://github.com/apple/darwin-xnu/blob/2ff845c2e033bd0ff64b5b6aa6063a1f8f65aa32/EXTERNAL_HEADERS/mach-o/reloc.h#L64 https://alexdremov.me/mystery-of-mach-o-object-file-builders/
struct relocation_info {
int32_t r_address; /* offset in the section to */
/* what is being relocated */
uint32_t r_symbolnum:24, /* symbol index if r_extern == 1 or */
/* section ordinal if r_extern == 0 */
r_pcrel:1, /* was relocated pc relative already */
r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
r_extern:1, /* does not include value of sym referenced */
r_type:4; /* if not 0, machine specific relocation type */
};
func (RelocationInfo) MarshalBinary ¶
func (r RelocationInfo) MarshalBinary() ([]byte, error)
type RelocationLength ¶
type RelocationLength uint32
const ( RelocationLengthByte RelocationLength = iota // 1 byte RelocationLengthWord // 2 bytes RelocationLengthLong // 4 bytes RelocationLengthQuad // 8 bytes )
type RelocationType ¶
type RelocationType uint32
The r_type:4 field contains the relocation type, which dictates where exactly and in what format the relocation is applied.
The zero value is a generic "vanilla" relocation which just writes the relocation value of the provided size (according to the r_length field). Other (non-zero) values are specific to the architecture.
The following resource contains a list of relocation types for x86, x86_64, and powerpc architectures: https://github.com/aidansteele/osx-abi-macho-file-format-reference
More relocation types can be found here: https://github.com/apple/darwin-xnu/blob/main/EXTERNAL_HEADERS/mach-o/arm64/reloc.h https://github.com/gimli-rs/object/blob/master/src/macho.rs
const ( // for pointers RelocationTypeArm64Unsigned RelocationType = iota // must be followed by a ARM64_RELOC_UNSIGNED RelocationTypeArm64Subtractor // a B/BL instruction with 26-bit displacement RelocationTypeArm64Branch26 // pc-rel distance to page of target RelocationTypeArm64Page21 // offset within page, scaled by r_length RelocationTypeArm64PageOff12 // pc-rel distance to page of GOT slot RelocationTypeArm64GotLoadPage21 // offset within page of GOT slot, scaled by r_length RelocationTypeArm64GotLoadPageOff12 // for pointers to GOT slots RelocationTypeArm64PointerToGot // pc-rel distance to page of TLVP slot RelocationTypeArm64TlvpLoadPage21 // offset within page of TLVP slot, scaled by r_length RelocationTypeArm64TlvpLoadPageOff12 // must be followed by PAGE21 or PAGEOFF12 RelocationTypeArm64Addend )
type Section64Builder ¶
type Section64Builder struct {
SectionName [16]byte
SegmentName [16]byte
Data []byte
Address uint64
Align uint32
Flags Section64Flags
Relocations []RelocationBuilder
}
func (Section64Builder) Build ¶
func (builder Section64Builder) Build( ctx *context.CommandContext, ) Section64Header
func (Section64Builder) DataLen ¶
func (builder Section64Builder) DataLen() uint64
func (Section64Builder) DataWriteTo ¶
func (builder Section64Builder) DataWriteTo(writer io.Writer) (int64, error)
func (Section64Builder) HeaderLen ¶
func (builder Section64Builder) HeaderLen() uint64
func (Section64Builder) HeaderWriteTo ¶
func (builder Section64Builder) HeaderWriteTo( writer io.Writer, ctx *context.CommandContext, ) (int64, error)
type Section64Flags ¶
type Section64Flags uint32
const ( RegularSection Section64Flags = 0x0 // regular section ZeroFillSection Section64Flags = 0x1 // zero fill on demand section CStringsSection Section64Flags = 0x2 // section with only literal C strings Only4ByteLiteralSection Section64Flags = 0x3 // section with only 4 byte literals Only8ByteLiteralSection Section64Flags = 0x4 // section with only 8 byte literals OnlyPointerLiteralSection Section64Flags = 0x5 // section with only pointers to literals NonLazySymbolPointersSection Section64Flags = 0x6 // section with only non-lazy symbol pointers LazySymbolPointersSection Section64Flags = 0x7 // section with only lazy symbol pointers SymbolStubsSection Section64Flags = 0x8 // section with only symbol stubs, byte size of stub in the reserved2 field ModInitFuncPointersSection Section64Flags = 0x9 // section with only function pointers for initialization ModTermFuncPointersSection Section64Flags = 0xa // section with only function pointers for termination CoalescedSection Section64Flags = 0xb // section contains symbols that are to be coalesced LargeZeroFillSection Section64Flags = 0xc // zero fill on demand section (that can be larger than 4 gigabytes) InterposingSection Section64Flags = 0xd // section with only pairs of function pointers for interposing Only16ByteLiteralSection Section64Flags = 0xe // section with only 16 byte literals DTraceDofSection Section64Flags = 0xf // section contains DTrace Object Format LazyDynamicLibSymbolPointersSection Section64Flags = 0x10 // section with only lazy symbol pointers to lazy loaded dylibs ThreadLocalRegularSection Section64Flags = 0x11 // template of initial values for TLVs ThreadLocalZeroFillSection Section64Flags = 0x12 // template of initial values for TLVs ThreadLocalVariablesSection Section64Flags = 0x13 // TLV descriptors ThreadLocalVariablePointersSection Section64Flags = 0x14 // pointers to TLV descriptors ThreadLocalInitFunctionPointersSection Section64Flags = 0x15 // functions to call to initialize TLV values AttrPureInstructions Section64Flags = 0x80000000 // section contains only true machine instructions AttrNoToc Section64Flags = 0x40000000 // section contains coalesced symbols that are not to be in a ranlib table of contents AttrStripStaticSyms Section64Flags = 0x20000000 // ok to strip static symbols in this section in files with the MH_DYLDLINK flag AttrNoDeadStrip Section64Flags = 0x10000000 // no dead stripping AttrLiveSupport Section64Flags = 0x08000000 // blocks are live if they reference live blocks AttrSelfModifyingCode Section64Flags = 0x04000000 // Used with i386 code stubs written on by dyld AttrDebug Section64Flags = 0x02000000 // a debug section AttrSomeInstructions Section64Flags = 0x00000400 // section contains some machine instructions AttrExternalRelocation Section64Flags = 0x00000200 // section has external relocation entries AttrLocalRelocation Section64Flags = 0x00000100 // section has local relocation entries )
type Section64Header ¶
type Section64Header struct {
SectionName [16]byte
SegmentName [16]byte
Address uint64
Size uint64
Offset uint32
Align uint32
RelocationOffset uint32
NumberOfRelocations uint32
Flags Section64Flags
Reserved1 uint32
Reserved2 uint32
Reserved3 uint32
}
func (Section64Header) MarshalBinary ¶
func (section Section64Header) MarshalBinary() ([]byte, error)