Add a bit along with the MCSymbols stored in the MachineModuleInfo maps that

indicates that an MCSymbol is external or not. (It's true if it's external.)
This will be used to specify the correct information to add to non-lazy
pointers. That will be explained further when this bit is used.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Bill Wendling 2010-03-10 22:34:10 +00:00
parent bfdf7f3852
commit cebae36f57
8 changed files with 140 additions and 98 deletions

View File

@ -31,48 +31,46 @@
#ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H #ifndef LLVM_CODEGEN_MACHINEMODULEINFO_H
#define LLVM_CODEGEN_MACHINEMODULEINFO_H #define LLVM_CODEGEN_MACHINEMODULEINFO_H
#include "llvm/Support/Dwarf.h"
#include "llvm/System/DataTypes.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/UniqueVector.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/MachineLocation.h"
#include "llvm/GlobalValue.h" #include "llvm/GlobalValue.h"
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Metadata.h" #include "llvm/Metadata.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/UniqueVector.h"
#include "llvm/CodeGen/MachineLocation.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/ValueHandle.h" #include "llvm/Support/ValueHandle.h"
#include "llvm/System/DataTypes.h"
namespace llvm { namespace llvm {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Forward declarations. // Forward declarations.
class Constant; class Constant;
class GlobalVariable;
class MCSymbol; class MCSymbol;
class MDNode; class MDNode;
class GlobalVariable;
class MachineBasicBlock; class MachineBasicBlock;
class MachineFunction; class MachineFunction;
class Module; class Module;
class PointerType; class PointerType;
class StructType; class StructType;
/// MachineModuleInfoImpl - This class can be derived from and used by targets /// MachineModuleInfoImpl - This class can be derived from and used by targets
/// to hold private target-specific information for each Module. Objects of /// to hold private target-specific information for each Module. Objects of
/// type are accessed/created with MMI::getInfo and destroyed when the /// type are accessed/created with MMI::getInfo and destroyed when the
/// MachineModuleInfo is destroyed. /// MachineModuleInfo is destroyed.
class MachineModuleInfoImpl { class MachineModuleInfoImpl {
public: public:
typedef PointerIntPair<MCSymbol*, 1, bool> StubValueTy;
virtual ~MachineModuleInfoImpl(); virtual ~MachineModuleInfoImpl();
typedef std::vector<std::pair<MCSymbol*, StubValueTy> > SymbolListTy;
typedef std::vector<std::pair<MCSymbol*, MCSymbol*> >
SymbolListTy;
protected: protected:
static SymbolListTy static SymbolListTy GetSortedStubs(const DenseMap<MCSymbol*, StubValueTy>&);
GetSortedStubs(const DenseMap<MCSymbol*, MCSymbol*> &Map);
}; };

View File

@ -25,32 +25,34 @@ namespace llvm {
class MachineModuleInfoMachO : public MachineModuleInfoImpl { class MachineModuleInfoMachO : public MachineModuleInfoImpl {
/// FnStubs - Darwin '$stub' stubs. The key is something like "Lfoo$stub", /// FnStubs - Darwin '$stub' stubs. The key is something like "Lfoo$stub",
/// the value is something like "_foo". /// the value is something like "_foo".
DenseMap<MCSymbol*, MCSymbol*> FnStubs; DenseMap<MCSymbol*, StubValueTy> FnStubs;
/// GVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like /// GVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like
/// "Lfoo$non_lazy_ptr", the value is something like "_foo". /// "Lfoo$non_lazy_ptr", the value is something like "_foo". The extra bit
DenseMap<MCSymbol*, MCSymbol*> GVStubs; /// is true if this GV is external.
DenseMap<MCSymbol*, StubValueTy> GVStubs;
/// HiddenGVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like /// HiddenGVStubs - Darwin '$non_lazy_ptr' stubs. The key is something like
/// "Lfoo$non_lazy_ptr", the value is something like "_foo". Unlike GVStubs /// "Lfoo$non_lazy_ptr", the value is something like "_foo". Unlike GVStubs
/// these are for things with hidden visibility. /// these are for things with hidden visibility. The extra bit is true if
DenseMap<MCSymbol*, MCSymbol*> HiddenGVStubs; /// this GV is external.
DenseMap<MCSymbol*, StubValueTy> HiddenGVStubs;
virtual void Anchor(); // Out of line virtual method. virtual void Anchor(); // Out of line virtual method.
public: public:
MachineModuleInfoMachO(const MachineModuleInfo &) {} MachineModuleInfoMachO(const MachineModuleInfo &) {}
MCSymbol *&getFnStubEntry(MCSymbol *Sym) { StubValueTy &getFnStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return FnStubs[Sym]; return FnStubs[Sym];
} }
MCSymbol *&getGVStubEntry(MCSymbol *Sym) { StubValueTy &getGVStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return GVStubs[Sym]; return GVStubs[Sym];
} }
MCSymbol *&getHiddenGVStubEntry(MCSymbol *Sym) { StubValueTy &getHiddenGVStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return HiddenGVStubs[Sym]; return HiddenGVStubs[Sym];
} }
@ -72,13 +74,13 @@ namespace llvm {
class MachineModuleInfoELF : public MachineModuleInfoImpl { class MachineModuleInfoELF : public MachineModuleInfoImpl {
/// GVStubs - These stubs are used to materialize global addresses in PIC /// GVStubs - These stubs are used to materialize global addresses in PIC
/// mode. /// mode.
DenseMap<MCSymbol*, MCSymbol*> GVStubs; DenseMap<MCSymbol*, StubValueTy> GVStubs;
virtual void Anchor(); // Out of line virtual method. virtual void Anchor(); // Out of line virtual method.
public: public:
MachineModuleInfoELF(const MachineModuleInfo &) {} MachineModuleInfoELF(const MachineModuleInfo &) {}
MCSymbol *&getGVStubEntry(MCSymbol *Sym) { StubValueTy &getGVStubEntry(MCSymbol *Sym) {
assert(Sym && "Key cannot be null"); assert(Sym && "Key cannot be null");
return GVStubs[Sym]; return GVStubs[Sym];
} }

View File

@ -25,10 +25,9 @@ void MachineModuleInfoMachO::Anchor() {}
void MachineModuleInfoELF::Anchor() {} void MachineModuleInfoELF::Anchor() {}
static int SortSymbolPair(const void *LHS, const void *RHS) { static int SortSymbolPair(const void *LHS, const void *RHS) {
const MCSymbol *LHSS = typedef std::pair<MCSymbol*, MachineModuleInfoImpl::StubValueTy> PairTy;
((const std::pair<MCSymbol*, MCSymbol*>*)LHS)->first; const MCSymbol *LHSS = ((const PairTy *)LHS)->first;
const MCSymbol *RHSS = const MCSymbol *RHSS = ((const PairTy *)RHS)->first;
((const std::pair<MCSymbol*, MCSymbol*>*)RHS)->first;
return LHSS->getName().compare(RHSS->getName()); return LHSS->getName().compare(RHSS->getName());
} }
@ -36,7 +35,7 @@ static int SortSymbolPair(const void *LHS, const void *RHS) {
/// sorted orer. /// sorted orer.
MachineModuleInfoImpl::SymbolListTy MachineModuleInfoImpl::SymbolListTy
MachineModuleInfoImpl::GetSortedStubs(const DenseMap<MCSymbol*, MachineModuleInfoImpl::GetSortedStubs(const DenseMap<MCSymbol*,
MCSymbol*> &Map) { MachineModuleInfoImpl::StubValueTy>&Map) {
MachineModuleInfoImpl::SymbolListTy List(Map.begin(), Map.end()); MachineModuleInfoImpl::SymbolListTy List(Map.begin(), Map.end());
if (!List.empty()) if (!List.empty())

View File

@ -404,14 +404,19 @@ getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
// Add information about the stub reference to ELFMMI so that the stub // Add information about the stub reference to ELFMMI so that the stub
// gets emitted by the asmprinter. // gets emitted by the asmprinter.
MCSymbol *Sym = getContext().GetOrCreateTemporarySymbol(Name.str()); MCSymbol *Sym = getContext().GetOrCreateTemporarySymbol(Name.str());
MCSymbol *&StubSym = ELFMMI.getGVStubEntry(Sym); MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(Sym);
if (StubSym == 0) { if (StubSym.getPointer() == 0) {
Name.clear(); Name.clear();
Mang->getNameWithPrefix(Name, GV, false); Mang->getNameWithPrefix(Name, GV, false);
if (GV->hasPrivateLinkage()) if (GV->hasPrivateLinkage())
StubSym = getContext().GetOrCreateTemporarySymbol(Name.str()); StubSym = MachineModuleInfoImpl::
StubValueTy(getContext().GetOrCreateTemporarySymbol(Name.str()),
false);
else else
StubSym = getContext().GetOrCreateSymbol(Name.str()); StubSym = MachineModuleInfoImpl::
StubValueTy(getContext().GetOrCreateSymbol(Name.str()),
!GV->hasInternalLinkage());
} }
return TargetLoweringObjectFile:: return TargetLoweringObjectFile::
@ -761,14 +766,19 @@ getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
// Add information about the stub reference to MachOMMI so that the stub // Add information about the stub reference to MachOMMI so that the stub
// gets emitted by the asmprinter. // gets emitted by the asmprinter.
MCSymbol *Sym = getContext().GetOrCreateTemporarySymbol(Name.str()); MCSymbol *Sym = getContext().GetOrCreateTemporarySymbol(Name.str());
MCSymbol *&StubSym = MachOMMI.getGVStubEntry(Sym); MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(Sym);
if (StubSym == 0) { if (StubSym.getPointer() == 0) {
Name.clear(); Name.clear();
Mang->getNameWithPrefix(Name, GV, false); Mang->getNameWithPrefix(Name, GV, false);
if (GV->hasPrivateLinkage()) if (GV->hasPrivateLinkage())
StubSym = getContext().GetOrCreateTemporarySymbol(Name.str()); StubSym = MachineModuleInfoImpl::
StubValueTy(getContext().GetOrCreateTemporarySymbol(Name.str()),
false);
else else
StubSym = getContext().GetOrCreateSymbol(Name.str()); StubSym = MachineModuleInfoImpl::
StubValueTy(getContext().GetOrCreateSymbol(Name.str()),
!GV->hasInternalLinkage());
} }
return TargetLoweringObjectFile:: return TargetLoweringObjectFile::

View File

@ -205,11 +205,12 @@ namespace {
MachineModuleInfoMachO &MMIMachO = MachineModuleInfoMachO &MMIMachO =
MMI->getObjFileInfo<MachineModuleInfoMachO>(); MMI->getObjFileInfo<MachineModuleInfoMachO>();
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) : GV->hasHiddenVisibility() ? MMIMachO.getHiddenGVStubEntry(Sym) :
MMIMachO.getGVStubEntry(Sym); MMIMachO.getGVStubEntry(Sym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV), !GV->hasInternalLinkage());
} }
} else { } else {
assert(ACPV->isExtSymbol() && "unrecognized constant pool value"); assert(ACPV->isExtSymbol() && "unrecognized constant pool value");
@ -1135,7 +1136,7 @@ void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
// L_foo$stub: // L_foo$stub:
OutStreamer.EmitLabel(Stubs[i].first); OutStreamer.EmitLabel(Stubs[i].first);
// .indirect_symbol _foo // .indirect_symbol _foo
MCSymbol *MCSym = Stubs[i].second; MCSymbol *MCSym = Stubs[i].second.getPointer();
OutStreamer.EmitSymbolAttribute(MCSym, MCSA_IndirectSymbol); OutStreamer.EmitSymbolAttribute(MCSym, MCSA_IndirectSymbol);
if (MCSym->isUndefined()) if (MCSym->isUndefined())
@ -1159,8 +1160,9 @@ void ARMAsmPrinter::EmitEndOfAsmFile(Module &M) {
// L_foo$stub: // L_foo$stub:
OutStreamer.EmitLabel(Stubs[i].first); OutStreamer.EmitLabel(Stubs[i].first);
// .long _foo // .long _foo
OutStreamer.EmitValue(MCSymbolRefExpr::Create(Stubs[i].second, OutStreamer.EmitValue(MCSymbolRefExpr::
OutContext), Create(Stubs[i].second.getPointer(),
OutContext),
4/*size*/, 0/*addrspace*/); 4/*size*/, 0/*addrspace*/);
} }

View File

@ -198,10 +198,11 @@ namespace {
if (GV->isDeclaration() || GV->isWeakForLinker()) { if (GV->isDeclaration() || GV->isWeakForLinker()) {
// Dynamically-resolved functions need a stub for the function. // Dynamically-resolved functions need a stub for the function.
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV),!GV->hasInternalLinkage());
O << *Sym; O << *Sym;
return; return;
} }
@ -212,10 +213,11 @@ namespace {
TempNameStr += StringRef("$stub"); TempNameStr += StringRef("$stub");
MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str()); MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetExternalSymbolSymbol(MO.getSymbolName()); StubSym = MachineModuleInfoImpl::
StubValueTy(GetExternalSymbolSymbol(MO.getSymbolName()), true);
O << *Sym; O << *Sym;
return; return;
} }
@ -404,10 +406,11 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
MCSymbol *NLPSym = MCSymbol *NLPSym =
OutContext.GetOrCreateSymbol(StringRef(MAI->getGlobalPrefix())+ OutContext.GetOrCreateSymbol(StringRef(MAI->getGlobalPrefix())+
MO.getSymbolName()+"$non_lazy_ptr"); MO.getSymbolName()+"$non_lazy_ptr");
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(NLPSym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(NLPSym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetExternalSymbolSymbol(MO.getSymbolName()); StubSym = MachineModuleInfoImpl::
StubValueTy(GetExternalSymbolSymbol(MO.getSymbolName()), true);
O << *NLPSym; O << *NLPSym;
return; return;
@ -422,19 +425,23 @@ void PPCAsmPrinter::printOp(const MachineOperand &MO) {
(GV->isDeclaration() || GV->isWeakForLinker())) { (GV->isDeclaration() || GV->isWeakForLinker())) {
if (!GV->hasHiddenVisibility()) { if (!GV->hasHiddenVisibility()) {
SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(SymToPrint); MMI->getObjFileInfo<MachineModuleInfoMachO>()
if (StubSym == 0) .getGVStubEntry(SymToPrint);
StubSym = GetGlobalValueSymbol(GV); if (StubSym.getPointer() == 0)
StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV), !GV->hasInternalLinkage());
} else if (GV->isDeclaration() || GV->hasCommonLinkage() || } else if (GV->isDeclaration() || GV->hasCommonLinkage() ||
GV->hasAvailableExternallyLinkage()) { GV->hasAvailableExternallyLinkage()) {
SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); SymToPrint = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>(). MMI->getObjFileInfo<MachineModuleInfoMachO>().
getHiddenGVStubEntry(SymToPrint); getHiddenGVStubEntry(SymToPrint);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV),
!GV->hasInternalLinkage());
} else { } else {
SymToPrint = GetGlobalValueSymbol(GV); SymToPrint = GetGlobalValueSymbol(GV);
} }
@ -704,7 +711,7 @@ EmitFunctionStubs(const MachineModuleInfoMachO::SymbolListTy &Stubs) {
EmitAlignment(4); EmitAlignment(4);
const MCSymbol *Stub = Stubs[i].first; const MCSymbol *Stub = Stubs[i].first;
const MCSymbol *RawSym = Stubs[i].second; const MCSymbol *RawSym = Stubs[i].second.getPointer();
const MCSymbol *LazyPtr = GetLazyPtr(Stub, OutContext); const MCSymbol *LazyPtr = GetLazyPtr(Stub, OutContext);
const MCSymbol *AnonSymbol = GetAnonSym(Stub, OutContext); const MCSymbol *AnonSymbol = GetAnonSym(Stub, OutContext);
@ -738,7 +745,7 @@ EmitFunctionStubs(const MachineModuleInfoMachO::SymbolListTy &Stubs) {
16, SectionKind::getText()); 16, SectionKind::getText());
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
const MCSymbol *Stub = Stubs[i].first; const MCSymbol *Stub = Stubs[i].first;
const MCSymbol *RawSym = Stubs[i].second; const MCSymbol *RawSym = Stubs[i].second.getPointer();
const MCSymbol *LazyPtr = GetLazyPtr(Stub, OutContext); const MCSymbol *LazyPtr = GetLazyPtr(Stub, OutContext);
OutStreamer.SwitchSection(StubSection); OutStreamer.SwitchSection(StubSection);
@ -781,8 +788,10 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
E = Personalities.end(); I != E; ++I) { E = Personalities.end(); I != E; ++I) {
if (*I) { if (*I) {
MCSymbol *NLPSym = GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr"); MCSymbol *NLPSym = GetSymbolWithGlobalValueBase(*I, "$non_lazy_ptr");
MCSymbol *&StubSym = MMIMacho.getGVStubEntry(NLPSym); MachineModuleInfoImpl::StubValueTy &StubSym =
StubSym = GetGlobalValueSymbol(*I); MMIMacho.getGVStubEntry(NLPSym);
StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(*I), true);
} }
} }
} }
@ -798,7 +807,8 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
O << *Stubs[i].first << ":\n"; O << *Stubs[i].first << ":\n";
O << "\t.indirect_symbol " << *Stubs[i].second << '\n'; O << "\t.indirect_symbol " << *Stubs[i].second.getPointer() << '\n';
// FIXME: This should use the "GV is external" bit.
O << (isPPC64 ? "\t.quad\t0\n" : "\t.long\t0\n"); O << (isPPC64 ? "\t.quad\t0\n" : "\t.long\t0\n");
} }
} }
@ -810,7 +820,8 @@ bool PPCDarwinAsmPrinter::doFinalization(Module &M) {
for (unsigned i = 0, e = Stubs.size(); i != e; ++i) { for (unsigned i = 0, e = Stubs.size(); i != e; ++i) {
O << *Stubs[i].first << ":\n"; O << *Stubs[i].first << ":\n";
O << (isPPC64 ? "\t.quad\t" : "\t.long\t") << *Stubs[i].second << '\n'; O << (isPPC64 ? "\t.quad\t" : "\t.long\t")
<< *Stubs[i].second.getPointer() << '\n';
} }
} }

