LLVM API Documentation

MachORelocation.h

Go to the documentation of this file.
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_MACHO_RELOCATION_H
00016 #define LLVM_CODEGEN_MACHO_RELOCATION_H
00017 
00018 namespace llvm {
00019 
00020   /// MachORelocation - This struct contains information about each relocation
00021   /// that needs to be emitted to the file.
00022   /// see <mach-o/reloc.h>
00023   class MachORelocation {
00024     uint32_t r_address;   // offset in the section to what is being  relocated
00025     uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index
00026     bool     r_pcrel;     // was relocated pc-relative already
00027     uint8_t  r_length;    // length = 2 ^ r_length
00028     bool     r_extern;    // 
00029     uint8_t  r_type;      // if not 0, machine-specific relocation type.
00030     bool     r_scattered; // 1 = scattered, 0 = non-scattered
00031     int32_t  r_value;     // the value the item to be relocated is referring
00032                           // to.
00033   public:      
00034     uint32_t getPackedFields() const {
00035       if (r_scattered)
00036         return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) | 
00037           ((r_type & 15) << 24) | (r_address & 0x00FFFFFF);
00038       else
00039         return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) |
00040           (r_extern << 4) | (r_type & 15);
00041     }
00042     uint32_t getAddress() const { return r_scattered ? r_value : r_address; }
00043     uint32_t getRawAddress() const { return r_address; }
00044 
00045     MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len,
00046                     bool ext, uint8_t type, bool scattered = false, 
00047                     int32_t value = 0) : 
00048       r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len),
00049       r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {}
00050   };
00051 
00052 } // end llvm namespace
00053 
00054 #endif // LLVM_CODEGEN_MACHO_RELOCATION_H