ELFRelocation.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //=== ELFRelocation.h - ELF 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 ELFRelocation class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_CODEGEN_ELF_RELOCATION_H
  14. #define LLVM_CODEGEN_ELF_RELOCATION_H
  15. #include "llvm/Support/DataTypes.h"
  16. namespace llvm {
  17. /// ELFRelocation - This class contains all the information necessary to
  18. /// to generate any 32-bit or 64-bit ELF relocation entry.
  19. class ELFRelocation {
  20. uint64_t r_offset; // offset in the section of the object this applies to
  21. uint32_t r_symidx; // symbol table index of the symbol to use
  22. uint32_t r_type; // machine specific relocation type
  23. int64_t r_add; // explicit relocation addend
  24. bool r_rela; // if true then the addend is part of the entry
  25. // otherwise the addend is at the location specified
  26. // by r_offset
  27. public:
  28. uint64_t getInfo(bool is64Bit = false) const {
  29. if (is64Bit)
  30. return ((uint64_t)r_symidx << 32) + ((uint64_t)r_type & 0xFFFFFFFFL);
  31. else
  32. return (r_symidx << 8) + (r_type & 0xFFL);
  33. }
  34. uint64_t getOffset() const { return r_offset; }
  35. uint64_t getAddress() const { return r_add; }
  36. ELFRelocation(uint64_t off, uint32_t sym, uint32_t type,
  37. bool rela = true, int64_t addend = 0) :
  38. r_offset(off), r_symidx(sym), r_type(type),
  39. r_add(addend), r_rela(rela) {}
  40. };
  41. } // end llvm namespace
  42. #endif // LLVM_CODEGEN_ELF_RELOCATION_H