View File

@ -133,24 +133,25 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) {
if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY || if (MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY ||
MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) { MO.getTargetFlags() == X86II::MO_DARWIN_NONLAZY_PIC_BASE) {
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
MachineModuleInfoImpl::StubValueTy &StubSym =
MCSymbol *&StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getGVStubEntry(Sym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV), !GV->hasInternalLinkage());
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){ } else if (MO.getTargetFlags() == X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE){
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$non_lazy_ptr");
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getHiddenGVStubEntry(Sym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV), !GV->hasInternalLinkage());
} else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) { } else if (MO.getTargetFlags() == X86II::MO_DARWIN_STUB) {
MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub"); MCSymbol *Sym = GetSymbolWithGlobalValueBase(GV, "$stub");
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) if (StubSym.getPointer() == 0)
StubSym = GetGlobalValueSymbol(GV); StubSym = MachineModuleInfoImpl::
StubValueTy(GetGlobalValueSymbol(GV), !GV->hasInternalLinkage());
} }
// If the name begins with a dollar-sign, enclose it in parens. We do this // If the name begins with a dollar-sign, enclose it in parens. We do this
@ -170,13 +171,15 @@ void X86AsmPrinter::printSymbolOperand(const MachineOperand &MO) {
TempNameStr += StringRef("$stub"); TempNameStr += StringRef("$stub");
MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str()); MCSymbol *Sym = GetExternalSymbolSymbol(TempNameStr.str());
MCSymbol *&StubSym = MachineModuleInfoImpl::StubValueTy &StubSym =
MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym); MMI->getObjFileInfo<MachineModuleInfoMachO>().getFnStubEntry(Sym);
if (StubSym == 0) { if (StubSym.getPointer() == 0) {
TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end()); TempNameStr.erase(TempNameStr.end()-5, TempNameStr.end());
StubSym = OutContext.GetOrCreateSymbol(TempNameStr.str()); StubSym = MachineModuleInfoImpl::
StubValueTy(OutContext.GetOrCreateSymbol(TempNameStr.str()),
true);
} }
SymToPrint = StubSym; SymToPrint = StubSym.getPointer();
} else { } else {
SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName()); SymToPrint = GetExternalSymbolSymbol(MO.getSymbolName());
} }
@ -507,7 +510,8 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
// L_foo$stub: // L_foo$stub:
OutStreamer.EmitLabel(Stubs[i].first); OutStreamer.EmitLabel(Stubs[i].first);
// .indirect_symbol _foo // .indirect_symbol _foo
OutStreamer.EmitSymbolAttribute(Stubs[i].second, MCSA_IndirectSymbol); OutStreamer.EmitSymbolAttribute(Stubs[i].second.getPointer(),
MCSA_IndirectSymbol);
// hlt; hlt; hlt; hlt; hlt hlt = 0xf4 = -12. // hlt; hlt; hlt; hlt; hlt hlt = 0xf4 = -12.
const char HltInsts[] = { -12, -12, -12, -12, -12 }; const char HltInsts[] = { -12, -12, -12, -12, -12 };
OutStreamer.EmitBytes(StringRef(HltInsts, 5), 0/*addrspace*/); OutStreamer.EmitBytes(StringRef(HltInsts, 5), 0/*addrspace*/);
@ -530,7 +534,8 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
// L_foo$non_lazy_ptr: // L_foo$non_lazy_ptr:
OutStreamer.EmitLabel(Stubs[i].first); OutStreamer.EmitLabel(Stubs[i].first);
// .indirect_symbol _foo // .indirect_symbol _foo
OutStreamer.EmitSymbolAttribute(Stubs[i].second, MCSA_IndirectSymbol); OutStreamer.EmitSymbolAttribute(Stubs[i].second.getPointer(),
MCSA_IndirectSymbol);
// .long 0 // .long 0
OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/); OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/);
} }
@ -547,8 +552,9 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
// L_foo$non_lazy_ptr: // L_foo$non_lazy_ptr:
OutStreamer.EmitLabel(Stubs[i].first); OutStreamer.EmitLabel(Stubs[i].first);
// .long _foo // .long _foo
OutStreamer.EmitValue(MCSymbolRefExpr::Create(Stubs[i].second, OutStreamer.EmitValue(MCSymbolRefExpr::
OutContext), Create(Stubs[i].second.getPointer(),
OutContext),
4/*size*/, 0/*addrspace*/); 4/*size*/, 0/*addrspace*/);
} }
Stubs.clear(); Stubs.clear();
@ -624,7 +630,7 @@ void X86AsmPrinter::EmitEndOfAsmFile(Module &M) {
O << *Stubs[i].first << ":\n" O << *Stubs[i].first << ":\n"
<< (TD->getPointerSize() == 8 ? << (TD->getPointerSize() == 8 ?
MAI->getData64bitsDirective() : MAI->getData32bitsDirective()) MAI->getData64bitsDirective() : MAI->getData32bitsDirective())
<< *Stubs[i].second << '\n'; << *Stubs[i].second.getPointer() << '\n';
Stubs.clear(); Stubs.clear();
} }

