mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-14 15:28:20 +00:00
Add back r201608, r201622, r201624 and r201625
r201608 made llvm corretly handle private globals with MachO. r201622 fixed a bug in it and r201624 and r201625 were changes for using private linkage, assuming that llvm would do the right thing. They all got reverted because r201608 introduced a crash in LTO. This patch includes a fix for that. The issue was that TargetLoweringObjectFile now has to be initialized before we can mangle names of private globals. This is trivially true during the normal codegen pipeline (the asm printer does it), but LTO has to do it manually. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201700 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -915,7 +915,7 @@ void generateStringPrint(llvm::LLVMContext &context,
|
|||||||
new llvm::GlobalVariable(module,
|
new llvm::GlobalVariable(module,
|
||||||
stringConstant->getType(),
|
stringConstant->getType(),
|
||||||
true,
|
true,
|
||||||
llvm::GlobalValue::LinkerPrivateLinkage,
|
llvm::GlobalValue::PrivateLinkage,
|
||||||
stringConstant,
|
stringConstant,
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
@@ -959,7 +959,7 @@ void generateIntegerPrint(llvm::LLVMContext &context,
|
|||||||
new llvm::GlobalVariable(module,
|
new llvm::GlobalVariable(module,
|
||||||
stringConstant->getType(),
|
stringConstant->getType(),
|
||||||
true,
|
true,
|
||||||
llvm::GlobalValue::LinkerPrivateLinkage,
|
llvm::GlobalValue::PrivateLinkage,
|
||||||
stringConstant,
|
stringConstant,
|
||||||
"");
|
"");
|
||||||
}
|
}
|
||||||
|
@@ -161,6 +161,9 @@ namespace llvm {
|
|||||||
/// getCurrentSection() - Return the current section we are emitting to.
|
/// getCurrentSection() - Return the current section we are emitting to.
|
||||||
const MCSection *getCurrentSection() const;
|
const MCSection *getCurrentSection() const;
|
||||||
|
|
||||||
|
void getNameWithPrefix(SmallVectorImpl<char> &Name,
|
||||||
|
const GlobalValue *GV) const;
|
||||||
|
|
||||||
MCSymbol *getSymbol(const GlobalValue *GV) const;
|
MCSymbol *getSymbol(const GlobalValue *GV) const;
|
||||||
|
|
||||||
//===------------------------------------------------------------------===//
|
//===------------------------------------------------------------------===//
|
||||||
|
@@ -57,14 +57,15 @@ public:
|
|||||||
|
|
||||||
/// Return an MCExpr to use for a reference to the specified type info global
|
/// Return an MCExpr to use for a reference to the specified type info global
|
||||||
/// variable from exception handling information.
|
/// variable from exception handling information.
|
||||||
const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
const MCExpr *
|
||||||
unsigned Encoding, Mangler &Mang,
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
||||||
MachineModuleInfo *MMI,
|
Mangler &Mang, const TargetMachine &TM,
|
||||||
MCStreamer &Streamer) const
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
// The symbol that gets passed to .cfi_personality.
|
// The symbol that gets passed to .cfi_personality.
|
||||||
MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
||||||
|
const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI) const LLVM_OVERRIDE;
|
MachineModuleInfo *MMI) const LLVM_OVERRIDE;
|
||||||
|
|
||||||
void InitializeELF(bool UseInitArray_);
|
void InitializeELF(bool UseInitArray_);
|
||||||
@@ -90,6 +91,9 @@ public:
|
|||||||
Mangler &Mang, const TargetMachine &TM) const
|
Mangler &Mang, const TargetMachine &TM) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
|
bool isSectionAtomizableBySymbols(const MCSection &Section) const
|
||||||
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
|
const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
|
||||||
SectionKind Kind, Mangler &Mang,
|
SectionKind Kind, Mangler &Mang,
|
||||||
const TargetMachine &TM) const
|
const TargetMachine &TM) const
|
||||||
@@ -105,18 +109,19 @@ public:
|
|||||||
/// This hook allows targets to selectively decide not to emit the
|
/// This hook allows targets to selectively decide not to emit the
|
||||||
/// UsedDirective for some symbols in llvm.used.
|
/// UsedDirective for some symbols in llvm.used.
|
||||||
/// FIXME: REMOVE this (rdar://7071300)
|
/// FIXME: REMOVE this (rdar://7071300)
|
||||||
bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler &Mang) const
|
bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler &Mang,
|
||||||
LLVM_OVERRIDE;
|
TargetMachine &TM) const LLVM_OVERRIDE;
|
||||||
|
|
||||||
/// The mach-o version of this method defaults to returning a stub reference.
|
/// The mach-o version of this method defaults to returning a stub reference.
|
||||||
const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
const MCExpr *
|
||||||
unsigned Encoding, Mangler &Mang,
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
||||||
MachineModuleInfo *MMI,
|
Mangler &Mang, const TargetMachine &TM,
|
||||||
MCStreamer &Streamer) const
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
// The symbol that gets passed to .cfi_personality.
|
// The symbol that gets passed to .cfi_personality.
|
||||||
MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
||||||
|
const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI) const LLVM_OVERRIDE;
|
MachineModuleInfo *MMI) const LLVM_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -51,9 +51,10 @@ public:
|
|||||||
/// Print the appropriate prefix and the specified global variable's name.
|
/// Print the appropriate prefix and the specified global variable's name.
|
||||||
/// If the global variable doesn't have a name, this fills in a unique name
|
/// If the global variable doesn't have a name, this fills in a unique name
|
||||||
/// for the global.
|
/// for the global.
|
||||||
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV) const;
|
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
|
||||||
void getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
bool CannotUsePrivateLabel) const;
|
||||||
const GlobalValue *GV) const;
|
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
||||||
|
bool CannotUsePrivateLabel) const;
|
||||||
|
|
||||||
/// Print the appropriate prefix and the specified name as the global variable
|
/// Print the appropriate prefix and the specified name as the global variable
|
||||||
/// name. GVName must not be empty.
|
/// name. GVName must not be empty.
|
||||||
|
@@ -48,8 +48,10 @@ namespace llvm {
|
|||||||
class MachineFunction;
|
class MachineFunction;
|
||||||
class MachineInstr;
|
class MachineInstr;
|
||||||
class MachineJumpTableInfo;
|
class MachineJumpTableInfo;
|
||||||
|
class Mangler;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class MCExpr;
|
class MCExpr;
|
||||||
|
class MCSymbol;
|
||||||
template<typename T> class SmallVectorImpl;
|
template<typename T> class SmallVectorImpl;
|
||||||
class DataLayout;
|
class DataLayout;
|
||||||
class TargetRegisterClass;
|
class TargetRegisterClass;
|
||||||
@@ -1343,6 +1345,10 @@ public:
|
|||||||
return LibcallCallingConvs[Call];
|
return LibcallCallingConvs[Call];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getNameWithPrefix(SmallVectorImpl<char> &Name, const GlobalValue *GV,
|
||||||
|
Mangler &Mang, bool MayAlwaysUsePrivate = false) const;
|
||||||
|
MCSymbol *getSymbol(const GlobalValue *GV, Mangler &Mang) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const TargetMachine &TM;
|
const TargetMachine &TM;
|
||||||
const DataLayout *DL;
|
const DataLayout *DL;
|
||||||
|
@@ -71,8 +71,8 @@ public:
|
|||||||
/// This hook allows targets to selectively decide not to emit the
|
/// This hook allows targets to selectively decide not to emit the
|
||||||
/// UsedDirective for some symbols in llvm.used.
|
/// UsedDirective for some symbols in llvm.used.
|
||||||
/// FIXME: REMOVE this (rdar://7071300)
|
/// FIXME: REMOVE this (rdar://7071300)
|
||||||
virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
|
virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler &Mang,
|
||||||
Mangler &Mang) const {
|
TargetMachine &TM) const {
|
||||||
return GV != 0;
|
return GV != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,25 +117,22 @@ public:
|
|||||||
|
|
||||||
/// Return an MCExpr to use for a reference to the specified global variable
|
/// Return an MCExpr to use for a reference to the specified global variable
|
||||||
/// from exception handling information.
|
/// from exception handling information.
|
||||||
virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
virtual const MCExpr *
|
||||||
unsigned Encoding,
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
||||||
Mangler &Mang,
|
Mangler &Mang, const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI,
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const;
|
||||||
MCStreamer &Streamer) const;
|
|
||||||
|
|
||||||
/// Return the MCSymbol for the specified global value. This symbol is the
|
|
||||||
/// main label that is the address of the global
|
|
||||||
MCSymbol *getSymbol(const GlobalValue *GV, Mangler &M) const;
|
|
||||||
|
|
||||||
/// Return the MCSymbol for a private symbol with global value name as its
|
/// Return the MCSymbol for a private symbol with global value name as its
|
||||||
/// base, with the specified suffix.
|
/// base, with the specified suffix.
|
||||||
MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
|
MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
|
||||||
StringRef Suffix, Mangler &M) const;
|
StringRef Suffix, Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const;
|
||||||
|
|
||||||
// The symbol that gets passed to .cfi_personality.
|
// The symbol that gets passed to .cfi_personality.
|
||||||
virtual MCSymbol *
|
virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
|
||||||
getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
Mangler &Mang,
|
||||||
MachineModuleInfo *MMI) const;
|
const TargetMachine &TM,
|
||||||
|
MachineModuleInfo *MMI) const;
|
||||||
|
|
||||||
const MCExpr *
|
const MCExpr *
|
||||||
getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
|
getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
|
||||||
@@ -157,10 +154,17 @@ public:
|
|||||||
virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
|
virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
|
||||||
|
|
||||||
virtual const MCExpr *
|
virtual const MCExpr *
|
||||||
getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang) const {
|
getExecutableRelativeSymbol(const ConstantExpr *CE, Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// \brief True if the section is atomized using the symbols in it.
|
||||||
|
/// This is false if the section is not atomized at all (most ELF sections) or
|
||||||
|
/// if it is atomized based on its contents (MachO' __TEXT,__cstring for
|
||||||
|
/// example).
|
||||||
|
virtual bool isSectionAtomizableBySymbols(const MCSection &Section) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual const MCSection *
|
virtual const MCSection *
|
||||||
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||||
|
@@ -311,8 +311,13 @@ void AsmPrinter::EmitLinkage(const GlobalValue *GV, MCSymbol *GVSym) const {
|
|||||||
llvm_unreachable("Unknown linkage type!");
|
llvm_unreachable("Unknown linkage type!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AsmPrinter::getNameWithPrefix(SmallVectorImpl<char> &Name,
|
||||||
|
const GlobalValue *GV) const {
|
||||||
|
TM.getTargetLowering()->getNameWithPrefix(Name, GV, *Mang);
|
||||||
|
}
|
||||||
|
|
||||||
MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
|
MCSymbol *AsmPrinter::getSymbol(const GlobalValue *GV) const {
|
||||||
return getObjFileLowering().getSymbol(GV, *Mang);
|
return TM.getTargetLowering()->getSymbol(GV, *Mang);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// EmitGlobalVariable - Emit the specified global variable to the .s file.
|
/// EmitGlobalVariable - Emit the specified global variable to the .s file.
|
||||||
@@ -1369,7 +1374,7 @@ void AsmPrinter::EmitLLVMUsedList(const ConstantArray *InitList) {
|
|||||||
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
|
||||||
const GlobalValue *GV =
|
const GlobalValue *GV =
|
||||||
dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
|
dyn_cast<GlobalValue>(InitList->getOperand(i)->stripPointerCasts());
|
||||||
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, *Mang))
|
if (GV && getObjFileLowering().shouldEmitUsedDirectiveFor(GV, *Mang, TM))
|
||||||
OutStreamer.EmitSymbolAttribute(getSymbol(GV), MCSA_NoDeadStrip);
|
OutStreamer.EmitSymbolAttribute(getSymbol(GV), MCSA_NoDeadStrip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1574,7 +1579,8 @@ static const MCExpr *lowerConstant(const Constant *CV, AsmPrinter &AP) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (const MCExpr *RelocExpr =
|
if (const MCExpr *RelocExpr =
|
||||||
AP.getObjFileLowering().getExecutableRelativeSymbol(CE, *AP.Mang))
|
AP.getObjFileLowering().getExecutableRelativeSymbol(CE, *AP.Mang,
|
||||||
|
AP.TM))
|
||||||
return RelocExpr;
|
return RelocExpr;
|
||||||
|
|
||||||
switch (CE->getOpcode()) {
|
switch (CE->getOpcode()) {
|
||||||
@@ -2103,7 +2109,8 @@ MCSymbol *AsmPrinter::GetJTSetSymbol(unsigned UID, unsigned MBBID) const {
|
|||||||
|
|
||||||
MCSymbol *AsmPrinter::getSymbolWithGlobalValueBase(const GlobalValue *GV,
|
MCSymbol *AsmPrinter::getSymbolWithGlobalValueBase(const GlobalValue *GV,
|
||||||
StringRef Suffix) const {
|
StringRef Suffix) const {
|
||||||
return getObjFileLowering().getSymbolWithGlobalValueBase(GV, Suffix, *Mang);
|
return getObjFileLowering().getSymbolWithGlobalValueBase(GV, Suffix, *Mang,
|
||||||
|
TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// GetExternalSymbolSymbol - Return the MCSymbol for the specified
|
/// GetExternalSymbolSymbol - Return the MCSymbol for the specified
|
||||||
|
@@ -143,7 +143,7 @@ void AsmPrinter::EmitTTypeReference(const GlobalValue *GV,
|
|||||||
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
|
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
|
||||||
|
|
||||||
const MCExpr *Exp =
|
const MCExpr *Exp =
|
||||||
TLOF.getTTypeGlobalReference(GV, Encoding, *Mang, MMI, OutStreamer);
|
TLOF.getTTypeGlobalReference(GV, Encoding, *Mang, TM, MMI, OutStreamer);
|
||||||
OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding));
|
OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding));
|
||||||
} else
|
} else
|
||||||
OutStreamer.EmitIntValue(0, GetSizeOfEncodedValue(Encoding));
|
OutStreamer.EmitIntValue(0, GetSizeOfEncodedValue(Encoding));
|
||||||
|
@@ -119,7 +119,8 @@ void DwarfCFIException::beginFunction(const MachineFunction *MF) {
|
|||||||
if (!shouldEmitPersonality)
|
if (!shouldEmitPersonality)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const MCSymbol *Sym = TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, MMI);
|
const MCSymbol *Sym =
|
||||||
|
TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, Asm->TM, MMI);
|
||||||
Asm->OutStreamer.EmitCFIPersonality(Sym, PerEncoding);
|
Asm->OutStreamer.EmitCFIPersonality(Sym, PerEncoding);
|
||||||
|
|
||||||
Asm->OutStreamer.EmitDebugLabel
|
Asm->OutStreamer.EmitDebugLabel
|
||||||
|
@@ -101,7 +101,8 @@ void Win64Exception::endFunction(const MachineFunction *) {
|
|||||||
if (shouldEmitPersonality) {
|
if (shouldEmitPersonality) {
|
||||||
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
|
||||||
const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()];
|
const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()];
|
||||||
const MCSymbol *Sym = TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, MMI);
|
const MCSymbol *Sym =
|
||||||
|
TLOF.getCFIPersonalitySymbol(Per, *Asm->Mang, Asm->TM, MMI);
|
||||||
|
|
||||||
Asm->OutStreamer.PushSection();
|
Asm->OutStreamer.PushSection();
|
||||||
Asm->OutStreamer.EmitWin64EHHandlerData();
|
Asm->OutStreamer.EmitWin64EHHandlerData();
|
||||||
|
@@ -24,7 +24,9 @@
|
|||||||
#include "llvm/IR/DataLayout.h"
|
#include "llvm/IR/DataLayout.h"
|
||||||
#include "llvm/IR/DerivedTypes.h"
|
#include "llvm/IR/DerivedTypes.h"
|
||||||
#include "llvm/IR/GlobalVariable.h"
|
#include "llvm/IR/GlobalVariable.h"
|
||||||
|
#include "llvm/IR/Mangler.h"
|
||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
|
#include "llvm/MC/MCContext.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
@@ -1426,3 +1428,30 @@ bool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TargetLoweringBase::getNameWithPrefix(SmallVectorImpl<char> &Name,
|
||||||
|
const GlobalValue *GV,
|
||||||
|
Mangler &Mang,
|
||||||
|
bool MayAlwaysUsePrivate) const {
|
||||||
|
if (MayAlwaysUsePrivate || !GV->hasPrivateLinkage()) {
|
||||||
|
// Simple case: If GV is not private, it is not important to find out if
|
||||||
|
// private labels are legal in this case or not.
|
||||||
|
Mang.getNameWithPrefix(Name, GV, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SectionKind GVKind =
|
||||||
|
TargetLoweringObjectFile::getKindForGlobal(GV, getTargetMachine());
|
||||||
|
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
|
||||||
|
const MCSection *TheSection =
|
||||||
|
TLOF.SectionForGlobal(GV, GVKind, Mang, getTargetMachine());
|
||||||
|
bool CannotUsePrivateLabel = TLOF.isSectionAtomizableBySymbols(*TheSection);
|
||||||
|
Mang.getNameWithPrefix(Name, GV, CannotUsePrivateLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
MCSymbol *TargetLoweringBase::getSymbol(const GlobalValue *GV,
|
||||||
|
Mangler &Mang) const {
|
||||||
|
SmallString<60> NameStr;
|
||||||
|
getNameWithPrefix(NameStr, GV, Mang);
|
||||||
|
const TargetLoweringObjectFile &TLOF = getObjFileLowering();
|
||||||
|
return TLOF.getContext().GetOrCreateSymbol(NameStr.str());
|
||||||
|
}
|
||||||
|
@@ -36,6 +36,7 @@
|
|||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
#include "llvm/Target/TargetLowering.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace dwarf;
|
using namespace dwarf;
|
||||||
|
|
||||||
@@ -43,19 +44,18 @@ using namespace dwarf;
|
|||||||
// ELF
|
// ELF
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
MCSymbol *
|
MCSymbol *TargetLoweringObjectFileELF::getCFIPersonalitySymbol(
|
||||||
TargetLoweringObjectFileELF::getCFIPersonalitySymbol(const GlobalValue *GV,
|
const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
|
||||||
Mangler &Mang,
|
MachineModuleInfo *MMI) const {
|
||||||
MachineModuleInfo *MMI) const {
|
|
||||||
unsigned Encoding = getPersonalityEncoding();
|
unsigned Encoding = getPersonalityEncoding();
|
||||||
switch (Encoding & 0x70) {
|
switch (Encoding & 0x70) {
|
||||||
default:
|
default:
|
||||||
report_fatal_error("We do not support this DWARF encoding yet!");
|
report_fatal_error("We do not support this DWARF encoding yet!");
|
||||||
case dwarf::DW_EH_PE_absptr:
|
case dwarf::DW_EH_PE_absptr:
|
||||||
return getSymbol(GV, Mang);
|
return TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
case dwarf::DW_EH_PE_pcrel: {
|
case dwarf::DW_EH_PE_pcrel: {
|
||||||
return getContext().GetOrCreateSymbol(StringRef("DW.ref.") +
|
return getContext().GetOrCreateSymbol(StringRef("DW.ref.") +
|
||||||
getSymbol(GV, Mang)->getName());
|
TM.getTargetLowering()->getSymbol(GV, Mang)->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,18 +89,19 @@ void TargetLoweringObjectFileELF::emitPersonalityValue(MCStreamer &Streamer,
|
|||||||
|
|
||||||
const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
|
const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
|
||||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||||
|
MCStreamer &Streamer) const {
|
||||||
|
|
||||||
if (Encoding & dwarf::DW_EH_PE_indirect) {
|
if (Encoding & dwarf::DW_EH_PE_indirect) {
|
||||||
MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
|
MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
|
||||||
|
|
||||||
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang);
|
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang, TM);
|
||||||
|
|
||||||
// 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.
|
||||||
MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
|
MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
|
||||||
if (StubSym.getPointer() == 0) {
|
if (StubSym.getPointer() == 0) {
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,8 +110,8 @@ const MCExpr *TargetLoweringObjectFileELF::getTTypeGlobalReference(
|
|||||||
Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
|
Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, Mang,
|
return TargetLoweringObjectFile::
|
||||||
MMI, Streamer);
|
getTTypeGlobalReference(GV, Encoding, Mang, TM, MMI, Streamer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SectionKind
|
static SectionKind
|
||||||
@@ -195,10 +196,9 @@ getELFSectionFlags(SectionKind K) {
|
|||||||
return Flags;
|
return Flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
|
||||||
const MCSection *TargetLoweringObjectFileELF::
|
const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
||||||
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
const TargetMachine &TM) const {
|
||||||
Mangler &Mang, const TargetMachine &TM) const {
|
|
||||||
StringRef SectionName = GV->getSection();
|
StringRef SectionName = GV->getSection();
|
||||||
|
|
||||||
// Infer section flags from the section name if we can.
|
// Infer section flags from the section name if we can.
|
||||||
@@ -248,12 +248,12 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
|||||||
Prefix = getSectionPrefixForGlobal(Kind);
|
Prefix = getSectionPrefixForGlobal(Kind);
|
||||||
|
|
||||||
SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
|
SmallString<128> Name(Prefix, Prefix+strlen(Prefix));
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
TM.getTargetLowering()->getNameWithPrefix(Name, GV, Mang, true);
|
||||||
Name.append(Sym->getName().begin(), Sym->getName().end());
|
|
||||||
StringRef Group = "";
|
StringRef Group = "";
|
||||||
unsigned Flags = getELFSectionFlags(Kind);
|
unsigned Flags = getELFSectionFlags(Kind);
|
||||||
if (GV->isWeakForLinker()) {
|
if (GV->isWeakForLinker()) {
|
||||||
Group = Sym->getName();
|
Group = Name.substr(strlen(Prefix));
|
||||||
Flags |= ELF::SHF_GROUP;
|
Flags |= ELF::SHF_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,9 +487,9 @@ emitModuleFlags(MCStreamer &Streamer,
|
|||||||
Streamer.AddBlankLine();
|
Streamer.AddBlankLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
const MCSection *TargetLoweringObjectFileMachO::
|
const MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
|
||||||
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
||||||
Mangler &Mang, const TargetMachine &TM) const {
|
const TargetMachine &TM) const {
|
||||||
// Parse the section specifier and create it if valid.
|
// Parse the section specifier and create it if valid.
|
||||||
StringRef Segment, Section;
|
StringRef Segment, Section;
|
||||||
unsigned TAA = 0, StubSize = 0;
|
unsigned TAA = 0, StubSize = 0;
|
||||||
@@ -526,6 +526,41 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
|||||||
return S;
|
return S;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TargetLoweringObjectFileMachO::isSectionAtomizableBySymbols(
|
||||||
|
const MCSection &Section) const {
|
||||||
|
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
|
||||||
|
|
||||||
|
// Sections holding 1 byte strings are atomized based on the data
|
||||||
|
// they contain.
|
||||||
|
// Sections holding 2 byte strings require symbols in order to be
|
||||||
|
// atomized.
|
||||||
|
// There is no dedicated section for 4 byte strings.
|
||||||
|
if (SMO.getKind().isMergeable1ByteCString())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (SMO.getSegmentName() == "__DATA" &&
|
||||||
|
SMO.getSectionName() == "__cfstring")
|
||||||
|
return false;
|
||||||
|
|
||||||
|
switch (SMO.getType()) {
|
||||||
|
default:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// These sections are atomized at the element boundaries without using
|
||||||
|
// symbols.
|
||||||
|
case MCSectionMachO::S_4BYTE_LITERALS:
|
||||||
|
case MCSectionMachO::S_8BYTE_LITERALS:
|
||||||
|
case MCSectionMachO::S_16BYTE_LITERALS:
|
||||||
|
case MCSectionMachO::S_LITERAL_POINTERS:
|
||||||
|
case MCSectionMachO::S_NON_LAZY_SYMBOL_POINTERS:
|
||||||
|
case MCSectionMachO::S_LAZY_SYMBOL_POINTERS:
|
||||||
|
case MCSectionMachO::S_MOD_INIT_FUNC_POINTERS:
|
||||||
|
case MCSectionMachO::S_MOD_TERM_FUNC_POINTERS:
|
||||||
|
case MCSectionMachO::S_INTERPOSING:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const MCSection *TargetLoweringObjectFileMachO::
|
const MCSection *TargetLoweringObjectFileMachO::
|
||||||
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||||
Mangler &Mang, const TargetMachine &TM) const {
|
Mangler &Mang, const TargetMachine &TM) const {
|
||||||
@@ -606,21 +641,17 @@ TargetLoweringObjectFileMachO::getSectionForConstant(SectionKind Kind) const {
|
|||||||
return ReadOnlySection; // .const
|
return ReadOnlySection; // .const
|
||||||
}
|
}
|
||||||
|
|
||||||
/// shouldEmitUsedDirectiveFor - This hook allows targets to selectively decide
|
/// This hook allows targets to selectively decide not to emit the UsedDirective
|
||||||
/// not to emit the UsedDirective for some symbols in llvm.used.
|
/// for some symbols in llvm.used.
|
||||||
// FIXME: REMOVE this (rdar://7071300)
|
// FIXME: REMOVE this (rdar://7071300)
|
||||||
bool TargetLoweringObjectFileMachO::
|
bool TargetLoweringObjectFileMachO::shouldEmitUsedDirectiveFor(
|
||||||
shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler &Mang) const {
|
const GlobalValue *GV, Mangler &Mang, TargetMachine &TM) const {
|
||||||
/// On Darwin, internally linked data beginning with "L" or "l" does not have
|
|
||||||
/// the directive emitted (this occurs in ObjC metadata).
|
|
||||||
if (!GV) return false;
|
|
||||||
|
|
||||||
// Check whether the mangled name has the "Private" or "LinkerPrivate" prefix.
|
// Check whether the mangled name has the "Private" or "LinkerPrivate" prefix.
|
||||||
if (GV->hasLocalLinkage() && !isa<Function>(GV)) {
|
if (GV->hasLocalLinkage() && !isa<Function>(GV)) {
|
||||||
// FIXME: ObjC metadata is currently emitted as internal symbols that have
|
// FIXME: ObjC metadata is currently emitted as internal symbols that have
|
||||||
// \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and
|
// \1L and \0l prefixes on them. Fix them to be Private/LinkerPrivate and
|
||||||
// this horrible hack can go away.
|
// this horrible hack can go away.
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l')
|
if (Sym->getName()[0] == 'L' || Sym->getName()[0] == 'l')
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -630,14 +661,16 @@ shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler &Mang) const {
|
|||||||
|
|
||||||
const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
||||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||||
|
MCStreamer &Streamer) const {
|
||||||
// The mach-o version of this method defaults to returning a stub reference.
|
// The mach-o version of this method defaults to returning a stub reference.
|
||||||
|
|
||||||
if (Encoding & DW_EH_PE_indirect) {
|
if (Encoding & DW_EH_PE_indirect) {
|
||||||
MachineModuleInfoMachO &MachOMMI =
|
MachineModuleInfoMachO &MachOMMI =
|
||||||
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
||||||
|
|
||||||
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang);
|
MCSymbol *SSym =
|
||||||
|
getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM);
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -645,7 +678,7 @@ const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
|||||||
GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) :
|
GV->hasHiddenVisibility() ? MachOMMI.getHiddenGVStubEntry(SSym) :
|
||||||
MachOMMI.getGVStubEntry(SSym);
|
MachOMMI.getGVStubEntry(SSym);
|
||||||
if (StubSym.getPointer() == 0) {
|
if (StubSym.getPointer() == 0) {
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,24 +687,24 @@ const MCExpr *TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
|||||||
Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
|
Encoding & ~dwarf::DW_EH_PE_indirect, Streamer);
|
||||||
}
|
}
|
||||||
|
|
||||||
return TargetLoweringObjectFile::
|
return TargetLoweringObjectFile::getTTypeGlobalReference(GV, Encoding, Mang,
|
||||||
getTTypeGlobalReference(GV, Encoding, Mang, MMI, Streamer);
|
TM, MMI, Streamer);
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSymbol *TargetLoweringObjectFileMachO::
|
MCSymbol *TargetLoweringObjectFileMachO::getCFIPersonalitySymbol(
|
||||||
getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI) const {
|
MachineModuleInfo *MMI) const {
|
||||||
// The mach-o version of this method defaults to returning a stub reference.
|
// The mach-o version of this method defaults to returning a stub reference.
|
||||||
MachineModuleInfoMachO &MachOMMI =
|
MachineModuleInfoMachO &MachOMMI =
|
||||||
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
MMI->getObjFileInfo<MachineModuleInfoMachO>();
|
||||||
|
|
||||||
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang);
|
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, "$non_lazy_ptr", Mang, TM);
|
||||||
|
|
||||||
// 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.
|
||||||
MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
|
MachineModuleInfoImpl::StubValueTy &StubSym = MachOMMI.getGVStubEntry(SSym);
|
||||||
if (StubSym.getPointer() == 0) {
|
if (StubSym.getPointer() == 0) {
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -717,9 +750,9 @@ getCOFFSectionFlags(SectionKind K) {
|
|||||||
return Flags;
|
return Flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MCSection *TargetLoweringObjectFileCOFF::
|
const MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
|
||||||
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
||||||
Mangler &Mang, const TargetMachine &TM) const {
|
const TargetMachine &TM) const {
|
||||||
int Selection = 0;
|
int Selection = 0;
|
||||||
unsigned Characteristics = getCOFFSectionFlags(Kind);
|
unsigned Characteristics = getCOFFSectionFlags(Kind);
|
||||||
StringRef Name = GV->getSection();
|
StringRef Name = GV->getSection();
|
||||||
@@ -727,7 +760,7 @@ getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
|||||||
if (GV->isWeakForLinker()) {
|
if (GV->isWeakForLinker()) {
|
||||||
Selection = COFF::IMAGE_COMDAT_SELECT_ANY;
|
Selection = COFF::IMAGE_COMDAT_SELECT_ANY;
|
||||||
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
|
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
COMDATSymName = Sym->getName();
|
COMDATSymName = Sym->getName();
|
||||||
}
|
}
|
||||||
return getContext().getCOFFSection(Name,
|
return getContext().getCOFFSection(Name,
|
||||||
@@ -761,7 +794,7 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
|||||||
unsigned Characteristics = getCOFFSectionFlags(Kind);
|
unsigned Characteristics = getCOFFSectionFlags(Kind);
|
||||||
|
|
||||||
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
|
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
return getContext().getCOFFSection(Name, Characteristics,
|
return getContext().getCOFFSection(Name, Characteristics,
|
||||||
Kind, Sym->getName(),
|
Kind, Sym->getName(),
|
||||||
COFF::IMAGE_COMDAT_SELECT_ANY);
|
COFF::IMAGE_COMDAT_SELECT_ANY);
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/MemoryBuffer.h"
|
#include "llvm/Support/MemoryBuffer.h"
|
||||||
#include "llvm/Support/MutexGuard.h"
|
#include "llvm/Support/MutexGuard.h"
|
||||||
|
#include "llvm/Target/TargetLowering.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -371,7 +372,7 @@ void *MCJIT::getPointerToFunction(Function *F) {
|
|||||||
// load address of the symbol, not the local address.
|
// load address of the symbol, not the local address.
|
||||||
Mangler Mang(TM->getDataLayout());
|
Mangler Mang(TM->getDataLayout());
|
||||||
SmallString<128> Name;
|
SmallString<128> Name;
|
||||||
Mang.getNameWithPrefix(Name, F);
|
TM->getTargetLowering()->getNameWithPrefix(Name, F, Mang);
|
||||||
return (void*)Dyld.getSymbolLoadAddress(Name);
|
return (void*)Dyld.getSymbolLoadAddress(Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -76,12 +76,18 @@ static void AddFastCallStdCallSuffix(raw_ostream &OS, const Function *F,
|
|||||||
OS << '@' << ArgWords;
|
OS << '@' << ArgWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV) const {
|
void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV,
|
||||||
|
bool CannotUsePrivateLabel) const {
|
||||||
ManglerPrefixTy PrefixTy = Mangler::Default;
|
ManglerPrefixTy PrefixTy = Mangler::Default;
|
||||||
if (GV->hasPrivateLinkage())
|
if (GV->hasPrivateLinkage()) {
|
||||||
PrefixTy = Mangler::Private;
|
if (CannotUsePrivateLabel)
|
||||||
else if (GV->hasLinkerPrivateLinkage() || GV->hasLinkerPrivateWeakLinkage())
|
PrefixTy = Mangler::LinkerPrivate;
|
||||||
|
else
|
||||||
|
PrefixTy = Mangler::Private;
|
||||||
|
} else if (GV->hasLinkerPrivateLinkage() ||
|
||||||
|
GV->hasLinkerPrivateWeakLinkage()) {
|
||||||
PrefixTy = Mangler::LinkerPrivate;
|
PrefixTy = Mangler::LinkerPrivate;
|
||||||
|
}
|
||||||
|
|
||||||
if (!GV->hasName()) {
|
if (!GV->hasName()) {
|
||||||
// Get the ID for the global, assigning a new one if we haven't got one
|
// Get the ID for the global, assigning a new one if we haven't got one
|
||||||
@@ -134,7 +140,8 @@ void Mangler::getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
||||||
const GlobalValue *GV) const {
|
const GlobalValue *GV,
|
||||||
|
bool CannotUsePrivateLabel) const {
|
||||||
raw_svector_ostream OS(OutName);
|
raw_svector_ostream OS(OutName);
|
||||||
getNameWithPrefix(OS, GV);
|
getNameWithPrefix(OS, GV, CannotUsePrivateLabel);
|
||||||
}
|
}
|
||||||
|
@@ -335,11 +335,17 @@ applyRestriction(GlobalValue &GV,
|
|||||||
std::vector<const char*> &MustPreserveList,
|
std::vector<const char*> &MustPreserveList,
|
||||||
SmallPtrSet<GlobalValue*, 8> &AsmUsed,
|
SmallPtrSet<GlobalValue*, 8> &AsmUsed,
|
||||||
Mangler &Mangler) {
|
Mangler &Mangler) {
|
||||||
SmallString<64> Buffer;
|
// There are no restrictions to apply to declarations.
|
||||||
Mangler.getNameWithPrefix(Buffer, &GV);
|
|
||||||
|
|
||||||
if (GV.isDeclaration())
|
if (GV.isDeclaration())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// There is nothing more restrictive than private linkage.
|
||||||
|
if (GV.hasPrivateLinkage())
|
||||||
|
return;
|
||||||
|
|
||||||
|
SmallString<64> Buffer;
|
||||||
|
TargetMach->getTargetLowering()->getNameWithPrefix(Buffer, &GV, Mangler);
|
||||||
|
|
||||||
if (MustPreserveSymbols.count(Buffer))
|
if (MustPreserveSymbols.count(Buffer))
|
||||||
MustPreserveList.push_back(GV.getName().data());
|
MustPreserveList.push_back(GV.getName().data());
|
||||||
if (AsmUndefinedRefs.count(Buffer))
|
if (AsmUndefinedRefs.count(Buffer))
|
||||||
|
@@ -176,6 +176,16 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
|
|||||||
m->materializeAllPermanently();
|
m->materializeAllPermanently();
|
||||||
|
|
||||||
LTOModule *Ret = new LTOModule(m.take(), target);
|
LTOModule *Ret = new LTOModule(m.take(), target);
|
||||||
|
|
||||||
|
// We need a MCContext set up in order to get mangled names of private
|
||||||
|
// symbols. It is a bit odd that we need to report uses and definitions
|
||||||
|
// of private symbols, but it does look like ld64 expects to be informed
|
||||||
|
// of at least the ones with an 'l' prefix.
|
||||||
|
MCContext &Context = Ret->_context;
|
||||||
|
const TargetLoweringObjectFile &TLOF =
|
||||||
|
target->getTargetLowering()->getObjFileLowering();
|
||||||
|
const_cast<TargetLoweringObjectFile &>(TLOF).Initialize(Context, *target);
|
||||||
|
|
||||||
if (Ret->parseSymbols(errMsg)) {
|
if (Ret->parseSymbols(errMsg)) {
|
||||||
delete Ret;
|
delete Ret;
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -381,7 +391,7 @@ void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) {
|
|||||||
|
|
||||||
// string is owned by _defines
|
// string is owned by _defines
|
||||||
SmallString<64> Buffer;
|
SmallString<64> Buffer;
|
||||||
_mangler.getNameWithPrefix(Buffer, def);
|
_target->getTargetLowering()->getNameWithPrefix(Buffer, def, _mangler);
|
||||||
|
|
||||||
// set alignment part log2() can have rounding errors
|
// set alignment part log2() can have rounding errors
|
||||||
uint32_t align = def->getAlignment();
|
uint32_t align = def->getAlignment();
|
||||||
@@ -517,7 +527,7 @@ LTOModule::addPotentialUndefinedSymbol(const GlobalValue *decl, bool isFunc) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
SmallString<64> name;
|
SmallString<64> name;
|
||||||
_mangler.getNameWithPrefix(name, decl);
|
_target->getTargetLowering()->getNameWithPrefix(name, decl, _mangler);
|
||||||
|
|
||||||
StringMap<NameAndAttributes>::value_type &entry =
|
StringMap<NameAndAttributes>::value_type &entry =
|
||||||
_undefines.GetOrCreateValue(name);
|
_undefines.GetOrCreateValue(name);
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
#include "llvm/MC/MCSectionELF.h"
|
#include "llvm/MC/MCSectionELF.h"
|
||||||
#include "llvm/Support/Dwarf.h"
|
#include "llvm/Support/Dwarf.h"
|
||||||
#include "llvm/Support/ELF.h"
|
#include "llvm/Support/ELF.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace dwarf;
|
using namespace dwarf;
|
||||||
|
|
||||||
@@ -43,12 +43,12 @@ void ARMElfTargetObjectFile::Initialize(MCContext &Ctx,
|
|||||||
|
|
||||||
const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
|
const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
|
||||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||||
|
MCStreamer &Streamer) const {
|
||||||
assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
|
assert(Encoding == DW_EH_PE_absptr && "Can handle absptr encoding only");
|
||||||
|
|
||||||
return MCSymbolRefExpr::Create(getSymbol(GV, Mang),
|
return MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
|
||||||
MCSymbolRefExpr::VK_ARM_TARGET2,
|
MCSymbolRefExpr::VK_ARM_TARGET2, getContext());
|
||||||
getContext());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const MCExpr *ARMElfTargetObjectFile::
|
const MCExpr *ARMElfTargetObjectFile::
|
||||||
|
@@ -28,10 +28,10 @@ public:
|
|||||||
|
|
||||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) LLVM_OVERRIDE;
|
void Initialize(MCContext &Ctx, const TargetMachine &TM) LLVM_OVERRIDE;
|
||||||
|
|
||||||
const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
const MCExpr *
|
||||||
unsigned Encoding, Mangler &Mang,
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
||||||
MachineModuleInfo *MMI,
|
Mangler &Mang, const TargetMachine &TM,
|
||||||
MCStreamer &Streamer) const
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
/// \brief Describe a TLS variable address within debug info.
|
/// \brief Describe a TLS variable address within debug info.
|
||||||
|
@@ -25,7 +25,8 @@
|
|||||||
#include "llvm/MC/MCAsmInfo.h"
|
#include "llvm/MC/MCAsmInfo.h"
|
||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCInst.h"
|
#include "llvm/MC/MCInst.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetLowering.h"
|
||||||
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
static MachineModuleInfoMachO &getMachOMMI(AsmPrinter &AP) {
|
static MachineModuleInfoMachO &getMachOMMI(AsmPrinter &AP) {
|
||||||
@@ -34,7 +35,9 @@ static MachineModuleInfoMachO &getMachOMMI(AsmPrinter &AP) {
|
|||||||
|
|
||||||
|
|
||||||
static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
|
static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
|
||||||
const DataLayout *DL = AP.TM.getDataLayout();
|
const TargetMachine &TM = AP.TM;
|
||||||
|
Mangler *Mang = AP.Mang;
|
||||||
|
const DataLayout *DL = TM.getDataLayout();
|
||||||
MCContext &Ctx = AP.OutContext;
|
MCContext &Ctx = AP.OutContext;
|
||||||
|
|
||||||
SmallString<128> Name;
|
SmallString<128> Name;
|
||||||
@@ -51,10 +54,10 @@ static MCSymbol *GetSymbolFromOperand(const MachineOperand &MO, AsmPrinter &AP){
|
|||||||
|
|
||||||
if (!MO.isGlobal()) {
|
if (!MO.isGlobal()) {
|
||||||
assert(MO.isSymbol() && "Isn't a symbol reference");
|
assert(MO.isSymbol() && "Isn't a symbol reference");
|
||||||
AP.Mang->getNameWithPrefix(Name, MO.getSymbolName());
|
Mang->getNameWithPrefix(Name, MO.getSymbolName());
|
||||||
} else {
|
} else {
|
||||||
const GlobalValue *GV = MO.getGlobal();
|
const GlobalValue *GV = MO.getGlobal();
|
||||||
AP.Mang->getNameWithPrefix(Name, GV);
|
TM.getTargetLowering()->getNameWithPrefix(Name, GV, *Mang);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned OrigLen = Name.size() - PrefixLen;
|
unsigned OrigLen = Name.size() - PrefixLen;
|
||||||
|
@@ -11,23 +11,25 @@
|
|||||||
#include "MCTargetDesc/SparcMCExpr.h"
|
#include "MCTargetDesc/SparcMCExpr.h"
|
||||||
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
#include "llvm/CodeGen/MachineModuleInfoImpls.h"
|
||||||
#include "llvm/Support/Dwarf.h"
|
#include "llvm/Support/Dwarf.h"
|
||||||
|
#include "llvm/Target/TargetLowering.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
|
const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
|
||||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||||
|
MCStreamer &Streamer) const {
|
||||||
|
|
||||||
if (Encoding & dwarf::DW_EH_PE_pcrel) {
|
if (Encoding & dwarf::DW_EH_PE_pcrel) {
|
||||||
MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
|
MachineModuleInfoELF &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
|
||||||
|
|
||||||
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang);
|
MCSymbol *SSym = getSymbolWithGlobalValueBase(GV, ".DW.stub", Mang, TM);
|
||||||
|
|
||||||
// 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.
|
||||||
MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
|
MachineModuleInfoImpl::StubValueTy &StubSym = ELFMMI.getGVStubEntry(SSym);
|
||||||
if (StubSym.getPointer() == 0) {
|
if (StubSym.getPointer() == 0) {
|
||||||
MCSymbol *Sym = getSymbol(GV, Mang);
|
MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
StubSym = MachineModuleInfoImpl::StubValueTy(Sym, !GV->hasLocalLinkage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,5 +39,5 @@ const MCExpr *SparcELFTargetObjectFile::getTTypeGlobalReference(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return TargetLoweringObjectFileELF::getTTypeGlobalReference(
|
return TargetLoweringObjectFileELF::getTTypeGlobalReference(
|
||||||
GV, Encoding, Mang, MMI, Streamer);
|
GV, Encoding, Mang, TM, MMI, Streamer);
|
||||||
}
|
}
|
||||||
|
@@ -23,10 +23,10 @@ public:
|
|||||||
TargetLoweringObjectFileELF()
|
TargetLoweringObjectFileELF()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
const MCExpr *
|
||||||
unsigned Encoding, Mangler &Mang,
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
||||||
MachineModuleInfo *MMI,
|
Mangler &Mang, const TargetMachine &TM,
|
||||||
MCStreamer &Streamer) const
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -28,6 +28,7 @@
|
|||||||
#include "llvm/Support/ErrorHandling.h"
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
#include "llvm/Target/TargetLowering.h"
|
||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@@ -99,30 +100,22 @@ static bool IsNullTerminatedString(const Constant *C) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the MCSymbol for the specified global value. This
|
|
||||||
/// symbol is the main label that is the address of the global.
|
|
||||||
MCSymbol *TargetLoweringObjectFile::getSymbol(const GlobalValue *GV,
|
|
||||||
Mangler &M) const {
|
|
||||||
SmallString<60> NameStr;
|
|
||||||
M.getNameWithPrefix(NameStr, GV);
|
|
||||||
return Ctx->GetOrCreateSymbol(NameStr.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
|
MCSymbol *TargetLoweringObjectFile::getSymbolWithGlobalValueBase(
|
||||||
const GlobalValue *GV, StringRef Suffix, Mangler &M) const {
|
const GlobalValue *GV, StringRef Suffix, Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const {
|
||||||
assert(!Suffix.empty());
|
assert(!Suffix.empty());
|
||||||
|
|
||||||
SmallString<60> NameStr;
|
SmallString<60> NameStr;
|
||||||
NameStr += DL->getPrivateGlobalPrefix();
|
NameStr += DL->getPrivateGlobalPrefix();
|
||||||
M.getNameWithPrefix(NameStr, GV);
|
TM.getTargetLowering()->getNameWithPrefix(NameStr, GV, Mang);
|
||||||
NameStr.append(Suffix.begin(), Suffix.end());
|
NameStr.append(Suffix.begin(), Suffix.end());
|
||||||
return Ctx->GetOrCreateSymbol(NameStr.str());
|
return Ctx->GetOrCreateSymbol(NameStr.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSymbol *TargetLoweringObjectFile::
|
MCSymbol *TargetLoweringObjectFile::getCFIPersonalitySymbol(
|
||||||
getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI) const {
|
MachineModuleInfo *MMI) const {
|
||||||
return getSymbol(GV, Mang);
|
return TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
|
void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
|
||||||
@@ -275,6 +268,10 @@ SectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler &Mang,
|
|||||||
return SelectSectionForGlobal(GV, Kind, Mang, TM);
|
return SelectSectionForGlobal(GV, Kind, Mang, TM);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TargetLoweringObjectFile::isSectionAtomizableBySymbols(
|
||||||
|
const MCSection &Section) const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Lame default implementation. Calculate the section name for global.
|
// Lame default implementation. Calculate the section name for global.
|
||||||
const MCSection *
|
const MCSection *
|
||||||
@@ -312,9 +309,11 @@ TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {
|
|||||||
/// handling information.
|
/// handling information.
|
||||||
const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
|
const MCExpr *TargetLoweringObjectFile::getTTypeGlobalReference(
|
||||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||||
|
MCStreamer &Streamer) const {
|
||||||
const MCSymbolRefExpr *Ref =
|
const MCSymbolRefExpr *Ref =
|
||||||
MCSymbolRefExpr::Create(getSymbol(GV, Mang), getContext());
|
MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GV, Mang),
|
||||||
|
getContext());
|
||||||
|
|
||||||
return getTTypeReference(Ref, Encoding, Streamer);
|
return getTTypeReference(Ref, Encoding, Streamer);
|
||||||
}
|
}
|
||||||
|
@@ -98,7 +98,7 @@ GetSymbolFromOperand(const MachineOperand &MO) const {
|
|||||||
|
|
||||||
if (MO.isGlobal()) {
|
if (MO.isGlobal()) {
|
||||||
const GlobalValue *GV = MO.getGlobal();
|
const GlobalValue *GV = MO.getGlobal();
|
||||||
getMang()->getNameWithPrefix(Name, GV);
|
AsmPrinter.getNameWithPrefix(Name, GV);
|
||||||
} else if (MO.isSymbol()) {
|
} else if (MO.isSymbol()) {
|
||||||
getMang()->getNameWithPrefix(Name, MO.getSymbolName());
|
getMang()->getNameWithPrefix(Name, MO.getSymbolName());
|
||||||
} else if (MO.isMBB()) {
|
} else if (MO.isMBB()) {
|
||||||
|
@@ -14,18 +14,20 @@
|
|||||||
#include "llvm/MC/MCExpr.h"
|
#include "llvm/MC/MCExpr.h"
|
||||||
#include "llvm/MC/MCSectionELF.h"
|
#include "llvm/MC/MCSectionELF.h"
|
||||||
#include "llvm/Support/Dwarf.h"
|
#include "llvm/Support/Dwarf.h"
|
||||||
|
#include "llvm/Target/TargetLowering.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace dwarf;
|
using namespace dwarf;
|
||||||
|
|
||||||
const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
|
const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
|
||||||
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
|
||||||
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
|
const TargetMachine &TM, MachineModuleInfo *MMI,
|
||||||
|
MCStreamer &Streamer) const {
|
||||||
|
|
||||||
// On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
|
// On Darwin/X86-64, we can reference dwarf symbols with foo@GOTPCREL+4, which
|
||||||
// is an indirect pc-relative reference.
|
// is an indirect pc-relative reference.
|
||||||
if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
|
if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
|
||||||
const MCSymbol *Sym = getSymbol(GV, Mang);
|
const MCSymbol *Sym = TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
const MCExpr *Res =
|
const MCExpr *Res =
|
||||||
MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
|
MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOTPCREL, getContext());
|
||||||
const MCExpr *Four = MCConstantExpr::Create(4, getContext());
|
const MCExpr *Four = MCConstantExpr::Create(4, getContext());
|
||||||
@@ -33,13 +35,13 @@ const MCExpr *X86_64MachoTargetObjectFile::getTTypeGlobalReference(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
|
||||||
GV, Encoding, Mang, MMI, Streamer);
|
GV, Encoding, Mang, TM, MMI, Streamer);
|
||||||
}
|
}
|
||||||
|
|
||||||
MCSymbol *X86_64MachoTargetObjectFile::
|
MCSymbol *X86_64MachoTargetObjectFile::getCFIPersonalitySymbol(
|
||||||
getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI) const {
|
MachineModuleInfo *MMI) const {
|
||||||
return getSymbol(GV, Mang);
|
return TM.getTargetLowering()->getSymbol(GV, Mang);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -54,9 +56,8 @@ X86LinuxTargetObjectFile::getDebugThreadLocalSymbol(
|
|||||||
return MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
|
return MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_DTPOFF, getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
const MCExpr *
|
const MCExpr *X86WindowsTargetObjectFile::getExecutableRelativeSymbol(
|
||||||
X86WindowsTargetObjectFile::getExecutableRelativeSymbol(const ConstantExpr *CE,
|
const ConstantExpr *CE, Mangler &Mang, const TargetMachine &TM) const {
|
||||||
Mangler &Mang) const {
|
|
||||||
// We are looking for the difference of two symbols, need a subtraction
|
// We are looking for the difference of two symbols, need a subtraction
|
||||||
// operation.
|
// operation.
|
||||||
const SubOperator *Sub = dyn_cast<SubOperator>(CE);
|
const SubOperator *Sub = dyn_cast<SubOperator>(CE);
|
||||||
@@ -101,6 +102,7 @@ X86WindowsTargetObjectFile::getExecutableRelativeSymbol(const ConstantExpr *CE,
|
|||||||
if (GVLHS->isThreadLocal())
|
if (GVLHS->isThreadLocal())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return MCSymbolRefExpr::Create(
|
return MCSymbolRefExpr::Create(TM.getTargetLowering()->getSymbol(GVLHS, Mang),
|
||||||
getSymbol(GVLHS, Mang), MCSymbolRefExpr::VK_COFF_IMGREL32, getContext());
|
MCSymbolRefExpr::VK_COFF_IMGREL32,
|
||||||
|
getContext());
|
||||||
}
|
}
|
||||||
|
@@ -20,15 +20,16 @@ namespace llvm {
|
|||||||
/// x86-64.
|
/// x86-64.
|
||||||
class X86_64MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
|
class X86_64MachoTargetObjectFile : public TargetLoweringObjectFileMachO {
|
||||||
public:
|
public:
|
||||||
const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
|
const MCExpr *
|
||||||
unsigned Encoding, Mangler &Mang,
|
getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
|
||||||
MachineModuleInfo *MMI,
|
Mangler &Mang, const TargetMachine &TM,
|
||||||
MCStreamer &Streamer) const
|
MachineModuleInfo *MMI, MCStreamer &Streamer) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
|
|
||||||
// getCFIPersonalitySymbol - The symbol that gets passed to
|
// getCFIPersonalitySymbol - The symbol that gets passed to
|
||||||
// .cfi_personality.
|
// .cfi_personality.
|
||||||
MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
|
||||||
|
const TargetMachine &TM,
|
||||||
MachineModuleInfo *MMI) const
|
MachineModuleInfo *MMI) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
};
|
};
|
||||||
@@ -46,7 +47,8 @@ namespace llvm {
|
|||||||
/// \brief This implementation is used for Windows targets on x86 and x86-64.
|
/// \brief This implementation is used for Windows targets on x86 and x86-64.
|
||||||
class X86WindowsTargetObjectFile : public TargetLoweringObjectFileCOFF {
|
class X86WindowsTargetObjectFile : public TargetLoweringObjectFileCOFF {
|
||||||
const MCExpr *getExecutableRelativeSymbol(const ConstantExpr *CE,
|
const MCExpr *getExecutableRelativeSymbol(const ConstantExpr *CE,
|
||||||
Mangler &Mang) const
|
Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const
|
||||||
LLVM_OVERRIDE;
|
LLVM_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -118,9 +118,10 @@ static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
|
|||||||
return Flags;
|
return Flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MCSection *XCoreTargetObjectFile::
|
const MCSection *
|
||||||
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
XCoreTargetObjectFile::getExplicitSectionGlobal(const GlobalValue *GV,
|
||||||
Mangler &Mang, const TargetMachine &TM) const {
|
SectionKind Kind, Mangler &Mang,
|
||||||
|
const TargetMachine &TM) const {
|
||||||
StringRef SectionName = GV->getSection();
|
StringRef SectionName = GV->getSection();
|
||||||
// Infer section flags from the section name if we can.
|
// Infer section flags from the section name if we can.
|
||||||
bool IsCPRel = SectionName.startswith(".cp.");
|
bool IsCPRel = SectionName.startswith(".cp.");
|
||||||
|
@@ -561,19 +561,13 @@ static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
|
|||||||
static GlobalVariable *createPrivateGlobalForString(
|
static GlobalVariable *createPrivateGlobalForString(
|
||||||
Module &M, StringRef Str, bool AllowMerging) {
|
Module &M, StringRef Str, bool AllowMerging) {
|
||||||
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
|
Constant *StrConst = ConstantDataArray::getString(M.getContext(), Str);
|
||||||
// For module-local strings that can be merged with another one we set the
|
// We use private linkage for module-local strings. If they can be merged
|
||||||
// private linkage and the unnamed_addr attribute.
|
// with another one, we set the unnamed_addr attribute.
|
||||||
// Non-mergeable strings are made linker_private to remove them from the
|
|
||||||
// symbol table. "private" linkage doesn't work for Darwin, where the
|
|
||||||
// "L"-prefixed globals end up in __TEXT,__const section
|
|
||||||
// (see http://llvm.org/bugs/show_bug.cgi?id=17976 for more info).
|
|
||||||
GlobalValue::LinkageTypes linkage =
|
|
||||||
AllowMerging ? GlobalValue::PrivateLinkage
|
|
||||||
: GlobalValue::LinkerPrivateLinkage;
|
|
||||||
GlobalVariable *GV =
|
GlobalVariable *GV =
|
||||||
new GlobalVariable(M, StrConst->getType(), true,
|
new GlobalVariable(M, StrConst->getType(), true,
|
||||||
linkage, StrConst, kAsanGenPrefix);
|
GlobalValue::PrivateLinkage, StrConst, kAsanGenPrefix);
|
||||||
if (AllowMerging) GV->setUnnamedAddr(true);
|
if (AllowMerging)
|
||||||
|
GV->setUnnamedAddr(true);
|
||||||
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
|
GV->setAlignment(1); // Strings may not be merged w/o setting align 1.
|
||||||
return GV;
|
return GV;
|
||||||
}
|
}
|
||||||
|
@@ -7,22 +7,22 @@
|
|||||||
; RUN: FileCheck --check-prefix=OSX %s
|
; RUN: FileCheck --check-prefix=OSX %s
|
||||||
|
|
||||||
; LINUX: .Lfoo:
|
; LINUX: .Lfoo:
|
||||||
; OSX: L_foo:
|
; OSX: l_foo:
|
||||||
define private void @foo() nounwind {
|
define private void @foo() nounwind {
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
define i32 @bar() nounwind {
|
define i32 @bar() nounwind {
|
||||||
; LINUX: bl{{.*}}.Lfoo
|
; LINUX: bl{{.*}}.Lfoo
|
||||||
; OSX: bl{{.*}}L_foo
|
; OSX: bl{{.*}}l_foo
|
||||||
call void @foo()
|
call void @foo()
|
||||||
|
|
||||||
; LINUX: lis{{.*}}.Lbaz
|
; LINUX: lis{{.*}}.Lbaz
|
||||||
; OSX: lis{{.*}}L_baz
|
; OSX: lis{{.*}}l_baz
|
||||||
%1 = load i32* @baz, align 4
|
%1 = load i32* @baz, align 4
|
||||||
ret i32 %1
|
ret i32 %1
|
||||||
}
|
}
|
||||||
|
|
||||||
; LINUX: .Lbaz:
|
; LINUX: .Lbaz:
|
||||||
; OSX: L_baz:
|
; OSX: l_baz:
|
||||||
@baz = private global i32 4
|
@baz = private global i32 4
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=corei7 | FileCheck %s
|
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=corei7 | FileCheck %s
|
||||||
; rdar://7396984
|
; rdar://7396984
|
||||||
|
|
||||||
@str = private constant [28 x i8] c"xxxxxxxxxxxxxxxxxxxxxxxxxxx\00", align 1
|
@str = private unnamed_addr constant [28 x i8] c"xxxxxxxxxxxxxxxxxxxxxxxxxxx\00", align 1
|
||||||
|
|
||||||
define void @t(i32 %count) ssp nounwind {
|
define void @t(i32 %count) ssp nounwind {
|
||||||
entry:
|
entry:
|
||||||
|
@@ -168,3 +168,11 @@
|
|||||||
; DARWIN: .zerofill __DATA,__common,_G12,1,3
|
; DARWIN: .zerofill __DATA,__common,_G12,1,3
|
||||||
; DARWIN: .globl _G13
|
; DARWIN: .globl _G13
|
||||||
; DARWIN: .zerofill __DATA,__common,_G13,1,3
|
; DARWIN: .zerofill __DATA,__common,_G13,1,3
|
||||||
|
|
||||||
|
@G14 = private unnamed_addr constant [4 x i8] c"foo\00", align 1
|
||||||
|
|
||||||
|
; LINUX-SECTIONS: .type .LG14,@object # @G14
|
||||||
|
; LINUX-SECTIONS: .section .rodata..LG14,"aMS",@progbits,1
|
||||||
|
; LINUX-SECTIONS: .LG14:
|
||||||
|
; LINUX-SECTIONS: .asciz "foo"
|
||||||
|
; LINUX-SECTIONS: .size .LG14, 4
|
||||||
|
71
test/CodeGen/X86/osx-private-labels.ll
Normal file
71
test/CodeGen/X86/osx-private-labels.ll
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s
|
||||||
|
; Test all the cases where a L label is safe. Removing any entry from
|
||||||
|
; TargetLoweringObjectFileMachO::isSectionAtomizableBySymbols should cause
|
||||||
|
; this to fail.
|
||||||
|
; We also test some noteworthy cases that require an l label.
|
||||||
|
|
||||||
|
@private1 = private unnamed_addr constant [4 x i8] c"zed\00"
|
||||||
|
; CHECK: .section __TEXT,__cstring,cstring_literals
|
||||||
|
; CHECK-NEXT: L_private1:
|
||||||
|
|
||||||
|
@private2 = private unnamed_addr constant [5 x i16] [i16 116, i16 101,
|
||||||
|
i16 115, i16 116, i16 0]
|
||||||
|
; CHECK: .section __TEXT,__ustring
|
||||||
|
; CHECK-NEXT: .align 1
|
||||||
|
; CHECK-NEXT: l_private2:
|
||||||
|
|
||||||
|
; There is no dedicated 4 byte strings on MachO.
|
||||||
|
|
||||||
|
%struct.NSConstantString = type { i32*, i32, i8*, i32 }
|
||||||
|
@private3 = private constant %struct.NSConstantString { i32* null, i32 1992, i8* null, i32 0 }, section "__DATA,__cfstring"
|
||||||
|
; CHECK: .section __DATA,__cfstring
|
||||||
|
; CHECK-NEXT: .align 4
|
||||||
|
; CHECK-NEXT: L_private3:
|
||||||
|
|
||||||
|
; There is no dedicated 1 or 2 byte constant section on MachO.
|
||||||
|
|
||||||
|
@private4 = private unnamed_addr constant i32 42
|
||||||
|
; CHECK: .section __TEXT,__literal4,4byte_literals
|
||||||
|
; CHECK-NEXT: .align 2
|
||||||
|
; CHECK-NEXT: L_private4:
|
||||||
|
|
||||||
|
@private5 = private unnamed_addr constant i64 42
|
||||||
|
; CHECK: .section __TEXT,__literal8,8byte_literals
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private5:
|
||||||
|
|
||||||
|
@private6 = private unnamed_addr constant i128 42
|
||||||
|
; CHECK: .section __TEXT,__literal16,16byte_literals
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private6:
|
||||||
|
|
||||||
|
%struct._objc_class = type { i8* }
|
||||||
|
@private7 = private global %struct._objc_class* null, section "__OBJC,__cls_refs,literal_pointers,no_dead_strip"
|
||||||
|
; CHECK: .section __OBJC,__cls_refs,literal_pointers,no_dead_strip
|
||||||
|
; CHECK: .align 3
|
||||||
|
; CHECK: L_private7:
|
||||||
|
|
||||||
|
@private8 = private global i32* null, section "__DATA,__nl_symbol_ptr,non_lazy_symbol_pointers"
|
||||||
|
; CHECK: .section __DATA,__nl_symbol_ptr,non_lazy_symbol_pointers
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private8:
|
||||||
|
|
||||||
|
@private9 = private global i32* null, section "__DATA,__la_symbol_ptr,lazy_symbol_pointers"
|
||||||
|
; CHECK: .section __DATA,__la_symbol_ptr,lazy_symbol_pointers
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private9:
|
||||||
|
|
||||||
|
@private10 = private global i32* null, section "__DATA,__mod_init_func,mod_init_funcs"
|
||||||
|
; CHECK: .section __DATA,__mod_init_func,mod_init_funcs
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private10:
|
||||||
|
|
||||||
|
@private11 = private global i32* null, section "__DATA,__mod_term_func,mod_term_funcs"
|
||||||
|
; CHECK: .section __DATA,__mod_term_func,mod_term_funcs
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private11:
|
||||||
|
|
||||||
|
@private12 = private global i32* null, section "__DATA,__foobar,interposing"
|
||||||
|
; CHECK: .section __DATA,__foobar,interposing
|
||||||
|
; CHECK-NEXT: .align 3
|
||||||
|
; CHECK-NEXT: L_private12:
|
@@ -14,7 +14,7 @@ define void @bar() {
|
|||||||
ret void;
|
ret void;
|
||||||
}
|
}
|
||||||
|
|
||||||
; CHECK: L_foo: ## @foo
|
; CHECK: l_foo: ## @foo
|
||||||
; CHECK-NEXT: Ltmp0:
|
; CHECK-NEXT: Ltmp0:
|
||||||
|
|
||||||
; CHECK: _bar: ## @bar
|
; CHECK: _bar: ## @bar
|
||||||
@@ -34,7 +34,7 @@ define void @bar() {
|
|||||||
; CHECK-NEXT: {{.quad|.long}} Ltmp[[NUM2]]
|
; CHECK-NEXT: {{.quad|.long}} Ltmp[[NUM2]]
|
||||||
|
|
||||||
|
|
||||||
; OLD: L_foo: ## @foo
|
; OLD: l_foo: ## @foo
|
||||||
; OLD-NEXT: Ltmp0:
|
; OLD-NEXT: Ltmp0:
|
||||||
|
|
||||||
; OLD: _bar: ## @bar
|
; OLD: _bar: ## @bar
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
; Quote should be outside of private prefix.
|
; Quote should be outside of private prefix.
|
||||||
; rdar://6855766x
|
; rdar://6855766x
|
||||||
|
|
||||||
; CHECK: L__ZZ20
|
; CHECK: "l__ZZ20-[Example1 whatever]E4C.91"
|
||||||
|
|
||||||
%struct.A = type { i32*, i32 }
|
%struct.A = type { i32*, i32 }
|
||||||
@"_ZZ20-[Example1 whatever]E4C.91" = private constant %struct.A { i32* null, i32 1 } ; <%struct.A*> [#uses=1]
|
@"_ZZ20-[Example1 whatever]E4C.91" = private constant %struct.A { i32* null, i32 1 } ; <%struct.A*> [#uses=1]
|
||||||
|
@@ -7,6 +7,7 @@ target triple = "x86_64-unknown-linux-gnu"
|
|||||||
; module ctor/dtor
|
; module ctor/dtor
|
||||||
|
|
||||||
; CHECK: llvm.global_ctors
|
; CHECK: llvm.global_ctors
|
||||||
|
; CHECK: @__asan_gen_ = private constant [8 x i8] c"<stdin>\00", align 1
|
||||||
; CHECK: llvm.global_dtors
|
; CHECK: llvm.global_dtors
|
||||||
|
|
||||||
; Test that we don't instrument global arrays with static initializer
|
; Test that we don't instrument global arrays with static initializer
|
||||||
|
7
test/LTO/private-symbol.ll
Normal file
7
test/LTO/private-symbol.ll
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
; RUN: llvm-as < %s >%t1
|
||||||
|
; RUN: llvm-lto -o %t2 %t1
|
||||||
|
|
||||||
|
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||||
|
target triple = "x86_64-unknown-linux-gnu"
|
||||||
|
|
||||||
|
@.str = private unnamed_addr constant [7 x i8] c"hello\0A\00", align 1
|
Reference in New Issue
Block a user