Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-14186] swiftc doesn't work under qemu-x86-64 emulation #56564

Closed
weissi opened this issue Feb 10, 2021 · 11 comments
Closed

[SR-14186] swiftc doesn't work under qemu-x86-64 emulation #56564

weissi opened this issue Feb 10, 2021 · 11 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@weissi
Copy link
Member

weissi commented Feb 10, 2021

Previous ID SR-14186
Radar rdar://problem/74204160
Original Reporter @weissi
Type Bug
Status Closed
Resolution Done
Additional Detail from JIRA
Votes 1
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 2010a8bbf8ef17bc2b4c8edbd4aa7eca

Issue Description:

When running the swift:5.3 docker image which is only available for x86-64 on the M1 Docker for Mac, swiftc crashes immediately.

Run docker on an M1 Mac as

docker run -it --rm --privileged  --platform linux/amd64 swift:5.3

then in the container, run swiftc

root@28b80e055bda:/# swiftc
Stack dump:
0.  Program arguments: /usr/bin/swiftc 
1.  Swift version 5.3.3 (swift-5.3.3-RELEASE)
/usr/bin/swiftc[0x51fa1c4]
/usr/bin/swiftc[0x51f7dbe]
/usr/bin/swiftc[0x51fa49c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12980)[0x4000a45980]
/usr/bin/swiftc[0x192e333]
/usr/bin/swiftc[0x192735f]
/usr/bin/swiftc[0x4e9956]
/usr/bin/swiftc[0x4e8ce8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x4002247bf7]
/usr/bin/swiftc[0x4e888a]
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction

symbolised, this roughly is

root@ea74002d281c:/# swiftc 2>&1 | cut -d '[' -f2 | addr2line -e /usr/bin/swiftc -f -p -a | c++filt
0x0000000000000000: ?? ??:0
0x0000000000000000: ?? ??:0
0x0000000000000001: ?? ??:0
0x00000000051fa1c4: PrintStackTraceSignalHandler(void*) at Signals.cpp:?
0x00000000051f7dbe: llvm::sys::RunSignalHandlers() at ??:?
0x00000000051fa49c: SignalHandler(int) at Signals.cpp:?
0x0000004000a45980: ?? ??:0
0x000000000192e333: std::vector<swift::DiagnosticState::Behavior, std::allocator<swift::DiagnosticState::Behavior> >::_M_fill_insert(__gnu_cxx::__normal_iterator<swift::DiagnosticState::Behavior*, std::vector<swift::DiagnosticState::Behavior, std::allocator<swift::DiagnosticState::Behavior> > >, unsigned long, swift::DiagnosticState::Behavior const&) at ??:?
0x000000000192735f: swift::DiagnosticState::DiagnosticState() at ??:?
0x00000000004e9956: run_driver(llvm::StringRef, llvm::ArrayRef<char const*>) at driver.cpp:?
0x00000000004e8ce8: main at ??:?
0x0000004002247bf7: ?? ??:0
0x00000000004e888a: _start at ??:?
0x0000000000000000: ?? ??:0
@weissi
Copy link
Member Author

weissi commented Feb 10, 2021

@swift-ci create

@weissi
Copy link
Member Author

weissi commented Feb 13, 2021

qemu's strace says

