MachORelocation.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //=== MachORelocation.h - Mach-O Relocation Info ----------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the MachORelocation class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CODEGEN_MACHORELOCATION_H
  13. #define LLVM_CODEGEN_MACHORELOCATION_H
  14. #include "llvm/Support/DataTypes.h"
  15. namespace llvm {
  16. /// MachORelocation - This struct contains information about each relocation
  17. /// that needs to be emitted to the file.
  18. /// see <mach-o/reloc.h>
  19. class MachORelocation {
  20. uint32_t r_address; // offset in the section to what is being relocated
  21. uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index
  22. bool r_pcrel; // was relocated pc-relative already
  23. uint8_t r_length; // length = 2 ^ r_length
  24. bool r_extern; //
  25. uint8_t r_type; // if not 0, machine-specific relocation type.
  26. bool r_scattered; // 1 = scattered, 0 = non-scattered
  27. int32_t r_value; // the value the item to be relocated is referring
  28. // to.
  29. public:
  30. uint32_t getPackedFields() const {
  31. if (r_scattered)
  32. return (1 << 31) | (r_pcrel << 30) | ((r_length & 3) << 28) |
  33. ((r_type & 15) << 24) | (r_address & 0x00FFFFFF);
  34. else
  35. return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) |
  36. (r_extern << 4) | (r_type & 15);
  37. }
  38. uint32_t getAddress() const { return r_scattered ? r_value : r_address; }
  39. uint32_t getRawAddress() const { return r_address; }
  40. MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len,
  41. bool ext, uint8_t type, bool scattered = false,
  42. int32_t value = 0) :
  43. r_address(addr), r_symbolnum(index), r_pcrel(pcrel), r_length(len),
  44. r_extern(ext), r_type(type), r_scattered(scattered), r_value(value) {}
  45. };
  46. } // end llvm namespace
  47. #endif // LLVM_CODEGEN_MACHORELOCATION_H