1 //=== MachORelocation.h - Mach-O Relocation Info ----------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Bill Wendling and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the MachORelocation class.
12 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_MACHO_RELOCATION_H
16 #define LLVM_CODEGEN_MACHO_RELOCATION_H
20 /// MachORelocation - This struct contains information about each relocation
21 /// that needs to be emitted to the file.
22 /// see <mach-o/reloc.h>
23 class MachORelocation {
24 uint32_t r_address; // offset in the section to what is being relocated
25 uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index
26 bool r_pcrel; // was relocated pc-relative already
27 uint8_t r_length; // length = 2 ^ r_length
29 uint8_t r_type; // if not 0, machine-specific relocation type.
30 bool r_scattered; // 1 = scattered, 0 = non-scattered
31 int32_t r_value; // the value the item to be relocated is referring
34 uint32_t getPackedFields() const {
36 return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) |
37 ((r_type & 15) << 24) | (r_address & 0x00FFFFFF);
39 return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) |
40 (r_extern << 4) | (r_type & 15);
42 uint32_t getAddress() const { return r_scattered ? r_value : r_address; }
43 uint32_t getRawAddress() const { return r_address; }
45 MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len,
46 bool ext, uint8_t type, bool scattered = false,
48 r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len),
49 r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {}
52 } // end llvm namespace
54 #endif // LLVM_CODEGEN_MACHO_RELOCATION_H