1 //=---- ARM64MCExpr.h - ARM64 specific MC expression classes ------*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes ARM64-specific MCExprs, used for modifiers like
11 // ":lo12:" or ":gottprel_g1:".
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_ARM64MCEXPR_H
16 #define LLVM_ARM64MCEXPR_H
18 #include "llvm/MC/MCExpr.h"
19 #include "llvm/Support/ErrorHandling.h"
23 class ARM64MCExpr : public MCTargetExpr {
28 // Symbol locations specifying (roughly speaking) what calculation should be
29 // performed to construct the final address for the relocated
30 // symbol. E.g. direct, via the GOT, ...
38 VK_SymLocBits = 0x00f,
40 // Variants specifying which part of the final address calculation is
41 // used. E.g. the low 12 bits for an ADD/LDR, the middle 16 bits for a
50 VK_AddressFragBits = 0x0f0,
52 // Whether the final relocation is a checked one (where a linker should
53 // perform a range-check on the final address) or not. Note that this field
54 // is unfortunately sometimes omitted from the assembly syntax. E.g. :lo12:
55 // on its own is a non-checked relocation. We side with ELF on being
56 // explicit about this!
59 // Convenience definitions for referring to specific textual representations
60 // of relocation specifiers. Note that this means the "_NC" is sometimes
61 // omitted in line with assembly syntax here (VK_LO12 rather than VK_LO12_NC
62 // since a user would write ":lo12:").
64 VK_ABS_PAGE = VK_ABS | VK_PAGE,
65 VK_ABS_G3 = VK_ABS | VK_G3,
66 VK_ABS_G2 = VK_ABS | VK_G2,
67 VK_ABS_G2_S = VK_SABS | VK_G2,
68 VK_ABS_G2_NC = VK_ABS | VK_G2 | VK_NC,
69 VK_ABS_G1 = VK_ABS | VK_G1,
70 VK_ABS_G1_S = VK_SABS | VK_G1,
71 VK_ABS_G1_NC = VK_ABS | VK_G1 | VK_NC,
72 VK_ABS_G0 = VK_ABS | VK_G0,
73 VK_ABS_G0_S = VK_SABS | VK_G0,
74 VK_ABS_G0_NC = VK_ABS | VK_G0 | VK_NC,
75 VK_LO12 = VK_ABS | VK_PAGEOFF | VK_NC,
76 VK_GOT_LO12 = VK_GOT | VK_PAGEOFF | VK_NC,
77 VK_GOT_PAGE = VK_GOT | VK_PAGE,
78 VK_DTPREL_G2 = VK_DTPREL | VK_G2,
79 VK_DTPREL_G1 = VK_DTPREL | VK_G1,
80 VK_DTPREL_G1_NC = VK_DTPREL | VK_G1 | VK_NC,
81 VK_DTPREL_G0 = VK_DTPREL | VK_G0,
82 VK_DTPREL_G0_NC = VK_DTPREL | VK_G0 | VK_NC,
83 VK_DTPREL_HI12 = VK_DTPREL | VK_HI12,
84 VK_DTPREL_LO12 = VK_DTPREL | VK_PAGEOFF,
85 VK_DTPREL_LO12_NC = VK_DTPREL | VK_PAGEOFF | VK_NC,
86 VK_GOTTPREL_PAGE = VK_GOTTPREL | VK_PAGE,
87 VK_GOTTPREL_LO12_NC = VK_GOTTPREL | VK_PAGEOFF | VK_NC,
88 VK_GOTTPREL_G1 = VK_GOTTPREL | VK_G1,
89 VK_GOTTPREL_G0_NC = VK_GOTTPREL | VK_G0 | VK_NC,
90 VK_TPREL_G2 = VK_TPREL | VK_G2,
91 VK_TPREL_G1 = VK_TPREL | VK_G1,
92 VK_TPREL_G1_NC = VK_TPREL | VK_G1 | VK_NC,
93 VK_TPREL_G0 = VK_TPREL | VK_G0,
94 VK_TPREL_G0_NC = VK_TPREL | VK_G0 | VK_NC,
95 VK_TPREL_HI12 = VK_TPREL | VK_HI12,
96 VK_TPREL_LO12 = VK_TPREL | VK_PAGEOFF,
97 VK_TPREL_LO12_NC = VK_TPREL | VK_PAGEOFF | VK_NC,
98 VK_TLSDESC_LO12 = VK_TLSDESC | VK_PAGEOFF | VK_NC,
99 VK_TLSDESC_PAGE = VK_TLSDESC | VK_PAGE,
106 const VariantKind Kind;
108 explicit ARM64MCExpr(const MCExpr *Expr, VariantKind Kind)
109 : Expr(Expr), Kind(Kind) {}
112 /// @name Construction
115 static const ARM64MCExpr *Create(const MCExpr *Expr, VariantKind Kind,
122 /// Get the kind of this expression.
123 VariantKind getKind() const { return static_cast<VariantKind>(Kind); }
125 /// Get the expression this modifier applies to.
126 const MCExpr *getSubExpr() const { return Expr; }
129 /// @name VariantKind information extractors.
132 static VariantKind getSymbolLoc(VariantKind Kind) {
133 return static_cast<VariantKind>(Kind & VK_SymLocBits);
136 static VariantKind getAddressFrag(VariantKind Kind) {
137 return static_cast<VariantKind>(Kind & VK_AddressFragBits);
140 static bool isNotChecked(VariantKind Kind) { return Kind & VK_NC; }
144 /// Convert the variant kind into an ELF-appropriate modifier
145 /// (e.g. ":got:", ":lo12:").
146 StringRef getVariantKindName() const;
148 void PrintImpl(raw_ostream &OS) const override;
150 void AddValueSymbols(MCAssembler *) const override;
152 const MCSection *FindAssociatedSection() const override;
154 bool EvaluateAsRelocatableImpl(MCValue &Res,
155 const MCAsmLayout *Layout) const override;
157 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override;
159 static bool classof(const MCExpr *E) {
160 return E->getKind() == MCExpr::Target;
163 static bool classof(const ARM64MCExpr *) { return true; }
166 } // end namespace llvm