mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-21 18:29:46 +00:00
Let Darwin linker auto-synthesize stubs and lazy-pointers. This deletes a bunch of nasty code in ARM asm printer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@80404 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dbfcdb9763
commit
e4e4ed3b56
@ -417,16 +417,9 @@ void Emitter<CodeEmitter>::emitConstPoolInstruction(const MachineInstr &MI) {
|
||||
|
||||
GlobalValue *GV = ACPV->getGV();
|
||||
if (GV) {
|
||||
assert(!ACPV->isStub() && "Don't know how to deal this yet!");
|
||||
if (ACPV->isNonLazyPointer())
|
||||
MCE.addRelocation(MachineRelocation::getIndirectSymbol(
|
||||
MCE.getCurrentPCOffset(), ARM::reloc_arm_machine_cp_entry, GV,
|
||||
(intptr_t)ACPV, false));
|
||||
else
|
||||
emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
|
||||
ACPV->isStub() || isa<Function>(GV), (intptr_t)ACPV);
|
||||
emitGlobalAddress(GV, ARM::reloc_arm_machine_cp_entry,
|
||||
isa<Function>(GV), (intptr_t)ACPV);
|
||||
} else {
|
||||
assert(!ACPV->isNonLazyPointer() && "Don't know how to deal this yet!");
|
||||
emitExternalSymbolAddress(ACPV->getSymbol(), ARM::reloc_arm_absolute);
|
||||
}
|
||||
emitWordLE(0);
|
||||
|
@ -20,29 +20,25 @@
|
||||
using namespace llvm;
|
||||
|
||||
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, unsigned id,
|
||||
ARMCP::ARMCPKind k,
|
||||
unsigned char PCAdj,
|
||||
const char *Modif,
|
||||
bool AddCA)
|
||||
: MachineConstantPoolValue((const Type*)gv->getType()),
|
||||
GV(gv), S(NULL), LabelId(id), Kind(k), PCAdjust(PCAdj),
|
||||
GV(gv), S(NULL), LabelId(id), PCAdjust(PCAdj),
|
||||
Modifier(Modif), AddCurrentAddress(AddCA) {}
|
||||
|
||||
ARMConstantPoolValue::ARMConstantPoolValue(LLVMContext &C,
|
||||
const char *s, unsigned id,
|
||||
ARMCP::ARMCPKind k,
|
||||
unsigned char PCAdj,
|
||||
const char *Modif,
|
||||
bool AddCA)
|
||||
: MachineConstantPoolValue((const Type*)Type::getInt32Ty(C)),
|
||||
GV(NULL), S(strdup(s)), LabelId(id), Kind(k), PCAdjust(PCAdj),
|
||||
GV(NULL), S(strdup(s)), LabelId(id), PCAdjust(PCAdj),
|
||||
Modifier(Modif), AddCurrentAddress(AddCA) {}
|
||||
|
||||
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv,
|
||||
ARMCP::ARMCPKind k,
|
||||
const char *Modif)
|
||||
ARMConstantPoolValue::ARMConstantPoolValue(GlobalValue *gv, const char *Modif)
|
||||
: MachineConstantPoolValue((const Type*)Type::getInt32Ty(gv->getContext())),
|
||||
GV(gv), S(NULL), LabelId(0), Kind(k), PCAdjust(0),
|
||||
GV(gv), S(NULL), LabelId(0), PCAdjust(0),
|
||||
Modifier(Modif) {}
|
||||
|
||||
int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
|
||||
@ -57,7 +53,6 @@ int ARMConstantPoolValue::getExistingMachineCPValue(MachineConstantPool *CP,
|
||||
if (CPV->GV == GV &&
|
||||
CPV->S == S &&
|
||||
CPV->LabelId == LabelId &&
|
||||
CPV->Kind == Kind &&
|
||||
CPV->PCAdjust == PCAdjust)
|
||||
return i;
|
||||
}
|
||||
@ -75,7 +70,6 @@ ARMConstantPoolValue::AddSelectionDAGCSEId(FoldingSetNodeID &ID) {
|
||||
ID.AddPointer(GV);
|
||||
ID.AddPointer(S);
|
||||
ID.AddInteger(LabelId);
|
||||
ID.AddInteger((unsigned)Kind);
|
||||
ID.AddInteger(PCAdjust);
|
||||
}
|
||||
|
||||
@ -89,8 +83,6 @@ void ARMConstantPoolValue::print(raw_ostream &O) const {
|
||||
O << GV->getName();
|
||||
else
|
||||
O << S;
|
||||
if (isNonLazyPointer()) O << "$non_lazy_ptr";
|
||||
else if (isStub()) O << "$stub";
|
||||
if (Modifier) O << "(" << Modifier << ")";
|
||||
if (PCAdjust != 0) {
|
||||
O << "-(LPC" << LabelId << "+" << (unsigned)PCAdjust;
|
||||
|
@ -21,14 +21,6 @@ namespace llvm {
|
||||
class GlobalValue;
|
||||
class LLVMContext;
|
||||
|
||||
namespace ARMCP {
|
||||
enum ARMCPKind {
|
||||
CPValue,
|
||||
CPNonLazyPtr,
|
||||
CPStub
|
||||
};
|
||||
}
|
||||
|
||||
/// ARMConstantPoolValue - ARM specific constantpool value. This is used to
|
||||
/// represent PC relative displacement between the address of the load
|
||||
/// instruction and the global value being loaded, i.e. (&GV-(LPIC+8)).
|
||||
@ -36,7 +28,6 @@ class ARMConstantPoolValue : public MachineConstantPoolValue {
|
||||
GlobalValue *GV; // GlobalValue being loaded.
|
||||
const char *S; // ExtSymbol being loaded.
|
||||
unsigned LabelId; // Label id of the load.
|
||||
ARMCP::ARMCPKind Kind; // non_lazy_ptr or stub?
|
||||
unsigned char PCAdjust; // Extra adjustment if constantpool is pc relative.
|
||||
// 8 for ARM, 4 for Thumb.
|
||||
const char *Modifier; // GV modifier i.e. (&GV(modifier)-(LPIC+8))
|
||||
@ -44,15 +35,12 @@ class ARMConstantPoolValue : public MachineConstantPoolValue {
|
||||
|
||||
public:
|
||||
ARMConstantPoolValue(GlobalValue *gv, unsigned id,
|
||||
ARMCP::ARMCPKind Kind = ARMCP::CPValue,
|
||||
unsigned char PCAdj = 0, const char *Modifier = NULL,
|
||||
bool AddCurrentAddress = false);
|
||||
ARMConstantPoolValue(LLVMContext &C, const char *s, unsigned id,
|
||||
ARMCP::ARMCPKind Kind = ARMCP::CPValue,
|
||||
unsigned char PCAdj = 0, const char *Modifier = NULL,
|
||||
bool AddCurrentAddress = false);
|
||||
ARMConstantPoolValue(GlobalValue *GV, ARMCP::ARMCPKind Kind,
|
||||
const char *Modifier);
|
||||
ARMConstantPoolValue(GlobalValue *GV, const char *Modifier);
|
||||
ARMConstantPoolValue();
|
||||
~ARMConstantPoolValue();
|
||||
|
||||
@ -63,8 +51,6 @@ public:
|
||||
bool hasModifier() const { return Modifier != NULL; }
|
||||
bool mustAddCurrentAddress() const { return AddCurrentAddress; }
|
||||
unsigned getLabelId() const { return LabelId; }
|
||||
bool isNonLazyPointer() const { return Kind == ARMCP::CPNonLazyPtr; }
|
||||
bool isStub() const { return Kind == ARMCP::CPStub; }
|
||||
unsigned char getPCAdjustment() const { return PCAdjust; }
|
||||
|
||||
virtual unsigned getRelocationInfo() const {
|
||||
|
@ -968,8 +968,8 @@ ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
|
||||
isLocalARMFunc = !Subtarget->isThumb() && !isExt;
|
||||
// tBX takes a register source operand.
|
||||
if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) {
|
||||
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
|
||||
ARMCP::CPStub, 4);
|
||||
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV,
|
||||
ARMPCLabelIndex, 4);
|
||||
SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4);
|
||||
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
|
||||
Callee = DAG.getLoad(getPointerTy(), dl,
|
||||
@ -988,8 +988,7 @@ ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee,
|
||||
const char *Sym = S->getSymbol();
|
||||
if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) {
|
||||
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(),
|
||||
Sym, ARMPCLabelIndex,
|
||||
ARMCP::CPStub, 4);
|
||||
Sym, ARMPCLabelIndex, 4);
|
||||
SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4);
|
||||
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
|
||||
Callee = DAG.getLoad(getPointerTy(), dl,
|
||||
@ -1166,7 +1165,7 @@ ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA,
|
||||
EVT PtrVT = getPointerTy();
|
||||
unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
|
||||
ARMConstantPoolValue *CPV =
|
||||
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue,
|
||||
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex,
|
||||
PCAdj, "tlsgd", true);
|
||||
SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument);
|
||||
@ -1208,7 +1207,7 @@ ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
|
||||
// initial exec model
|
||||
unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8;
|
||||
ARMConstantPoolValue *CPV =
|
||||
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, ARMCP::CPValue,
|
||||
new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex,
|
||||
PCAdj, "gottpoff", true);
|
||||
Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset);
|
||||
@ -1221,8 +1220,7 @@ ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA,
|
||||
Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0);
|
||||
} else {
|
||||
// local exec model
|
||||
ARMConstantPoolValue *CPV =
|
||||
new ARMConstantPoolValue(GV, ARMCP::CPValue, "tpoff");
|
||||
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, "tpoff");
|
||||
Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset);
|
||||
Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, NULL, 0);
|
||||
@ -1256,7 +1254,7 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
|
||||
if (RelocM == Reloc::PIC_) {
|
||||
bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility();
|
||||
ARMConstantPoolValue *CPV =
|
||||
new ARMConstantPoolValue(GV, ARMCP::CPValue, UseGOTOFF ? "GOTOFF":"GOT");
|
||||
new ARMConstantPoolValue(GV, UseGOTOFF ? "GOTOFF" : "GOT");
|
||||
SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
|
||||
SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(),
|
||||
@ -1274,34 +1272,19 @@ SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op,
|
||||
}
|
||||
}
|
||||
|
||||
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol
|
||||
/// even in non-static mode.
|
||||
static bool GVIsIndirectSymbol(GlobalValue *GV, Reloc::Model RelocM) {
|
||||
// If symbol visibility is hidden, the extra load is not needed if
|
||||
// the symbol is definitely defined in the current translation unit.
|
||||
bool isDecl = GV->isDeclaration() || GV->hasAvailableExternallyLinkage();
|
||||
if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage()))
|
||||
return false;
|
||||
return RelocM != Reloc::Static && (isDecl || GV->isWeakForLinker());
|
||||
}
|
||||
|
||||
SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,
|
||||
SelectionDAG &DAG) {
|
||||
EVT PtrVT = getPointerTy();
|
||||
DebugLoc dl = Op.getDebugLoc();
|
||||
GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
|
||||
Reloc::Model RelocM = getTargetMachine().getRelocationModel();
|
||||
bool IsIndirect = GVIsIndirectSymbol(GV, RelocM);
|
||||
SDValue CPAddr;
|
||||
if (RelocM == Reloc::Static)
|
||||
CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4);
|
||||
else {
|
||||
unsigned PCAdj = (RelocM != Reloc::PIC_)
|
||||
? 0 : (Subtarget->isThumb() ? 4 : 8);
|
||||
ARMCP::ARMCPKind Kind = IsIndirect ? ARMCP::CPNonLazyPtr
|
||||
: ARMCP::CPValue;
|
||||
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMPCLabelIndex,
|
||||
Kind, PCAdj);
|
||||
unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8);
|
||||
ARMConstantPoolValue *CPV =
|
||||
new ARMConstantPoolValue(GV, ARMPCLabelIndex, PCAdj);
|
||||
CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
}
|
||||
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
|
||||
@ -1313,7 +1296,8 @@ SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op,
|
||||
SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex++, MVT::i32);
|
||||
Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel);
|
||||
}
|
||||
if (IsIndirect)
|
||||
|
||||
if (Subtarget->GVIsIndirectSymbol(GV, RelocM == Reloc::Static))
|
||||
Result = DAG.getLoad(PtrVT, dl, Chain, Result, NULL, 0);
|
||||
|
||||
return Result;
|
||||
@ -1328,8 +1312,7 @@ SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op,
|
||||
unsigned PCAdj = Subtarget->isThumb() ? 4 : 8;
|
||||
ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(),
|
||||
"_GLOBAL_OFFSET_TABLE_",
|
||||
ARMPCLabelIndex,
|
||||
ARMCP::CPValue, PCAdj);
|
||||
ARMPCLabelIndex, PCAdj);
|
||||
SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
|
||||
SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, NULL, 0);
|
||||
@ -1403,14 +1386,13 @@ ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG) {
|
||||
SDValue CPAddr;
|
||||
unsigned PCAdj = (RelocM != Reloc::PIC_)
|
||||
? 0 : (Subtarget->isThumb() ? 4 : 8);
|
||||
ARMCP::ARMCPKind Kind = ARMCP::CPValue;
|
||||
// Save off the LSDA name for the AsmPrinter to use when it's time
|
||||
// to emit the table
|
||||
std::string LSDAName = "L_lsda_";
|
||||
LSDAName += MF.getFunction()->getName();
|
||||
ARMConstantPoolValue *CPV =
|
||||
new ARMConstantPoolValue(*DAG.getContext(), LSDAName.c_str(),
|
||||
ARMPCLabelIndex, Kind, PCAdj);
|
||||
ARMPCLabelIndex, PCAdj);
|
||||
CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4);
|
||||
CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr);
|
||||
SDValue Result =
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "ARMSubtarget.h"
|
||||
#include "ARMGenSubtarget.inc"
|
||||
#include "llvm/GlobalValue.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
using namespace llvm;
|
||||
@ -92,3 +93,13 @@ ARMSubtarget::ARMSubtarget(const std::string &TT, const std::string &FS,
|
||||
if (isTargetDarwin())
|
||||
IsR9Reserved = ReserveR9 | (ARMArchVersion < V6);
|
||||
}
|
||||
|
||||
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect symbol.
|
||||
bool ARMSubtarget::GVIsIndirectSymbol(GlobalValue *GV, bool isStatic) const {
|
||||
// If symbol visibility is hidden, the extra load is not needed if
|
||||
// the symbol is definitely defined in the current translation unit.
|
||||
bool isDecl = GV->isDeclaration() || GV->hasAvailableExternallyLinkage();
|
||||
if (GV->hasHiddenVisibility() && (!isDecl && !GV->hasCommonLinkage()))
|
||||
return false;
|
||||
return !isStatic && (isDecl || GV->isWeakForLinker());
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace llvm {
|
||||
class GlobalValue;
|
||||
|
||||
class ARMSubtarget : public TargetSubtarget {
|
||||
protected:
|
||||
@ -129,6 +130,10 @@ protected:
|
||||
/// stack frame on entry to the function and which must be maintained by every
|
||||
/// function for this subtarget.
|
||||
unsigned getStackAlignment() const { return stackAlignment; }
|
||||
|
||||
/// GVIsIndirectSymbol - true if the GV will be accessed via an indirect
|
||||
/// symbol.
|
||||
bool GVIsIndirectSymbol(GlobalValue *GV, bool isStatic) const;
|
||||
};
|
||||
} // End llvm namespace
|
||||
|
||||
|
@ -79,34 +79,6 @@ namespace {
|
||||
/// visibility that require non-lazy-pointers for indirect access.
|
||||
StringMap<std::string> HiddenGVNonLazyPtrs;
|
||||
|
||||
struct FnStubInfo {
|
||||
std::string Stub, LazyPtr, SLP, SCV;
|
||||
|
||||
FnStubInfo() {}
|
||||
|
||||
void Init(const GlobalValue *GV, Mangler *Mang) {
|
||||
// Already initialized.
|
||||
if (!Stub.empty()) return;
|
||||
Stub = Mang->getMangledName(GV, "$stub", true);
|
||||
LazyPtr = Mang->getMangledName(GV, "$lazy_ptr", true);
|
||||
SLP = Mang->getMangledName(GV, "$slp", true);
|
||||
SCV = Mang->getMangledName(GV, "$scv", true);
|
||||
}
|
||||
|
||||
void Init(const std::string &GV, Mangler *Mang) {
|
||||
// Already initialized.
|
||||
if (!Stub.empty()) return;
|
||||
Stub = Mang->makeNameProper(GV + "$stub", Mangler::Private);
|
||||
LazyPtr = Mang->makeNameProper(GV + "$lazy_ptr", Mangler::Private);
|
||||
SLP = Mang->makeNameProper(GV + "$slp", Mangler::Private);
|
||||
SCV = Mang->makeNameProper(GV + "$scv", Mangler::Private);
|
||||
}
|
||||
};
|
||||
|
||||
/// FnStubs - Keeps the set of external function GlobalAddresses that the
|
||||
/// asm printer should generate stubs for.
|
||||
StringMap<FnStubInfo> FnStubs;
|
||||
|
||||
/// True if asm printer is printing a series of CONSTPOOL_ENTRY.
|
||||
bool InCPMode;
|
||||
public:
|
||||
@ -188,36 +160,26 @@ namespace {
|
||||
GlobalValue *GV = ACPV->getGV();
|
||||
std::string Name;
|
||||
|
||||
|
||||
if (ACPV->isNonLazyPointer()) {
|
||||
std::string SymName = Mang->getMangledName(GV);
|
||||
Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
|
||||
|
||||
if (GV->hasHiddenVisibility())
|
||||
HiddenGVNonLazyPtrs[SymName] = Name;
|
||||
else
|
||||
GVNonLazyPtrs[SymName] = Name;
|
||||
} else if (ACPV->isStub()) {
|
||||
if (GV) {
|
||||
FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
|
||||
FnInfo.Init(GV, Mang);
|
||||
Name = FnInfo.Stub;
|
||||
} else {
|
||||
FnStubInfo &FnInfo = FnStubs[Mang->makeNameProper(ACPV->getSymbol())];
|
||||
FnInfo.Init(ACPV->getSymbol(), Mang);
|
||||
Name = FnInfo.Stub;
|
||||
}
|
||||
} else {
|
||||
if (GV)
|
||||
if (GV) {
|
||||
bool isIndirect = Subtarget->isTargetDarwin() &&
|
||||
Subtarget->GVIsIndirectSymbol(GV,
|
||||
TM.getRelocationModel() == Reloc::Static);
|
||||
if (!isIndirect)
|
||||
Name = Mang->getMangledName(GV);
|
||||
else if (!strncmp(ACPV->getSymbol(), "L_lsda_", 7))
|
||||
Name = ACPV->getSymbol();
|
||||
else
|
||||
Name = Mang->makeNameProper(ACPV->getSymbol());
|
||||
}
|
||||
O << Name;
|
||||
|
||||
|
||||
else {
|
||||
// FIXME: Remove this when Darwin transition to @GOT like syntax.
|
||||
std::string SymName = Mang->getMangledName(GV);
|
||||
Name = Mang->getMangledName(GV, "$non_lazy_ptr", true);
|
||||
if (GV->hasHiddenVisibility())
|
||||
HiddenGVNonLazyPtrs[SymName] = Name;
|
||||
else
|
||||
GVNonLazyPtrs[SymName] = Name;
|
||||
}
|
||||
} else if (!strncmp(ACPV->getSymbol(), "L_lsda_", 7))
|
||||
Name = ACPV->getSymbol();
|
||||
else
|
||||
Name = Mang->makeNameProper(ACPV->getSymbol());
|
||||
O << Name;
|
||||
|
||||
if (ACPV->hasModifier()) O << "(" << ACPV->getModifier() << ")";
|
||||
if (ACPV->getPCAdjustment() != 0) {
|
||||
@ -372,18 +334,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
|
||||
case MachineOperand::MO_GlobalAddress: {
|
||||
bool isCallOp = Modifier && !strcmp(Modifier, "call");
|
||||
GlobalValue *GV = MO.getGlobal();
|
||||
std::string Name;
|
||||
bool isExt = GV->isDeclaration() || GV->isWeakForLinker();
|
||||
if (isExt && isCallOp && Subtarget->isTargetDarwin() &&
|
||||
TM.getRelocationModel() != Reloc::Static) {
|
||||
FnStubInfo &FnInfo = FnStubs[Mang->getMangledName(GV)];
|
||||
FnInfo.Init(GV, Mang);
|
||||
Name = FnInfo.Stub;
|
||||
} else {
|
||||
Name = Mang->getMangledName(GV);
|
||||
}
|
||||
|
||||
O << Name;
|
||||
O << Mang->getMangledName(GV);
|
||||
|
||||
printOffset(MO.getOffset());
|
||||
|
||||
@ -394,14 +345,7 @@ void ARMAsmPrinter::printOperand(const MachineInstr *MI, int OpNum,
|
||||
}
|
||||
case MachineOperand::MO_ExternalSymbol: {
|
||||
bool isCallOp = Modifier && !strcmp(Modifier, "call");
|
||||
std::string Name;
|
||||
if (isCallOp && Subtarget->isTargetDarwin() &&
|
||||
TM.getRelocationModel() != Reloc::Static) {
|
||||
FnStubInfo &FnInfo = FnStubs[Mang->makeNameProper(MO.getSymbolName())];
|
||||
FnInfo.Init(MO.getSymbolName(), Mang);
|
||||
Name = FnInfo.Stub;
|
||||
} else
|
||||
Name = Mang->makeNameProper(MO.getSymbolName());
|
||||
std::string Name = Mang->makeNameProper(MO.getSymbolName());
|
||||
|
||||
O << Name;
|
||||
if (isCallOp && Subtarget->isTargetELF() &&
|
||||
@ -1277,55 +1221,7 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
static_cast<TargetLoweringObjectFileMachO &>(getObjFileLowering());
|
||||
|
||||
O << '\n';
|
||||
|
||||
if (!FnStubs.empty()) {
|
||||
unsigned StubSize = 12;
|
||||
const char *StubSectionName = "__symbol_stub4";
|
||||
|
||||
if (TM.getRelocationModel() == Reloc::PIC_) {
|
||||
StubSize = 16;
|
||||
StubSectionName = "__picsymbolstub4";
|
||||
}
|
||||
|
||||
const MCSection *StubSection
|
||||
= TLOFMacho.getMachOSection("__TEXT", StubSectionName,
|
||||
MCSectionMachO::S_SYMBOL_STUBS,
|
||||
StubSize, SectionKind::getText());
|
||||
|
||||
const MCSection *LazySymbolPointerSection
|
||||
= TLOFMacho.getLazySymbolPointerSection();
|
||||
|
||||
// Output stubs for dynamically-linked functions
|
||||
for (StringMap<FnStubInfo>::iterator I = FnStubs.begin(),
|
||||
E = FnStubs.end(); I != E; ++I) {
|
||||
const FnStubInfo &Info = I->second;
|
||||
|
||||
OutStreamer.SwitchSection(StubSection);
|
||||
EmitAlignment(2);
|
||||
O << "\t.code\t32\n";
|
||||
|
||||
O << Info.Stub << ":\n";
|
||||
O << "\t.indirect_symbol " << I->getKeyData() << '\n';
|
||||
O << "\tldr ip, " << Info.SLP << '\n';
|
||||
if (TM.getRelocationModel() == Reloc::PIC_) {
|
||||
O << Info.SCV << ":\n";
|
||||
O << "\tadd ip, pc, ip\n";
|
||||
}
|
||||
O << "\tldr pc, [ip, #0]\n";
|
||||
O << Info.SLP << ":\n";
|
||||
O << "\t.long\t" << Info.LazyPtr;
|
||||
if (TM.getRelocationModel() == Reloc::PIC_)
|
||||
O << "-(" << Info.SCV << "+8)";
|
||||
O << '\n';
|
||||
|
||||
OutStreamer.SwitchSection(LazySymbolPointerSection);
|
||||
O << Info.LazyPtr << ":\n";
|
||||
O << "\t.indirect_symbol " << I->getKeyData() << "\n";
|
||||
O << "\t.long\tdyld_stub_binding_helper\n";
|
||||
}
|
||||
O << '\n';
|
||||
}
|
||||
|
||||
// Output non-lazy-pointers for external and common global variables.
|
||||
if (!GVNonLazyPtrs.empty()) {
|
||||
// Switch with ".non_lazy_symbol_pointer" directive.
|
||||
@ -1349,7 +1245,6 @@ bool ARMAsmPrinter::doFinalization(Module &M) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Funny Darwin hack: This flag tells the linker that no global symbols
|
||||
// contain code that falls through to other global symbols (e.g. the obvious
|
||||
// implementation of multiple entry points). If this doesn't occur, the
|
||||
|
@ -1,67 +0,0 @@
|
||||
; RUN: llvm-as < %s | llc -relocation-model=static | FileCheck %s -check-prefix=STATIC
|
||||
; RUN: llvm-as < %s | llc -relocation-model=pic | FileCheck %s -check-prefix=PIC
|
||||
; RUN: llvm-as < %s | llc -relocation-model=dynamic-no-pic | FileCheck %s -check-prefix=DYNAMIC
|
||||
; PR4482
|
||||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
|
||||
target triple = "armv6-apple-darwin2"
|
||||
|
||||
define i32 @foo(i64 %x) nounwind {
|
||||
entry:
|
||||
; STATIC: _foo:
|
||||
; STATIC: bl _exact_log2
|
||||
; STATIC: ldmfd sp!, {r7, pc}
|
||||
; STATIC: .subsections_via_symbols
|
||||
|
||||
; PIC: _foo:
|
||||
; PIC: bl L_exact_log2$stub
|
||||
; PIC: ldmfd sp!, {r7, pc}
|
||||
|
||||
; DYNAMIC: _foo:
|
||||
; DYNAMIC: bl L_exact_log2$stub
|
||||
; DYNAMIC: ldmfd sp!, {r7, pc}
|
||||
|
||||
%A = call i32 @exact_log2(i64 %x)
|
||||
ret i32 %A
|
||||
}
|
||||
|
||||
define available_externally i32 @exact_log2(i64 %x) nounwind {
|
||||
ret i32 4
|
||||
}
|
||||
|
||||
|
||||
; PIC: .section __TEXT,__picsymbolstub4,symbol_stubs,none,16
|
||||
; PIC: L_exact_log2$stub:
|
||||
; PIC: .indirect_symbol _exact_log2
|
||||
; PIC: ldr ip, L_exact_log2$slp
|
||||
; PIC: L_exact_log2$scv:
|
||||
; PIC: add ip, pc, ip
|
||||
; PIC: ldr pc, [ip, #0]
|
||||
; PIC: L_exact_log2$slp:
|
||||
; PIC: .long L_exact_log2$lazy_ptr-(L_exact_log2$scv+8)
|
||||
|
||||
; PIC: .section __DATA,__la_symbol_ptr,lazy_symbol_pointers
|
||||
; PIC: L_exact_log2$lazy_ptr:
|
||||
; PIC: .indirect_symbol _exact_log2
|
||||
; PIC: .long dyld_stub_binding_helper
|
||||
|
||||
; PIC: .subsections_via_symbols
|
||||
|
||||
|
||||
; DYNAMIC: .section __TEXT,__symbol_stub4,symbol_stubs,none,12
|
||||
; DYNAMIC: L_exact_log2$stub:
|
||||
; DYNAMIC: .indirect_symbol _exact_log2
|
||||
; DYNAMIC: ldr ip, L_exact_log2$slp
|
||||
; DYNAMIC: ldr pc, [ip, #0]
|
||||
; DYNAMIC: L_exact_log2$slp:
|
||||
; DYNAMIC: .long L_exact_log2$lazy_ptr
|
||||
|
||||
; DYNAMIC: .section __DATA,__la_symbol_ptr,lazy_symbol_pointers
|
||||
; DYNAMIC: L_exact_log2$lazy_ptr:
|
||||
; DYNAMIC: .indirect_symbol _exact_log2
|
||||
; DYNAMIC: .long dyld_stub_binding_helper
|
||||
; DYNAMIC: .subsections_via_symbols
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -7,7 +7,7 @@ declare void @g(i32, i32, i32, i32)
|
||||
|
||||
define void @f() {
|
||||
; DARWIN: f:
|
||||
; DARWIN: blx L_g$stub
|
||||
; DARWIN: blx _g
|
||||
|
||||
; LINUX: f:
|
||||
; LINUX: bl g
|
||||
|
Loading…
Reference in New Issue
Block a user