Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:32

0001 //=== MachORelocation.h - Mach-O Relocation Info ----------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the MachORelocation class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 
0014 #ifndef LLVM_CODEGEN_MACHORELOCATION_H
0015 #define LLVM_CODEGEN_MACHORELOCATION_H
0016 
0017 #include "llvm/Support/DataTypes.h"
0018 
0019 namespace llvm {
0020 
0021   /// MachORelocation - This struct contains information about each relocation
0022   /// that needs to be emitted to the file.
0023   /// see <mach-o/reloc.h>
0024   class MachORelocation {
0025     uint32_t r_address;   // offset in the section to what is being  relocated
0026     uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index
0027     bool     r_pcrel;     // was relocated pc-relative already
0028     uint8_t  r_length;    // length = 2 ^ r_length
0029     bool     r_extern;    //
0030     uint8_t  r_type;      // if not 0, machine-specific relocation type.
0031     bool     r_scattered; // 1 = scattered, 0 = non-scattered
0032     int32_t  r_value;     // the value the item to be relocated is referring
0033                           // to.
0034   public:
0035     uint32_t getPackedFields() const {
0036       if (r_scattered)
0037         return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) |
0038           ((r_type & 15) << 24) | (r_address & 0x00FFFFFF);
0039       else
0040         return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) |
0041           (r_extern << 4) | (r_type & 15);
0042     }
0043     uint32_t getAddress() const { return r_scattered ? r_value : r_address; }
0044     uint32_t getRawAddress() const { return r_address; }
0045 
0046     MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len,
0047                     bool ext, uint8_t type, bool scattered = false,
0048                     int32_t value = 0) :
0049       r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len),
0050       r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {}
0051   };
0052 
0053 } // end llvm namespace
0054 
0055 #endif // LLVM_CODEGEN_MACHORELOCATION_H