mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
When in -static mode, force the PIC style to none. Doing this requires fixing
code which conflated RIPRel PIC with x86-64. Fix these to just check for X86-64 directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75092 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1021,7 +1021,7 @@ SDValue X86TargetLowering::getPICJumpTableRelocBase(SDValue Table,
|
|||||||
SelectionDAG &DAG) const {
|
SelectionDAG &DAG) const {
|
||||||
if (usesGlobalOffsetTable())
|
if (usesGlobalOffsetTable())
|
||||||
return DAG.getGLOBAL_OFFSET_TABLE(getPointerTy());
|
return DAG.getGLOBAL_OFFSET_TABLE(getPointerTy());
|
||||||
if (!Subtarget->isPICStyleRIPRel())
|
if (!Subtarget->is64Bit())
|
||||||
// This doesn't have DebugLoc associated with it, but is not really the
|
// This doesn't have DebugLoc associated with it, but is not really the
|
||||||
// same as a Register.
|
// same as a Register.
|
||||||
return DAG.getNode(X86ISD::GlobalBaseReg, DebugLoc::getUnknownLoc(),
|
return DAG.getNode(X86ISD::GlobalBaseReg, DebugLoc::getUnknownLoc(),
|
||||||
@@ -4434,14 +4434,15 @@ X86TargetLowering::LowerConstantPool(SDValue Op, SelectionDAG &DAG) {
|
|||||||
// global base reg.
|
// global base reg.
|
||||||
unsigned char OpFlag = 0;
|
unsigned char OpFlag = 0;
|
||||||
unsigned WrapperKind = X86ISD::Wrapper;
|
unsigned WrapperKind = X86ISD::Wrapper;
|
||||||
if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
|
||||||
|
if (Subtarget->is64Bit() &&
|
||||||
|
getTargetMachine().getCodeModel() == CodeModel::Small) {
|
||||||
|
WrapperKind = X86ISD::WrapperRIP;
|
||||||
|
} else if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
||||||
if (Subtarget->isPICStyleStub())
|
if (Subtarget->isPICStyleStub())
|
||||||
OpFlag = X86II::MO_PIC_BASE_OFFSET;
|
OpFlag = X86II::MO_PIC_BASE_OFFSET;
|
||||||
else if (Subtarget->isPICStyleGOT())
|
else if (Subtarget->isPICStyleGOT())
|
||||||
OpFlag = X86II::MO_GOTOFF;
|
OpFlag = X86II::MO_GOTOFF;
|
||||||
else if (Subtarget->isPICStyleRIPRel() &&
|
|
||||||
getTargetMachine().getCodeModel() == CodeModel::Small)
|
|
||||||
WrapperKind = X86ISD::WrapperRIP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(),
|
SDValue Result = DAG.getTargetConstantPool(CP->getConstVal(), getPointerTy(),
|
||||||
@@ -4467,13 +4468,14 @@ SDValue X86TargetLowering::LowerJumpTable(SDValue Op, SelectionDAG &DAG) {
|
|||||||
// global base reg.
|
// global base reg.
|
||||||
unsigned char OpFlag = 0;
|
unsigned char OpFlag = 0;
|
||||||
unsigned WrapperKind = X86ISD::Wrapper;
|
unsigned WrapperKind = X86ISD::Wrapper;
|
||||||
if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
|
||||||
|
if (Subtarget->is64Bit()) {
|
||||||
|
WrapperKind = X86ISD::WrapperRIP;
|
||||||
|
} else if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
||||||
if (Subtarget->isPICStyleStub())
|
if (Subtarget->isPICStyleStub())
|
||||||
OpFlag = X86II::MO_PIC_BASE_OFFSET;
|
OpFlag = X86II::MO_PIC_BASE_OFFSET;
|
||||||
else if (Subtarget->isPICStyleGOT())
|
else if (Subtarget->isPICStyleGOT())
|
||||||
OpFlag = X86II::MO_GOTOFF;
|
OpFlag = X86II::MO_GOTOFF;
|
||||||
else if (Subtarget->isPICStyleRIPRel())
|
|
||||||
WrapperKind = X86ISD::WrapperRIP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy(),
|
SDValue Result = DAG.getTargetJumpTable(JT->getIndex(), getPointerTy(),
|
||||||
@@ -4500,13 +4502,13 @@ X86TargetLowering::LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) {
|
|||||||
// global base reg.
|
// global base reg.
|
||||||
unsigned char OpFlag = 0;
|
unsigned char OpFlag = 0;
|
||||||
unsigned WrapperKind = X86ISD::Wrapper;
|
unsigned WrapperKind = X86ISD::Wrapper;
|
||||||
if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
if (Subtarget->is64Bit()) {
|
||||||
|
WrapperKind = X86ISD::WrapperRIP;
|
||||||
|
} else if (getTargetMachine().getRelocationModel() == Reloc::PIC_) {
|
||||||
if (Subtarget->isPICStyleStub())
|
if (Subtarget->isPICStyleStub())
|
||||||
OpFlag = X86II::MO_PIC_BASE_OFFSET;
|
OpFlag = X86II::MO_PIC_BASE_OFFSET;
|
||||||
else if (Subtarget->isPICStyleGOT())
|
else if (Subtarget->isPICStyleGOT())
|
||||||
OpFlag = X86II::MO_GOTOFF;
|
OpFlag = X86II::MO_GOTOFF;
|
||||||
else if (Subtarget->isPICStyleRIPRel())
|
|
||||||
WrapperKind = X86ISD::WrapperRIP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlag);
|
SDValue Result = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlag);
|
||||||
@@ -4517,7 +4519,7 @@ X86TargetLowering::LowerExternalSymbol(SDValue Op, SelectionDAG &DAG) {
|
|||||||
|
|
||||||
// With PIC, the address is actually $g + Offset.
|
// With PIC, the address is actually $g + Offset.
|
||||||
if (getTargetMachine().getRelocationModel() == Reloc::PIC_ &&
|
if (getTargetMachine().getRelocationModel() == Reloc::PIC_ &&
|
||||||
!Subtarget->isPICStyleRIPRel()) {
|
!Subtarget->is64Bit()) {
|
||||||
Result = DAG.getNode(ISD::ADD, DL, getPointerTy(),
|
Result = DAG.getNode(ISD::ADD, DL, getPointerTy(),
|
||||||
DAG.getNode(X86ISD::GlobalBaseReg,
|
DAG.getNode(X86ISD::GlobalBaseReg,
|
||||||
DebugLoc::getUnknownLoc(),
|
DebugLoc::getUnknownLoc(),
|
||||||
@@ -4563,14 +4565,14 @@ X86TargetLowering::LowerGlobalAddress(const GlobalValue *GV, DebugLoc dl,
|
|||||||
Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), 0, OpFlags);
|
Result = DAG.getTargetGlobalAddress(GV, getPointerTy(), 0, OpFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Subtarget->isPICStyleRIPRel() &&
|
if (Subtarget->is64Bit() &&
|
||||||
getTargetMachine().getCodeModel() == CodeModel::Small)
|
getTargetMachine().getCodeModel() == CodeModel::Small)
|
||||||
Result = DAG.getNode(X86ISD::WrapperRIP, dl, getPointerTy(), Result);
|
Result = DAG.getNode(X86ISD::WrapperRIP, dl, getPointerTy(), Result);
|
||||||
else
|
else
|
||||||
Result = DAG.getNode(X86ISD::Wrapper, dl, getPointerTy(), Result);
|
Result = DAG.getNode(X86ISD::Wrapper, dl, getPointerTy(), Result);
|
||||||
|
|
||||||
// With PIC, the address is actually $g + Offset.
|
// With PIC, the address is actually $g + Offset.
|
||||||
if (IsPic && !Subtarget->isPICStyleRIPRel()) {
|
if (IsPic && !Subtarget->is64Bit()) {
|
||||||
Result = DAG.getNode(ISD::ADD, dl, getPointerTy(),
|
Result = DAG.getNode(ISD::ADD, dl, getPointerTy(),
|
||||||
DAG.getNode(X86ISD::GlobalBaseReg, dl, getPointerTy()),
|
DAG.getNode(X86ISD::GlobalBaseReg, dl, getPointerTy()),
|
||||||
Result);
|
Result);
|
||||||
|
@@ -22,9 +22,14 @@ class Module;
|
|||||||
class GlobalValue;
|
class GlobalValue;
|
||||||
class TargetMachine;
|
class TargetMachine;
|
||||||
|
|
||||||
|
/// PICStyles - The X86 backend supports a number of different styles of PIC.
|
||||||
|
///
|
||||||
namespace PICStyles {
|
namespace PICStyles {
|
||||||
enum Style {
|
enum Style {
|
||||||
Stub, GOT, RIPRel, WinPIC, None
|
Stub, // Used on i386-darwin
|
||||||
|
GOT, // Used on many 32-bit unices.
|
||||||
|
RIPRel, // Used on X86-64 when not in -static mode.
|
||||||
|
None // Set when in -static mode (not PIC or DynamicNoPIC mode).
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,7 +190,6 @@ public:
|
|||||||
bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
|
bool isPICStyleGOT() const { return PICStyle == PICStyles::GOT; }
|
||||||
bool isPICStyleStub() const { return PICStyle == PICStyles::Stub; }
|
bool isPICStyleStub() const { return PICStyle == PICStyles::Stub; }
|
||||||
bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
|
bool isPICStyleRIPRel() const { return PICStyle == PICStyles::RIPRel; }
|
||||||
bool isPICStyleWinPIC() const { return PICStyle == PICStyles::WinPIC; }
|
|
||||||
|
|
||||||
/// getDarwinVers - Return the darwin version number, 8 = tiger, 9 = leopard.
|
/// getDarwinVers - Return the darwin version number, 8 = tiger, 9 = leopard.
|
||||||
unsigned getDarwinVers() const { return DarwinVers; }
|
unsigned getDarwinVers() const { return DarwinVers; }
|
||||||
|
@@ -147,6 +147,9 @@ X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS,
|
|||||||
setRelocationModel(Reloc::Static);
|
setRelocationModel(Reloc::Static);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(getRelocationModel() != Reloc::Default &&
|
||||||
|
"Relocation mode not picked");
|
||||||
|
|
||||||
// ELF doesn't have a distinct dynamic-no-PIC model. Dynamic-no-PIC
|
// ELF doesn't have a distinct dynamic-no-PIC model. Dynamic-no-PIC
|
||||||
// is defined as a model for code which may be used in static or
|
// is defined as a model for code which may be used in static or
|
||||||
// dynamic executables but not necessarily a shared library. On ELF
|
// dynamic executables but not necessarily a shared library. On ELF
|
||||||
@@ -164,9 +167,9 @@ X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS,
|
|||||||
setCodeModel(CodeModel::Small);
|
setCodeModel(CodeModel::Small);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Subtarget.isTargetCygMing())
|
if (Subtarget.isTargetCygMing()) {
|
||||||
Subtarget.setPICStyle(PICStyles::WinPIC);
|
Subtarget.setPICStyle(PICStyles::None);
|
||||||
else if (Subtarget.isTargetDarwin()) {
|
} else if (Subtarget.isTargetDarwin()) {
|
||||||
if (Subtarget.is64Bit())
|
if (Subtarget.is64Bit())
|
||||||
Subtarget.setPICStyle(PICStyles::RIPRel);
|
Subtarget.setPICStyle(PICStyles::RIPRel);
|
||||||
else
|
else
|
||||||
@@ -177,6 +180,11 @@ X86TargetMachine::X86TargetMachine(const Module &M, const std::string &FS,
|
|||||||
else
|
else
|
||||||
Subtarget.setPICStyle(PICStyles::GOT);
|
Subtarget.setPICStyle(PICStyles::GOT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Finally, unless we're in PIC or DynamicNoPIC mode, set the PIC style to
|
||||||
|
// None.
|
||||||
|
if (getRelocationModel() == Reloc::Static)
|
||||||
|
Subtarget.setPICStyle(PICStyles::None);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
Reference in New Issue
Block a user