forked from facebookarchive/BOLT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathllvm.patch
4268 lines (4040 loc) · 160 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/include/llvm/ADT/BitVector.h b/include/llvm/ADT/BitVector.h
index 124c2a8c86d..03af230f2e7 100644
--- a/include/llvm/ADT/BitVector.h
+++ b/include/llvm/ADT/BitVector.h
@@ -591,6 +591,11 @@ public:
return *this;
}
+ friend BitVector operator|(BitVector LHS, const BitVector &RHS) {
+ LHS |= RHS;
+ return LHS;
+ }
+
BitVector &operator^=(const BitVector &RHS) {
if (size() < RHS.size())
resize(RHS.size());
diff --git a/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h b/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
index 84b23398b8c..9ed1792f0c9 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
@@ -28,12 +28,15 @@ class raw_ostream;
class DWARFAbbreviationDeclaration {
public:
struct AttributeSpec {
- AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value)
- : Attr(A), Form(F), Value(Value) {
+ AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value,
+ uint32_t AttrOffset = -1U, uint32_t FormOffset = -1U)
+ : Attr(A), Form(F), AttrOffset(AttrOffset), FormOffset(FormOffset),
+ Value(Value) {
assert(isImplicitConst());
}
- AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize)
- : Attr(A), Form(F) {
+ AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize,
+ uint32_t AttrOffset = -1U, uint32_t FormOffset = -1U)
+ : Attr(A), Form(F), AttrOffset(AttrOffset), FormOffset(FormOffset) {
assert(!isImplicitConst());
this->ByteSize.HasByteSize = ByteSize.hasValue();
if (this->ByteSize.HasByteSize)
@@ -42,6 +45,8 @@ public:
dwarf::Attribute Attr;
dwarf::Form Form;
+ uint32_t AttrOffset;
+ uint32_t FormOffset;
private:
/// The following field is used for ByteSize for non-implicit_const
@@ -112,6 +117,8 @@ public:
return AttributeSpecs[idx].Attr;
}
+ const AttributeSpec *findAttribute(dwarf::Attribute Attr) const;
+
/// Get the index of the specified attribute.
///
/// Searches the this abbreviation declaration for the index of the specified
@@ -133,7 +140,8 @@ public:
/// \returns Optional DWARF form value if the attribute was extracted.
Optional<DWARFFormValue> getAttributeValue(const uint32_t DIEOffset,
const dwarf::Attribute Attr,
- const DWARFUnit &U) const;
+ const DWARFUnit &U,
+ uint32_t *OffsetPtr = 0) const;
bool extract(DataExtractor Data, uint32_t* OffsetPtr);
void dump(raw_ostream &OS) const;
diff --git a/include/llvm/DebugInfo/DWARF/DWARFContext.h b/include/llvm/DebugInfo/DWARF/DWARFContext.h
index e842cf231e7..90eb7961649 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFContext.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFContext.h
@@ -225,6 +225,10 @@ public:
/// Get a pointer to the parsed DebugLoc object.
const DWARFDebugLoc *getDebugLoc();
+ /// Extract one location list corresponding in \p Offset
+ Optional<DWARFDebugLoc::LocationList>
+ getOneDebugLocList(uint32_t *Offset, uint64_t CUBaseAddress = 0);
+
/// Get a pointer to the parsed dwo abbreviations object.
const DWARFDebugAbbrev *getDebugAbbrevDWO();
@@ -280,6 +284,10 @@ public:
/// given address where applicable.
DIEsForAddress getDIEsForAddress(uint64_t Address);
+ /// Get offset to an attribute value within a compile unit
+ /// or 0 if the attribute was not found.
+ uint32_t getAttrFieldOffsetForUnit(DWARFUnit *U, dwarf::Attribute Attr) const;
+
DILineInfo getLineInfoForAddress(uint64_t Address,
DILineInfoSpecifier Specifier = DILineInfoSpecifier()) override;
DILineInfoTable getLineInfoForAddressRange(uint64_t Address, uint64_t Size,
@@ -302,7 +310,7 @@ public:
static std::unique_ptr<DWARFContext>
create(const object::ObjectFile &Obj, const LoadedObjectInfo *L = nullptr,
function_ref<ErrorPolicy(Error)> HandleError = defaultErrorHandler,
- std::string DWPName = "");
+ std::string DWPName = "", bool UsesRelocs = true);
static std::unique_ptr<DWARFContext>
create(const StringMap<std::unique_ptr<MemoryBuffer>> &Sections,
@@ -313,7 +321,6 @@ public:
/// have initialized the relevant target descriptions.
Error loadRegisterInfo(const object::ObjectFile &Obj);
-private:
/// Return the compile unit that includes an offset (relative to .debug_info).
DWARFCompileUnit *getCompileUnitForOffset(uint32_t Offset);
diff --git a/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h b/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
index ff1c7fb3838..2622a4e7eef 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFDebugFrame.h
@@ -16,6 +16,7 @@
#include "llvm/DebugInfo/DWARF/DWARFDataExtractor.h"
#include "llvm/DebugInfo/DWARF/DWARFExpression.h"
#include "llvm/Support/Error.h"
+#include <functional>
#include <memory>
#include <vector>
@@ -279,9 +280,20 @@ public:
void dump(raw_ostream &OS, const MCRegisterInfo *MRI,
Optional<uint64_t> Offset) const;
+ using RefHandlerType =
+ std::function<void(uint64_t, uint64_t, uint64_t)>;
+
/// Parse the section from raw data. \p Data is assumed to contain the whole
/// frame section contents to be parsed.
- void parse(DWARFDataExtractor Data);
+ /// If non-null RefHandler is passed, call it for every encountered external
+ /// reference in frame data. The expected signature is:
+ ///
+ /// void RefHandler(uint64_t Value, uint64_t Offset, uint64_t Type);
+ ///
+ /// where Value is a value of the reference, Offset - is an offset into the
+ /// frame data at which the reference occured, and Type is a DWARF encoding
+ /// type of the reference.
+ void parse(DWARFDataExtractor Data, RefHandlerType RefHandler= nullptr);
/// Return whether the section has any entries.
bool empty() const { return Entries.empty(); }
@@ -293,6 +305,12 @@ public:
return iterator_range<iterator>(Entries.begin(), Entries.end());
}
+ using FDEFunction = std::function<void(const dwarf::FDE *)>;
+
+ /// Call function F for every FDE in the frame.
+ void for_each_FDE(FDEFunction F) const;
+
+
uint64_t getEHFrameAddress() const { return EHFrameAddress; }
};
diff --git a/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h b/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h
index a6d319a9045..c099007c132 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFDebugLoc.h
@@ -68,8 +68,12 @@ public:
/// Return the location list at the given offset or nullptr.
LocationList const *getLocationListAtOffset(uint64_t Offset) const;
+ /// Returns the parsed location lists.
+ const LocationLists &getLocationLists() const { return Locations; }
+
Optional<LocationList> parseOneLocationList(DWARFDataExtractor Data,
- uint32_t *Offset);
+ uint32_t *Offset,
+ uint64_t CUBaseAddress = 0);
};
class DWARFDebugLocDWO {
diff --git a/include/llvm/DebugInfo/DWARF/DWARFDie.h b/include/llvm/DebugInfo/DWARF/DWARFDie.h
index 39a3dd32c0f..84279875611 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFDie.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFDie.h
@@ -130,7 +130,8 @@ public:
/// \param Attr the attribute to extract.
/// \returns an optional DWARFFormValue that will have the form value if the
/// attribute was successfully extracted.
- Optional<DWARFFormValue> find(dwarf::Attribute Attr) const;
+ Optional<DWARFFormValue> find(dwarf::Attribute Attr,
+ uint32_t *OffsetPtr = 0) const;
/// Extract the first value of any attribute in Attrs from this DIE.
///
diff --git a/include/llvm/DebugInfo/DWARF/DWARFObject.h b/include/llvm/DebugInfo/DWARF/DWARFObject.h
index 795eddd1c5d..43243e70474 100644
--- a/include/llvm/DebugInfo/DWARF/DWARFObject.h
+++ b/include/llvm/DebugInfo/DWARF/DWARFObject.h
@@ -41,6 +41,7 @@ public:
virtual StringRef getARangeSection() const { return ""; }
virtual StringRef getDebugFrameSection() const { return ""; }
virtual StringRef getEHFrameSection() const { return ""; }
+ virtual uint64_t getEHFrameAddress() const { return 0; }
virtual const DWARFSection &getLineSection() const { return Dummy; }
virtual StringRef getLineStringSection() const { return ""; }
virtual StringRef getStringSection() const { return ""; }
diff --git a/include/llvm/ExecutionEngine/ExecutionEngine.h b/include/llvm/ExecutionEngine/ExecutionEngine.h
index 7932688290e..51bf4719f6c 100644
--- a/include/llvm/ExecutionEngine/ExecutionEngine.h
+++ b/include/llvm/ExecutionEngine/ExecutionEngine.h
@@ -251,6 +251,16 @@ public:
"EE!");
}
+ /// mapSectionAddress - map a section to its target address space value.
+ /// Map a JIT section with a given ID to the address in the target process
+ /// as the running code will see it. This is the address which will be used
+ /// for relocation resolution.
+ virtual void mapSectionAddress(unsigned SectionID,
+ uint64_t TargetAddress) {
+ llvm_unreachable("Re-mapping of section addresses not supported with this "
+ "EE!");
+ }
+
/// generateCodeForModule - Run code generation for the specified module and
/// load it into memory.
///
diff --git a/include/llvm/ExecutionEngine/JITSymbol.h b/include/llvm/ExecutionEngine/JITSymbol.h
index 86ab17363e1..257ed03371b 100644
--- a/include/llvm/ExecutionEngine/JITSymbol.h
+++ b/include/llvm/ExecutionEngine/JITSymbol.h
@@ -297,7 +297,17 @@ public:
/// missing. Instead, that symbol will be left out of the result map.
virtual Expected<LookupFlagsResult> lookupFlags(const LookupSet &Symbols) = 0;
+ /// Specify if this resolver can return valid symbols with zero value.
+ virtual void setAllowsZeroSymbols(bool Value = true) {
+ AllowsZeroSymbols = Value;
+ }
+
+ /// Return true if the resolver can return a valid symbol with zero value.
+ virtual bool allowsZeroSymbols() { return AllowsZeroSymbols; }
+
private:
+ bool AllowsZeroSymbols = false;
+
virtual void anchor();
};
diff --git a/include/llvm/ExecutionEngine/Orc/Core.h b/include/llvm/ExecutionEngine/Orc/Core.h
index 26fec8b359f..c5330034335 100644
--- a/include/llvm/ExecutionEngine/Orc/Core.h
+++ b/include/llvm/ExecutionEngine/Orc/Core.h
@@ -110,7 +110,17 @@ public:
virtual SymbolNameSet lookup(std::shared_ptr<AsynchronousSymbolQuery> Query,
SymbolNameSet Symbols) = 0;
+ /// Specify if this resolver can return valid symbols with zero value.
+ virtual void setAllowsZeroSymbols(bool Value = true) {
+ AllowsZeroSymbols = Value;
+ }
+
+ /// Return true if the resolver can return a valid symbol with zero value.
+ virtual bool allowsZeroSymbols() { return AllowsZeroSymbols; }
+
private:
+ bool AllowsZeroSymbols = false;
+
virtual void anchor();
};
diff --git a/include/llvm/ExecutionEngine/Orc/Legacy.h b/include/llvm/ExecutionEngine/Orc/Legacy.h
index b2b389ad339..7c108ef848f 100644
--- a/include/llvm/ExecutionEngine/Orc/Legacy.h
+++ b/include/llvm/ExecutionEngine/Orc/Legacy.h
@@ -25,6 +25,10 @@ public:
JITSymbolResolverAdapter(ExecutionSession &ES, SymbolResolver &R);
Expected<LookupFlagsResult> lookupFlags(const LookupSet &Symbols) override;
Expected<LookupResult> lookup(const LookupSet &Symbols) override;
+ bool allowsZeroSymbols() override { return R.allowsZeroSymbols(); }
+ void setAllowsZeroSymbols(bool Value) override {
+ R.setAllowsZeroSymbols(Value);
+ }
private:
ExecutionSession &ES;
@@ -70,11 +74,13 @@ Expected<SymbolNameSet> lookupFlagsWithLegacyFn(SymbolFlagsMap &SymbolFlags,
template <typename FindSymbolFn>
SymbolNameSet lookupWithLegacyFn(AsynchronousSymbolQuery &Query,
const SymbolNameSet &Symbols,
- FindSymbolFn FindSymbol) {
+ FindSymbolFn FindSymbol,
+ bool AllowZeroSymbols = false) {
SymbolNameSet SymbolsNotFound;
for (auto &S : Symbols) {
- if (JITSymbol Sym = FindSymbol(*S)) {
+ JITSymbol Sym = FindSymbol(*S);
+ if (Sym || (AllowZeroSymbols && !Sym.getFlags().hasError())) {
if (auto Addr = Sym.getAddress()) {
Query.setDefinition(S, JITEvaluatedSymbol(*Addr, Sym.getFlags()));
Query.notifySymbolFinalized();
@@ -116,7 +122,8 @@ public:
SymbolNameSet lookup(std::shared_ptr<AsynchronousSymbolQuery> Query,
SymbolNameSet Symbols) final {
- return lookupWithLegacyFn(*Query, Symbols, LegacyLookup);
+ return lookupWithLegacyFn(*Query, Symbols, LegacyLookup,
+ this->allowsZeroSymbols());
}
private:
diff --git a/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h b/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
index cfc3922ebb5..c0b43ce8639 100644
--- a/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
+++ b/include/llvm/ExecutionEngine/Orc/ObjectTransformLayer.h
@@ -80,6 +80,12 @@ public:
BaseLayer.mapSectionAddress(K, LocalAddress, TargetAddr);
}
+ /// @brief Map section addresses for the objects associated with the handle H.
+ void mapSectionAddress(VModuleKey K, unsigned SectionID,
+ JITTargetAddress TargetAddr) {
+ BaseLayer.mapSectionAddress(K, SectionID, TargetAddr);
+ }
+
/// @brief Access the transform functor directly.
TransformFtor &getTransform() { return Transform; }
diff --git a/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h b/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
index 8f0d9fa6eb6..ada93a275e5 100644
--- a/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
+++ b/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h
@@ -62,6 +62,8 @@ protected:
virtual void mapSectionAddress(const void *LocalAddress,
JITTargetAddress TargetAddr) const = 0;
+ virtual void mapSectionAddress(unsigned SectionID,
+ JITTargetAddress TargetAddr) const = 0;
JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly) {
auto SymEntry = SymbolTable.find(Name);
@@ -133,6 +135,9 @@ private:
std::unique_ptr<RuntimeDyld::LoadedObjectInfo> Info =
PFC->RTDyld->loadObject(*PFC->Obj.getBinary());
+ if (PFC->Parent.NotifyLoaded)
+ PFC->Parent.NotifyLoaded(PFC->K, *PFC->Obj.getBinary(), *Info);
+
// Copy the symbol table out of the RuntimeDyld instance.
{
auto SymTab = PFC->RTDyld->getSymbolTable();
@@ -140,9 +145,6 @@ private:
SymbolTable[KV.first] = KV.second;
}
- if (PFC->Parent.NotifyLoaded)
- PFC->Parent.NotifyLoaded(PFC->K, *PFC->Obj.getBinary(), *Info);
-
PFC->RTDyld->finalizeWithMemoryManagerLocking();
if (PFC->RTDyld->hasError())
@@ -175,6 +177,13 @@ private:
PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
}
+ void mapSectionAddress(unsigned SectionID,
+ JITTargetAddress TargetAddr) const override {
+ assert(PFC && "mapSectionAddress called on finalized LinkedObject");
+ assert(PFC->RTDyld && "mapSectionAddress called on raw LinkedObject");
+ PFC->RTDyld->mapSectionAddress(SectionID, TargetAddr);
+ }
+
private:
void buildInitialSymbolTable(const OwnedObject &Obj) {
for (auto &Symbol : Obj.getBinary()->symbols()) {
@@ -325,6 +334,13 @@ public:
LinkedObjects[K]->mapSectionAddress(LocalAddress, TargetAddr);
}
+ /// @brief Map section addresses for the objects associated with the handle H.
+ void mapSectionAddress(VModuleKey K, unsigned SectionID,
+ JITTargetAddress TargetAddr) {
+ assert(LinkedObjects.count(K) && "VModuleKey not associated with object");
+ LinkedObjects[K]->mapSectionAddress(SectionID, TargetAddr);
+ }
+
/// @brief Immediately emit and finalize the object represented by the given
/// VModuleKey.
/// @param K VModuleKey for object to emit/finalize.
diff --git a/include/llvm/ExecutionEngine/RuntimeDyld.h b/include/llvm/ExecutionEngine/RuntimeDyld.h
index 14da5af0206..27b02437b98 100644
--- a/include/llvm/ExecutionEngine/RuntimeDyld.h
+++ b/include/llvm/ExecutionEngine/RuntimeDyld.h
@@ -112,6 +112,14 @@ public:
StringRef SectionName,
bool IsReadOnly) = 0;
+ /// Notify that a comment/note section exists and where it's located
+ /// in case the user needs to look up extra information about the
+ /// code, e.g. debugging information.
+ virtual uint8_t *recordNoteSection(const uint8_t *Data, uintptr_t Size,
+ unsigned Alignment,
+ unsigned SectionID,
+ StringRef SectionName) { return nullptr;}
+
/// Inform the memory manager about the total amount of memory required to
/// allocate all sections to be loaded:
/// \p CodeSize - the total size of all code sections
@@ -129,6 +137,11 @@ public:
/// Override to return true to enable the reserveAllocationSpace callback.
virtual bool needsToReserveAllocationSpace() { return false; }
+ /// Override to return false to tell LLVM no stub space will be needed.
+ /// This requires some guarantees depending on architecuture, but when
+ /// you know what you are doing it saves allocated space.
+ virtual bool allowStubAllocation() const { return true; }
+
/// Register the EH frames with the runtime so that c++ exceptions work.
///
/// \p Addr parameter provides the local address of the EH frame section
@@ -205,6 +218,12 @@ public:
/// This is the address which will be used for relocation resolution.
void mapSectionAddress(const void *LocalAddress, uint64_t TargetAddress);
+ /// Map a section to its target address space value.
+ /// Map a JIT section with a given ID to the address in the target process as
+ /// the running code will see it. This is the address which will be used for
+ /// relocation resolution.
+ void mapSectionAddress(unsigned SectionID, uint64_t TargetAddress);
+
/// Register any EH frame sections that have been loaded but not previously
/// registered with the memory manager. Note, RuntimeDyld is responsible
/// for identifying the EH frame and calling the memory manager with the
diff --git a/include/llvm/MC/MCAsmBackend.h b/include/llvm/MC/MCAsmBackend.h
index a8a5850899e..d8fc72dcbaf 100644
--- a/include/llvm/MC/MCAsmBackend.h
+++ b/include/llvm/MC/MCAsmBackend.h
@@ -49,6 +49,9 @@ public:
MCAsmBackend &operator=(const MCAsmBackend &) = delete;
virtual ~MCAsmBackend();
+ virtual void alignBranchesBegin(MCObjectStreamer &OS, const MCInst &Inst) {}
+ virtual void alignBranchesEnd(MCObjectStreamer &OS, const MCInst &Inst) {}
+
/// lifetime management
virtual void reset() {}
diff --git a/include/llvm/MC/MCAsmInfo.h b/include/llvm/MC/MCAsmInfo.h
index c538c46fc07..7b168971a3d 100644
--- a/include/llvm/MC/MCAsmInfo.h
+++ b/include/llvm/MC/MCAsmInfo.h
@@ -225,6 +225,10 @@ protected:
/// result of a alignment directive. Defaults to 0
unsigned TextAlignFillValue = 0;
+ /// If non-zero, this is used to fill the executable space with instructions
+ /// that will trap. Defaults to 0
+ unsigned TrapFillValue = 0;
+
//===--- Global Variable Emission Directives --------------------------===//
/// This is the directive used to declare a global entity. Defaults to
@@ -504,6 +508,7 @@ public:
const char *getAscizDirective() const { return AscizDirective; }
bool getAlignmentIsInBytes() const { return AlignmentIsInBytes; }
unsigned getTextAlignFillValue() const { return TextAlignFillValue; }
+ unsigned getTrapFillValue() const { return TrapFillValue; }
const char *getGlobalDirective() const { return GlobalDirective; }
bool doesSetDirectiveSuppressReloc() const {
diff --git a/include/llvm/MC/MCAssembler.h b/include/llvm/MC/MCAssembler.h
index b91b0441402..385fad92c76 100644
--- a/include/llvm/MC/MCAssembler.h
+++ b/include/llvm/MC/MCAssembler.h
@@ -188,6 +188,8 @@ private:
bool relaxInstruction(MCAsmLayout &Layout, MCRelaxableFragment &IF);
+ bool relaxBoundaryAlign(MCAsmLayout &Layout, MCBoundaryAlignFragment &BF);
+
bool relaxPaddingFragment(MCAsmLayout &Layout, MCPaddingFragment &PF);
bool relaxLEB(MCAsmLayout &Layout, MCLEBFragment &IF);
diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h
index c110ffd3a77..a29f32091ca 100644
--- a/include/llvm/MC/MCContext.h
+++ b/include/llvm/MC/MCContext.h
@@ -506,6 +506,10 @@ namespace llvm {
return MCDwarfLineTablesCUMap;
}
+ std::map<unsigned, MCDwarfLineTable> &getMCDwarfLineTables() {
+ return MCDwarfLineTablesCUMap;
+ }
+
MCDwarfLineTable &getMCDwarfLineTable(unsigned CUID) {
return MCDwarfLineTablesCUMap[CUID];
}
@@ -552,13 +556,14 @@ namespace llvm {
/// instruction will be created.
void setCurrentDwarfLoc(unsigned FileNum, unsigned Line, unsigned Column,
unsigned Flags, unsigned Isa,
- unsigned Discriminator) {
+ unsigned Discriminator, uint64_t Addr = -1ULL) {
CurrentDwarfLoc.setFileNum(FileNum);
CurrentDwarfLoc.setLine(Line);
CurrentDwarfLoc.setColumn(Column);
CurrentDwarfLoc.setFlags(Flags);
CurrentDwarfLoc.setIsa(Isa);
CurrentDwarfLoc.setDiscriminator(Discriminator);
+ CurrentDwarfLoc.setAbsoluteAddr(Addr);
DwarfLocSeen = true;
}
diff --git a/include/llvm/MC/MCDwarf.h b/include/llvm/MC/MCDwarf.h
index 5cdb176e8e2..cd466322894 100644
--- a/include/llvm/MC/MCDwarf.h
+++ b/include/llvm/MC/MCDwarf.h
@@ -73,6 +73,7 @@ class MCDwarfLoc {
uint8_t Flags;
uint8_t Isa;
uint32_t Discriminator;
+ uint64_t AbsoluteAddr;
// Flag that indicates the initial value of the is_stmt_start flag.
#define DWARF2_LINE_DEFAULT_IS_STMT 1
@@ -87,14 +88,17 @@ private: // MCContext manages these
friend class MCDwarfLineEntry;
MCDwarfLoc(unsigned fileNum, unsigned line, unsigned column, unsigned flags,
- unsigned isa, unsigned discriminator)
+ unsigned isa, unsigned discriminator, uint64_t addr=-1ULL)
: FileNum(fileNum), Line(line), Column(column), Flags(flags), Isa(isa),
- Discriminator(discriminator) {}
+ Discriminator(discriminator), AbsoluteAddr(addr) {}
// Allow the default copy constructor and assignment operator to be used
// for an MCDwarfLoc object.
public:
+ /// \brief Get the AbsoluteAddr of this MCDwarfLoc.
+ uint64_t getAbsoluteAddr() const { return AbsoluteAddr; }
+
/// \brief Get the FileNum of this MCDwarfLoc.
unsigned getFileNum() const { return FileNum; }
@@ -141,6 +145,11 @@ public:
void setDiscriminator(unsigned discriminator) {
Discriminator = discriminator;
}
+
+ /// \brief Set the AbsoluteAddr of this MCDwarfLoc.
+ void setAbsoluteAddr(uint64_t addr) {
+ AbsoluteAddr = addr;
+ }
};
/// \brief Instances of this class represent the line information for
@@ -274,7 +283,7 @@ public:
// This emits the Dwarf file and the line tables for a given Compile Unit.
void EmitCU(MCObjectStreamer *MCOS, MCDwarfLineTableParams Params,
- Optional<MCDwarfLineStr> &LineStr) const;
+ Optional<MCDwarfLineStr> &LineStr);
Expected<unsigned> tryGetFile(StringRef &Directory, StringRef &FileName,
MD5::MD5Result *Checksum,
@@ -380,6 +389,57 @@ public:
SMLoc &Loc);
};
+/// \brief A sequence of MCDwarfOperations corresponds to a DWARF expression,
+/// used as operand in some MCCFIInstructions.
+struct MCDwarfOperation {
+ uint8_t Operation{0};
+ uint64_t Operand0{0};
+ uint64_t Operand1{0};
+
+ MCDwarfOperation(uint8_t O, uint64_t O0, uint64_t O1)
+ : Operation(O), Operand0(O0), Operand1(O1) {}
+
+ bool operator==(const MCDwarfOperation &Other) const {
+ return (Other.Operation == Operation && Other.Operand0 == Operand0 &&
+ Other.Operand1 == Operand1);
+ }
+};
+typedef std::vector<MCDwarfOperation> MCDwarfExpression;
+
+/// \brief This builder should be used to create MCDwarfExpression objects
+/// before feeding them to a CFIInstruction factory method.
+class MCDwarfExprBuilder {
+public:
+ MCDwarfExprBuilder() {}
+
+private:
+ MCDwarfExpression Expr;
+
+public:
+ MCDwarfExprBuilder &appendOperation(uint8_t Operation) {
+ Expr.push_back(MCDwarfOperation(Operation, 0, 0));
+ return *this;
+ }
+
+ MCDwarfExprBuilder &appendOperation(uint8_t Operation, uint64_t Op0) {
+ Expr.push_back(MCDwarfOperation(Operation, Op0, 0));
+ return *this;
+ }
+
+ MCDwarfExprBuilder &appendOperation(uint8_t Operation, uint64_t Op0,
+ uint64_t Op1) {
+ Expr.push_back(MCDwarfOperation(Operation, Op0, Op1));
+ return *this;
+ }
+
+ /// \brief Return the resulting expression and reset internal state
+ MCDwarfExpression take() {
+ MCDwarfExpression Res;
+ std::swap(Res, Expr);
+ return Res;
+ }
+};
+
class MCCFIInstruction {
public:
enum OpType {
@@ -397,6 +457,9 @@ public:
OpUndefined,
OpRegister,
OpWindowSave,
+ OpExpression,
+ OpDefCfaExpression,
+ OpValExpression,
OpGnuArgsSize
};
@@ -409,11 +472,13 @@ private:
unsigned Register2;
};
std::vector<char> Values;
+ MCDwarfExpression Expression;
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, int O, StringRef V)
: Operation(Op), Label(L), Register(R), Offset(O),
Values(V.begin(), V.end()) {
- assert(Op != OpRegister);
+ assert(Op != OpRegister && Op != OpDefCfaExpression &&
+ Op != OpValExpression && Op != OpExpression);
}
MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R1, unsigned R2)
@@ -421,6 +486,20 @@ private:
assert(Op == OpRegister);
}
+ MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R,
+ const MCDwarfExpression &E)
+ : Operation(Op), Label(L), Register(R), Offset(0), Expression(E) {
+ assert(Op == OpDefCfaExpression || Op == OpValExpression ||
+ Op == OpExpression);
+ }
+
+ MCCFIInstruction(OpType Op, MCSymbol *L, unsigned R, MCDwarfExpression &&E)
+ : Operation(Op), Label(L), Register(R), Offset(0),
+ Expression(std::move(E)) {
+ assert(Op == OpDefCfaExpression || Op == OpValExpression ||
+ Op == OpExpression);
+ }
+
public:
/// \brief .cfi_def_cfa defines a rule for computing CFA as: take address from
/// Register and add Offset to it.
@@ -516,14 +595,56 @@ public:
return MCCFIInstruction(OpGnuArgsSize, L, 0, Size, "");
}
+ /// \brief MCCFIInstructions that refer to an expression, expression object is
+ /// created by copying
+ static MCCFIInstruction createDefCfaExpression(MCSymbol *L,
+ const MCDwarfExpression &E) {
+ return MCCFIInstruction(OpDefCfaExpression, L, 0, E);
+ }
+
+ static MCCFIInstruction createValExpression(MCSymbol *L, unsigned R,
+ const MCDwarfExpression &E) {
+ return MCCFIInstruction(OpValExpression, L, R, E);
+ }
+
+ static MCCFIInstruction createExpression(MCSymbol *L, unsigned R,
+ const MCDwarfExpression &E) {
+ return MCCFIInstruction(OpExpression, L, R, E);
+ }
+
+ /// \brief MCCFIInstructions that refer to an expression, expression object is
+ /// moved from an r-value
+ static MCCFIInstruction createDefCfaExpression(MCSymbol *L,
+ MCDwarfExpression &&E) {
+ return MCCFIInstruction(OpDefCfaExpression, L, 0, E);
+ }
+
+ static MCCFIInstruction createValExpression(MCSymbol *L, unsigned R,
+ MCDwarfExpression &&E) {
+ return MCCFIInstruction(OpValExpression, L, R, E);
+ }
+
+ static MCCFIInstruction createExpression(MCSymbol *L, unsigned R,
+ MCDwarfExpression &&E) {
+ return MCCFIInstruction(OpExpression, L, R, E);
+ }
+
+ bool operator==(const MCCFIInstruction &Other) const {
+ return (Other.Operation == Operation && Other.Label == Label &&
+ Other.Offset == Offset && Other.Register == Register &&
+ Other.Expression == Expression);
+ }
+
OpType getOperation() const { return Operation; }
MCSymbol *getLabel() const { return Label; }
+ void setLabel(MCSymbol *L) { Label = L; }
unsigned getRegister() const {
assert(Operation == OpDefCfa || Operation == OpOffset ||
Operation == OpRestore || Operation == OpUndefined ||
Operation == OpSameValue || Operation == OpDefCfaRegister ||
- Operation == OpRelOffset || Operation == OpRegister);
+ Operation == OpRelOffset || Operation == OpRegister ||
+ Operation == OpExpression || Operation == OpValExpression);
return Register;
}
@@ -539,6 +660,33 @@ public:
return Offset;
}
+ void setOffset(int NewOffset) {
+ assert(Operation == OpDefCfa || Operation == OpOffset ||
+ Operation == OpRelOffset || Operation == OpDefCfaOffset ||
+ Operation == OpAdjustCfaOffset || Operation == OpGnuArgsSize);
+ Offset = NewOffset;
+ }
+
+ void setRegister(unsigned NewReg) {
+ assert(Operation == OpDefCfa || Operation == OpOffset ||
+ Operation == OpRestore || Operation == OpUndefined ||
+ Operation == OpSameValue || Operation == OpDefCfaRegister ||
+ Operation == OpRelOffset || Operation == OpRegister ||
+ Operation == OpExpression || Operation == OpValExpression);
+ Register = NewReg;
+ }
+
+ void setRegister2(unsigned NewReg) {
+ assert(Operation == OpRegister);
+ Register2 = NewReg;
+ }
+
+ const MCDwarfExpression &getExpression() const {
+ assert(Operation == OpDefCfaExpression || Operation == OpExpression ||
+ Operation == OpValExpression);
+ return Expression;
+ }
+
StringRef getValues() const {
assert(Operation == OpEscape);
return StringRef(&Values[0], Values.size());
diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h
index fcbbe650d26..25847aa2946 100644
--- a/include/llvm/MC/MCExpr.h
+++ b/include/llvm/MC/MCExpr.h
@@ -123,6 +123,9 @@ public:
/// expression.
MCFragment *findAssociatedFragment() const;
+ /// Helper method that returns the Symbol of an MCSymbolRef Expression.
+ const MCSymbol &getSymbol() const;
+
/// @}
};
diff --git a/include/llvm/MC/MCFragment.h b/include/llvm/MC/MCFragment.h
index 38c365538e3..685a8e1f8d7 100644
--- a/include/llvm/MC/MCFragment.h
+++ b/include/llvm/MC/MCFragment.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/ilist_node.h"
#include "llvm/MC/MCFixup.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/Support/Alignment.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/SMLoc.h"
#include <cstdint>
@@ -34,6 +35,7 @@ class MCFragment : public ilist_node_with_parent<MCFragment, MCSection> {
public:
enum FragmentType : uint8_t {
FT_Align,
+ FT_NeverAlign,
FT_Data,
FT_CompactEncodedInst,
FT_Fill,
@@ -42,6 +44,7 @@ public:
FT_Dwarf,
FT_DwarfFrame,
FT_LEB,
+ FT_BoundaryAlign,
FT_Padding,
FT_SymbolId,
FT_CVInlineLines,
@@ -325,6 +328,46 @@ public:
}
};
+class MCNeverAlignFragment : public MCFragment {
+ /// Alignment - The alignment the end of the next fragment should avoid
+ unsigned Alignment;
+
+ /// EmitNops - Flag to indicate that (optimal) NOPs should be emitted instead
+ /// of using the provided value. The exact interpretation of this flag is
+ /// target dependent.
+ bool EmitNops : 1;
+
+ /// Value - Value to use for filling padding bytes.
+ int64_t Value;
+
+ /// ValueSize - The size of the integer (in bytes) of \p Value.
+ unsigned ValueSize;
+
+ public:
+ MCNeverAlignFragment(unsigned Alignment,
+ int64_t Value, unsigned ValueSize, MCSection *Sec = nullptr)
+ : MCFragment(FT_NeverAlign, false, 0, Sec), Alignment(Alignment),
+ EmitNops(false), Value(Value), ValueSize(ValueSize) {}
+
+ /// \name Accessors
+ /// @{
+
+ unsigned getAlignment() const { return Alignment; }
+
+ int64_t getValue() const { return Value; }
+
+ unsigned getValueSize() const { return ValueSize; }
+
+ bool hasEmitNops() const { return EmitNops; }
+ void setEmitNops(bool Value) { EmitNops = Value; }
+
+ /// @}
+
+ static bool classof(const MCFragment *F) {
+ return F->getKind() == MCFragment::FT_NeverAlign;
+ }
+};
+
/// Fragment for adding required padding.
/// This fragment is always inserted before an instruction, and holds that
/// instruction as context information (as well as a mask of kinds) for
@@ -661,6 +704,49 @@ public:
}
};
+class MCBoundaryAlignFragment : public MCFragment {
+private:
+ /// The size of the MCBoundaryAlignFragment.
+ /// Note: The size is lazily set during relaxation, and is not meaningful
+ /// before that.
+ uint64_t Size = 0;
+ /// The alignment requirement of the branch to be aligned.
+ Align AlignBoundary;
+ /// Flag to indicate whether the branch is fused.
+ bool Fused : 1;
+ /// Flag to indicate whether NOPs should be emitted.
+ bool EmitNops : 1;
+
+public:
+ MCBoundaryAlignFragment(Align AlignBoundary, bool Fused = false,
+ bool EmitNops = false, MCSection *Sec = nullptr)
+ : MCFragment(FT_BoundaryAlign, false, 0, Sec),
+ AlignBoundary(AlignBoundary), Fused(Fused), EmitNops(EmitNops) {}
+
+ /// \name Accessors
+ /// @{
+
+ Align getAlignment() const { return AlignBoundary; }
+
+ uint64_t getSize() const { return Size; }
+
+ bool canEmitNops() const { return EmitNops; }
+
+ bool isFused() const { return Fused; }
+
+ void setFused(bool Value) { Fused = Value; }
+
+ void setEmitNops(bool Value) { EmitNops = Value; }
+
+ void setSize(uint64_t Value) { Size = Value; }
+
+ /// @}
+ //
+
+ static bool classof(const MCFragment *F) {
+ return F->getKind() == MCFragment::FT_BoundaryAlign;
+ }
+};
} // end namespace llvm
#endif // LLVM_MC_MCFRAGMENT_H
diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h
index db28fd0fd6d..fbe315b4bd0 100644
--- a/include/llvm/MC/MCInst.h
+++ b/include/llvm/MC/MCInst.h
@@ -159,7 +159,7 @@ template <> struct isPodLike<MCOperand> { static const bool value = true; };
class MCInst {
unsigned Opcode = 0;
SMLoc Loc;
- SmallVector<MCOperand, 8> Operands;
+ SmallVector<MCOperand, 2> Operands;
// These flags could be used to pass some info from one target subcomponent
// to another, for example, from disassembler to asm printer. The values of
// the flags have any sense on target level only (e.g. prefixes on x86).
@@ -187,7 +187,7 @@ public:
using const_iterator = SmallVectorImpl<MCOperand>::const_iterator;
void clear() { Operands.clear(); }
- void erase(iterator I) { Operands.erase(I); }
+ iterator erase(iterator I) { return Operands.erase(I); }
size_t size() const { return Operands.size(); }
iterator begin() { return Operands.begin(); }
const_iterator begin() const { return Operands.begin(); }
diff --git a/include/llvm/MC/MCMachObjectWriter.h b/include/llvm/MC/MCMachObjectWriter.h
index 594869f7463..b6e9e2d5fcd 100644
--- a/include/llvm/MC/MCMachObjectWriter.h
+++ b/include/llvm/MC/MCMachObjectWriter.h
@@ -79,7 +79,7 @@ class MachObjectWriter : public MCObjectWriter {
struct MachSymbolData {
const MCSymbol *Symbol;
uint64_t StringIndex;
- uint8_t SectionIndex;
+ uint64_t SectionIndex;
// Support lexicographic sorting.
bool operator<(const MachSymbolData &RHS) const;
diff --git a/include/llvm/MC/MCObjectFileInfo.h b/include/llvm/MC/MCObjectFileInfo.h
index c99f2521f8f..e6b4a88f469 100644
--- a/include/llvm/MC/MCObjectFileInfo.h
+++ b/include/llvm/MC/MCObjectFileInfo.h
@@ -65,6 +65,9 @@ protected:
/// constants.
MCSection *ReadOnlySection;
+ /// Same as the above but for infrequently used data.
+ MCSection *ReadOnlyColdSection;
+
/// If exception handling is supported by the target, this is the section the
/// Language Specific Data Area information is emitted to.
MCSection *LSDASection;
@@ -230,6 +233,7 @@ public:
MCSection *getDataSection() const { return DataSection; }
MCSection *getBSSSection() const { return BSSSection; }
MCSection *getReadOnlySection() const { return ReadOnlySection; }
+ MCSection *getReadOnlyColdSection() const { return ReadOnlyColdSection; }
MCSection *getLSDASection() const { return LSDASection; }
MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
diff --git a/include/llvm/MC/MCObjectStreamer.h b/include/llvm/MC/MCObjectStreamer.h
index 8e9b4ac5632..50b8c9e305b 100644
--- a/include/llvm/MC/MCObjectStreamer.h
+++ b/include/llvm/MC/MCObjectStreamer.h
@@ -121,6 +121,8 @@ public:
unsigned MaxBytesToEmit = 0) override;
void EmitCodeAlignment(unsigned ByteAlignment,
unsigned MaxBytesToEmit = 0) override;
+ void EmitNeverAlignCodeAtEnd(unsigned ByteAlignment, int64_t Value = 0,
+ unsigned ValueSize = 1) override;
void emitValueToOffset(const MCExpr *Offset, unsigned char Value,
SMLoc Loc) override;
void
@@ -134,6 +136,9 @@ public:
void EmitDwarfAdvanceLineAddr(int64_t LineDelta, const MCSymbol *LastLabel,
const MCSymbol *Label,
unsigned PointerSize);
+ void EmitDwarfAdvanceLineAddr(int64_t LineDelta, uint64_t Address,
+ uint64_t AddressDelta,
+ unsigned PointerSize);
void EmitDwarfAdvanceFrameAddr(const MCSymbol *LastLabel,
const MCSymbol *Label);
void EmitCVLocDirective(unsigned FunctionId, unsigned FileNo, unsigned Line,
diff --git a/include/llvm/MC/MCStreamer.h b/include/llvm/MC/MCStreamer.h
index 582a836023b..f1e341bd624 100644
--- a/include/llvm/MC/MCStreamer.h
+++ b/include/llvm/MC/MCStreamer.h
@@ -199,7 +199,7 @@ class MCStreamer {
/// \brief Tracks an index to represent the order a symbol was emitted in.
/// Zero means we did not emit that symbol.
- DenseMap<const MCSymbol *, unsigned> SymbolOrdering;
+ unsigned SymbolOrdering = 1;
/// \brief This is stack of current and previous section values saved by
/// PushSection.
@@ -338,9 +338,7 @@ public:
/// \brief Returns an index to represent the order a symbol was emitted in.
/// (zero if we did not emit that symbol)
- unsigned GetSymbolOrder(const MCSymbol *Sym) const {
- return SymbolOrdering.lookup(Sym);
- }
+ unsigned GetSymbolOrder(const MCSymbol *Sym) const;