LLVM API Documentation
00001 //=== MachORelocation.h - Mach-O Relocation Info ----------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the MachORelocation class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 00015 #ifndef LLVM_CODEGEN_MACHORELOCATION_H 00016 #define LLVM_CODEGEN_MACHORELOCATION_H 00017 00018 #include "llvm/Support/DataTypes.h" 00019 00020 namespace llvm { 00021 00022 /// MachORelocation - This struct contains information about each relocation 00023 /// that needs to be emitted to the file. 00024 /// see <mach-o/reloc.h> 00025 class MachORelocation { 00026 uint32_t r_address; // offset in the section to what is being relocated 00027 uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index 00028 bool r_pcrel; // was relocated pc-relative already 00029 uint8_t r_length; // length = 2 ^ r_length 00030 bool r_extern; // 00031 uint8_t r_type; // if not 0, machine-specific relocation type. 00032 bool r_scattered; // 1 = scattered, 0 = non-scattered 00033 int32_t r_value; // the value the item to be relocated is referring 00034 // to. 00035 public: 00036 uint32_t getPackedFields() const { 00037 if (r_scattered) 00038 return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) | 00039 ((r_type & 15) << 24) | (r_address & 0x00FFFFFF); 00040 else 00041 return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) | 00042 (r_extern << 4) | (r_type & 15); 00043 } 00044 uint32_t getAddress() const { return r_scattered ? r_value : r_address; } 00045 uint32_t getRawAddress() const { return r_address; } 00046 00047 MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len, 00048 bool ext, uint8_t type, bool scattered = false, 00049 int32_t value = 0) : 00050 r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len), 00051 r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {} 00052 }; 00053 00054 } // end llvm namespace 00055 00056 #endif // LLVM_CODEGEN_MACHORELOCATION_H