View File

@ -91,35 +91,49 @@ GetSymbolFromOperand(const MachineOperand &MO) const {
Name += "$non_lazy_ptr"; Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateTemporarySymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateTemporarySymbol(Name.str());
MCSymbol *&StubSym = getMachOMMI().getGVStubEntry(Sym); MachineModuleInfoImpl::StubValueTy &StubSym =
if (StubSym == 0) { getMachOMMI().getGVStubEntry(Sym);
if (StubSym.getPointer() == 0) {
assert(MO.isGlobal() && "Extern symbol not handled yet"); assert(MO.isGlobal() && "Extern symbol not handled yet");
StubSym = AsmPrinter.GetGlobalValueSymbol(MO.getGlobal()); StubSym =
MachineModuleInfoImpl::
StubValueTy(AsmPrinter.GetGlobalValueSymbol(MO.getGlobal()),
!MO.getGlobal()->hasInternalLinkage());
} }
return Sym; return Sym;
} }
case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: { case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: {
Name += "$non_lazy_ptr"; Name += "$non_lazy_ptr";
MCSymbol *Sym = Ctx.GetOrCreateTemporarySymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateTemporarySymbol(Name.str());
MCSymbol *&StubSym = getMachOMMI().getHiddenGVStubEntry(Sym); MachineModuleInfoImpl::StubValueTy &StubSym =
if (StubSym == 0) { getMachOMMI().getHiddenGVStubEntry(Sym);
if (StubSym.getPointer() == 0) {
assert(MO.isGlobal() && "Extern symbol not handled yet"); assert(MO.isGlobal() && "Extern symbol not handled yet");
StubSym = AsmPrinter.GetGlobalValueSymbol(MO.getGlobal()); StubSym =
MachineModuleInfoImpl::
StubValueTy(AsmPrinter.GetGlobalValueSymbol(MO.getGlobal()),
!MO.getGlobal()->hasInternalLinkage());
} }
return Sym; return Sym;
} }
case X86II::MO_DARWIN_STUB: { case X86II::MO_DARWIN_STUB: {
Name += "$stub"; Name += "$stub";
MCSymbol *Sym = Ctx.GetOrCreateTemporarySymbol(Name.str()); MCSymbol *Sym = Ctx.GetOrCreateTemporarySymbol(Name.str());
MCSymbol *&StubSym = getMachOMMI().getFnStubEntry(Sym); MachineModuleInfoImpl::StubValueTy &StubSym =
if (StubSym) getMachOMMI().getFnStubEntry(Sym);
if (StubSym.getPointer())
return Sym; return Sym;
if (MO.isGlobal()) { if (MO.isGlobal()) {
StubSym = AsmPrinter.GetGlobalValueSymbol(MO.getGlobal()); StubSym =
MachineModuleInfoImpl::
StubValueTy(AsmPrinter.GetGlobalValueSymbol(MO.getGlobal()),
!MO.getGlobal()->hasInternalLinkage());
} else { } else {
Name.erase(Name.end()-5, Name.end()); Name.erase(Name.end()-5, Name.end());
StubSym = Ctx.GetOrCreateTemporarySymbol(Name.str()); StubSym =
MachineModuleInfoImpl::
StubValueTy(Ctx.GetOrCreateTemporarySymbol(Name.str()), false);
} }
return Sym; return Sym;
} }