/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/MC/MCFixup.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===-- llvm/MC/MCFixup.h - Instruction Relocation and Patching -*- 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 | | #ifndef LLVM_MC_MCFIXUP_H |
11 | | #define LLVM_MC_MCFIXUP_H |
12 | | |
13 | | #include "llvm/MC/MCExpr.h" |
14 | | #include "llvm/Support/DataTypes.h" |
15 | | #include "llvm/Support/ErrorHandling.h" |
16 | | #include "llvm/Support/SMLoc.h" |
17 | | #include <cassert> |
18 | | |
19 | | namespace llvm { |
20 | | class MCExpr; |
21 | | |
22 | | /// \brief Extensible enumeration to represent the type of a fixup. |
23 | | enum MCFixupKind { |
24 | | FK_Data_1 = 0, ///< A one-byte fixup. |
25 | | FK_Data_2, ///< A two-byte fixup. |
26 | | FK_Data_4, ///< A four-byte fixup. |
27 | | FK_Data_8, ///< A eight-byte fixup. |
28 | | FK_PCRel_1, ///< A one-byte pc relative fixup. |
29 | | FK_PCRel_2, ///< A two-byte pc relative fixup. |
30 | | FK_PCRel_4, ///< A four-byte pc relative fixup. |
31 | | FK_PCRel_8, ///< A eight-byte pc relative fixup. |
32 | | FK_GPRel_1, ///< A one-byte gp relative fixup. |
33 | | FK_GPRel_2, ///< A two-byte gp relative fixup. |
34 | | FK_GPRel_4, ///< A four-byte gp relative fixup. |
35 | | FK_GPRel_8, ///< A eight-byte gp relative fixup. |
36 | | FK_DTPRel_4, ///< A four-byte dtp relative fixup. |
37 | | FK_DTPRel_8, ///< A eight-byte dtp relative fixup. |
38 | | FK_TPRel_4, ///< A four-byte tp relative fixup. |
39 | | FK_TPRel_8, ///< A eight-byte tp relative fixup. |
40 | | FK_SecRel_1, ///< A one-byte section relative fixup. |
41 | | FK_SecRel_2, ///< A two-byte section relative fixup. |
42 | | FK_SecRel_4, ///< A four-byte section relative fixup. |
43 | | FK_SecRel_8, ///< A eight-byte section relative fixup. |
44 | | |
45 | | FirstTargetFixupKind = 128, |
46 | | |
47 | | // Limit range of target fixups, in case we want to pack more efficiently |
48 | | // later. |
49 | | MaxTargetFixupKind = (1 << 8) |
50 | | }; |
51 | | |
52 | | /// \brief Encode information on a single operation to perform on a byte |
53 | | /// sequence (e.g., an encoded instruction) which requires assemble- or run- |
54 | | /// time patching. |
55 | | /// |
56 | | /// Fixups are used any time the target instruction encoder needs to represent |
57 | | /// some value in an instruction which is not yet concrete. The encoder will |
58 | | /// encode the instruction assuming the value is 0, and emit a fixup which |
59 | | /// communicates to the assembler backend how it should rewrite the encoded |
60 | | /// value. |
61 | | /// |
62 | | /// During the process of relaxation, the assembler will apply fixups as |
63 | | /// symbolic values become concrete. When relaxation is complete, any remaining |
64 | | /// fixups become relocations in the object file (or errors, if the fixup cannot |
65 | | /// be encoded on the target). |
66 | | class MCFixup { |
67 | | /// The value to put into the fixup location. The exact interpretation of the |
68 | | /// expression is target dependent, usually it will be one of the operands to |
69 | | /// an instruction or an assembler directive. |
70 | | const MCExpr *Value; |
71 | | |
72 | | /// The byte index of start of the relocation inside the MCFragment. |
73 | | uint32_t Offset; |
74 | | |
75 | | /// The target dependent kind of fixup item this is. The kind is used to |
76 | | /// determine how the operand value should be encoded into the instruction. |
77 | | unsigned Kind; |
78 | | |
79 | | /// The source location which gave rise to the fixup, if any. |
80 | | SMLoc Loc; |
81 | | public: |
82 | | static MCFixup create(uint32_t Offset, const MCExpr *Value, |
83 | 7.73M | MCFixupKind Kind, SMLoc Loc = SMLoc()) { |
84 | 7.73M | assert(unsigned(Kind) < MaxTargetFixupKind && "Kind out of range!"); |
85 | 7.73M | MCFixup FI; |
86 | 7.73M | FI.Value = Value; |
87 | 7.73M | FI.Offset = Offset; |
88 | 7.73M | FI.Kind = unsigned(Kind); |
89 | 7.73M | FI.Loc = Loc; |
90 | 7.73M | return FI; |
91 | 7.73M | } |
92 | | |
93 | 49.0M | MCFixupKind getKind() const { return MCFixupKind(Kind); } |
94 | | |
95 | 22.0M | uint32_t getOffset() const { return Offset; } |
96 | 7.13M | void setOffset(uint32_t Value) { Offset = Value; } |
97 | | |
98 | 7.86M | const MCExpr *getValue() const { return Value; } |
99 | | |
100 | | /// \brief Return the generic fixup kind for a value with the given size. It |
101 | | /// is an error to pass an unsupported size. |
102 | 660k | static MCFixupKind getKindForSize(unsigned Size, bool isPCRel) { |
103 | 660k | switch (Size) { |
104 | 0 | default: 0 llvm_unreachable0 ("Invalid generic fixup size!"); |
105 | 98.0k | case 1: return isPCRel ? 98.0k FK_PCRel_140.0k : FK_Data_158.0k ; |
106 | 2.04k | case 2: return isPCRel ? 2.04k FK_PCRel_25 : FK_Data_22.04k ; |
107 | 249k | case 4: return isPCRel ? 249k FK_PCRel_432.6k : FK_Data_4217k ; |
108 | 310k | case 8: return isPCRel ? 310k FK_PCRel_80 : FK_Data_8310k ; |
109 | 660k | } |
110 | 660k | } |
111 | | |
112 | 4.03k | SMLoc getLoc() const { return Loc; } |
113 | | }; |
114 | | |
115 | | } // End llvm namespace |
116 | | |
117 | | #endif |