llvm.org GIT mirror llvm / 7bbd6e3
Support for generating ELF objects on Windows. This adds 'elf' as a recognized target triple environment value and overrides the default generated object format on Windows platforms if that value is present. This patch also enables MCJIT tests on Windows using the new environment value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165030 91177308-0d34-0410-b5e6-96231b3b80d8 Andrew Kaylor 6 years ago
57 changed file(s) with 84 addition(s) and 59 deletion(s). Raw diff Collapse all Expand all
110110 GNUEABIHF,
111111 EABI,
112112 MachO,
113 Android
113 Android,
114 ELF
114115 };
115116
116117 private:
2525 using namespace llvm;
2626
2727 TargetMachine *EngineBuilder::selectTarget() {
28 Triple TT(LLVM_HOSTTRIPLE);
28 Triple TT;
29
30 // MCJIT can generate code for remote targets, but the old JIT and Interpreter
31 // must use the host architecture.
32 if (UseMCJIT && WhichEngine != EngineKind::Interpreter && M)
33 TT.setTriple(M->getTargetTriple());
34 else
35 TT.setTriple(LLVM_HOSTTRIPLE);
2936 return selectTarget(TT, MArch, MCPU, MAttrs);
3037 }
3138
564564 Env = IsMachO;
565565 InitMachOMCObjectFileInfo(T);
566566 } else if ((Arch == Triple::x86 || Arch == Triple::x86_64) &&
567 (T.getEnvironment() != Triple::ELF) &&
567568 (T.getOS() == Triple::MinGW32 || T.getOS() == Triple::Cygwin ||
568569 T.getOS() == Triple::Win32)) {
569570 Env = IsCOFF;
141141 case EABI: return "eabi";
142142 case MachO: return "macho";
143143 case Android: return "android";
144 case ELF: return "elf";
144145 }
145146
146147 llvm_unreachable("Invalid EnvironmentType!");
313314 .StartsWith("gnu", Triple::GNU)
314315 .StartsWith("macho", Triple::MachO)
315316 .StartsWith("android", Triple::Android)
317 .StartsWith("elf", Triple::ELF)
316318 .Default(Triple::UnknownEnvironment);
317319 }
318320
452452 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO)
453453 return new DarwinX86_32AsmBackend(T, CPU);
454454
455 if (TheTriple.isOSWindows())
455 if (TheTriple.isOSWindows() && TheTriple.getEnvironment() != Triple::ELF)
456456 return new WindowsX86AsmBackend(T, false, CPU);
457457
458458 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
465465 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO)
466466 return new DarwinX86_64AsmBackend(T, CPU);
467467
468 if (TheTriple.isOSWindows())
468 if (TheTriple.isOSWindows() && TheTriple.getEnvironment() != Triple::ELF)
469469 return new WindowsX86AsmBackend(T, true, CPU);
470470
471471 uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());
383383 MAI = new X86_64MCAsmInfoDarwin(TheTriple);
384384 else
385385 MAI = new X86MCAsmInfoDarwin(TheTriple);
386 } else if (TheTriple.getEnvironment() == Triple::ELF) {
387 // Force the use of an ELF container.
388 MAI = new X86ELFMCAsmInfo(TheTriple);
386389 } else if (TheTriple.getOS() == Triple::Win32) {
387390 MAI = new X86MCAsmInfoMicrosoft(TheTriple);
388391 } else if (TheTriple.getOS() == Triple::MinGW32 || TheTriple.getOS() == Triple::Cygwin) {
389392 MAI = new X86MCAsmInfoGNUCOFF(TheTriple);
390393 } else {
394 // The default is ELF.
391395 MAI = new X86ELFMCAsmInfo(TheTriple);
392396 }
393397
469473 if (TheTriple.isOSDarwin() || TheTriple.getEnvironment() == Triple::MachO)
470474 return createMachOStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll);
471475
472 if (TheTriple.isOSWindows())
476 if (TheTriple.isOSWindows() && TheTriple.getEnvironment() != Triple::ELF)
473477 return createWinCOFFStreamer(Ctx, MAB, *_Emitter, _OS, RelaxAll);
474478
475479 return createELFStreamer(Ctx, MAB, _OS, _Emitter, RelaxAll, NoExecStack);
236236 bool isTargetSolaris() const {
237237 return TargetTriple.getOS() == Triple::Solaris;
238238 }
239
240 // ELF is a reasonably sane default and the only other X86 targets we
241 // support are Darwin and Windows. Just use "not those".
242 bool isTargetELF() const { return TargetTriple.isOSBinFormatELF(); }
239 bool isTargetELF() const {
240 return (TargetTriple.getEnvironment() == Triple::ELF ||
241 TargetTriple.isOSBinFormatELF());
242 }
243243 bool isTargetLinux() const { return TargetTriple.getOS() == Triple::Linux; }
244244 bool isTargetNaCl() const {
245245 return TargetTriple.getOS() == Triple::NativeClient;
250250 bool isTargetMingw() const { return TargetTriple.getOS() == Triple::MinGW32; }
251251 bool isTargetCygwin() const { return TargetTriple.getOS() == Triple::Cygwin; }
252252 bool isTargetCygMing() const { return TargetTriple.isOSCygMing(); }
253 bool isTargetCOFF() const { return TargetTriple.isOSBinFormatCOFF(); }
253 bool isTargetCOFF() const {
254 return (TargetTriple.getEnvironment() != Triple::ELF &&
255 TargetTriple.isOSBinFormatCOFF());
256 }
254257 bool isTargetEnvMacho() const { return TargetTriple.isEnvironmentMachO(); }
255258
256259 bool isTargetWin64() const {
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 @.LC0 = internal global [10 x i8] c"argc: %d\0A\00" ; <[10 x i8]*> [#uses=1]
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @foo(i32 %X, i32 %Y, double %A) {
33 %cond212 = fcmp une double %A, 1.000000e+00 ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 call i32 @mylog( i32 4 ) ; :1 [#uses=0]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 ;
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; We were accidentally inverting the signedness of right shifts. Whoops.
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 %X = fadd double 0.000000e+00, 1.000000e+00 ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @bar(i8* %X) {
33 ; pointer should be 4 byte aligned!
0 ; This testcase should return with an exit code of 1.
11 ;
2 ; RUN: not %lli -use-mcjit %s
2 ; RUN: not %lli -mtriple=%mcjit_triple -use-mcjit %s
33
44 @test = global i64 0 ; [#uses=1]
55
None ; RUN: %lli -use-mcjit %s test
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s test
11
22 declare i32 @puts(i8*)
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 target datalayout = "e-p:32:32"
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; Testcase distilled from 256.bzip2.
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; Testcase distilled from 256.bzip2.
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; This testcase failed to work because two variable sized allocas confused the
33 ; local register allocator.
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ;
33 ; Regression Test: EnvironmentTest.ll
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; This testcase exposes a bug in the local register allocator where it runs out
33 ; of registers (due to too many overlapping live ranges), but then attempts to
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 @A = global i32 0 ; [#uses=1]
33
0 ; PR672
1 ; RUN: %lli -use-mcjit %s
1 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s
22 ; XFAIL: mcjit-ia32
33
44 define i32 @main() {
None ; RUN: %lli -use-mcjit -force-interpreter %s
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter %s
11 ; PR1836
22
33 define i32 @main() {
None ; RUN: %lli -use-mcjit -force-interpreter=true %s | grep 1
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter=true %s | grep 1
11
22 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:32:32"
33 target triple = "i686-pc-linux-gnu"
None ; RUN: %lli -use-mcjit -force-interpreter=true %s
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter=true %s > /dev/null
11
22 define i32 @main() {
33 %a = add i32 0, undef
None ; RUN: %lli -use-mcjit -force-interpreter=true %s | grep 40091eb8
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter=true %s | grep 40091eb8
11 ;
22 define i32 @test(double %x) {
33 entry:
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 @.LC0 = internal global [12 x i8] c"Hello World\00" ; <[12 x i8]*> [#uses=1]
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 @X = global i32 7 ; [#uses=0]
33 @msg = internal global [13 x i8] c"Hello World\0A\00" ; <[13 x i8]*> [#uses=1]
1515 if root.host_arch not in ['x86', 'x86_64', 'ARM', 'Mips']:
1616 config.unsupported = True
1717
18 if root.host_os in ['Win32', 'Cygwin', 'MingW', 'Windows', 'Darwin']:
18 if root.host_os in ['Cygwin', 'MingW', 'Darwin']:
1919 config.unsupported = True
None ; RUN: %lli -use-mcjit -O0 -disable-lazy-compilation=false %s
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 -disable-lazy-compilation=false %s
11
22 ; The intention of this test is to verify that symbols mapped to COMMON in ELF
33 ; work as expected.
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 ret i32 0
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @bar() {
33 ret i32 0
None ; RUN: %lli -use-mcjit -disable-lazy-compilation=false %s
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -disable-lazy-compilation=false %s
11
22 define i32 @main() nounwind {
33 entry:
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 %A = add i8 0, 12 ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; test unconditional branch
33 define i32 @main() {
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @_Z14func_exit_codev() nounwind uwtable {
33 entry:
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 declare void @exit(i32)
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @foo() {
33 ret i32 0
None ; RUN: %lli -use-mcjit -O0 -disable-lazy-compilation=false %s
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 -disable-lazy-compilation=false %s
11
22 ; The intention of this test is to verify that symbols mapped to COMMON in ELF
33 ; work as expected.
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; This tests to make sure that we can evaluate weird constant expressions
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define double @test(double* %DP, double %Arg) {
33 %D = load double* %DP ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define double @test(double* %DP, double %Arg) {
33 %D = load double* %DP ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 @count = global i32 1, align 4
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 @count = global i32 0, align 4
33
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define void @test(i8* %P, i16* %P.upgrd.1, i32* %P.upgrd.2, i64* %P.upgrd.3) {
33 %V = load i8* %P ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() nounwind uwtable {
33 entry:
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 %A = and i8 4, 8 ; [#uses=2]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 ;
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; test phi node
33 @Y = global i32 6 ; [#uses=1]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 ; test return instructions
33 define void @test1() {
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() nounwind uwtable {
33 entry:
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22
33 define i32 @main() {
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 %int1 = add i32 0, 0 ; [#uses=6]
None ; RUN: %lli -use-mcjit %s > /dev/null
0 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
11
22 define i32 @main() {
33 %shamt = add i8 0, 1 ; [#uses=8]
137137 raise SystemExit
138138
139139 ###
140
141 # Provide a target triple for mcjit tests
142 mcjit_triple = config.target_triple
143 # Force ELF format on Windows
144 if 'win32' in mcjit_triple.lower():
145 mcjit_triple += "-elf"
146 config.substitutions.append( ('%mcjit_triple', mcjit_triple) )
140147
141148 # When running under valgrind, we mangle '-vg' or '-vg_leak' onto the end of the
142149 # triple so we can check it with XFAIL and XTARGET.