llvm.org GIT mirror llvm / fbb662f
Introduce llvm::sys::getProcessTriple() function. In r143502, we renamed getHostTriple() to getDefaultTargetTriple() as part of work to allow the user to supply a different default target triple at configure time. This change also affected the JIT. However, it is inappropriate to use the default target triple in the JIT in most circumstances because this will not necessarily match the current architecture used by the process, leading to illegal instruction and other such errors at run time. Introduce the getProcessTriple() function for use in the JIT and its clients, and cause the JIT to use it. On architectures with a single bitness, the host and process triples are identical. On other architectures, the host triple represents the architecture of the host CPU, while the process triple represents the architecture used by the host CPU to interpret machine code within the current process. For example, when executing 32-bit code on a 64-bit Linux machine, the host triple may be 'x86_64-unknown-linux-gnu', while the process triple may be 'i386-unknown-linux-gnu'. This fixes JIT for the 32-on-64-bit (and vice versa) build on non-Apple platforms. Differential Revision: http://llvm-reviews.chandlerc.com/D254 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172627 91177308-0d34-0410-b5e6-96231b3b80d8 Peter Collingbourne 7 years ago
68 changed file(s) with 95 addition(s) and 81 deletion(s). Raw diff Collapse all Expand all
132132
133133 # Triple for configuring build tools when cross-compiling
134134 BUILD_TRIPLE=@build@
135
136 # Target triple (cpu-vendor-os) which LLVM is compiled for
137 HOST_TRIPLE=@host@
135138
136139 # Target triple (cpu-vendor-os) for which we should generate code
137140 TARGET_TRIPLE=@target@
4141 /// CPU_TYPE-VENDOR-KERNEL-OPERATING_SYSTEM
4242 std::string getDefaultTargetTriple();
4343
44 /// getProcessTriple() - Return an appropriate target triple for generating
45 /// code to be loaded into the current process, e.g. when using the JIT.
46 std::string getProcessTriple();
47
4448 /// getHostCPUName - Get the LLVM name for the host CPU. The particular format
4549 /// of the name is target dependent, and suitable for passing as -mcpu to the
4650 /// target which matches the host.
3131 // must use the host architecture.
3232 if (UseMCJIT && WhichEngine != EngineKind::Interpreter && M)
3333 TT.setTriple(M->getTargetTriple());
34 else {
35 TT.setTriple(LLVM_HOSTTRIPLE);
36 #if defined(__APPLE__)
37 #if defined(__LP64__)
38 if (TT.isArch32Bit())
39 TT = TT.get64BitArchVariant();
40 #else
41 if (TT.isArch64Bit())
42 TT = TT.get32BitArchVariant();
43 #endif
44 #endif // APPLE
45 }
34
4635 return selectTarget(TT, MArch, MCPU, MAttrs);
4736 }
4837
5443 const SmallVectorImpl& MAttrs) {
5544 Triple TheTriple(TargetTriple);
5645 if (TheTriple.getTriple().empty())
57 TheTriple.setTriple(sys::getDefaultTargetTriple());
46 TheTriple.setTriple(sys::getProcessTriple());
5847
5948 // Adjust the triple to match what the user requested.
6049 const Target *TheTarget = 0;
1414 #include "llvm/ADT/SmallVector.h"
1515 #include "llvm/ADT/StringRef.h"
1616 #include "llvm/ADT/StringSwitch.h"
17 #include "llvm/ADT/Triple.h"
1718 #include "llvm/Config/config.h"
1819 #include "llvm/Support/DataStream.h"
1920 #include "llvm/Support/Debug.h"
577578 return false;
578579 }
579580 #endif
581
582 std::string sys::getProcessTriple() {
583 Triple PT(LLVM_HOSTTRIPLE);
584
585 if (sizeof(void *) == 8 && PT.isArch32Bit())
586 PT = PT.get64BitArchVariant();
587 if (sizeof(void *) == 4 && PT.isArch64Bit())
588 PT = PT.get32BitArchVariant();
589
590 return PT.str();
591 }
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 call i32 @mylog( i32 4 ) ; :1 [#uses=0]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 ;
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; We were accidentally inverting the signedness of right shifts. Whoops.
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 %X = fadd double 0.000000e+00, 1.000000e+00 ; [#uses=1]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s
2 ; RUN: not %lli_mcjit %s
33
44 @test = global i64 0 ; [#uses=1]
55
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s test
0 ; RUN: %lli_mcjit %s test
11
22 declare i32 @puts(i8*)
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 target datalayout = "e-p:32:32"
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; Testcase distilled from 256.bzip2.
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; Testcase distilled from 256.bzip2.
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ;
33 ; Regression Test: EnvironmentTest.ll
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 @A = global i32 0 ; [#uses=1]
33
0 ; PR672
1 ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s
1 ; RUN: %lli_mcjit %s
22 ; XFAIL: mcjit-ia32
33
44 define i32 @main() {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter %s
0 ; RUN: %lli_mcjit -force-interpreter %s
11 ; PR1836
22
33 define i32 @main() {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter=true %s | grep 1
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit -force-interpreter=true %s > /dev/null
0 ; RUN: %lli_mcjit -force-interpreter=true %s > /dev/null
11
22 define i32 @main() {
33 %a = add i32 0, undef
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -force-interpreter=true %s | grep 40091eb8
0 ; RUN: %lli_mcjit -force-interpreter=true %s | grep 40091eb8
11 ;
22 define i32 @test(double %x) {
33 entry:
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 -disable-lazy-compilation=false %s
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 ret i32 0
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit -remote-mcjit %s > /dev/null
11 ; XFAIL: arm, mips
22
33 define i32 @bar() {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @bar() {
33 ret i32 0
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit -disable-lazy-compilation=false %s
0 ; RUN: %lli_mcjit -remote-mcjit -disable-lazy-compilation=false %s
11 ; XFAIL: arm, mips
22
33 define i32 @main() nounwind {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -disable-lazy-compilation=false %s
0 ; RUN: %lli_mcjit -disable-lazy-compilation=false %s
11
22 define i32 @main() nounwind {
33 entry:
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 %A = add i8 0, 12 ; [#uses=1]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; test unconditional branch
33 define i32 @main() {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @_Z14func_exit_codev() nounwind uwtable {
33 entry:
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 declare void @exit(i32)
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @foo() {
33 ret i32 0
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 %s
0 ; RUN: %lli_mcjit -O0 %s
11
22 ; This test checks that common symbols have been allocated addresses honouring
33 ; the alignment requirement.
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit -O0 -disable-lazy-compilation=false %s
0 ; RUN: %lli_mcjit -remote-mcjit -O0 -disable-lazy-compilation=false %s
11 ; XFAIL: arm, mips
22
33 ; The intention of this test is to verify that symbols mapped to COMMON in ELF
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 -disable-lazy-compilation=false %s
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; This tests to make sure that we can evaluate weird constant expressions
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit -O0 %s
0 ; RUN: %lli_mcjit -remote-mcjit -O0 %s
11 ; XFAIL: arm, mips
22
33 ; Check that a variable is always aligned as specified.
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 %s
0 ; RUN: %lli_mcjit -O0 %s
11
22 ; Check that a variable is always aligned as specified.
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit -remote-mcjit %s > /dev/null
11 ; XFAIL: arm, mips
22
33 define double @test(double* %DP, double %Arg) {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define double @test(double* %DP, double %Arg) {
33 %D = load double* %DP ; [#uses=1]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define double @test(double* %DP, double %Arg) {
33 %D = load double* %DP ; [#uses=1]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11 @var = global i32 1, align 4
22 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @ctor_func }]
33 @llvm.global_dtors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @dtor_func }]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit -remote-mcjit %s > /dev/null
11 ; XFAIL: arm, mips
22
33 @count = global i32 1, align 4
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 @count = global i32 1, align 4
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 @count = global i32 0, align 4
33
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_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 -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() nounwind uwtable {
33 entry:
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 %A = and i8 4, 8 ; [#uses=2]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 ;
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; test phi node
33 @Y = global i32 6 ; [#uses=1]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -remote-mcjit -O0 %s
0 ; RUN: %lli_mcjit -remote-mcjit -O0 %s
11 ; XFAIL: arm, mips
22
33 @.str = private unnamed_addr constant [6 x i8] c"data1\00", align 1
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit -O0 %s
0 ; RUN: %lli_mcjit -O0 %s
11
22 @.str = private unnamed_addr constant [6 x i8] c"data1\00", align 1
33 @ptr = global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), align 4
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 ; test return instructions
33 define void @test1() {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() nounwind uwtable {
33 entry:
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22
33 define i32 @main() {
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 %int1 = add i32 0, 0 ; [#uses=6]
None ; RUN: %lli -mtriple=%mcjit_triple -use-mcjit %s > /dev/null
0 ; RUN: %lli_mcjit %s > /dev/null
11
22 define i32 @main() {
33 %shamt = add i8 0, 1 ; [#uses=8]
130130
131131 lit.site.cfg: FORCE
132132 @echo "Making LLVM 'lit.site.cfg' file..."
133 @$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g > lit.tmp
133 @$(ECHOPATH) s=@LLVM_HOSTTRIPLE@=$(HOST_TRIPLE)=g > lit.tmp
134 @$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g >> lit.tmp
134135 @$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g >> lit.tmp
135136 @$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp
136137 @$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> lit.tmp
139139
140140 ###
141141
142 # Provide a target triple for mcjit tests
143 mcjit_triple = config.target_triple
144 # Force ELF format on Windows
145 if re.search(r'cygwin|mingw32|win32', mcjit_triple):
146 mcjit_triple += "-elf"
147 config.substitutions.append( ('%mcjit_triple', mcjit_triple) )
142 # Provide a command line for mcjit tests
143 lli_mcjit = 'lli -use-mcjit'
144 # The target triple used by default by lli is the process target triple (some
145 # triple appropriate for generating code for the current process) but because
146 # we don't support COFF in MCJIT well enough for the tests, force ELF format on
147 # Windows. FIXME: the process target triple should be used here, but this is
148 # difficult to obtain on Windows.
149 if re.search(r'cygwin|mingw32|win32', config.host_triple):
150 lli_mcjit += ' -mtriple='+config.host_triple+'-elf'
151 config.substitutions.append( ('%lli_mcjit', lli_mcjit) )
148152
149153 # Provide a substition for those tests that need to run the jit to obtain data
150154 # but simply want use the currently considered most reliable jit for platform
0 ## Autogenerated by LLVM/Clang configuration.
11 # Do not edit!
2 config.host_triple = "@LLVM_HOSTTRIPLE@"
23 config.target_triple = "@TARGET_TRIPLE@"
34 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
45 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
136136 // Override the triple to generate ELF on Windows since that's supported
137137 Triple Tuple(TheModule->getTargetTriple());
138138 if (Tuple.getTriple().empty())
139 Tuple.setTriple(LLVM_HOSTTRIPLE);
139 Tuple.setTriple(sys::getProcessTriple());
140140
141141 if (Tuple.isOSWindows() && Triple::ELF != Tuple.getEnvironment()) {
142142 Tuple.setEnvironment(Triple::ELF);
5151 , MArch("")
5252 , Builder(Context)
5353 , MM(new SectionMemoryManager)
54 , HostTriple(LLVM_HOSTTRIPLE)
54 , HostTriple(sys::getProcessTriple())
5555 {
5656 InitializeNativeTarget();
5757 InitializeNativeTargetAsmPrinter();