MachORelocation.h revision 249423
1146297Sobrien//=== MachORelocation.h - Mach-O Relocation Info ----------------*- C++ -*-===// 2240373Sdelphij// 3146297Sobrien// The LLVM Compiler Infrastructure 4146297Sobrien// 5146297Sobrien// This file is distributed under the University of Illinois Open Source 6146297Sobrien// License. See LICENSE.TXT for details. 7146297Sobrien// 8146297Sobrien//===----------------------------------------------------------------------===// 9146297Sobrien// 10146297Sobrien// This file defines the MachORelocation class. 11146297Sobrien// 12146297Sobrien//===----------------------------------------------------------------------===// 13146297Sobrien 14146297Sobrien 15146297Sobrien#ifndef LLVM_CODEGEN_MACHORELOCATION_H 16240373Sdelphij#define LLVM_CODEGEN_MACHORELOCATION_H 17146297Sobrien 18146297Sobrien#include "llvm/Support/DataTypes.h" 19146297Sobrien 20240373Sdelphijnamespace llvm { 21146297Sobrien 22146297Sobrien /// MachORelocation - This struct contains information about each relocation 23146297Sobrien /// that needs to be emitted to the file. 24146297Sobrien /// see <mach-o/reloc.h> 25146297Sobrien class MachORelocation { 26146297Sobrien uint32_t r_address; // offset in the section to what is being relocated 27 uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index 28 bool r_pcrel; // was relocated pc-relative already 29 uint8_t r_length; // length = 2 ^ r_length 30 bool r_extern; // 31 uint8_t r_type; // if not 0, machine-specific relocation type. 32 bool r_scattered; // 1 = scattered, 0 = non-scattered 33 int32_t r_value; // the value the item to be relocated is referring 34 // to. 35 public: 36 uint32_t getPackedFields() const { 37 if (r_scattered) 38 return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) | 39 ((r_type & 15) << 24) | (r_address & 0x00FFFFFF); 40 else 41 return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) | 42 (r_extern << 4) | (r_type & 15); 43 } 44 uint32_t getAddress() const { return r_scattered ? r_value : r_address; } 45 uint32_t getRawAddress() const { return r_address; } 46 47 MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len, 48 bool ext, uint8_t type, bool scattered = false, 49 int32_t value = 0) : 50 r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len), 51 r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {} 52 }; 53 54} // end llvm namespace 55 56#endif // LLVM_CODEGEN_MACHORELOCATION_H 57