llvm.org GIT mirror llvm / c49542e
[FaultMaps] Move FaultMapParser to Object/ Summary: That way llvm-objdump can rely on it without adding an extra dependency on CodeGen. This change duplicates the FaultKind enum and the code that serializes it to a string. I could not figure out a way to get around this without adding a new dependency to Object Reviewers: rafael, ab Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D10619 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240364 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 5 years ago
6 changed file(s) with 230 addition(s) and 183 deletion(s). Raw diff Collapse all Expand all
1111
1212 #include "llvm/ADT/DenseMap.h"
1313 #include "llvm/MC/MCSymbol.h"
14 #include "llvm/Support/Endian.h"
15 #include "llvm/Support/Format.h"
1614
1715 #include
1816 #include
7068 void emitFunctionInfo(const MCSymbol *FnLabel, const FunctionFaultInfos &FFI);
7169 };
7270
73 /// A parser for the __llvm_faultmaps section generated by the FaultMaps class
74 /// above. This parser is version locked with with the __llvm_faultmaps section
75 /// generated by the version of LLVM that includes it. No guarantees are made
76 /// with respect to forward or backward compatibility.
77 class FaultMapParser {
78 typedef uint8_t FaultMapVersionType;
79 static const size_t FaultMapVersionOffset = 0;
80
81 typedef uint8_t Reserved0Type;
82 static const size_t Reserved0Offset =
83 FaultMapVersionOffset + sizeof(FaultMapVersionType);
84
85 typedef uint16_t Reserved1Type;
86 static const size_t Reserved1Offset = Reserved0Offset + sizeof(Reserved0Type);
87
88 typedef uint32_t NumFunctionsType;
89 static const size_t NumFunctionsOffset =
90 Reserved1Offset + sizeof(Reserved1Type);
91
92 static const size_t FunctionInfosOffset =
93 NumFunctionsOffset + sizeof(NumFunctionsType);
94
95 const uint8_t *P;
96 const uint8_t *E;
97
98 template static T read(const uint8_t *P, const uint8_t *E) {
99 assert(P + sizeof(T) <= E && "out of bounds read!");
100 return support::endian::read(P);
101 }
102
103 public:
104 class FunctionFaultInfoAccessor {
105 typedef uint32_t FaultKindType;
106 static const size_t FaultKindOffset = 0;
107
108 typedef uint32_t FaultingPCOffsetType;
109 static const size_t FaultingPCOffsetOffset =
110 FaultKindOffset + sizeof(FaultKindType);
111
112 typedef uint32_t HandlerPCOffsetType;
113 static const size_t HandlerPCOffsetOffset =
114 FaultingPCOffsetOffset + sizeof(FaultingPCOffsetType);
115
116 const uint8_t *P;
117 const uint8_t *E;
118
119 public:
120 static const size_t Size =
121 HandlerPCOffsetOffset + sizeof(HandlerPCOffsetType);
122
123 explicit FunctionFaultInfoAccessor(const uint8_t *P, const uint8_t *E)
124 : P(P), E(E) {}
125
126 FaultKindType getFaultKind() const {
127 return read(P + FaultKindOffset, E);
128 }
129
130 FaultingPCOffsetType getFaultingPCOffset() const {
131 return read(P + FaultingPCOffsetOffset, E);
132 }
133
134 HandlerPCOffsetType getHandlerPCOffset() const {
135 return read(P + HandlerPCOffsetOffset, E);
136 }
137 };
138
139 class FunctionInfoAccessor {
140 typedef uint64_t FunctionAddrType;
141 static const size_t FunctionAddrOffset = 0;
142
143 typedef uint32_t NumFaultingPCsType;
144 static const size_t NumFaultingPCsOffset =
145 FunctionAddrOffset + sizeof(FunctionAddrType);
146
147 typedef uint32_t ReservedType;
148 static const size_t ReservedOffset =
149 NumFaultingPCsOffset + sizeof(NumFaultingPCsType);
150
151 static const size_t FunctionFaultInfosOffset =
152 ReservedOffset + sizeof(ReservedType);
153
154 static const size_t FunctionInfoHeaderSize = FunctionFaultInfosOffset;
155
156 const uint8_t *P;
157 const uint8_t *E;
158
159 public:
160 FunctionInfoAccessor() : P(nullptr), E(nullptr) {}
161
162 explicit FunctionInfoAccessor(const uint8_t *P, const uint8_t *E)
163 : P(P), E(E) {}
164
165 FunctionAddrType getFunctionAddr() const {
166 return read(P + FunctionAddrOffset, E);
167 }
168
169 NumFaultingPCsType getNumFaultingPCs() const {
170 return read(P + NumFaultingPCsOffset, E);
171 }
172
173 FunctionFaultInfoAccessor getFunctionFaultInfoAt(uint32_t Index) const {
174 assert(Index < getNumFaultingPCs() && "index out of bounds!");
175 const uint8_t *Begin = P + FunctionFaultInfosOffset +
176 FunctionFaultInfoAccessor::Size * Index;
177 return FunctionFaultInfoAccessor(Begin, E);
178 }
179
180 FunctionInfoAccessor getNextFunctionInfo() const {
181 size_t MySize = FunctionInfoHeaderSize +
182 getNumFaultingPCs() * FunctionFaultInfoAccessor::Size;
183
184 const uint8_t *Begin = P + MySize;
185 assert(Begin < E && "out of bounds!");
186 return FunctionInfoAccessor(Begin, E);
187 }
188 };
189
190 explicit FaultMapParser(const uint8_t *Begin, const uint8_t *End)
191 : P(Begin), E(End) {}
192
193 FaultMapVersionType getFaultMapVersion() const {
194 auto Version = read(P + FaultMapVersionOffset, E);
195 assert(Version == 1 && "only version 1 supported!");
196 return Version;
197 }
198
199 NumFunctionsType getNumFunctions() const {
200 return read(P + NumFunctionsOffset, E);
201 }
202
203 FunctionInfoAccessor getFirstFunctionInfo() const {
204 const uint8_t *Begin = P + FunctionInfosOffset;
205 return FunctionInfoAccessor(Begin, E);
206 }
207 };
208
209 raw_ostream &
210 operator<<(raw_ostream &OS, const FaultMapParser::FunctionFaultInfoAccessor &);
211
212 raw_ostream &operator<<(raw_ostream &OS,
213 const FaultMapParser::FunctionInfoAccessor &);
214
215 raw_ostream &operator<<(raw_ostream &OS, const FaultMapParser &);
216
21771 } // namespace llvm
21872
21973 #endif
0 //===-- FaultMapParser.h - Parser for the "FaultMaps" section --*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Support/Endian.h"
10 #include "llvm/Support/raw_ostream.h"
11
12 #ifndef LLVM_OBJECT_FAULTMAPPARSER_H
13 #define LLVM_OBJECT_FAULTMAPPARSER_H
14
15 namespace llvm {
16
17 /// A parser for the __llvm_faultmaps section generated by the FaultMaps class
18 /// declared in llvm/CodeGen/FaultMaps.h. This parser is version locked with
19 /// with the __llvm_faultmaps section generated by the version of LLVM that
20 /// includes it. No guarantees are made with respect to forward or backward
21 /// compatibility.
22 class FaultMapParser {
23 typedef uint8_t FaultMapVersionType;
24 static const size_t FaultMapVersionOffset = 0;
25
26 typedef uint8_t Reserved0Type;
27 static const size_t Reserved0Offset =
28 FaultMapVersionOffset + sizeof(FaultMapVersionType);
29
30 typedef uint16_t Reserved1Type;
31 static const size_t Reserved1Offset = Reserved0Offset + sizeof(Reserved0Type);
32
33 typedef uint32_t NumFunctionsType;
34 static const size_t NumFunctionsOffset =
35 Reserved1Offset + sizeof(Reserved1Type);
36
37 static const size_t FunctionInfosOffset =
38 NumFunctionsOffset + sizeof(NumFunctionsType);
39
40 const uint8_t *P;
41 const uint8_t *E;
42
43 template static T read(const uint8_t *P, const uint8_t *E) {
44 assert(P + sizeof(T) <= E && "out of bounds read!");
45 return support::endian::read(P);
46 }
47
48 public:
49 enum FaultKind { FaultingLoad = 1, FaultKindMax };
50
51 class FunctionFaultInfoAccessor {
52 typedef uint32_t FaultKindType;
53 static const size_t FaultKindOffset = 0;
54
55 typedef uint32_t FaultingPCOffsetType;
56 static const size_t FaultingPCOffsetOffset =
57 FaultKindOffset + sizeof(FaultKindType);
58
59 typedef uint32_t HandlerPCOffsetType;
60 static const size_t HandlerPCOffsetOffset =
61 FaultingPCOffsetOffset + sizeof(FaultingPCOffsetType);
62
63 const uint8_t *P;
64 const uint8_t *E;
65
66 public:
67 static const size_t Size =
68 HandlerPCOffsetOffset + sizeof(HandlerPCOffsetType);
69
70 explicit FunctionFaultInfoAccessor(const uint8_t *P, const uint8_t *E)
71 : P(P), E(E) {}
72
73 FaultKindType getFaultKind() const {
74 return read(P + FaultKindOffset, E);
75 }
76
77 FaultingPCOffsetType getFaultingPCOffset() const {
78 return read(P + FaultingPCOffsetOffset, E);
79 }
80
81 HandlerPCOffsetType getHandlerPCOffset() const {
82 return read(P + HandlerPCOffsetOffset, E);
83 }
84 };
85
86 class FunctionInfoAccessor {
87 typedef uint64_t FunctionAddrType;
88 static const size_t FunctionAddrOffset = 0;
89
90 typedef uint32_t NumFaultingPCsType;
91 static const size_t NumFaultingPCsOffset =
92 FunctionAddrOffset + sizeof(FunctionAddrType);
93
94 typedef uint32_t ReservedType;
95 static const size_t ReservedOffset =
96 NumFaultingPCsOffset + sizeof(NumFaultingPCsType);
97
98 static const size_t FunctionFaultInfosOffset =
99 ReservedOffset + sizeof(ReservedType);
100
101 static const size_t FunctionInfoHeaderSize = FunctionFaultInfosOffset;
102
103 const uint8_t *P;
104 const uint8_t *E;
105
106 public:
107 FunctionInfoAccessor() : P(nullptr), E(nullptr) {}
108
109 explicit FunctionInfoAccessor(const uint8_t *P, const uint8_t *E)
110 : P(P), E(E) {}
111
112 FunctionAddrType getFunctionAddr() const {
113 return read(P + FunctionAddrOffset, E);
114 }
115
116 NumFaultingPCsType getNumFaultingPCs() const {
117 return read(P + NumFaultingPCsOffset, E);
118 }
119
120 FunctionFaultInfoAccessor getFunctionFaultInfoAt(uint32_t Index) const {
121 assert(Index < getNumFaultingPCs() && "index out of bounds!");
122 const uint8_t *Begin = P + FunctionFaultInfosOffset +
123 FunctionFaultInfoAccessor::Size * Index;
124 return FunctionFaultInfoAccessor(Begin, E);
125 }
126
127 FunctionInfoAccessor getNextFunctionInfo() const {
128 size_t MySize = FunctionInfoHeaderSize +
129 getNumFaultingPCs() * FunctionFaultInfoAccessor::Size;
130
131 const uint8_t *Begin = P + MySize;
132 assert(Begin < E && "out of bounds!");
133 return FunctionInfoAccessor(Begin, E);
134 }
135 };
136
137 explicit FaultMapParser(const uint8_t *Begin, const uint8_t *End)
138 : P(Begin), E(End) {}
139
140 FaultMapVersionType getFaultMapVersion() const {
141 auto Version = read(P + FaultMapVersionOffset, E);
142 assert(Version == 1 && "only version 1 supported!");
143 return Version;
144 }
145
146 NumFunctionsType getNumFunctions() const {
147 return read(P + NumFunctionsOffset, E);
148 }
149
150 FunctionInfoAccessor getFirstFunctionInfo() const {
151 const uint8_t *Begin = P + FunctionInfosOffset;
152 return FunctionInfoAccessor(Begin, E);
153 }
154 };
155
156 raw_ostream &
157 operator<<(raw_ostream &OS, const FaultMapParser::FunctionFaultInfoAccessor &);
158
159 raw_ostream &operator<<(raw_ostream &OS,
160 const FaultMapParser::FunctionInfoAccessor &);
161
162 raw_ostream &operator<<(raw_ostream &OS, const FaultMapParser &);
163
164 } // namespace llvm
165
166 #endif
111111 return "FaultingLoad";
112112 }
113113 }
114
115 raw_ostream &llvm::
116 operator<<(raw_ostream &OS,
117 const FaultMapParser::FunctionFaultInfoAccessor &FFI) {
118 OS << "Fault kind: "
119 << FaultMaps::faultTypeToString((FaultMaps::FaultKind)FFI.getFaultKind())
120 << ", faulting PC offset: " << FFI.getFaultingPCOffset()
121 << ", handling PC offset: " << FFI.getHandlerPCOffset();
122 return OS;
123 }
124
125 raw_ostream &llvm::
126 operator<<(raw_ostream &OS, const FaultMapParser::FunctionInfoAccessor &FI) {
127 OS << "FunctionAddress: " << format_hex(FI.getFunctionAddr(), 8)
128 << ", NumFaultingPCs: " << FI.getNumFaultingPCs() << "\n";
129 for (unsigned i = 0, e = FI.getNumFaultingPCs(); i != e; ++i)
130 OS << FI.getFunctionFaultInfoAt(i) << "\n";
131 return OS;
132 }
133
134 raw_ostream &llvm::operator<<(raw_ostream &OS, const FaultMapParser &FMP) {
135 OS << "Version: " << format_hex(FMP.getFaultMapVersion(), 2) << "\n";
136 OS << "NumFunctions: " << FMP.getNumFunctions() << "\n";
137
138 if (FMP.getNumFunctions() == 0)
139 return OS;
140
141 FaultMapParser::FunctionInfoAccessor FI;
142
143 for (unsigned i = 0, e = FMP.getNumFunctions(); i != e; ++i) {
144 FI = (i == 0) ? FMP.getFirstFunctionInfo() : FI.getNextFunctionInfo();
145 OS << FI;
146 }
147
148 return OS;
149 }
77 ELFObjectFile.cpp
88 ELFYAML.cpp
99 Error.cpp
10 FaultMapParser.cpp
1011 IRObjectFile.cpp
1112 MachOObjectFile.cpp
1213 MachOUniversal.cpp
0 //===----------------------- FaultMapParser.cpp ---------------------------===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "llvm/Object/FaultMapParser.h"
10
11 #include "llvm/Support/ErrorHandling.h"
12 #include "llvm/Support/Format.h"
13
14 using namespace llvm;
15
16 const char *faultKindToString(FaultMapParser::FaultKind FT) {
17 switch (FT) {
18 default:
19 llvm_unreachable("unhandled fault type!");
20
21 case FaultMapParser::FaultingLoad:
22 return "FaultingLoad";
23 }
24 }
25
26 raw_ostream &llvm::
27 operator<<(raw_ostream &OS,
28 const FaultMapParser::FunctionFaultInfoAccessor &FFI) {
29 OS << "Fault kind: "
30 << faultKindToString((FaultMapParser::FaultKind)FFI.getFaultKind())
31 << ", faulting PC offset: " << FFI.getFaultingPCOffset()
32 << ", handling PC offset: " << FFI.getHandlerPCOffset();
33 return OS;
34 }
35
36 raw_ostream &llvm::
37 operator<<(raw_ostream &OS, const FaultMapParser::FunctionInfoAccessor &FI) {
38 OS << "FunctionAddress: " << format_hex(FI.getFunctionAddr(), 8)
39 << ", NumFaultingPCs: " << FI.getNumFaultingPCs() << "\n";
40 for (unsigned i = 0, e = FI.getNumFaultingPCs(); i != e; ++i)
41 OS << FI.getFunctionFaultInfoAt(i) << "\n";
42 return OS;
43 }
44
45 raw_ostream &llvm::operator<<(raw_ostream &OS, const FaultMapParser &FMP) {
46 OS << "Version: " << format_hex(FMP.getFaultMapVersion(), 2) << "\n";
47 OS << "NumFunctions: " << FMP.getNumFunctions() << "\n";
48
49 if (FMP.getNumFunctions() == 0)
50 return OS;
51
52 FaultMapParser::FunctionInfoAccessor FI;
53
54 for (unsigned i = 0, e = FMP.getNumFunctions(); i != e; ++i) {
55 FI = (i == 0) ? FMP.getFirstFunctionInfo() : FI.getNextFunctionInfo();
56 OS << FI;
57 }
58
59 return OS;
60 }
2020 #include "llvm/ADT/STLExtras.h"
2121 #include "llvm/ADT/StringExtras.h"
2222 #include "llvm/ADT/Triple.h"
23 #include "llvm/CodeGen/FaultMaps.h"
2423 #include "llvm/MC/MCAsmInfo.h"
2524 #include "llvm/MC/MCContext.h"
2625 #include "llvm/MC/MCDisassembler.h"
3433 #include "llvm/MC/MCSubtargetInfo.h"
3534 #include "llvm/Object/Archive.h"
3635 #include "llvm/Object/ELFObjectFile.h"
36 #include "llvm/Object/FaultMapParser.h"
3737 #include "llvm/Object/COFF.h"
3838 #include "llvm/Object/MachO.h"
3939 #include "llvm/Object/ObjectFile.h"