1193323Sed//=== MachORelocation.h - Mach-O Relocation Info ----------------*- C++ -*-===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file defines the MachORelocation class. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed 15249423Sdim#ifndef LLVM_CODEGEN_MACHORELOCATION_H 16249423Sdim#define LLVM_CODEGEN_MACHORELOCATION_H 17193323Sed 18218893Sdim#include "llvm/Support/DataTypes.h" 19199481Srdivacky 20193323Sednamespace llvm { 21193323Sed 22193323Sed /// MachORelocation - This struct contains information about each relocation 23193323Sed /// that needs to be emitted to the file. 24193323Sed /// see <mach-o/reloc.h> 25193323Sed class MachORelocation { 26193323Sed uint32_t r_address; // offset in the section to what is being relocated 27193323Sed uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index 28193323Sed bool r_pcrel; // was relocated pc-relative already 29193323Sed uint8_t r_length; // length = 2 ^ r_length 30193323Sed bool r_extern; // 31193323Sed uint8_t r_type; // if not 0, machine-specific relocation type. 32193323Sed bool r_scattered; // 1 = scattered, 0 = non-scattered 33193323Sed int32_t r_value; // the value the item to be relocated is referring 34193323Sed // to. 35193323Sed public: 36193323Sed uint32_t getPackedFields() const { 37193323Sed if (r_scattered) 38193323Sed return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) | 39193323Sed ((r_type & 15) << 24) | (r_address & 0x00FFFFFF); 40193323Sed else 41193323Sed return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) | 42193323Sed (r_extern << 4) | (r_type & 15); 43193323Sed } 44193323Sed uint32_t getAddress() const { return r_scattered ? r_value : r_address; } 45193323Sed uint32_t getRawAddress() const { return r_address; } 46193323Sed 47193323Sed MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len, 48193323Sed bool ext, uint8_t type, bool scattered = false, 49193323Sed int32_t value = 0) : 50193323Sed r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len), 51193323Sed r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {} 52193323Sed }; 53193323Sed 54193323Sed} // end llvm namespace 55193323Sed 56249423Sdim#endif // LLVM_CODEGEN_MACHORELOCATION_H 57