| 1 |
//! Bind opcodes are interpreted by the dynamic linker to efficiently collect every symbol imported by this binary, and from which library using two-level namespacing |
| 2 |
//! |
| 3 |
//! Some uses of external symbols do not need to be bound immediately. |
| 4 |
//! Instead they can be lazily bound on first use. The lazy_bind |
| 5 |
//! are contains a stream of BIND opcodes to bind all lazy symbols. |
| 6 |
//! Normal use is that dyld ignores the lazy_bind section when |
| 7 |
//! loading an image. Instead the static linker arranged for a |
| 8 |
//! lazy pointer to initially point to a helper function which |
| 9 |
//! pushes the offset into the lazy_bind area for the symbol |
| 10 |
//! needing to be bound, then jumps to dyld which simply adds |
| 11 |
//! the offset to lazy_bind_off to get the information on what |
| 12 |
//! to bind. |
| 13 |
|
| 14 |
pub type Opcode = u8; |
| 15 |
|
| 16 |
// The following are used to encode binding information |
| 17 |
pub const BIND_TYPE_POINTER: u8 = 1; |
| 18 |
pub const BIND_TYPE_TEXT_ABSOLUTE32: u8 = 2; |
| 19 |
pub const BIND_TYPE_TEXT_PCREL32: u8 = 3; |
| 20 |
pub const BIND_SPECIAL_DYLIB_SELF: u8 = 0; |
| 21 |
pub const BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE: u8 = 0xf; // -1 |
| 22 |
pub const BIND_SPECIAL_DYLIB_FLAT_LOOKUP: u8 = 0xe; // -2 |
| 23 |
pub const BIND_SYMBOL_FLAGS_WEAK_IMPORT: u8 = 0x1; |
| 24 |
pub const BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION: u8 = 0x8; |
| 25 |
pub const BIND_OPCODE_MASK: u8 = 0xF0; |
| 26 |
pub const BIND_IMMEDIATE_MASK: u8 = 0x0F; |
| 27 |
pub const BIND_OPCODE_DONE: Opcode = 0x00; |
| 28 |
pub const BIND_OPCODE_SET_DYLIB_ORDINAL_IMM: Opcode = 0x10; |
| 29 |
pub const BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB: Opcode = 0x20; |
| 30 |
pub const BIND_OPCODE_SET_DYLIB_SPECIAL_IMM: Opcode = 0x30; |
| 31 |
pub const BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM: Opcode = 0x40; |
| 32 |
pub const BIND_OPCODE_SET_TYPE_IMM: Opcode = 0x50; |
| 33 |
pub const BIND_OPCODE_SET_ADDEND_SLEB: Opcode = 0x60; |
| 34 |
pub const BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB: Opcode = 0x70; |
| 35 |
pub const BIND_OPCODE_ADD_ADDR_ULEB: Opcode = 0x80; |
| 36 |
pub const BIND_OPCODE_DO_BIND: Opcode = 0x90; |
| 37 |
pub const BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB: Opcode = 0xA0; |
| 38 |
pub const BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED: Opcode = 0xB0; |
| 39 |
pub const BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB: Opcode = 0xC0; |
| 40 |
|
| 41 |
pub fn opcode_to_str(opcode: Opcode) -> &'static str { |
| 42 |
match opcode { |
| 43 |
BIND_OPCODE_DONE => "BIND_OPCODE_DONE", |
| 44 |
BIND_OPCODE_SET_DYLIB_ORDINAL_IMM => "BIND_OPCODE_SET_DYLIB_ORDINAL_IMM", |
| 45 |
BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB => "BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB", |
| 46 |
BIND_OPCODE_SET_DYLIB_SPECIAL_IMM => "BIND_OPCODE_SET_DYLIB_SPECIAL_IMM", |
| 47 |
BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM => "BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM", |
| 48 |
BIND_OPCODE_SET_TYPE_IMM => "BIND_OPCODE_SET_TYPE_IMM", |
| 49 |
BIND_OPCODE_SET_ADDEND_SLEB => "BIND_OPCODE_SET_ADDEND_SLEB", |
| 50 |
BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB => "BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB", |
| 51 |
BIND_OPCODE_ADD_ADDR_ULEB => "BIND_OPCODE_ADD_ADDR_ULEB", |
| 52 |
BIND_OPCODE_DO_BIND => "BIND_OPCODE_DO_BIND", |
| 53 |
BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB => "BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB", |
| 54 |
BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED => "BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED", |
| 55 |
BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB => { |
| 56 |
"BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB" |
| 57 |
} |
| 58 |
_ => "UNKNOWN OPCODE", |
| 59 |
} |
| 60 |
} |