I was surprised to see the code model being passed to MC. After all,
it assembles code, it doesn't create it.
The one place it is used is in the expansion of .cfi directives to
handle .eh_frame being more that 2gb away from the code.
As far as I can tell, gnu assembler doesn't even have an option to
enable this. Compiling a c file with gcc -mcmodel=large produces a
regular looking .eh_frame. This is probably because in practice linker
parse and recreate .eh_frames.
In llvm this is used because the JIT can place the code and .eh_frame
very far apart. Ideally we would fix the jit and delete this
option. This is hard.
Apart from confusion another problem with the current interface is
that most callers pass CodeModel::Default, which is bad since MC has
no way to map it to the target default if it actually needed to.
This patch then replaces the argument with a boolean with a default
value. The vast majority of users don't ever need to look at it. In
fact, only CodeGen and llvm-mc use it and llvm-mc just to enable more
testing.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@309884
91177308-0d34-0410-b5e6-
96231b3b80d8
MCSection *SXDataSection;
public:
- void InitMCObjectFileInfo(const Triple &TT, bool PIC, CodeModel::Model CM,
- MCContext &ctx);
+ void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
+ bool LargeCodeModel = false);
bool getSupportsWeakOmittedEHFrame() const {
return SupportsWeakOmittedEHFrame;
private:
Environment Env;
bool PositionIndependent;
- CodeModel::Model CMModel;
MCContext *Ctx;
Triple TT;
void initMachOMCObjectFileInfo(const Triple &T);
- void initELFMCObjectFileInfo(const Triple &T);
+ void initELFMCObjectFileInfo(const Triple &T, bool Large);
void initCOFFMCObjectFileInfo(const Triple &T);
void initWasmMCObjectFileInfo(const Triple &T);
TLSExtraDataSection = TLSTLVSection;
}
-void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T) {
+void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
switch (T.getArch()) {
case Triple::mips:
case Triple::mipsel:
break;
case Triple::x86_64:
FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
- ((CMModel == CodeModel::Large) ? dwarf::DW_EH_PE_sdata8
- : dwarf::DW_EH_PE_sdata4);
+ (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
break;
case Triple::bpfel:
case Triple::bpfeb:
break;
case Triple::x86_64:
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);
+ PersonalityEncoding =
+ dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
+ (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
LSDAEncoding = dwarf::DW_EH_PE_pcrel |
- (CMModel == CodeModel::Small
- ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
+ (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
TTypeEncoding = 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);
+ (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
} else {
PersonalityEncoding =
- (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
- ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
- LSDAEncoding = (CMModel == CodeModel::Small)
- ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
- TTypeEncoding = (CMModel == CodeModel::Small)
- ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
+ Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
+ LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
+ TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
}
break;
case Triple::hexagon:
}
void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
- CodeModel::Model cm,
- MCContext &ctx) {
+ MCContext &ctx,
+ bool LargeCodeModel) {
PositionIndependent = PIC;
- CMModel = cm;
Ctx = &ctx;
// Common.
break;
case Triple::ELF:
Env = IsELF;
- initELFMCObjectFileInfo(TT);
+ initELFMCObjectFileInfo(TT, LargeCodeModel);
break;
case Triple::Wasm:
Env = IsWasm;
MCObjectFileInfo MOFI;
MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
- MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, CodeModel::Default, MCCtx);
+ MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, MCCtx);
RecordStreamer Streamer(MCCtx);
T->createNullTargetStreamer(Streamer);
// `Initialize` can be called more than once.
delete Mang;
Mang = new Mangler();
- InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(),
- TM.getCodeModel(), *Ctx);
+ InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx,
+ TM.getCodeModel() == CodeModel::Large);
}
TargetLoweringObjectFile::~TargetLoweringObjectFile() {
-# RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -code-model=small -filetype=obj -o %T/foo.o %s
+# RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -filetype=obj -o %T/foo.o %s
# RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -map-section foo.o,__text=0x10bc0 -verify -check=%s %/T/foo.o
.section __TEXT,__text,regular,pure_instructions
-# RUN: llvm-mc -triple=mips64el-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_Mips64N64.o %s
+# RUN: llvm-mc -triple=mips64el-unknown-linux -filetype=obj -o %T/test_ELF_Mips64N64.o %s
# RUN: llc -mtriple=mips64el-unknown-linux -filetype=obj -o %T/test_ELF_ExternalFunction_Mips64N64.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64el-unknown-linux -verify -map-section test_ELF_Mips64N64.o,.text=0x1000 -map-section test_ELF_ExternalFunction_Mips64N64.o,.text=0x10000 -check=%s %/T/test_ELF_Mips64N64.o %T/test_ELF_ExternalFunction_Mips64N64.o
-# RUN: llvm-mc -triple=mips64-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_Mips64N64.o %s
+# RUN: llvm-mc -triple=mips64-unknown-linux -filetype=obj -o %T/test_ELF_Mips64N64.o %s
# RUN: llc -mtriple=mips64-unknown-linux -filetype=obj -o %T/test_ELF_ExternalFunction_Mips64N64.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64-unknown-linux -verify -map-section test_ELF_Mips64N64.o,.text=0x1000 -map-section test_ELF_ExternalFunction_Mips64N64.o,.text=0x10000 -check=%s %/T/test_ELF_Mips64N64.o %T/test_ELF_ExternalFunction_Mips64N64.o
-# RUN: llvm-mc -triple=mips64el-unknown-linux -target-abi n32 -code-model=small -filetype=obj -o %T/test_ELF_N32.o %s
+# RUN: llvm-mc -triple=mips64el-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_N32.o %s
# RUN: llc -mtriple=mips64el-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_ExternalFunction_N32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64el-unknown-linux -verify -map-section test_ELF_N32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_N32.o,.text=0x10000 -check=%s %/T/test_ELF_N32.o %T/test_ELF_ExternalFunction_N32.o
-# RUN: llvm-mc -triple=mips64-unknown-linux -target-abi n32 -code-model=small -filetype=obj -o %T/test_ELF_N32.o %s
+# RUN: llvm-mc -triple=mips64-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_N32.o %s
# RUN: llc -mtriple=mips64-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_ExternalFunction_N32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64-unknown-linux -verify -map-section test_ELF_N32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_N32.o,.text=0x10000 -check=%s %/T/test_ELF_N32.o %T/test_ELF_ExternalFunction_N32.o
-# RUN: llvm-mc -triple=mips64el-unknown-linux -mcpu=mips64r6 -code-model=small -filetype=obj -o %T/test_ELF_N64R6.o %s
+# RUN: llvm-mc -triple=mips64el-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_N64R6.o %s
# RUN: llc -mtriple=mips64el-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_ExternalFunction_N64R6.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64el-unknown-linux -mcpu=mips64r6 -verify -map-section test_ELF_N64R6.o,.text=0x1000 -map-section test_ELF_ExternalFunction_N64R6.o,.text=0x10000 -check=%s %/T/test_ELF_N64R6.o %T/test_ELF_ExternalFunction_N64R6.o
-# RUN: llvm-mc -triple=mips64-unknown-linux -mcpu=mips64r6 -code-model=small -filetype=obj -o %T/test_ELF_N64R6.o %s
+# RUN: llvm-mc -triple=mips64-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_N64R6.o %s
# RUN: llc -mtriple=mips64-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_ExternalFunction_N64R6.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips64-unknown-linux -mcpu=mips64r6 -verify -map-section test_ELF_N64R6.o,.text=0x1000 -map-section test_ELF_ExternalFunction_N64R6.o,.text=0x10000 -check=%s %/T/test_ELF_N64R6.o %T/test_ELF_ExternalFunction_N64R6.o
-# RUN: llvm-mc -triple=mipsel-unknown-linux -mcpu=mips32r6 -code-model=small -filetype=obj -o %T/test_ELF_O32R6.o %s
+# RUN: llvm-mc -triple=mipsel-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_O32R6.o %s
# RUN: llc -mtriple=mipsel-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_ExternalFunction_O32R6.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mipsel-unknown-linux -mcpu=mips32r6 -verify -map-section test_ELF_O32R6.o,.text=0x1000 -map-section test_ELF_ExternalFunction_O32R6.o,.text=0x10000 -check=%s %/T/test_ELF_O32R6.o %T/test_ELF_ExternalFunction_O32R6.o
-# RUN: llvm-mc -triple=mips-unknown-linux -mcpu=mips32r6 -code-model=small -filetype=obj -o %T/test_ELF_O32R6.o %s
+# RUN: llvm-mc -triple=mips-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_O32R6.o %s
# RUN: llc -mtriple=mips-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_ExternalFunction_O32R6.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips-unknown-linux -mcpu=mips32r6 -verify -map-section test_ELF_O32R6.o,.text=0x1000 -map-section test_ELF_ExternalFunction_O32R6.o,.text=0x10000 -check=%s %/T/test_ELF_O32R6.o %T/test_ELF_ExternalFunction_O32R6.o
-# RUN: llvm-mc -triple=mipsel-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_O32.o %s
+# RUN: llvm-mc -triple=mipsel-unknown-linux -filetype=obj -o %T/test_ELF_O32.o %s
# RUN: llc -mtriple=mipsel-unknown-linux -filetype=obj -o %T/test_ELF_ExternalFunction_O32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mipsel-unknown-linux -verify -map-section test_ELF_O32.o,"<common symbols>"=0x7FF8 -map-section test_ELF_O32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_O32.o,.text=0x10000 -check=%s %T/test_ELF_O32.o %T/test_ELF_ExternalFunction_O32.o
-# RUN: llvm-mc -triple=mips-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_O32.o %s
+# RUN: llvm-mc -triple=mips-unknown-linux -filetype=obj -o %T/test_ELF_O32.o %s
# RUN: llc -mtriple=mips-unknown-linux -filetype=obj -o %/T/test_ELF_ExternalFunction_O32.o %S/Inputs/ExternalFunction.ll
# RUN: llvm-rtdyld -triple=mips-unknown-linux -verify -map-section test_ELF_O32.o,"<common symbols>"=0x7FF8 -map-section test_ELF_O32.o,.text=0x1000 -map-section test_ELF_ExternalFunction_O32.o,.text=0x10000 -check=%s %T/test_ELF_O32.o %T/test_ELF_ExternalFunction_O32.o
-# RUN: llvm-mc -triple=x86_64-unknown-freebsd -code-model=small -filetype=obj -o %T/testsmall_x86-64.o %s
+# RUN: llvm-mc -triple=x86_64-unknown-freebsd -filetype=obj -o %T/testsmall_x86-64.o %s
# RUN: llvm-rtdyld -triple=x86_64-unknown-freebsd -verify -check=%s %/T/testsmall_x86-64.o
.globl foo
-// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -code-model=large %s \
+// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -large-code-model %s \
// RUN: -o - | llvm-readobj -s -sd | FileCheck %s
// CHECK: Section {
MOFI.reset(new MCObjectFileInfo);
MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
- MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, *MC);
+ MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC);
MCTargetOptions Options;
MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "", Options);
MCObjectFileInfo MOFI;
MCContext MC(MAI.get(), MRI.get(), &MOFI);
- MOFI.InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, MC);
+ MOFI.InitMCObjectFileInfo(TheTriple, /*PIC*/ false, MC);
MCTargetOptions Options;
auto MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "", Options);
static cl::opt<bool> PIC("position-independent",
cl::desc("Position independent"), cl::init(false));
-static cl::opt<llvm::CodeModel::Model>
-CMModel("code-model",
- cl::desc("Choose code model"),
- cl::init(CodeModel::Default),
- cl::values(clEnumValN(CodeModel::Default, "default",
- "Target default code model"),
- clEnumValN(CodeModel::Small, "small",
- "Small code model"),
- clEnumValN(CodeModel::Kernel, "kernel",
- "Kernel code model"),
- clEnumValN(CodeModel::Medium, "medium",
- "Medium code model"),
- clEnumValN(CodeModel::Large, "large",
- "Large code model")));
+static cl::opt<bool>
+ LargeCodeModel("large-code-model",
+ cl::desc("Create cfi directives that assume the code might "
+ "be more than 2gb away"));
static cl::opt<bool>
NoInitialTextSection("n", cl::desc("Don't assume assembly file starts "
// MCObjectFileInfo needs a MCContext reference in order to initialize itself.
MCObjectFileInfo MOFI;
MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
- MOFI.InitMCObjectFileInfo(TheTriple, PIC, CMModel, Ctx);
+ MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel);
if (SaveTempLabels)
Ctx.setAllowTemporaryLabels(false);
MCObjectFileInfo MOFI;
MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
// FIXME: for now initialize MCObjectFileInfo with default values
- MOFI.InitMCObjectFileInfo(Triple(TripleName), false, CodeModel::Default, Ctx);
+ MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx);
std::unique_ptr<MCDisassembler> DisAsm(
TheTarget->createMCDisassembler(*STI, Ctx));
MOFI.reset(new MCObjectFileInfo);
MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
- MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, *MC);
+ MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC);
MCTargetOptions Options;
MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "", Options);