llvm.org GIT mirror llvm / 4c553e0
Recommit r224935 with a fix for the ObjC++/AArch64 bug that that revision introduced. A test case for the bug was already committed in r225385. Patch by Rafael Espindola. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225534 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 5 years ago
15 changed file(s) with 83 addition(s) and 104 deletion(s). Raw diff Collapse all Expand all
8888 ArrayRef ModuleFlags,
8989 Mangler &Mang, const TargetMachine &TM) const override;
9090
91 bool isSectionAtomizableBySymbols(const MCSection &Section) const override;
92
9391 const MCSection *
9492 SelectSectionForGlobal(const GlobalValue *GV,
9593 SectionKind Kind, Mangler &Mang,
6464 /// all symbols (even temporaries) have symbol table entries.
6565 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
6666 return false;
67 }
68
69 /// isSectionAtomizable - Check whether the given section can be split into
70 /// atoms.
71 ///
72 /// \see MCAssembler::isSymbolLinkerVisible().
73 virtual bool isSectionAtomizable(const MCSection &Section) const {
74 return true;
7567 }
7668
7769 /// @name Target Fixup Interfaces
381381 return nullptr;
382382 }
383383
384 /// \brief True if the section is atomized using the symbols in it.
385 /// This is false if the section is not atomized at all (most ELF sections) or
386 /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
387 /// example).
388 virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
389
384390 virtual const MCExpr *getExprForPersonalitySymbol(const MCSymbol *Sym,
385391 unsigned Encoding,
386392 MCStreamer &Streamer) const;
1818
1919 namespace llvm {
2020 class MCAsmInfoDarwin : public MCAsmInfo {
21 virtual void anchor();
2221 public:
2322 explicit MCAsmInfoDarwin();
23 bool isSectionAtomizableBySymbols(const MCSection &Section) const override;
2424 };
2525 }
2626
150150 return nullptr;
151151 }
152152
153 /// \brief True if the section is atomized using the symbols in it.
154 /// This is false if the section is not atomized at all (most ELF sections) or
155 /// if it is atomized based on its contents (MachO' __TEXT,__cstring for
156 /// example).
157 virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
158
159153 protected:
160154 virtual const MCSection *
161155 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
572572 return S;
573573 }
574574
575 bool TargetLoweringObjectFileMachO::isSectionAtomizableBySymbols(
576 const MCSection &Section) const {
577 const MCSectionMachO &SMO = static_cast(Section);
578
579 // Sections holding 1 byte strings are atomized based on the data
580 // they contain.
581 // Sections holding 2 byte strings require symbols in order to be
582 // atomized.
583 // There is no dedicated section for 4 byte strings.
584 if (SMO.getKind().isMergeable1ByteCString())
585 return false;
586
587 if (SMO.getSegmentName() == "__TEXT" &&
588 SMO.getSectionName() == "__objc_classname" &&
589 SMO.getType() == MachO::S_CSTRING_LITERALS)
590 return false;
591
592 if (SMO.getSegmentName() == "__TEXT" &&
593 SMO.getSectionName() == "__objc_methname" &&
594 SMO.getType() == MachO::S_CSTRING_LITERALS)
595 return false;
596
597 if (SMO.getSegmentName() == "__TEXT" &&
598 SMO.getSectionName() == "__objc_methtype" &&
599 SMO.getType() == MachO::S_CSTRING_LITERALS)
600 return false;
601
602 if (SMO.getSegmentName() == "__DATA" &&
603 SMO.getSectionName() == "__cfstring")
604 return false;
605
606 // no_dead_strip sections are not atomized in practice.
607 if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP))
608 return false;
609
610 switch (SMO.getType()) {
611 default:
612 return true;
613
614 // These sections are atomized at the element boundaries without using
615 // symbols.
616 case MachO::S_4BYTE_LITERALS:
617 case MachO::S_8BYTE_LITERALS:
618 case MachO::S_16BYTE_LITERALS:
619 case MachO::S_LITERAL_POINTERS:
620 case MachO::S_NON_LAZY_SYMBOL_POINTERS:
621 case MachO::S_LAZY_SYMBOL_POINTERS:
622 case MachO::S_MOD_INIT_FUNC_POINTERS:
623 case MachO::S_MOD_TERM_FUNC_POINTERS:
624 case MachO::S_INTERPOSING:
625 return false;
626 }
627 }
628
629575 const MCSection *TargetLoweringObjectFileMachO::
630576 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
631577 Mangler &Mang, const TargetMachine &TM) const {
108108 MCAsmInfo::~MCAsmInfo() {
109109 }
110110
111 bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const {
112 return false;
113 }
114
111115 const MCExpr *
112116 MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym,
113117 unsigned Encoding,
1414 #include "llvm/MC/MCAsmInfoDarwin.h"
1515 #include "llvm/MC/MCContext.h"
1616 #include "llvm/MC/MCExpr.h"
17 #include "llvm/MC/MCSectionMachO.h"
1718 #include "llvm/MC/MCStreamer.h"
1819 using namespace llvm;
1920
20 void MCAsmInfoDarwin::anchor() { }
21 bool MCAsmInfoDarwin::isSectionAtomizableBySymbols(
22 const MCSection &Section) const {
23 const MCSectionMachO &SMO = static_cast(Section);
24
25 // Sections holding 1 byte strings are atomized based on the data they
26 // contain.
27 // Sections holding 2 byte strings require symbols in order to be atomized.
28 // There is no dedicated section for 4 byte strings.
29 if (SMO.getKind().isMergeable1ByteCString())
30 return false;
31
32 if (SMO.getSegmentName() == "__TEXT" &&
33 SMO.getSectionName() == "__objc_classname" &&
34 SMO.getType() == MachO::S_CSTRING_LITERALS)
35 return false;
36
37 if (SMO.getSegmentName() == "__TEXT" &&
38 SMO.getSectionName() == "__objc_methname" &&
39 SMO.getType() == MachO::S_CSTRING_LITERALS)
40 return false;
41
42 if (SMO.getSegmentName() == "__TEXT" &&
43 SMO.getSectionName() == "__objc_methtype" &&
44 SMO.getType() == MachO::S_CSTRING_LITERALS)
45 return false;
46
47 if (SMO.getSegmentName() == "__DATA" && SMO.getSectionName() == "__cfstring")
48 return false;
49
50 switch (SMO.getType()) {
51 default:
52 return true;
53
54 // These sections are atomized at the element boundaries without using
55 // symbols.
56 case MachO::S_4BYTE_LITERALS:
57 case MachO::S_8BYTE_LITERALS:
58 case MachO::S_16BYTE_LITERALS:
59 case MachO::S_LITERAL_POINTERS:
60 case MachO::S_NON_LAZY_SYMBOL_POINTERS:
61 case MachO::S_LAZY_SYMBOL_POINTERS:
62 case MachO::S_MOD_INIT_FUNC_POINTERS:
63 case MachO::S_MOD_TERM_FUNC_POINTERS:
64 case MachO::S_INTERPOSING:
65 return false;
66 }
67 }
2168
2269 MCAsmInfoDarwin::MCAsmInfoDarwin() {
2370 // Common settings for all Darwin targets.
1111 #include "llvm/ADT/StringExtras.h"
1212 #include "llvm/ADT/Twine.h"
1313 #include "llvm/MC/MCAsmBackend.h"
14 #include "llvm/MC/MCAsmInfo.h"
1415 #include "llvm/MC/MCAsmLayout.h"
1516 #include "llvm/MC/MCCodeEmitter.h"
1617 #include "llvm/MC/MCContext.h"
447448
448449 // Non-linker visible symbols in sections which can't be atomized have no
449450 // defining atom.
450 if (!getBackend().isSectionAtomizable(
451 SD->getFragment()->getParent()->getSection()))
451 if (!getContext().getAsmInfo()->isSectionAtomizableBySymbols(
452 SD->getFragment()->getParent()->getSection()))
452453 return nullptr;
453454
454455 // Otherwise, return the atom for the containing fragment.
2020 namespace llvm {
2121
2222 class ARMMCAsmInfoDarwin : public MCAsmInfoDarwin {
23 void anchor() override;
23 virtual void anchor();
24
2425 public:
2526 explicit ARMMCAsmInfoDarwin(StringRef TT);
2627 };
2020 class Triple;
2121
2222 class PPCMCAsmInfoDarwin : public MCAsmInfoDarwin {
23 void anchor() override;
23 virtual void anchor();
24
2425 public:
2526 explicit PPCMCAsmInfoDarwin(bool is64Bit, const Triple&);
2627 };
269269 return SelectSectionForGlobal(GV, Kind, Mang, TM);
270270 }
271271
272 bool TargetLoweringObjectFile::isSectionAtomizableBySymbols(
273 const MCSection &Section) const {
274 return false;
275 }
276
277
278272 /// getSectionForConstant - Given a mergable constant with the
279273 /// specified size and relocation information, return a section that it
280274 /// should be placed in.
2020 #include "llvm/MC/MCAsmInfo.h"
2121 #include "llvm/MC/MCCodeGenInfo.h"
2222 #include "llvm/MC/MCContext.h"
23 #include "llvm/MC/MCSectionMachO.h"
2324 #include "llvm/MC/MCTargetOptions.h"
2425 #include "llvm/MC/SectionKind.h"
2526 #include "llvm/Support/CommandLine.h"
168169 Options.DataSections = V;
169170 }
170171
172 static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
173 const MCSection &Section) {
174 if (!AsmInfo.isSectionAtomizableBySymbols(Section))
175 return true;
176
177 // If it is not dead stripped, it is safe to use private labels.
178 const MCSectionMachO &SMO = cast(Section);
179 if (SMO.hasAttribute(MachO::S_ATTR_NO_DEAD_STRIP))
180 return true;
181
182 return false;
183 }
184
171185 void TargetMachine::getNameWithPrefix(SmallVectorImpl &Name,
172186 const GlobalValue *GV, Mangler &Mang,
173187 bool MayAlwaysUsePrivate) const {
181195 const TargetLoweringObjectFile &TLOF =
182196 getSubtargetImpl()->getTargetLowering()->getObjFileLowering();
183197 const MCSection *TheSection = TLOF.SectionForGlobal(GV, GVKind, Mang, *this);
184 bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
198 bool CannotUsePrivateLabel = !canUsePrivateLabel(*AsmInfo, *TheSection);
185199 Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
186200 }
187201
789789 return SMO.getType() == MachO::S_CSTRING_LITERALS;
790790 }
791791
792 bool isSectionAtomizable(const MCSection &Section) const override {
793 const MCSectionMachO &SMO = static_cast(Section);
794 // Fixed sized data sections are uniqued, they cannot be diced into atoms.
795 switch (SMO.getType()) {
796 default:
797 return true;
798
799 case MachO::S_4BYTE_LITERALS:
800 case MachO::S_8BYTE_LITERALS:
801 case MachO::S_16BYTE_LITERALS:
802 case MachO::S_LITERAL_POINTERS:
803 case MachO::S_NON_LAZY_SYMBOL_POINTERS:
804 case MachO::S_LAZY_SYMBOL_POINTERS:
805 case MachO::S_MOD_INIT_FUNC_POINTERS:
806 case MachO::S_MOD_TERM_FUNC_POINTERS:
807 case MachO::S_INTERPOSING:
808 return false;
809 }
810 }
811
812792 /// \brief Generate the compact unwind encoding for the CFI instructions.
813793 uint32_t generateCompactUnwindEncoding(
814794 ArrayRef Instrs) const override {
2222 class Triple;
2323
2424 class X86MCAsmInfoDarwin : public MCAsmInfoDarwin {
25 void anchor() override;
25 virtual void anchor();
26
2627 public:
2728 explicit X86MCAsmInfoDarwin(const Triple &Triple);
2829 };