-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
llvm.patch
333 lines (310 loc) · 14.6 KB
/
llvm.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
diff --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index a00000bc11b60cae8567ee49da9dd7a4967aac1e..810fe68fc5bf3501c7a3543696485990ea558cb9 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -120,6 +120,11 @@ public:
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
void emitValueImpl(const MCExpr *Value, unsigned Size,
SMLoc Loc = SMLoc()) override;
+ /// \brief EmitValueImpl with additional param, that allows to emit PCRelative
+ /// MCFixup.
+ void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc,
+ bool isPCRelative);
+
void emitULEB128Value(const MCExpr *Value) override;
void emitSLEB128Value(const MCExpr *Value) override;
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h
index cdc728f7377207f809781e53831fe4e8cc32d82e..8457b465e807bf5b8ee889548074de00a199a81f 100644
--- a/llvm/include/llvm/MC/MCStreamer.h
+++ b/llvm/include/llvm/MC/MCStreamer.h
@@ -146,6 +146,7 @@ public:
virtual void emitPad(int64_t Offset);
virtual void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector);
+ virtual void emitLsda(const MCSymbol *Symbol);
virtual void emitUnwindRaw(int64_t StackOffset,
const SmallVectorImpl<uint8_t> &Opcodes);
@@ -669,6 +670,9 @@ public:
/// etc.
virtual void emitBytes(StringRef Data);
+ /// \brief Emit the given \p Instruction data into the current section.
+ virtual void emitInstructionBytes(StringRef Data);
+
/// Functionally identical to EmitBytes. When emitting textual assembly, this
/// method uses .byte directives instead of .ascii or .asciz for readability.
virtual void emitBinaryData(StringRef Data);
diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp
index 1c23d31f8744a6f842fa96279daf7ab7770157b1..1c7012bd9b77360d20c860fc6fa198c4cc06e6e5 100644
--- a/llvm/lib/MC/MCObjectStreamer.cpp
+++ b/llvm/lib/MC/MCObjectStreamer.cpp
@@ -223,7 +223,7 @@ void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
}
void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
- SMLoc Loc) {
+ SMLoc Loc, bool isPCRelative) {
MCStreamer::emitValueImpl(Value, Size, Loc);
MCDataFragment *DF = getOrCreateDataFragment();
flushPendingLabels(DF, DF->getContents().size());
@@ -243,10 +243,15 @@ void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
}
DF->getFixups().push_back(
MCFixup::create(DF->getContents().size(), Value,
- MCFixup::getKindForSize(Size, false), Loc));
+ MCFixup::getKindForSize(Size, isPCRelative), Loc));
DF->getContents().resize(DF->getContents().size() + Size, 0);
}
+void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,
+ SMLoc Loc) {
+ emitValueImpl(Value, Size, Loc, false);
+}
+
MCSymbol *MCObjectStreamer::emitCFILabel() {
MCSymbol *Label = getContext().createTempSymbol("cfi");
emitLabel(Label);
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 4b5ae3cc202de943e93ea7f3d84cfe9b47c40baf..623e06fa6ba889c6d0c7cc203821f4411678e39e 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -1136,6 +1136,7 @@ void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol,
void MCStreamer::changeSection(MCSection *, const MCExpr *) {}
void MCStreamer::emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) {}
void MCStreamer::emitBytes(StringRef Data) {}
+void MCStreamer::emitInstructionBytes(StringRef Data) { emitBytes(Data); }
void MCStreamer::emitBinaryData(StringRef Data) { emitBytes(Data); }
void MCStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) {
visitUsedExpr(*Value);
diff --git a/llvm/lib/MC/WinCOFFObjectWriter.cpp b/llvm/lib/MC/WinCOFFObjectWriter.cpp
index 901d2c06e716f0ab05ea18385662ab548fcba9b4..932f487f7dcd612627f6aa205edea86c969d1740 100644
--- a/llvm/lib/MC/WinCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/WinCOFFObjectWriter.cpp
@@ -794,7 +794,9 @@ void WinCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
if ((Header.Machine == COFF::IMAGE_FILE_MACHINE_AMD64 &&
Reloc.Data.Type == COFF::IMAGE_REL_AMD64_REL32) ||
(Header.Machine == COFF::IMAGE_FILE_MACHINE_I386 &&
- Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32))
+ Reloc.Data.Type == COFF::IMAGE_REL_I386_REL32) ||
+ (Header.Machine == COFF::IMAGE_FILE_MACHINE_ARM64 &&
+ Reloc.Data.Type == COFF::IMAGE_REL_ARM64_REL32))
FixedValue += 4;
if (Header.Machine == COFF::IMAGE_FILE_MACHINE_ARMNT) {
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
index 75a9f2f5c80e3b6c81258084f52237a54f6aad43..73a2d7b2c5bf966bddc0d0435ca6c008bd8bc6c9 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64AsmBackend.cpp
@@ -141,6 +141,7 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
case AArch64::fixup_aarch64_pcrel_call26:
case FK_Data_4:
case FK_SecRel_4:
+ case FK_PCRel_4:
return 4;
case FK_Data_8:
@@ -330,13 +331,19 @@ static uint64_t adjustFixupValue(const MCFixup &Fixup, const MCValue &Target,
case FK_Data_8:
case FK_SecRel_2:
case FK_SecRel_4:
+ case FK_PCRel_4:
return Value;
}
}
Optional<MCFixupKind> AArch64AsmBackend::getFixupKind(StringRef Name) const {
- if (!TheTriple.isOSBinFormatELF())
- return None;
+ if (!TheTriple.isOSBinFormatELF()) {
+ return StringSwitch<Optional<MCFixupKind>>(Name)
+ .Case("R_AARCH64_CALL26", (MCFixupKind)AArch64::fixup_aarch64_pcrel_call26)
+ .Case("R_AARCH64_ADR_PREL_PG_HI21", (MCFixupKind)AArch64::fixup_aarch64_pcrel_adrp_imm21)
+ .Case("R_AARCH64_ADD_ABS_LO12_NC", (MCFixupKind)AArch64::fixup_aarch64_add_imm12)
+ .Default(MCAsmBackend::getFixupKind(Name));
+ }
unsigned Type = llvm::StringSwitch<unsigned>(Name)
#define ELF_RELOC(X, Y) .Case(#X, Y)
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
index fcf67bd2f740f5f01454029d0d33c5f1172737f8..c6bcf963f6f89fe6eb7962c3fc0edd08cad94816 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64ELFObjectWriter.cpp
@@ -130,6 +130,7 @@ unsigned AArch64ELFObjectWriter::getRelocType(MCContext &Ctx,
return ELF::R_AARCH64_NONE;
case FK_Data_2:
return R_CLS(PREL16);
+ case FK_PCRel_4:
case FK_Data_4: {
return Target.getAccessVariant() == MCSymbolRefExpr::VK_PLT
? R_CLS(PLT32)
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
index aaadc8dc1b6001ace9268be68eadb7bd38035304..48ed1e63f6d9bd73a4816e5816b6e34992c5c0a1 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64WinCOFFObjectWriter.cpp
@@ -91,6 +91,9 @@ unsigned AArch64WinCOFFObjectWriter::getRelocType(
case FK_Data_8:
return COFF::IMAGE_REL_ARM64_ADDR64;
+ case FK_PCRel_4:
+ return COFF::IMAGE_REL_ARM64_REL32;
+
case FK_SecRel_2:
return COFF::IMAGE_REL_ARM64_SECTION;
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
index b02aef3c338b8fcc4f7d3f110a6a9c5417518c88..f9636aed5068c8fdd20d1b5b2c03e97c9f1b2f20 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMAsmBackend.cpp
@@ -448,6 +448,8 @@ unsigned ARMAsmBackend::adjustFixupValue(const MCAssembler &Asm,
case FK_Data_2:
case FK_Data_4:
return Value;
+ case FK_PCRel_4:
+ return Value;
case FK_SecRel_2:
return Value;
case FK_SecRel_4:
@@ -967,6 +969,9 @@ static unsigned getFixupKindNumBytes(unsigned Kind) {
case ARM::fixup_le:
return 4;
+ case FK_PCRel_4:
+ return 4;
+
case FK_SecRel_2:
return 2;
case FK_SecRel_4:
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
index 37d81e4b0af13dd0c450849d2a24ab33a5b0c6d1..00a543cc08a9665c42dafa8a863aa41e85705ee9 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFObjectWriter.cpp
@@ -111,6 +111,8 @@ unsigned ARMELFObjectWriter::GetRelocTypeInner(const MCValue &Target,
case MCSymbolRefExpr::VK_ARM_PREL31:
return ELF::R_ARM_PREL31;
}
+ case FK_PCRel_4:
+ return ELF::R_ARM_REL32;
case ARM::fixup_arm_blx:
case ARM::fixup_arm_uncondbl:
switch (Modifier) {
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
index 07ca5c29f0ec995c9f0213a78d3f0f6e386289e0..fa9f498182403136765f29136a1318260c14deb2 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
@@ -84,6 +84,7 @@ class ARMTargetAsmStreamer : public ARMTargetStreamer {
void emitPad(int64_t Offset) override;
void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) override;
+ void emitLsda(const MCSymbol* Symbol) override;
void emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) override;
@@ -272,6 +273,8 @@ void ARMTargetAsmStreamer::emitUnwindRaw(int64_t Offset,
OS << '\n';
}
+void ARMTargetAsmStreamer::emitLsda(const MCSymbol* Symbol) {}
+
class ARMTargetELFStreamer : public ARMTargetStreamer {
private:
// This structure holds all attributes, accounting for
@@ -388,6 +391,7 @@ private:
void emitPad(int64_t Offset) override;
void emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) override;
+ void emitLsda(const MCSymbol *Symbol) override;
void emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) override;
@@ -457,6 +461,7 @@ public:
void emitMovSP(unsigned Reg, int64_t Offset = 0);
void emitPad(int64_t Offset);
void emitRegSave(const SmallVectorImpl<unsigned> &RegList, bool isVector);
+ void emitLsda(const MCSymbol* Symbol);
void emitUnwindRaw(int64_t Offset, const SmallVectorImpl<uint8_t> &Opcodes);
void emitFill(const MCExpr &NumBytes, uint64_t FillValue,
SMLoc Loc) override {
@@ -536,6 +541,18 @@ public:
MCELFStreamer::emitBytes(Data);
}
+ /// This function is the one used to emit instruction data into the ELF
+ /// streamer. We override it to add the appropriate mapping symbol if
+ /// necessary.
+ void emitInstructionBytes(StringRef Data) override {
+ if (IsThumb)
+ EmitThumbMappingSymbol();
+ else
+ EmitARMMappingSymbol();
+
+ MCELFStreamer::emitBytes(Data);
+ }
+
void FlushPendingMappingSymbol() {
if (!LastEMSInfo->hasInfo())
return;
@@ -699,6 +716,7 @@ private:
bool CantUnwind;
SmallVector<uint8_t, 64> Opcodes;
UnwindOpcodeAssembler UnwindOpAsm;
+ const MCSymbol *Lsda;
};
} // end anonymous namespace
@@ -741,6 +759,10 @@ void ARMTargetELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
getStreamer().emitRegSave(RegList, isVector);
}
+void ARMTargetELFStreamer::emitLsda(const MCSymbol *Symbol) {
+ getStreamer().emitLsda(Symbol);
+}
+
void ARMTargetELFStreamer::emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) {
getStreamer().emitUnwindRaw(Offset, Opcodes);
@@ -1241,6 +1263,7 @@ void ARMELFStreamer::EHReset() {
PendingOffset = 0;
UsedFP = false;
CantUnwind = false;
+ Lsda = nullptr;
Opcodes.clear();
UnwindOpAsm.Reset();
@@ -1343,6 +1366,8 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
}
// Finalize the unwind opcode sequence
+ if (Lsda != nullptr && Opcodes.size() <= 4u)
+ PersonalityIndex = ARM::EHABI::AEABI_UNWIND_CPP_PR1;
UnwindOpAsm.Finalize(PersonalityIndex, Opcodes);
// For compact model 0, we have to emit the unwind opcodes in the .ARM.exidx
@@ -1387,7 +1412,13 @@ void ARMELFStreamer::FlushUnwindOpcodes(bool NoHandlerData) {
//
// In case that the .handlerdata directive is not specified by the
// programmer, we should emit zero to terminate the handler data.
- if (NoHandlerData && !Personality)
+ if (Lsda != nullptr) {
+ const MCSymbolRefExpr *LsdaRef =
+ MCSymbolRefExpr::create(Lsda,
+ MCSymbolRefExpr::VK_None,
+ getContext());
+ emitValue(LsdaRef, 4);
+ } else if (NoHandlerData && !Personality)
emitInt32(0);
}
@@ -1470,6 +1501,10 @@ void ARMELFStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
UnwindOpAsm.EmitRegSave(Mask);
}
+void ARMELFStreamer::emitLsda(const MCSymbol *Symbol) {
+ Lsda = Symbol;
+}
+
void ARMELFStreamer::emitUnwindRaw(int64_t Offset,
const SmallVectorImpl<uint8_t> &Opcodes) {
FlushPendingOffset();
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
index 1fee354cad93266060222bec3ed6ceef3d310e54..7d2eb8ef5e367372466c0bf1fb7d98494a00cfcd 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMTargetStreamer.cpp
@@ -97,6 +97,7 @@ void ARMTargetStreamer::emitMovSP(unsigned Reg, int64_t Offset) {}
void ARMTargetStreamer::emitPad(int64_t Offset) {}
void ARMTargetStreamer::emitRegSave(const SmallVectorImpl<unsigned> &RegList,
bool isVector) {}
+void ARMTargetStreamer::emitLsda(const MCSymbol *Symbol) {}
void ARMTargetStreamer::emitUnwindRaw(int64_t StackOffset,
const SmallVectorImpl<uint8_t> &Opcodes) {
}
diff --git a/llvm/tools/CMakeLists.txt b/llvm/tools/CMakeLists.txt
index b6d3b2c2fcbeb1f3c9ec041766ae60604ec2db64..491715166e96527b09d3299f35615fd9f8ad5fd8 100644
--- a/llvm/tools/CMakeLists.txt
+++ b/llvm/tools/CMakeLists.txt
@@ -39,6 +39,7 @@ add_llvm_external_project(lldb)
add_llvm_external_project(mlir)
# Flang depends on mlir, so place it afterward
add_llvm_external_project(flang)
+add_llvm_external_project(ObjWriter)
# Automatically add remaining sub-directories containing a 'CMakeLists.txt'
# file as external projects.