Open Quuxplusone opened 7 years ago
Bugzilla Link | PR34268 |
Status | NEW |
Importance | P normal |
Reported by | AlexDenisov (1101.debian@gmail.com) |
Reported on | 2017-08-21 14:18:50 -0700 |
Last modified on | 2020-11-29 13:30:38 -0800 |
Version | 4.0 |
Hardware | Macintosh Linux |
CC | 1101.debian@gmail.com, dblaikie@gmail.com, glaubitz@physik.fu-berlin.de, harald@gigawatt.nl, lhames@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@ndave.org, llvm-dev@redking.me.uk, stefan.graenitz@gmail.com |
Fixed by commit(s) | |
Attachments | |
Blocks | |
Blocked by | |
See also | PR36743 |
CC'ing Lang Hames, jfyi.
Looks like this may be the same bug as http://llvm.org/PR36743. If so, it is not JIT specific, but even if it were fixed it is possible we would need to do some work to support the X32 ABI in ORC.
Recommended workaround: build LLVM and Orc for x32:
cmake -DLLVM_BUILD_32_BITS=On path-to-llvm-sources
I think this needs some clarification. PR36743 states that: "-fno-plt -mx32" at
any optimization level higher than -O0 will break at isel
In this report neither -fno-plt nor -Ox are involved. It's about -m32 and not -
mx32. While I don't know much about their difference, I see:
$ bin/clang --version
clang version 9.0.0 (https://github.com/llvm/llvm-project.git
51dc59d0903fc86b37e9d910aa6f33dd87fdaae5)
Target: x86_64-apple-darwin18.5.0
Thread model: posix
$ cat main.c
int square(int x) { return x * x; }
int main(int argc, char **argv) { return square(argc); }
$ bin/clang -m32 main.c -o main-m32
$ ./main-m32
$ echo $?
1
$ bin/clang -m32 -mx32 main.c -o main-m32
$ ./main-m32
$ echo $?
1
$ bin/clang -c -emit-llvm -m32 main.c -o - | bin/lli
Illegal instruction: 4
$ bin/clang -c -emit-llvm -m32 -mx32 main.c -o - | bin/lli
$ echo $?
1
This means passing -m32 and avoiding the -mx32 flag causes clang to emit
bitcode that lli doesn't interpret correctly.
How the failure manifests depends on the JIT engine:
$ bin/clang -c -emit-llvm -m32 main.c -o - | bin/lli -jit-kind=orc-lazy
Segmentation fault: 11
$ bin/clang -c -emit-llvm -m32 main.c -o - | bin/lli -jit-kind=orc-mcjit
Illegal instruction: 4
In fact I can reproduce the instruction selection issue (only) with an
incompatible target (I couldn't link that statically either):
$ bin/clang -c -emit-llvm -mx32 --target=i386-apple-darwin main.c -o - | bin/lli
$ echo $?
1
$ bin/clang -c -emit-llvm -mx32 --target=i386-unknown-unknown main.c -o - |
bin/lli
LLVM ERROR: Cannot select: t9: ch,glue = X86ISD::CALL t7, t17, Register:i32
$edi, RegisterMask:Untyped, t7:1
t17: i32 = X86ISD::Wrapper TargetGlobalAddress:i32<i32 (i32)* @square> 0
t16: i32 = TargetGlobalAddress<i32 (i32)* @square> 0
t6: i32 = Register $edi
t8: Untyped = RegisterMask
t7: ch,glue = CopyToReg t5, Register:i32 $edi, t3
t6: i32 = Register $edi
t3: i32,ch = CopyFromReg t0, Register:i32 %5
t2: i32 = Register %5
In function: main
So either I am missing something, or the situation changed entirely since the
report, or there was some other factor that we didn't consider.