llvm.org GIT mirror llvm / d269a6e
make MachineModuleInfoMachO hold non-const MCSymbol*'s instead of const ones. non-const ones aren't very useful, because you can't even, say, emit them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95205 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
7 changed file(s) with 32 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
2424 class MachineModuleInfoMachO : public MachineModuleInfoImpl {
2525 /// FnStubs - Darwin '$stub' stubs. The key is something like "Lfoo$stub",
2626 /// the value is something like "_foo".
27 DenseMap<const MCSymbol*, const MCSymbol*> FnStubs;
27 DenseMap<MCSymbol*, MCSymbol*> FnStubs;
2828
2929 /// GVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like
3030 /// "Lfoo$non_lazy_ptr", the value is something like "_foo".
31 DenseMap<const MCSymbol*, const MCSymbol*> GVStubs;
31 DenseMap<MCSymbol*, MCSymbol*> GVStubs;
3232
3333 /// HiddenGVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like
3434 /// "Lfoo$non_lazy_ptr", the value is something like "_foo". Unlike GVStubs
3535 /// these are for things with hidden visibility.
36 DenseMap<const MCSymbol*, const MCSymbol*> HiddenGVStubs;
36 DenseMap<MCSymbol*, MCSymbol*> HiddenGVStubs;
3737
3838 virtual void Anchor(); // Out of line virtual method.
3939 public:
4040 MachineModuleInfoMachO(const MachineModuleInfo &) {}
4141
42 const MCSymbol *&getFnStubEntry(const MCSymbol *Sym) {
42 MCSymbol *&getFnStubEntry(MCSymbol *Sym) {
4343 assert(Sym && "Key cannot be null");
4444 return FnStubs[Sym];
4545 }
4646
47 const MCSymbol *&getGVStubEntry(const MCSymbol *Sym) {
47 MCSymbol *&getGVStubEntry(MCSymbol *Sym) {
4848 assert(Sym && "Key cannot be null");
4949 return GVStubs[Sym];
5050 }
5151
52 const MCSymbol *&getHiddenGVStubEntry(const MCSymbol *Sym) {
52 MCSymbol *&getHiddenGVStubEntry(MCSymbol *Sym) {
5353 assert(Sym && "Key cannot be null");
5454 return HiddenGVStubs[Sym];
5555 }
5656
5757 /// Accessor methods to return the set of stubs in sorted order.
58 typedef std::vector >
59 SymbolListTy;
58 typedef std::vector > SymbolListTy;
6059
6160 SymbolListTy GetFnStubList() const {
6261 return GetSortedStubs(FnStubs);
7069
7170 private:
7271 static SymbolListTy
73 GetSortedStubs(const DenseMap<const MCSymbol*, const MCSymbol*> &Map);
72 GetSortedStubs(const DenseMap<MCSymbol*, MCSymbol*> &Map);
7473 };
7574
7675 } // end namespace llvm
2525
2626 static int SortSymbolPair(const void *LHS, const void *RHS) {
2727 const MCSymbol *LHSS =
28 ((const std::pair<const MCSymbol*, const MCSymbol*>*)LHS)->first;
28 ((const std::pair<MCSymbol*, MCSymbol*>*)LHS)->first;
2929 const MCSymbol *RHSS =
30 ((const std::pair<const MCSymbol*, const MCSymbol*>*)RHS)->first;
30 ((const std::pair<MCSymbol*, MCSymbol*>*)RHS)->first;
3131 return LHSS->getName().compare(RHSS->getName());
3232 }
3333
3434 /// GetSortedStubs - Return the entries from a DenseMap in a deterministic
3535 /// sorted orer.
3636 MachineModuleInfoMachO::SymbolListTy
37 MachineModuleInfoMachO::GetSortedStubs(const DenseMap
38 const MCSymbol*> &Map) {
37 MachineModuleInfoMachO::GetSortedStubs(const DenseMap
38 MCSymbol*> &Map) {
3939 MachineModuleInfoMachO::SymbolListTy List(Map.begin(), Map.end());
4040 if (!List.empty())
4141 qsort(&List[0], List.size(), sizeof(List[0]), SortSymbolPair);
199199
200200 MachineModuleInfoMachO &MMIMachO =
201201 MMI->getObjFileInfo();
202 const MCSymbol *&StubSym =
202 MCSymbol *&StubSym =
203203 GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) :
204204 MMIMachO.getGVStubEntry(Sym);
205205 if (StubSym == 0)
197197 if (GV->isDeclaration() || GV->isWeakForLinker()) {
198198 // Dynamically-resolved functions need a stub for the function.
199199 MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
200 const MCSymbol *&StubSym =
200 MCSymbol *&StubSym =
201201 MMI->getObjFileInfo().getFnStubEntry(Sym);
202202 if (StubSym == 0)
203203 StubSym = GetGlobalValueSymbol(GV);
210210 TempNameStr += StringRef(MO.getSymbolName());
211211 TempNameStr += StringRef("$stub");
212212
213 const MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
214 const MCSymbol *&StubSym =
213 MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
214 MCSymbol *&StubSym =
215215 MMI->getObjFileInfo().getFnStubEntry(Sym);
216216 if (StubSym == 0)
217217 StubSym = GetExternalSymbolSymbol(MO.getSymbolName());
400400 return;
401401 }
402402
403 const MCSymbol *NLPSym =
403 MCSymbol *NLPSym =
404404 OutContext.GetOrCreateSymbol(StringRef(MAI->getGlobalPrefix())+
405405 MO.getSymbolName()+"$non_lazy_ptr");
406 const MCSymbol *&StubSym =
406 MCSymbol *&StubSym =
407407 MMI->getObjFileInfo().getGVStubEntry(NLPSym);
408408 if (StubSym == 0)
409409 StubSym = GetExternalSymbolSymbol(MO.getSymbolName());
421421 (GV->isDeclaration() || GV->isWeakForLinker())) {
422422 if (!GV->hasHiddenVisibility()) {
423423 SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
424 const MCSymbol *&StubSym =
424 MCSymbol *&StubSym =
425425 MMI->getObjFileInfo().getGVStubEntry(SymToPrint);
426426 if (StubSym == 0)
427427 StubSym = GetGlobalValueSymbol(GV);
429429 GV->hasAvailableExternallyLinkage()) {
430430 SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
431431
432 const MCSymbol *&StubSym =
432 MCSymbol *&StubSym =
433433 MMI->getObjFileInfo().
434434 getHiddenGVStubEntry(SymToPrint);
435435 if (StubSym == 0)
779779 for (std::vector::const_iterator I = Personalities.begin(),
780780 E = Personalities.end(); I != E; ++I) {
781781 if (*I) {
782 const MCSymbol *NLPSym =
783 GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr");
784 const MCSymbol *&StubSym = MMIMacho.getGVStubEntry(NLPSym);
782 MCSymbol *NLPSym = GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr");
783 MCSymbol *&StubSym = MMIMacho.getGVStubEntry(NLPSym);
785784 StubSym = GetGlobalValueSymbol(*I);
786785 }
787786 }
131131 MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
132132 MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
133133
134 const MCSymbol *&StubSym =
134 MCSymbol *&StubSym =
135135 MMI->getObjFileInfo().getGVStubEntry(Sym);
136136 if (StubSym == 0)
137137 StubSym = GetGlobalValueSymbol(GV);
138138
139139 } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){
140140 MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
141 const MCSymbol *&StubSym =
141 MCSymbol *&StubSym =
142142 MMI->getObjFileInfo().getHiddenGVStubEntry(Sym);
143143 if (StubSym == 0)
144144 StubSym = GetGlobalValueSymbol(GV);
145145 } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
146146 MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
147 const MCSymbol *&StubSym =
147 MCSymbol *&StubSym =
148148 MMI->getObjFileInfo().getFnStubEntry(Sym);
149149 if (StubSym == 0)
150150 StubSym = GetGlobalValueSymbol(GV);
166166 TempNameStr += StringRef(MO.getSymbolName());
167167 TempNameStr += StringRef("$stub");
168168
169 const MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
170 const MCSymbol *&StubSym =
169 MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
170 MCSymbol *&StubSym =
171171 MMI->getObjFileInfo().getFnStubEntry(Sym);
172172 if (StubSym == 0) {
173173 TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end());
8181 Name += "$non_lazy_ptr";
8282 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
8383
84 const MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym);
84 MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym);
8585 if (StubSym == 0)
8686 StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
8787 return Sym;
8989 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: {
9090 Name += "$non_lazy_ptr";
9191 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
92 const MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym);
92 MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym);
9393 if (StubSym == 0)
9494 StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
9595 return Sym;
9797 case X86II::MO_DARWIN_STUB: {
9898 Name += "$stub";
9999 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
100 const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
100 MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
101101 if (StubSym == 0)
102102 StubSym = AsmPrinter.GetGlobalValueSymbol(GV);
103103 return Sym;
138138 case X86II::MO_DARWIN_STUB: {
139139 Name += "$stub";
140140 MCSymbol *Sym = Ctx.GetOrCreateSymbol(Name.str());
141 const MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
141 MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym);
142142
143143 if (StubSym == 0) {
144144 Name.erase(Name.end()-5, Name.end());
3434 // Add information about the stub reference to MachOMMI so that the stub gets
3535 // emitted by the asmprinter.
3636 MCSymbol *Sym = getContext().GetOrCreateSymbol(Name.str());
37 const MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym);
37 MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym);
3838 if (StubSym == 0) {
3939 Name.clear();
4040 Mang->getNameWithPrefix(Name, GV, false);