llvm.org GIT mirror llvm / 2600a67
Don't pass the code model to MC 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 Rafael Espindola 2 years ago
17 changed file(s) with 41 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
190190 MCSection *SXDataSection;
191191
192192 public:
193 void InitMCObjectFileInfo(const Triple &TT, bool PIC, CodeModel::Model CM,
194 MCContext &ctx);
193 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
194 bool LargeCodeModel = false);
195195
196196 bool getSupportsWeakOmittedEHFrame() const {
197197 return SupportsWeakOmittedEHFrame;
349349 private:
350350 Environment Env;
351351 bool PositionIndependent;
352 CodeModel::Model CMModel;
353352 MCContext *Ctx;
354353 Triple TT;
355354
356355 void initMachOMCObjectFileInfo(const Triple &T);
357 void initELFMCObjectFileInfo(const Triple &T);
356 void initELFMCObjectFileInfo(const Triple &T, bool Large);
358357 void initCOFFMCObjectFileInfo(const Triple &T);
359358 void initWasmMCObjectFileInfo(const Triple &T);
360359
273273 TLSExtraDataSection = TLSTLVSection;
274274 }
275275
276 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T) {
276 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {
277277 switch (T.getArch()) {
278278 case Triple::mips:
279279 case Triple::mipsel:
285285 break;
286286 case Triple::x86_64:
287287 FDECFIEncoding = dwarf::DW_EH_PE_pcrel |
288 ((CMModel == CodeModel::Large) ? dwarf::DW_EH_PE_sdata8
289 : dwarf::DW_EH_PE_sdata4);
288 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
290289 break;
291290 case Triple::bpfel:
292291 case Triple::bpfeb:
323322 break;
324323 case Triple::x86_64:
325324 if (PositionIndependent) {
326 PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
328 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
325 PersonalityEncoding =
326 dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
327 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
329328 LSDAEncoding = dwarf::DW_EH_PE_pcrel |
330 (CMModel == CodeModel::Small
331 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
329 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
332330 TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel |
333 ((CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
334 ? dwarf::DW_EH_PE_sdata4 : dwarf::DW_EH_PE_sdata8);
331 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);
335332 } else {
336333 PersonalityEncoding =
337 (CMModel == CodeModel::Small || CMModel == CodeModel::Medium)
338 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
339 LSDAEncoding = (CMModel == CodeModel::Small)
340 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
341 TTypeEncoding = (CMModel == CodeModel::Small)
342 ? dwarf::DW_EH_PE_udata4 : dwarf::DW_EH_PE_absptr;
334 Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
335 LSDAEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
336 TTypeEncoding = Large ? dwarf::DW_EH_PE_absptr : dwarf::DW_EH_PE_udata4;
343337 }
344338 break;
345339 case Triple::hexagon:
848842 }
849843
850844 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC,
851 CodeModel::Model cm,
852 MCContext &ctx) {
845 MCContext &ctx,
846 bool LargeCodeModel) {
853847 PositionIndependent = PIC;
854 CMModel = cm;
855848 Ctx = &ctx;
856849
857850 // Common.
889882 break;
890883 case Triple::ELF:
891884 Env = IsELF;
892 initELFMCObjectFileInfo(TT);
885 initELFMCObjectFileInfo(TT, LargeCodeModel);
893886 break;
894887 case Triple::Wasm:
895888 Env = IsWasm;
174174
175175 MCObjectFileInfo MOFI;
176176 MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
177 MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, CodeModel::Default, MCCtx);
177 MOFI.InitMCObjectFileInfo(TT, /*PIC*/ false, MCCtx);
178178 RecordStreamer Streamer(MCCtx);
179179 T->createNullTargetStreamer(Streamer);
180180
4545 // `Initialize` can be called more than once.
4646 delete Mang;
4747 Mang = new Mangler();
48 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(),
49 TM.getCodeModel(), *Ctx);
48 InitMCObjectFileInfo(TM.getTargetTriple(), TM.isPositionIndependent(), *Ctx,
49 TM.getCodeModel() == CodeModel::Large);
5050 }
5151
5252 TargetLoweringObjectFile::~TargetLoweringObjectFile() {
None # RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -code-model=small -filetype=obj -o %T/foo.o %s
0 # RUN: llvm-mc -triple=arm64-apple-ios7.0.0 -filetype=obj -o %T/foo.o %s
11 # RUN: llvm-rtdyld -triple=arm64-apple-ios7.0.0 -map-section foo.o,__text=0x10bc0 -verify -check=%s %/T/foo.o
22
33 .section __TEXT,__text,regular,pure_instructions
None # RUN: llvm-mc -triple=mips64el-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_Mips64N64.o %s
0 # RUN: llvm-mc -triple=mips64el-unknown-linux -filetype=obj -o %T/test_ELF_Mips64N64.o %s
11 # RUN: llc -mtriple=mips64el-unknown-linux -filetype=obj -o %T/test_ELF_ExternalFunction_Mips64N64.o %S/Inputs/ExternalFunction.ll
22 # 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
33
4 # RUN: llvm-mc -triple=mips64-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_Mips64N64.o %s
4 # RUN: llvm-mc -triple=mips64-unknown-linux -filetype=obj -o %T/test_ELF_Mips64N64.o %s
55 # RUN: llc -mtriple=mips64-unknown-linux -filetype=obj -o %T/test_ELF_ExternalFunction_Mips64N64.o %S/Inputs/ExternalFunction.ll
66 # 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
77
None # RUN: llvm-mc -triple=mips64el-unknown-linux -target-abi n32 -code-model=small -filetype=obj -o %T/test_ELF_N32.o %s
0 # RUN: llvm-mc -triple=mips64el-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_N32.o %s
11 # RUN: llc -mtriple=mips64el-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_ExternalFunction_N32.o %S/Inputs/ExternalFunction.ll
22 # 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
33
4 # RUN: llvm-mc -triple=mips64-unknown-linux -target-abi n32 -code-model=small -filetype=obj -o %T/test_ELF_N32.o %s
4 # RUN: llvm-mc -triple=mips64-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_N32.o %s
55 # RUN: llc -mtriple=mips64-unknown-linux -target-abi n32 -filetype=obj -o %T/test_ELF_ExternalFunction_N32.o %S/Inputs/ExternalFunction.ll
66 # 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
77
None # RUN: llvm-mc -triple=mips64el-unknown-linux -mcpu=mips64r6 -code-model=small -filetype=obj -o %T/test_ELF_N64R6.o %s
0 # RUN: llvm-mc -triple=mips64el-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_N64R6.o %s
11 # RUN: llc -mtriple=mips64el-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_ExternalFunction_N64R6.o %S/Inputs/ExternalFunction.ll
22 # 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
33
4 # RUN: llvm-mc -triple=mips64-unknown-linux -mcpu=mips64r6 -code-model=small -filetype=obj -o %T/test_ELF_N64R6.o %s
4 # RUN: llvm-mc -triple=mips64-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_N64R6.o %s
55 # RUN: llc -mtriple=mips64-unknown-linux -mcpu=mips64r6 -filetype=obj -o %T/test_ELF_ExternalFunction_N64R6.o %S/Inputs/ExternalFunction.ll
66 # 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
77
None # RUN: llvm-mc -triple=mipsel-unknown-linux -mcpu=mips32r6 -code-model=small -filetype=obj -o %T/test_ELF_O32R6.o %s
0 # RUN: llvm-mc -triple=mipsel-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_O32R6.o %s
11 # RUN: llc -mtriple=mipsel-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_ExternalFunction_O32R6.o %S/Inputs/ExternalFunction.ll
22 # 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
33
4 # RUN: llvm-mc -triple=mips-unknown-linux -mcpu=mips32r6 -code-model=small -filetype=obj -o %T/test_ELF_O32R6.o %s
4 # RUN: llvm-mc -triple=mips-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_O32R6.o %s
55 # RUN: llc -mtriple=mips-unknown-linux -mcpu=mips32r6 -filetype=obj -o %T/test_ELF_ExternalFunction_O32R6.o %S/Inputs/ExternalFunction.ll
66 # 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
77
None # RUN: llvm-mc -triple=mipsel-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_O32.o %s
0 # RUN: llvm-mc -triple=mipsel-unknown-linux -filetype=obj -o %T/test_ELF_O32.o %s
11 # RUN: llc -mtriple=mipsel-unknown-linux -filetype=obj -o %T/test_ELF_ExternalFunction_O32.o %S/Inputs/ExternalFunction.ll
22 # RUN: llvm-rtdyld -triple=mipsel-unknown-linux -verify -map-section test_ELF_O32.o,""=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
33
4 # RUN: llvm-mc -triple=mips-unknown-linux -code-model=small -filetype=obj -o %T/test_ELF_O32.o %s
4 # RUN: llvm-mc -triple=mips-unknown-linux -filetype=obj -o %T/test_ELF_O32.o %s
55 # RUN: llc -mtriple=mips-unknown-linux -filetype=obj -o %/T/test_ELF_ExternalFunction_O32.o %S/Inputs/ExternalFunction.ll
66 # RUN: llvm-rtdyld -triple=mips-unknown-linux -verify -map-section test_ELF_O32.o,""=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
77
None # RUN: llvm-mc -triple=x86_64-unknown-freebsd -code-model=small -filetype=obj -o %T/testsmall_x86-64.o %s
0 # RUN: llvm-mc -triple=x86_64-unknown-freebsd -filetype=obj -o %T/testsmall_x86-64.o %s
11 # RUN: llvm-rtdyld -triple=x86_64-unknown-freebsd -verify -check=%s %/T/testsmall_x86-64.o
22
33 .globl foo
None // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -code-model=large %s \
0 // RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu -large-code-model %s \
11 // RUN: -o - | llvm-readobj -s -sd | FileCheck %s
22
33 // CHECK: Section {
590590
591591 MOFI.reset(new MCObjectFileInfo);
592592 MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
593 MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, *MC);
593 MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC);
594594
595595 MCTargetOptions Options;
596596 MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "", Options);
641641
642642 MCObjectFileInfo MOFI;
643643 MCContext MC(MAI.get(), MRI.get(), &MOFI);
644 MOFI.InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, MC);
644 MOFI.InitMCObjectFileInfo(TheTriple, /*PIC*/ false, MC);
645645
646646 MCTargetOptions Options;
647647 auto MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "", Options);
130130 static cl::opt PIC("position-independent",
131131 cl::desc("Position independent"), cl::init(false));
132132
133 static cl::opt
134 CMModel("code-model",
135 cl::desc("Choose code model"),
136 cl::init(CodeModel::Default),
137 cl::values(clEnumValN(CodeModel::Default, "default",
138 "Target default code model"),
139 clEnumValN(CodeModel::Small, "small",
140 "Small code model"),
141 clEnumValN(CodeModel::Kernel, "kernel",
142 "Kernel code model"),
143 clEnumValN(CodeModel::Medium, "medium",
144 "Medium code model"),
145 clEnumValN(CodeModel::Large, "large",
146 "Large code model")));
133 static cl::opt
134 LargeCodeModel("large-code-model",
135 cl::desc("Create cfi directives that assume the code might "
136 "be more than 2gb away"));
147137
148138 static cl::opt
149139 NoInitialTextSection("n", cl::desc("Don't assume assembly file starts "
505495 // MCObjectFileInfo needs a MCContext reference in order to initialize itself.
506496 MCObjectFileInfo MOFI;
507497 MCContext Ctx(MAI.get(), MRI.get(), &MOFI, &SrcMgr);
508 MOFI.InitMCObjectFileInfo(TheTriple, PIC, CMModel, Ctx);
498 MOFI.InitMCObjectFileInfo(TheTriple, PIC, Ctx, LargeCodeModel);
509499
510500 if (SaveTempLabels)
511501 Ctx.setAllowTemporaryLabels(false);
12221222 MCObjectFileInfo MOFI;
12231223 MCContext Ctx(AsmInfo.get(), MRI.get(), &MOFI);
12241224 // FIXME: for now initialize MCObjectFileInfo with default values
1225 MOFI.InitMCObjectFileInfo(Triple(TripleName), false, CodeModel::Default, Ctx);
1225 MOFI.InitMCObjectFileInfo(Triple(TripleName), false, Ctx);
12261226
12271227 std::unique_ptr DisAsm(
12281228 TheTarget->createMCDisassembler(*STI, Ctx));
152152
153153 MOFI.reset(new MCObjectFileInfo);
154154 MC.reset(new MCContext(MAI.get(), MRI.get(), MOFI.get()));
155 MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, CodeModel::Default, *MC);
155 MOFI->InitMCObjectFileInfo(TheTriple, /*PIC*/ false, *MC);
156156
157157 MCTargetOptions Options;
158158 MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, "", Options);