AArch64MCExpr.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //=--- AArch64MCExpr.h - AArch64 specific MC expression classes ---*- 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 describes AArch64-specific MCExprs, used for modifiers like
  10. // ":lo12:" or ":gottprel_g1:".
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H
  14. #define LLVM_LIB_TARGET_AARCH64_MCTARGETDESC_AARCH64MCEXPR_H
  15. #include "llvm/MC/MCExpr.h"
  16. #include "llvm/Support/ErrorHandling.h"
  17. namespace llvm {
  18. class AArch64MCExpr : public MCTargetExpr {
  19. public:
  20. enum VariantKind {
  21. // Symbol locations specifying (roughly speaking) what calculation should be
  22. // performed to construct the final address for the relocated
  23. // symbol. E.g. direct, via the GOT, ...
  24. VK_ABS = 0x001,
  25. VK_SABS = 0x002,
  26. VK_PREL = 0x003,
  27. VK_GOT = 0x004,
  28. VK_DTPREL = 0x005,
  29. VK_GOTTPREL = 0x006,
  30. VK_TPREL = 0x007,
  31. VK_TLSDESC = 0x008,
  32. VK_SECREL = 0x009,
  33. VK_SymLocBits = 0x00f,
  34. // Variants specifying which part of the final address calculation is
  35. // used. E.g. the low 12 bits for an ADD/LDR, the middle 16 bits for a
  36. // MOVZ/MOVK.
  37. VK_PAGE = 0x010,
  38. VK_PAGEOFF = 0x020,
  39. VK_HI12 = 0x030,
  40. VK_G0 = 0x040,
  41. VK_G1 = 0x050,
  42. VK_G2 = 0x060,
  43. VK_G3 = 0x070,
  44. VK_LO15 = 0x080,
  45. VK_AddressFragBits = 0x0f0,
  46. // Whether the final relocation is a checked one (where a linker should
  47. // perform a range-check on the final address) or not. Note that this field
  48. // is unfortunately sometimes omitted from the assembly syntax. E.g. :lo12:
  49. // on its own is a non-checked relocation. We side with ELF on being
  50. // explicit about this!
  51. VK_NC = 0x100,
  52. // Convenience definitions for referring to specific textual representations
  53. // of relocation specifiers. Note that this means the "_NC" is sometimes
  54. // omitted in line with assembly syntax here (VK_LO12 rather than VK_LO12_NC
  55. // since a user would write ":lo12:").
  56. VK_CALL = VK_ABS,
  57. VK_ABS_PAGE = VK_ABS | VK_PAGE,
  58. VK_ABS_PAGE_NC = VK_ABS | VK_PAGE | VK_NC,
  59. VK_ABS_G3 = VK_ABS | VK_G3,
  60. VK_ABS_G2 = VK_ABS | VK_G2,
  61. VK_ABS_G2_S = VK_SABS | VK_G2,
  62. VK_ABS_G2_NC = VK_ABS | VK_G2 | VK_NC,
  63. VK_ABS_G1 = VK_ABS | VK_G1,
  64. VK_ABS_G1_S = VK_SABS | VK_G1,
  65. VK_ABS_G1_NC = VK_ABS | VK_G1 | VK_NC,
  66. VK_ABS_G0 = VK_ABS | VK_G0,
  67. VK_ABS_G0_S = VK_SABS | VK_G0,
  68. VK_ABS_G0_NC = VK_ABS | VK_G0 | VK_NC,
  69. VK_LO12 = VK_ABS | VK_PAGEOFF | VK_NC,
  70. VK_PREL_G3 = VK_PREL | VK_G3,
  71. VK_PREL_G2 = VK_PREL | VK_G2,
  72. VK_PREL_G2_NC = VK_PREL | VK_G2 | VK_NC,
  73. VK_PREL_G1 = VK_PREL | VK_G1,
  74. VK_PREL_G1_NC = VK_PREL | VK_G1 | VK_NC,
  75. VK_PREL_G0 = VK_PREL | VK_G0,
  76. VK_PREL_G0_NC = VK_PREL | VK_G0 | VK_NC,
  77. VK_GOT_LO12 = VK_GOT | VK_PAGEOFF | VK_NC,
  78. VK_GOT_PAGE = VK_GOT | VK_PAGE,
  79. VK_GOT_PAGE_LO15 = VK_GOT | VK_LO15 | VK_NC,
  80. VK_DTPREL_G2 = VK_DTPREL | VK_G2,
  81. VK_DTPREL_G1 = VK_DTPREL | VK_G1,
  82. VK_DTPREL_G1_NC = VK_DTPREL | VK_G1 | VK_NC,
  83. VK_DTPREL_G0 = VK_DTPREL | VK_G0,
  84. VK_DTPREL_G0_NC = VK_DTPREL | VK_G0 | VK_NC,
  85. VK_DTPREL_HI12 = VK_DTPREL | VK_HI12,
  86. VK_DTPREL_LO12 = VK_DTPREL | VK_PAGEOFF,
  87. VK_DTPREL_LO12_NC = VK_DTPREL | VK_PAGEOFF | VK_NC,
  88. VK_GOTTPREL_PAGE = VK_GOTTPREL | VK_PAGE,
  89. VK_GOTTPREL_LO12_NC = VK_GOTTPREL | VK_PAGEOFF | VK_NC,
  90. VK_GOTTPREL_G1 = VK_GOTTPREL | VK_G1,
  91. VK_GOTTPREL_G0_NC = VK_GOTTPREL | VK_G0 | VK_NC,
  92. VK_TPREL_G2 = VK_TPREL | VK_G2,
  93. VK_TPREL_G1 = VK_TPREL | VK_G1,
  94. VK_TPREL_G1_NC = VK_TPREL | VK_G1 | VK_NC,
  95. VK_TPREL_G0 = VK_TPREL | VK_G0,
  96. VK_TPREL_G0_NC = VK_TPREL | VK_G0 | VK_NC,
  97. VK_TPREL_HI12 = VK_TPREL | VK_HI12,
  98. VK_TPREL_LO12 = VK_TPREL | VK_PAGEOFF,
  99. VK_TPREL_LO12_NC = VK_TPREL | VK_PAGEOFF | VK_NC,
  100. VK_TLSDESC_LO12 = VK_TLSDESC | VK_PAGEOFF,
  101. VK_TLSDESC_PAGE = VK_TLSDESC | VK_PAGE,
  102. VK_SECREL_LO12 = VK_SECREL | VK_PAGEOFF,
  103. VK_SECREL_HI12 = VK_SECREL | VK_HI12,
  104. VK_INVALID = 0xfff
  105. };
  106. private:
  107. const MCExpr *Expr;
  108. const VariantKind Kind;
  109. explicit AArch64MCExpr(const MCExpr *Expr, VariantKind Kind)
  110. : Expr(Expr), Kind(Kind) {}
  111. public:
  112. /// @name Construction
  113. /// @{
  114. static const AArch64MCExpr *create(const MCExpr *Expr, VariantKind Kind,
  115. MCContext &Ctx);
  116. /// @}
  117. /// @name Accessors
  118. /// @{
  119. /// Get the kind of this expression.
  120. VariantKind getKind() const { return Kind; }
  121. /// Get the expression this modifier applies to.
  122. const MCExpr *getSubExpr() const { return Expr; }
  123. /// @}
  124. /// @name VariantKind information extractors.
  125. /// @{
  126. static VariantKind getSymbolLoc(VariantKind Kind) {
  127. return static_cast<VariantKind>(Kind & VK_SymLocBits);
  128. }
  129. static VariantKind getAddressFrag(VariantKind Kind) {
  130. return static_cast<VariantKind>(Kind & VK_AddressFragBits);
  131. }
  132. static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; }
  133. /// @}
  134. /// Convert the variant kind into an ELF-appropriate modifier
  135. /// (e.g. ":got:", ":lo12:").
  136. StringRef getVariantKindName() const;
  137. void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
  138. void visitUsedExpr(MCStreamer &Streamer) const override;
  139. MCFragment *findAssociatedFragment() const override;
  140. bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
  141. const MCFixup *Fixup) const override;
  142. void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
  143. static bool classof(const MCExpr *E) {
  144. return E->getKind() == MCExpr::Target;
  145. }
  146. static bool classof(const AArch64MCExpr *) { return true; }
  147. };
  148. } // end namespace llvm
  149. #endif