Don't pass a Reloc::Model to MC.

MC only needs to know if the output is PIC or not. It never has to
decide about creating GOTs and PLTs for example. The only thing that
MC itself uses this information for is expanding "macros" in sparc and
mips. The rest I am pretty sure could be moved to CodeGen.

This is a cleanup and isolates the code from future changes to
Reloc::Model.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@269909 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2016-05-18 11:58:50 +00:00
parent 9c1a0c965c
commit 2dc637165b
17 changed files with 59 additions and 71 deletions

View File

@ -194,8 +194,8 @@ protected:
MCSection *SXDataSection;
public:
void InitMCObjectFileInfo(const Triple &TT, Reloc::Model RM,
CodeModel::Model CM, MCContext &ctx);
void InitMCObjectFileInfo(const Triple &TT, bool PIC, CodeModel::Model CM,
MCContext &ctx);
bool getSupportsWeakOmittedEHFrame() const {
return SupportsWeakOmittedEHFrame;
@ -347,11 +347,11 @@ public:
enum Environment { IsMachO, IsELF, IsCOFF };
Environment getObjectFileType() const { return Env; }
Reloc::Model getRelocM() const { return RelocM; }
bool isPositionIndependent() const { return PositionIndependent; }
private:
Environment Env;
Reloc::Model RelocM;
bool PositionIndependent;
CodeModel::Model CMModel;
MCContext *Ctx;
Triple TT;

View File

@ -177,7 +177,7 @@ void MCObjectFileInfo::initMachOMCObjectFileInfo(Triple T) {
MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,
SectionKind::getMetadata());
if (RelocM == Reloc::Static) {
if (!PositionIndependent) {
StaticCtorSection = Ctx->getMachOSection("__TEXT", "__constructor", 0,
SectionKind::getData());
StaticDtorSection = Ctx->getMachOSection("__TEXT", "__destructor", 0,
@ -313,18 +313,21 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
// Fallthrough if not using EHABI
case Triple::ppc:
case Triple::x86:
PersonalityEncoding = (RelocM == Reloc::PIC_)
? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
LSDAEncoding = (RelocM == Reloc::PIC_)
? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
TTypeEncoding = (RelocM == Reloc::PIC_)
? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
PersonalityEncoding = PositionIndependent
? dwarf::DW_EH_PE_indirect |
dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
LSDAEncoding = PositionIndependent
? dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
TTypeEncoding = PositionIndependent
? dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4
: dwarf::DW_EH_PE_absptr;
break;
case Triple::x86_64:
if (RelocM == Reloc::PIC_) {
if (PositionIndependent) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
@ -349,7 +352,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
LSDAEncoding = dwarf::DW_EH_PE_absptr;
FDECFIEncoding = dwarf::DW_EH_PE_absptr;
TTypeEncoding = dwarf::DW_EH_PE_absptr;
if (RelocM == Reloc::PIC_){
if (PositionIndependent) {
PersonalityEncoding |= dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel;
LSDAEncoding |= dwarf::DW_EH_PE_pcrel;
FDECFIEncoding |= dwarf::DW_EH_PE_pcrel;
@ -361,7 +364,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
// The small model guarantees static code/data size < 4GB, but not where it
// will be in memory. Most of these could end up >2GB away so even a signed
// pc-relative 32-bit address is insufficient, theoretically.
if (RelocM == Reloc::PIC_) {
if (PositionIndependent) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata8;
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8;
@ -403,7 +406,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
break;
case Triple::sparcel:
case Triple::sparc:
if (RelocM == Reloc::PIC_) {
if (PositionIndependent) {
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
@ -417,7 +420,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
break;
case Triple::sparcv9:
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
if (RelocM == Reloc::PIC_) {
if (PositionIndependent) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
@ -430,7 +433,7 @@ void MCObjectFileInfo::initELFMCObjectFileInfo(Triple T) {
case Triple::systemz:
// All currently-defined code models guarantee that 4-byte PC-relative
// values will be in range.
if (RelocM == Reloc::PIC_) {
if (PositionIndependent) {
PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
dwarf::DW_EH_PE_sdata4;
LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;
@ -824,11 +827,10 @@ void MCObjectFileInfo::initCOFFMCObjectFileInfo(Triple T) {
SectionKind::getReadOnly());
}
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple,
Reloc::Model relocm,
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
CodeModel::Model cm,
MCContext &ctx) {
RelocM = relocm;
PositionIndependent = PIC;
CMModel = cm;
Ctx = &ctx;

View File

@ -79,7 +79,7 @@ void IRObjectFile::CollectAsmUndefinedRefs(
MCObjectFileInfo MOFI;
MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
MOFI.InitMCObjectFileInfo(TT, Reloc::Default, CodeModel::Default, MCCtx);
MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, CodeModel::Default, MCCtx);
std::unique_ptr<RecordStreamer> Streamer(new RecordStreamer(MCCtx));
T->createNullTargetStreamer(*Streamer);

View File

@ -433,8 +433,7 @@ public:
CurrentFn = nullptr;
IsPicEnabled =
(getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_);
IsPicEnabled = getContext().getObjectFileInfo()->isPositionIndependent();
IsCpRestoreSet = false;
CpRestoreOffset = -1;

View File

@ -668,7 +668,7 @@ MipsTargetELFStreamer::MipsTargetELFStreamer(MCStreamer &S,
// covers all cases so this statement covers most cases and direct object
// emission must call setPic() once MCObjectFileInfo has been initialized. The
// cases we don't handle here are covered by MipsAsmPrinter.
Pic = MCA.getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_;
Pic = MCA.getContext().getObjectFileInfo()->isPositionIndependent();
const FeatureBitset &Features = STI.getFeatureBits();

View File

@ -674,7 +674,7 @@ void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
// MipsTargetStreamer has an initialization order problem when emitting an
// object file directly (see MipsTargetELFStreamer for full details). Work
// around it by re-initializing the PIC state here.
TS.setPic(OutContext.getObjectFileInfo()->getRelocM());
TS.setPic(OutContext.getObjectFileInfo()->isPositionIndependent());
// Compute MIPS architecture attributes based on the default subtarget
// that we'd have constructed. Module level directives aren't LTO

View File

@ -899,8 +899,7 @@ SparcAsmParser::parseSparcAsmOperand(std::unique_ptr<SparcOperand> &Op,
const MCExpr *Res = MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None,
getContext());
if (isCall &&
getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_)
if (isCall && getContext().getObjectFileInfo()->isPositionIndependent())
Res = SparcMCExpr::create(SparcMCExpr::VK_Sparc_WPLT30, Res,
getContext());
Op = SparcOperand::CreateImm(Res, S, E);
@ -1221,7 +1220,7 @@ SparcAsmParser::adjustPICRelocation(SparcMCExpr::VariantKind VK,
// actually a %pc10 or %pc22 relocation. Otherwise, they are interpreted
// as %got10 or %got22 relocation.
if (getContext().getObjectFileInfo()->getRelocM() == Reloc::PIC_) {
if (getContext().getObjectFileInfo()->isPositionIndependent()) {
switch(VK) {
default: break;
case SparcMCExpr::VK_Sparc_LO:

View File

@ -43,7 +43,8 @@ using namespace llvm;
void TargetLoweringObjectFile::Initialize(MCContext &ctx,
const TargetMachine &TM) {
Ctx = &ctx;
InitMCObjectFileInfo(TM.getTargetTriple(), TM.getRelocationModel(),
InitMCObjectFileInfo(TM.getTargetTriple(),
TM.getRelocationModel() == Reloc::PIC_,
TM.getCodeModel(), *Ctx);
}

View File

@ -1,17 +1,17 @@
# RUN: not llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic -filetype=obj \
# RUN: not llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -filetype=obj \
# RUN: -o /dev/null 2>&1 | FileCheck %s -check-prefix=O32
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic \
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 \
# RUN: -filetype=obj -o /dev/null 2>&1 | FileCheck %s -allow-empty -check-prefix=N32
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic -target-abi=n32 \
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi=n32 \
# RUN: -filetype=obj -o /dev/null 2>&1 | FileCheck %s -allow-empty -check-prefix=N64
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic -target-abi=n32 \
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi=n32 \
# RUN: -filetype=obj -o - | llvm-objdump -d -r - | \
# RUN: FileCheck %s -check-prefix=NO-STORE
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -relocation-model=pic -filetype=obj -o - | \
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -filetype=obj -o - | \
# RUN: llvm-objdump -d -r - | \
# RUN: FileCheck %s -check-prefix=NO-STORE

View File

@ -1,20 +1,20 @@
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -show-encoding | \
# RUN: FileCheck %s
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic -filetype=obj -o -| \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -filetype=obj -o -| \
# RUN: llvm-objdump -d -r -arch=mips - | \
# RUN: FileCheck %s -check-prefix=CHECK-FOR-STORE
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=+micromips -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=+micromips --position-independent -show-encoding | \
# RUN: FileCheck %s -check-prefix=MICROMIPS
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=static -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -show-encoding | \
# RUN: FileCheck %s -check-prefix=NO-PIC
# RUN: llvm-mc %s -arch=mips -mcpu=mips64 -target-abi n32 -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips64 -target-abi n32 --position-independent -show-encoding | \
# RUN: FileCheck %s -check-prefix=BAD-ABI -check-prefix=BAD-ABI-N32
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 --position-independent -show-encoding | \
# RUN: FileCheck %s -check-prefix=BAD-ABI -check-prefix=BAD-ABI-N64
.text

View File

@ -1,20 +1,20 @@
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -show-encoding | \
# RUN: FileCheck %s
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic -filetype=obj -o -| \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent -filetype=obj -o -| \
# RUN: llvm-objdump -d -r -arch=mips - | \
# RUN: FileCheck %s -check-prefix=CHECK-FOR-STORE
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=+micromips -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -mattr=+micromips --position-independent -show-encoding | \
# RUN: FileCheck %s -check-prefix=MICROMIPS
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=static -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -show-encoding | \
# RUN: FileCheck %s -check-prefix=NO-PIC
# RUN: llvm-mc %s -arch=mips -mcpu=mips64 -target-abi n32 -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips -mcpu=mips64 -target-abi n32 --position-independent -show-encoding | \
# RUN: FileCheck %s -check-prefix=BAD-ABI -check-prefix=BAD-ABI-N32
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 -relocation-model=pic -show-encoding | \
# RUN: llvm-mc %s -arch=mips64 -mcpu=mips64 -target-abi n64 --position-independent -show-encoding | \
# RUN: FileCheck %s -check-prefix=BAD-ABI -check-prefix=BAD-ABI-N64
.text

View File

@ -1,4 +1,4 @@
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 -relocation-model=pic 2>%t1
# RUN: llvm-mc %s -arch=mips -mcpu=mips32 --position-independent 2>%t1
# RUN: FileCheck %s < %t1
.text

View File

@ -1,5 +1,5 @@
; RUN: llc -mtriple=mipsel-linux-gnu -relocation-model=pic -filetype=asm < %s | \
; RUN: llvm-mc -triple=mipsel-linux-gnu -relocation-model=pic -filetype=obj | \
; RUN: llvm-mc -triple=mipsel-linux-gnu --position-independent -filetype=obj | \
; RUN: llvm-objdump -d - | FileCheck %s
; RUN: llc -mtriple=mipsel-linux-gnu -relocation-model=pic -filetype=obj < %s | \
; RUN: llvm-objdump -d - | FileCheck %s

View File

@ -1,5 +1,5 @@
! RUN: llvm-mc %s -arch=sparcv9 --relocation-model=pic -filetype=obj | llvm-readobj -r | FileCheck --check-prefix=PIC %s
! RUN: llvm-mc %s -arch=sparcv9 --relocation-model=static -filetype=obj | llvm-readobj -r | FileCheck --check-prefix=NOPIC %s
! RUN: llvm-mc %s -arch=sparcv9 --position-independent -filetype=obj | llvm-readobj -r | FileCheck --check-prefix=PIC %s
! RUN: llvm-mc %s -arch=sparcv9 -filetype=obj | llvm-readobj -r | FileCheck --check-prefix=NOPIC %s
! PIC: Relocations [

View File

@ -595,8 +595,7 @@ bool DwarfStreamer::init(Triple TheTriple, StringRef OutputFilename) {
MOFI.reset(new MCObjectFileInfo);
MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
MOFI->InitMCObjectFileInfo(TheTriple, Reloc::Default, CodeModel::Default,
*MC);
MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, *MC);
MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "");
if (!MAB)

View File

@ -616,7 +616,7 @@ int main(int argc, char **argv) {
MCObjectFileInfo MOFI;
MCContext MC(MAI.get(), MRI.get(), &MOFI);
MOFI.InitMCObjectFileInfo(TheTriple, Reloc::Default, CodeModel::Default, MC);
MOFI.InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, MC);
auto MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "");
if (!MAB)

View File

@ -115,20 +115,8 @@ MAttrs("mattr",
cl::desc("Target specific attributes (-mattr=help for details)"),
cl::value_desc("a1,+a2,-a3,..."));
static cl::opt<Reloc::Model>
RelocModel("relocation-model",
cl::desc("Choose relocation model"),
cl::init(Reloc::Default),
cl::values(
clEnumValN(Reloc::Default, "default",
"Target default relocation model"),
clEnumValN(Reloc::Static, "static",
"Non-relocatable code"),
clEnumValN(Reloc::PIC_, "pic",
"Fully relocatable, position independent code"),
clEnumValN(Reloc::DynamicNoPIC, "dynamic-no-pic",
"Relocatable external references, non-relocatable code"),
clEnumValEnd));
static cl::opt<bool> PIC("position-independent",
cl::desc("Position independent"), cl::init(false));
static cl::opt<llvm::CodeModel::Model>
CMModel("code-model",
@ -432,7 +420,7 @@ int main(int argc, char **argv) {
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
MCObjectFileInfo MOFI;
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
MOFI.InitMCObjectFileInfo(TheTriple, RelocModel, CMModel, Ctx);
MOFI.InitMCObjectFileInfo(TheTriple, PIC, CMModel, Ctx);
if (SaveTempLabels)
Ctx.setAllowTemporaryLabels(false);