root@d8b253e9d4d0:/# chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo -strace /swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swiftc -c  /tmp//test.swift
4608 brk(NULL) = 0x0000000007f56000
4608 uname(0x40008002d0) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 access("/etc/ld.so.preload",R_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3
4608 fstat(3,0x00000040007ffcb0) = 0
4608 mmap(NULL,25776,PROT_READ,MAP_PRIVATE,3,0) = 0x0000004000a2f000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libpthread.so.0",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffe78,832) = 832
4608 fstat(3,0x00000040007ffd10) = 0
4608 mmap(NULL,2221184,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004000a36000
4608 mprotect(0x0000004000a50000,2093056,PROT_NONE) = 0
4608 mmap(0x0000004000c4f000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x19000) = 0x0000004000c4f000
4608 mmap(0x0000004000c51000,13440,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x0000004000c51000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libdl.so.2",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffe48,832) = 832
4608 fstat(3,0x00000040007ffce0) = 0
4608 mmap(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x0000004000c55000
4608 mmap(NULL,2109712,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004000c57000
4608 mprotect(0x0000004000c5a000,2093056,PROT_NONE) = 0
4608 mmap(0x0000004000e59000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x2000) = 0x0000004000e59000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/usr/lib/x86_64-linux-gnu/libedit.so.2",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffe18,832) = 832
4608 fstat(3,0x00000040007ffcb0) = 0
4608 mmap(NULL,2318400,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004000e5b000
4608 mprotect(0x0000004000e8c000,2093056,PROT_NONE) = 0
4608 mmap(0x000000400108b000,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x30000) = 0x000000400108b000
4608 mmap(0x000000400108e000,12352,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x000000400108e000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libuuid.so.1",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffde8,832) = 832
4608 fstat(3,0x00000040007ffc80) = 0
4608 mmap(NULL,2122112,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004001092000
4608 mprotect(0x0000004001098000,2093056,PROT_NONE) = 0
4608 mmap(0x0000004001297000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x5000) = 0x0000004001297000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libz.so.1",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffdb8,832) = 832
4608 fstat(3,0x00000040007ffc50) = 0
4608 mmap(NULL,2212016,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004001299000
4608 mprotect(0x00000040012b5000,2093056,PROT_NONE) = 0
4608 mmap(0x00000040014b4000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x1b000) = 0x00000040014b4000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/librt.so.1",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffd88,832) = 832
4608 fstat(3,0x00000040007ffc20) = 0
4608 mmap(NULL,2128864,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x00000040014b6000
4608 mprotect(0x00000040014bd000,2093056,PROT_NONE) = 0
4608 mmap(0x00000040016bc000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x6000) = 0x00000040016bc000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libtinfo.so.5",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffd58,832) = 832
4608 fstat(3,0x00000040007ffbf0) = 0
4608 mmap(NULL,2267936,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x00000040016be000
4608 mprotect(0x00000040016e3000,2097152,PROT_NONE) = 0
4608 mmap(0x00000040018e3000,20480,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x25000) = 0x00000040018e3000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libm.so.6",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffd28,832) = 832
4608 fstat(3,0x00000040007ffbc0) = 0
4608 mmap(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x00000040018e8000
4608 mmap(NULL,3789144,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x00000040018ea000
4608 mprotect(0x0000004001a87000,2093056,PROT_NONE) = 0
4608 mmap(0x0000004001c86000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x19c000) = 0x0000004001c86000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/usr/lib/x86_64-linux-gnu/libstdc++.so.6",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffcf8,832) = 832
4608 fstat(3,0x00000040007ffb90) = 0
4608 mmap(NULL,3702848,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004001c88000
4608 mprotect(0x0000004001e01000,2097152,PROT_NONE) = 0
4608 mmap(0x0000004002001000,49152,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x179000) = 0x0000004002001000
4608 mmap(0x000000400200d000,12352,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x000000400200d000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libgcc_s.so.1",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffcc8,832) = 832
4608 fstat(3,0x00000040007ffb60) = 0
4608 mmap(NULL,2192432,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004002011000
4608 mprotect(0x0000004002028000,2093056,PROT_NONE) = 0
4608 mmap(0x0000004002227000,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x16000) = 0x0000004002227000
4608 close(3) = 0
4608 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or directory)
4608 openat(-100,"/lib/x86_64-linux-gnu/libc.so.6",O_RDONLY|O_CLOEXEC) = 3
4608 read(3,0x7ffc98,832) = 832
4608 fstat(3,0x00000040007ffb30) = 0
4608 mmap(NULL,4131552,PROT_EXEC|PROT_READ,MAP_PRIVATE|MAP_DENYWRITE,3,0) = 0x0000004002229000
4608 mprotect(0x0000004002410000,2097152,PROT_NONE) = 0
4608 mmap(0x0000004002610000,24576,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_DENYWRITE|MAP_FIXED,3,0x1e7000) = 0x0000004002610000
4608 mmap(0x0000004002616000,15072,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED,-1,0) = 0x0000004002616000
4608 close(3) = 0
4608 mmap(NULL,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x000000400261a000
4608 mmap(NULL,12288,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0) = 0x000000400261c000
4608 arch_prctl(4098,274917867136,274917869472,34,4294967295,0) = 0
4608 mprotect(0x0000004002610000,16384,PROT_READ) = 0
4608 mprotect(0x0000004002227000,4096,PROT_READ) = 0
4608 mprotect(0x0000004001c86000,4096,PROT_READ) = 0
4608 mprotect(0x0000004002001000,40960,PROT_READ) = 0
4608 mprotect(0x00000040018e3000,16384,PROT_READ) = 0
4608 mprotect(0x0000004000c4f000,4096,PROT_READ) = 0
4608 mprotect(0x00000040016bc000,4096,PROT_READ) = 0
4608 mprotect(0x00000040014b4000,4096,PROT_READ) = 0
4608 mprotect(0x0000004001297000,4096,PROT_READ) = 0
4608 mprotect(0x000000400108b000,8192,PROT_READ) = 0
4608 mprotect(0x0000004000e59000,4096,PROT_READ) = 0
4608 mprotect(0x000000000793f000,5775360,PROT_READ) = 0
4608 mprotect(0x0000004000a2a000,4096,PROT_READ) = 0
4608 munmap(0x0000004000a2f000,25776) = 0
4608 set_tid_address(274917867856,274886297480,274917867136,274888571376,0,192) = 4608
4608 set_robust_list(274917867872,24,274917867136,274888571376,0,192) = -1 errno=38 (Function not implemented)
4608 rt_sigaction(32,0x00000040008004f0,NULL) = 0
4608 rt_sigaction(33,0x00000040008004f0,NULL) = -1 errno=22 (Invalid argument)
4608 rt_sigprocmask(SIG_UNBLOCK,0x0000004000800668,NULL) = 0
4608 prlimit64(0,3,0,274886297168,0,192) = 0
4608 brk(NULL) = 0x0000000007f56000
4608 brk(0x0000000007f77000) = 0x0000000007f77000
4608 futex(0x0000000007f53eb8,FUTEX_PRIVATE_FLAG|FUTEX_WAKE,2147483647,NULL,0x00000000000000ca,202) = 0
4608 futex(0x000000400200e09c,FUTEX_PRIVATE_FLAG|FUTEX_WAKE,2147483647,NULL,0x00000000000000ca,202) = 0
4608 futex(0x000000400200e0a8,FUTEX_PRIVATE_FLAG|FUTEX_WAKE,2147483647,NULL,0x00000000000000ca,202) = 0
4608 brk(0x0000000007f98000) = 0x0000000007f98000
4608 sigaltstack((nil),0x7f550c0) = 0
4608 brk(0x0000000007fc9000) = 0x0000000007fc9000
4608 sigaltstack(0x40007ff150,0x7f550c0) = 0
4608 rt_sigaction(SIGHUP,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGINT,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGTERM,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGUSR2,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGILL,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(5,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGABRT,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGFPE,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(7,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGSEGV,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGQUIT,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(31,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(24,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(25,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 rt_sigaction(SIGUSR1,0x00000040007ff000,0x00000040007ff0a0) = 0
4608 access("/proc/self/exe",F_OK) = 0
4608 readlink("/proc/self/exe",0x00000040007fc860,4096) = 46
4608 lstat("/swift-5.3.3-RELEASE-ubuntu18.04",0x00000040007fb6e0) = 0
4608 lstat("/swift-5.3.3-RELEASE-ubuntu18.04/usr",0x00000040007fb6e0) = 0
4608 lstat("/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin",0x00000040007fb6e0) = 0
4608 lstat("/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift",0x00000040007fb6e0) = 0
4608 lseek(2,0,1,13,3831846841167082287,5495889274361230126) = -1 errno=29 (Illegal seek)
4608 clock_gettime(0,274886286944,133861712,13,0,274915225808) = 0
4608 access("/tmp//test.swift",F_OK) = 0
4608 ioctl(2,21505,274886284112,13,274886284176,133894640) = 0
4608 stat("/root/.terminfo",0x0000000007fb29f0) = -1 errno=2 (No such file or directory)
4608 stat("/etc/terminfo",0x0000000007fb29f0) = 0
4608 stat("/lib/terminfo",0x0000000007fb2a80) = 0
4608 stat("/usr/share/terminfo",0x0000000007fb2b10) = 0
4608 time(0,133900720,111,3021841,0,1) = 1613244907
4608 access("/etc/terminfo/x/xterm",R_OK) = -1 errno=2 (No such file or directory)
4608 access("/lib/terminfo/x/xterm",R_OK) = 0
4608 openat(-100,"/lib/terminfo/x/xterm",O_RDONLY) = 3
4608 fstat(3,0x00000040007fa140) = 0
4608 read(3,0x7fa2a0,4096) = 3455
4608 read(3,0x7fb2f90,4096) = 0
4608 close(3) = 0
4608 time(0,133521688,274901849255,413,274917867136,38) = 1613244907
4608 ioctl(2,21505,274886284064,-1603,274886284128,7593743402633359973) = 0
4608 ioctl(2,21505,274886284096,-1603,133900444,7593743402633359973) = 0
4608 ioctl(2,21505,274886284112,-1603,133900504,7593743402633359973) = 0
4608 ioctl(2,21505,274886283952,-1603,274886284016,7593743402633359973) = 0
4608 ioctl(2,21523,274886284144,-1603,274886284016,7593743402633359973) = 0
4608 prlimit64(0,3,0,274886284736,2,274915225880) = 0
4608 execve("/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift",{"/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift","-frontend","-c","-primary-file","/tmp//test.swift","-target","x86_64-unknown-linux-gnu","-disable-objc-interop","-color-diagnostics","-module-name","test","-o","test.o",NULL})Stack dump:
0.  Program arguments: /swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift -frontend -c -primary-file /tmp//test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name test -o test.o 
1.  Swift version 5.3.3 (swift-5.3.3-RELEASE)
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x51fa1c4]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x51f7dbe]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x51fa49c]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x12980)[0x4000a48980]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x192e333]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x192735f]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x6b0384]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x55e3ad]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x4e8ce8]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x400224abf7]
/swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift[0x4e888a]
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction

but weirdly, if I just run the step that allegedly failed, it works:

chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo  /swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swift -frontend -c -primary-file /tmp//test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name test -o /tmp/test-1ef85c.o

finishes without an error and produces /tmp/test-1ef85c.o.

More interestingly, if I link that myself using

chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo  /swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/clang -o /tmp/test -lswiftCore  -L /swift-5.3.3-RELEASE-ubuntu18.04/usr/lib/swift/linux -L /amd64/swift-5.3.3-RELEASE-ubuntu18.04/usr/lib/swift/linux/x86_64/ -lswiftSwiftOnoneSupport /tmp/test-1ef85c.o

that works and produces /tmp/test which I can also execute:

root@d8b253e9d4d0:/# chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo /bin/bash -c 'LD_LIBRARY_PATH=/swift-5.3.3-RELEASE-ubuntu18.04/usr/lib/swift/linux  /tmp/test'
hello world

@weissi
Copy link
Member Author

weissi commented Feb 15, 2021

Same with the latest main snapshots. If run manually, the compiler invocations actually work but when run through the Swift driver, they don't. I now installed llvm in the emulated x86 which includes llvm-symbolizer so we actually get symbols:

root@d8b253e9d4d0:/# chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo  /swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swiftc  /tmp//test.swift
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend -frontend -c -primary-file /tmp//test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name test -o /tmp/test-d8e021.o
1.  Swift version 5.4-dev (LLVM 1e4181b99f530d2, Swift 842cc9c88f5463b)
 #&#8203;0 0x0000000005cb5c13 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x5cb5c13)
 #&#8203;1 0x0000000005cb396e llvm::sys::RunSignalHandlers() (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x5cb396e)
 #&#8203;2 0x0000000005cb5f9c SignalHandler(int) (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x5cb5f9c)
 #&#8203;3 0x0000004000a48980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #&#8203;4 0x00000000018a7f63 std::vector<swift::DiagnosticState::Behavior, std::allocator<swift::DiagnosticState::Behavior> >::_M_fill_insert(__gnu_cxx::__normal_iterator<swift::DiagnosticState::Behavior*, std::vector<swift::DiagnosticState::Behavior, std::allocator<swift::DiagnosticState::Behavior> > >, unsigned long, swift::DiagnosticState::Behavior const&) (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x18a7f63)
 #&#8203;5 0x00000000018a237f swift::DiagnosticState::DiagnosticState() (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x18a237f)
 #&#8203;6 0x00000000006ae240 swift::CompilerInstance::CompilerInstance() (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x6ae240)
 #&#8203;7 0x0000000000513165 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x513165)
 #&#8203;8 0x00000000004ad906 main (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x4ad906)
 #&#8203;9 0x0000004002013bf7 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21bf7)
#&#8203;10 0x00000000004ad57a _start (/swift-DEVELOPMENT-SNAPSHOT-2021-02-09-a-ubuntu18.04/usr/bin/swift-frontend+0x4ad57a)
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
<unknown>:0: error: unable to execute command: Illegal instruction
<unknown>:0: error: compile command failed due to signal 4 (use -v to see invocation)

@weissi
Copy link
Member Author

weissi commented Feb 18, 2021

Okay, so I think the problem is here:

std::vector<swift::DiagnosticState::Behavior, std::allocator<swift::DiagnosticState::Behavior> >::_M_fill_insert(__gnu_cxx::__normal_iterator<swift::DiagnosticState::Behavior*, std::vector<swift::DiagnosticState::Behavior, std::allocator<swift::DiagnosticState::Behavior> > >, unsigned long, swift::DiagnosticState::Behavior const&)

contains this Intel code

0x000000000192e327:  movzbl 0x0(%rbp),%esi
0x000000000192e32b:  movd   %esi,%xmm0
0x000000000192e32f:  pxor   %xmm1,%xmm1
0x000000000192e333:  pshufb %xmm1,%xmm0

and after that's run, we get into SignalHandler(int). So my guess is that the pshufb emulation somehow isn't quite right maybe?

The ARM code for that above TB (translation block) is

OUT: [size=100]
0x00cd93c0:  b85e4274      ldur w20, [x19, #-28]
0x00cd93c4:  7100029f      cmp w20, #&#8203;0x0 (0)
0x00cd93c8:  5400028b      b.lt #+0x50 (addr 0xcd9418)
0x00cd93cc:  f9401674      ldr x20, [x19, #&#8203;40]
0x00cd93d0:  38746b94      ldrb w20, [x28, x20]
0x00cd93d4:  f9001a74      str x20, [x19, #&#8203;48]
0x00cd93d8:  910c6275      add x21, x19, #&#8203;0x318 (792)
0x00cd93dc:  aa1503e0      mov x0, x21
0x00cd93e0:  2a1403e1      mov w1, w20
0x00cd93e4:  97de7fdf      bl #-0x860084 (addr 0x479360)
0x00cd93e8:  910d6274      add x20, x19, #&#8203;0x358 (856)
0x00cd93ec:  910d6275      add x21, x19, #&#8203;0x358 (856)
0x00cd93f0:  aa1303e0      mov x0, x19
0x00cd93f4:  aa1403e1      mov x1, x20
0x00cd93f8:  aa1503e2      mov x2, x21
0x00cd93fc:  97de7ce5      bl #-0x860c6c (addr 0x478790)
0x00cd9400:  529c6674      mov w20, #&#8203;0xe333
0x00cd9404:  72a03254      movk w20, #&#8203;0x192, lsl #&#8203;16
0x00cd9408:  f9004274      str x20, [x19, #&#8203;128]
0x00cd940c:  aa1303e0      mov x0, x19
0x00cd9410:  528000c1      mov w1, #&#8203;0x6
0x00cd9414:  97de5527      bl #-0x86ab64 (addr 0x46e8b0)
0x00cd9418:  52926060      mov w0, #&#8203;0x9303
0x00cd941c:  72a019a0      movk w0, #&#8203;0xcd, lsl #&#8203;16
0x00cd9420:  97e85f05      bl #-0x5e83ec (addr 0x6f1034)

@weissi
Copy link
Member Author

weissi commented Feb 18, 2021

yes, when running qemu like

chroot /amd64 /usr/bin/qemu-x86_64-static -d trace:user_handle_signal,trace:user_host_signal,in_asm,out_asm   /swift-5.3.3-RELEASE-ubuntu18.04/usr/bin/swiftc  /tmp//test.swift

it outputs

----------------
IN: _ZNSt6vectorIN5swift15DiagnosticState8BehaviorESaIS2_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS2_S4_EEmRKS2_
0x000000000192e327:  movzbl 0x0(%rbp),%esi
0x000000000192e32b:  movd   %esi,%xmm0
0x000000000192e32f:  pxor   %xmm1,%xmm1
0x000000000192e333:  pshufb %xmm1,%xmm0

OUT: [size=100]
0x00cd93c0:  b85e4274      ldur w20, [x19, #-28]
0x00cd93c4:  7100029f      cmp w20, #&#8203;0x0 (0)
0x00cd93c8:  5400028b      b.lt #+0x50 (addr 0xcd9418)
0x00cd93cc:  f9401674      ldr x20, [x19, #&#8203;40]
0x00cd93d0:  38746b94      ldrb w20, [x28, x20]
0x00cd93d4:  f9001a74      str x20, [x19, #&#8203;48]
0x00cd93d8:  910c6275      add x21, x19, #&#8203;0x318 (792)
0x00cd93dc:  aa1503e0      mov x0, x21
0x00cd93e0:  2a1403e1      mov w1, w20
0x00cd93e4:  97de7fdf      bl #-0x860084 (addr 0x479360)
0x00cd93e8:  910d6274      add x20, x19, #&#8203;0x358 (856)
0x00cd93ec:  910d6275      add x21, x19, #&#8203;0x358 (856)
0x00cd93f0:  aa1303e0      mov x0, x19
0x00cd93f4:  aa1403e1      mov x1, x20
0x00cd93f8:  aa1503e2      mov x2, x21
0x00cd93fc:  97de7ce5      bl #-0x860c6c (addr 0x478790)
0x00cd9400:  529c6674      mov w20, #&#8203;0xe333
0x00cd9404:  72a03254      movk w20, #&#8203;0x192, lsl #&#8203;16
0x00cd9408:  f9004274      str x20, [x19, #&#8203;128]
0x00cd940c:  aa1303e0      mov x0, x19
0x00cd9410:  528000c1      mov w1, #&#8203;0x6
0x00cd9414:  97de5527      bl #-0x86ab64 (addr 0x46e8b0)
0x00cd9418:  52926060      mov w0, #&#8203;0x9303
0x00cd941c:  72a019a0      movk w0, #&#8203;0xcd, lsl #&#8203;16
0x00cd9420:  97e85f05      bl #-0x5e83ec (addr 0x6f1034)

2491@1613682557.871285:user_handle_signal env=0x15124d30 signal 4

so there's a signal 4 (SIGILL) right when running that code.

@weissi
Copy link
Member Author

weissi commented Apr 8, 2021

I've played a little more with this. First of all, I created this (multi-stage) docker file which gets you from nothing to:

  • a qemu compiled from qemu's main branch (trunk)

  • an x86_64 Ubuntu 20.04 inside of the ARM64 docker container. That x86_64 Linux is the one you'll chroot into with qemu

  • a downloaded Swift 5.3.3 toolchain (for x86_64)

So basically if you put the following file as Dockerfile into an empty directory

FROM ubuntu:20.04 AS qemu-source

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -yy install git build-essential vim libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev
RUN git clone --recurse-submodules -j4 https://gitlab.com/qemu-project/qemu.git
RUN apt-get update && apt-get -yy install ninja-build
WORKDIR /qemu
RUN mkdir build
WORKDIR build
RUN ../configure --disable-system --disable-gtk --disable-fuse  --static --target-list=x86_64-linux-user
RUN make

FROM ubuntu:20.04
RUN apt-get update && apt-get -y install curl vim net-tools xz-utils llvm
RUN curl -O https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-root.tar.xz
RUN curl -O https://swift.org/builds/swift-5.3.3-release/ubuntu2004/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
RUN mkdir /amd64
WORKDIR /amd64
RUN tar xf /focal-server-cloudimg-amd64-root.tar.xz
RUN tar xf /swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
COPY --from=qemu-source /qemu/build/x86_64-linux-user/qemu-x86_64 /amd64/usr/bin/qemu-x86_64-static
WORKDIR /
RUN echo '91.189.88.152 archive.ubuntu.com' >> /amd64/etc/hosts
RUN echo '91.189.91.38 security.ubuntu.com' >> /amd64/etc/hosts
RUN cat /amd64/etc/hosts
RUN chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo /bin/bash -c 'apt-get update && apt-get -y install libz3-4'
RUN echo 'print("hello world")' > /amd64/tmp/test.swift

and then you run

docker build -t qemu-x86-swift .

then after a while you should have a docker image called qemu-x86-swift which you can a container with

docker run -it --rm qemu-x86-swift

inside there, you can then

chroot /amd64 /usr/bin/qemu-x86_64-static /swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/swiftc  /tmp//test.swift

to give it a shot. I'll fail, but you can then further debug with for example

chroot /amd64 /usr/bin/qemu-x86_64-static -d trace:user_handle_signal,trace:user_host_signal,in_asm,out_asm /swift-5.3.3-RELEASE-ubuntu20.04/usr/bin/swiftc  /tmp//test.swift

which in my case again leads to

[...]

8BehaviorESaIS2_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS2_S4_EEmRKS2_
0x018c48b9:  66 0f 38 00 c1           pshufb   %xmm1, %xmm0

OUT: [size=52]
  -- guest addr 0x00000000018c48b9 + tb prologue
0xffff78697840:  b85f8274  ldur     w20, [x19, #-8]
0xffff78697844:  7100029f  cmp      w20, #&#8203;0
0xffff78697848:  5400012b  b.lt     #&#8203;0xffff7869786c
0xffff7869784c:  52891734  mov      w20, #&#8203;0x48b9
0xffff78697850:  72a03194  movk     w20, #&#8203;0x18c, lsl #&#8203;16
0xffff78697854:  f9004274  str      x20, [x19, #&#8203;0x80]
0xffff78697858:  aa1303e0  mov      x0, x19
0xffff7869785c:  528000c1  mov      w1, #&#8203;6
0xffff78697860:  5297501e  mov      w30, #&#8203;0xba80
0xffff78697864:  72a0089e  movk     w30, #&#8203;0x44, lsl #&#8203;16
0xffff78697868:  d63f03c0  blr      x30
0xffff7869786c:  70fff8a0  adr      x0, #&#8203;0xffff78697783
0xffff78697870:  17e5a1f1  b        #&#8203;0xffff78000034

user_handle_signal env=0x80976e0 signal 4
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction

again pointing to that pshufb

@weissi
Copy link
Member Author

weissi commented Apr 9, 2021

Okay, I made a major leap forward and could reproduce this in a tiny C program. First of all, my latest Dockerfile:

FROM ubuntu:20.04 AS qemu-source

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -yy install git build-essential vim libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev
RUN git clone --recurse-submodules -j4 https://gitlab.com/qemu-project/qemu.git
RUN apt-get update && apt-get -yy install ninja-build
WORKDIR /qemu
RUN mkdir build
WORKDIR build
RUN ../configure --disable-system --disable-gtk --disable-fuse  --static --target-list=x86_64-linux-user
RUN make

FROM ubuntu:20.04
RUN apt-get update && apt-get -y install curl vim net-tools xz-utils llvm
RUN curl -O https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-root.tar.xz
RUN curl -O https://swift.org/builds/swift-5.3.3-release/ubuntu2004/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
RUN mkdir /amd64
WORKDIR /amd64
RUN tar xf /focal-server-cloudimg-amd64-root.tar.xz
RUN tar xf /swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
COPY --from=qemu-source /qemu/build/x86_64-linux-user/qemu-x86_64 /amd64/usr/bin/qemu-x86_64-static
WORKDIR /
RUN echo '91.189.88.152 archive.ubuntu.com' >> /amd64/etc/hosts
RUN echo '91.189.91.38 security.ubuntu.com' >> /amd64/etc/hosts
RUN cat /amd64/etc/hosts
RUN chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo /bin/bash -c 'apt-get update && apt-get -y install libz3-4 llvm build-essential'
RUN echo 'print("hello world")' > /amd64/tmp/test.swift

and then the C repro program:

#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

int main(int argc, char **argv) {
    bool should_fork = false;
    bool should_exec = false;

    if (argc > 1) {
        should_fork = (strcmp(argv[1], "fork") == 0);
        if (strcmp(argv[1], "fork+exec") == 0) {
            should_fork = true;
            should_exec = true;
        }
    }
    printf("PARENT[%d]: should_fork: %d\n", getpid(), should_fork);
    int pid = 0;
    if (should_fork && (pid = fork())) {
        int stat = 0;
        int err = waitpid(pid, &stat, 0);
        if (err == -1) {
            perror("waitpid");
            exit(1);
        }
        if (WIFEXITED(stat)) {
            printf("PARENT [%d]: child [%d] exited with %d\n", getpid(), pid, WEXITSTATUS(stat));
            exit(WEXITSTATUS(stat));
        } else {
            printf("PARENT [%d]: child [%d] signalled with %d\n", getpid(), pid, WTERMSIG(stat));
            exit(128 + WTERMSIG(stat));
        }
    } else {
        if (should_exec) {
            char *args[] = { argv[0], NULL };
            int err = execve(argv[0], args, NULL);
            perror("execve");
            return 2;
        } else {
            printf("%s [%d]: alive\n", should_fork ? "CHILD" : "CHILD (execd)", getpid());
            __asm__("pxor %xmm0, %xmm0\n"
                    "pxor %xmm1, %xmm1\n"
                    "pshufb %xmm1, %xmm0");
            printf("%s [%d]: exiting\n", should_fork ? "CHILD" : "CHILD (execd)", getpid());
            return 0;
        }
    }
}

The C program just executes a pshufb xmm1, xmm0 instruction when started with no arguments. If started with "fork" as the argument, the C program first forks itself and then runs pshufb xmm1, xmm0 in the child.
And finally, if you invoke the C program with "fork+exec" then it will first fork itself and then – in the child – exec itself without arguments, which will also run the pshufb xmm1, xmm0 in the child.

The outcome is this:

1. works when run directly (no fork/exec)

root@d546c256067a:/# chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo -- /a.out 
PARENT[202]: should_fork: 0
CHILD (execd) [202]: alive
CHILD (execd) [202]: exiting

2. works when we do the pshufb in a fork'd child

root@d546c256067a:/# chroot /amd64 /usr/bin/qemu-x86_64-static -cpu core2duo -- /a.out fork
PARENT[204]: should_fork: 1
CHILD [206]: alive
CHILD [206]: exiting
PARENT [204]: child [206] exited with 0

3. FAILS if the pshufb is run in a fork/exec'd child

PARENT[208]: should_fork: 1
PARENT[210]: should_fork: 0
CHILD (execd) [210]: alive
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
PARENT [208]: child [210] signalled with 4

The reason the third case fails is because likely because it uses pshufb (which is available if you pass -cpu core2duo (or better) but not if you don't pass a -cpu argument). So I reckon the problem is that Qemu forgets to pass on the -cpu parameter to exec'd child processes so pshufb is only available until you exec 🙂

@weissi
Copy link
Member Author

weissi commented Apr 10, 2021

Okay, I have not fully debugged this. So basically the problem is that qemu-user doesn't do anything special on exec. That means that in most cases, execing from a qemu-user (if the target architecture is different to the host architecture) would actually fail because the exec'd binary will be for the wrong architecture.
The reason is kinda worked for me (modulo the pshufb and other modern Intel CPU features) is that Docker for Mac installs a binfmt_misc handler which is also a qemu-user!!! So essentially what happened is:
My qemu-user (with the -cpu core2duo argument) runs the Swift driver, when that forks, it forks a swift -frontend which (because of the installed binfmt_misc handler) gets run by the built-in qemu-user that Docker for Mac ships! That one however doesn't obviously default to -cpu core2duo. This took me so long to find because the qemu-user that docker ships lives in the same path (but in the actual VM) as my qemu-user lives (in my container).

Long story "short": I can work around this problem by doing the following steps:

  1. build qemu-user with a tiny patch (sed -i 's/cpu_model = NULL/cpu_model = "core2duo"/g' linux-user/main.c) which makes it default to emulate a core2duo (which has pshufb. I compiled this as a binary called qemu-x86_64-static-c2d in a docker container
  2. using Justin Cormack's justincormack/nsenter1: enter the actual Linux VM that's run by Docker for Mac
  3. in the actual VM, uninstall the binfmt_misc handler: /containers/services/binfmt/rootfs/usr/bin/binfmt -uninstall qemu-x86_64
  4. in the actual VM, run a find / -name qemu-x86_64-static-c2d to find the weird path to that qemu
  5. in the actual VM, run echo ":qemu-x86_64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x3e\x00:\xff\xff\xff\xff\xff\xfe\xfe\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/var/lib/docker/overlay2/80s11o66od7msjkcmt4hal5ui/diff/amd64/usr/bin/qemu-x86_64-static-c2d:OCF" > /proc/sys/fs/binfmt_misc/register (note, you'll need to replace /var/lib/docker/overlay2/80s11o66od7msjkcmt4hal5ui/diff/amd64/usr/bin/qemu-x86_64-static-c2d with the result of the find above)

Then, I actually got the whole thing working!!! I just successfully compiled SwiftNIO for x86_64 using the normal swift.org toolchain for Ubuntu 20.04 (on x86_64) on an M1 Mac in Docker 🙂

@weissi
Copy link
Member Author

weissi commented Apr 10, 2021

My Dockerfile that builds the whole thing, including the Qemu patch but EXCLUDING (don't think that's possible) the binfmt_misc handler is here

FROM ubuntu:20.04 AS qemu-source

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get -yy install git build-essential vim libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev
RUN git clone --recurse-submodules -j4 https://gitlab.com/qemu-project/qemu.git
RUN apt-get update && apt-get -yy install ninja-build
WORKDIR /qemu
RUN sed -i 's/cpu_model = NULL/cpu_model = "core2duo"/g' linux-user/main.c
RUN mkdir build
WORKDIR build
RUN ../configure --disable-system --disable-gtk --disable-fuse  --static --target-list=x86_64-linux-user
RUN make

FROM ubuntu:20.04
RUN apt-get update && apt-get -y install curl vim net-tools xz-utils llvm
RUN curl -O https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64-root.tar.xz
RUN curl -O https://swift.org/builds/swift-5.3.3-release/ubuntu2004/swift-5.3.3-RELEASE/swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
RUN mkdir /amd64
WORKDIR /amd64
RUN tar xf /focal-server-cloudimg-amd64-root.tar.xz
RUN tar xf /swift-5.3.3-RELEASE-ubuntu20.04.tar.gz
COPY --from=qemu-source /qemu/build/x86_64-linux-user/qemu-x86_64 /amd64/usr/bin/qemu-x86_64-static-c2d
WORKDIR /
RUN echo '91.189.88.152 archive.ubuntu.com' >> /amd64/etc/hosts
RUN echo '91.189.91.38 security.ubuntu.com' >> /amd64/etc/hosts
RUN cat /amd64/etc/hosts
RUN chroot /amd64 /usr/bin/qemu-x86_64-static-c2d /bin/bash -c 'apt-get update && apt-get -y install libz3-4 llvm build-essential'
RUN echo 'print("hello world")' > /amd64/tmp/test.swift

@weissi
Copy link
Member Author

weissi commented Apr 15, 2021

This issue can be closed. It works with docker run -it --rm --platform linux/amd64 -v "$PWD:$PWD" -w "$PWD" -e QEMU_CPU=max swift:5.3 swift build . Qemu allows the -cpu option to be passed as QEMU_CPU in the environment which solves the issue.

Selecting max should work as it will select the best CPU model that Qemu can emulate which seems to be good enough. However, Swift should still document what micro-architectures it expects (by default): SR-14474

@weissi
Copy link
Member Author

weissi commented Apr 15, 2021

If Docker for Mac fix issue docker/for-mac#5561 , then we can probably remove the QEMU_CPU=max workaround.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant