Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
2.2 KiB

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