rustc_codegen_cranelift
rustc_codegen_cranelift copied to clipboard
Windows support
I believe cranelift is cross-platform. At least on windows.
However I only found Bash scripts for building with cargo for example. Is this a limitation, or am I missing something?
If a port from Bash to Batch (or something else like python) is needed I am of course happy to help!
I have been focusing on Linux and macOS. There are several places where Windows support is missing:
-
Abi::System
: This is equivalent toAbi::C
on x86_64 I think, but I am not sure. -
.rlib
: Therust-ar
crate only supports BSD and Gnu stylear
archives. I believe Windows uses a slightly different format. - The bash scripts, as you already noticed. (only
config.sh
,prepare.sh
,test.sh
andcargo.sh
need to be ported.rustup.sh
is just for me to switch to a new rustc version more easily. I haven't usedflamegraph.sh
in ages.) - Probably other things.
I did some experimentation on the windows_support
branch, but it currently fails as I used bash
to run the scripts and bash
turns C:\
into /c/
, which rustc doesn't recognize. As I don't use Windows, I have to wait for CI every time I try to fix something.
I don't think I will add Windows support soon, but PR's are of course welcome.
I got working support for cross compilation from Linux to MinGW on the wip_windows_support
branch. For reference: see the comment thread starting at https://github.com/bytecodealliance/wasmtime/pull/1510#issuecomment-633693913.
The branch depends on https://github.com/bytecodealliance/wasmtime/pull/1670 and an update to object 0.19.0
.
Wow amazing work, I will check this out soon!
The branch now also depends on https://github.com/bytecodealliance/wasmtime/pull/1767 for the object 0.19.0
update. (You need to merge both PR's into one branch)
Updated the wip_windows_support
branch for the latest Cranelift, which includes both bytecodealliance/wasmtime#1670 as well as bytecodealliance/wasmtime#1767.
Patches in wip_windows_support
:
- [x]
backtrace-sys 0.1.37
giving gcc ice with mingw (newerbacktrace
versions use gimli instead) - [ ]
Patchcompiler-builtins
to revert the "win64 128bit abi hack" - [ ]
PatchPassMode::ByRef
to not useArgumentPurpose::StructArgument
(unimplemented in Cranelift forWindowsFastcall
) - [ ]
Codegen___chkstk
,___chkstk_ms
and__alloca
- [x] Use
x86_64-w64-mingw32-ranlib
instead of plainranlib
(ranlib no longer used since #1067) - [ ]
Missing TLS support in Cranelift for COFF/PE files (https://github.com/bytecodealliance/wasmtime/issues/1885)(Not actually used by libstd) - [x] Disable the atomics shim, as pthreads is not available (fixed by #1140)
- [x] Use the correct abi for calling 128bit int op intrinsics (9c980276d81b727bb8efcbe63f51866ba19793a0 and 1122f42e2872a4bb65adeb990fb73cc555f5c3cf)
- [x] Implement
WindowsFastcall
abi for the new x64 Cranelift backend (https://github.com/bytecodealliance/wasmtime/pull/2678)
9384af41986da8c1697acde643b3f899d7becaf2 makes the examples link on windows. 9c943bf5de795c784aa33e29cb25fa51bc76c833 and 9164653c10b7aa7cfea2b0556ca7c332e6df4a0b together add support for building the sysroot for windows. The examples and sysroot will still fail to build for windows though until the above todo list is fixed. a77ee9eeed478139bffb47729a0b255456ae55fd is a workaround for these things when using the old x86 cranelift backend, but I won't merge that commit as it negatively affects other platforms too.
9c980276d81b727bb8efcbe63f51866ba19793a0 reduced the amount of used 128bit int intrinsics.
To work with the MSVC toolchain at the very least the unwind info registering for the jit will need to be adapted:
From https://github.com/rust-lang/rust/pull/81746#issuecomment-830003237:
I finally found the time to leave my Windows machine to build this and it returns the following error when running python x.py dist.
error: linking with `link.exe` failed: exit code: 1120 | = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-sysroot\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.0.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.1.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.10.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.11.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.12.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.13.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.14.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.15.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.2.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.3.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.4.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.5.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.6.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.7.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.8.rcgu.o" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.9.rcgu.o" "/OUT:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.dll" "/DEF:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\lib.def" "E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.12gfo8yp2jl73bli.rcgu.o" "/OPT:REF,ICF" "/DLL" "/IMPLIB:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps\\rustc_codegen_cranelift-009ac88bd40450d4.dll.lib" "/DEBUG" "/LIBPATH:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\x86_64-pc-windows-msvc\\release\\deps" "/LIBPATH:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-codegen\\release\\deps" "/LIBPATH:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-sysroot\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liblibloading-214e9bb7fb37b849.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liblibloading-214e9bb7fb37b849.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libar-8f3d8f4144fc4037.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libar-8f3d8f4144fc4037.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_frontend-174eb29dede6ee42.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_frontend-174eb29dede6ee42.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_jit-b42a1c3b008e58ee.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_jit-b42a1c3b008e58ee.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libregion-03c6a75666b44698.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libregion-03c6a75666b44698.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liblibc-474cdeaf049dc977.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liblibc-474cdeaf049dc977.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liberrno-c3e08586003e932f.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liberrno-c3e08586003e932f.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libwinapi-05975613c8de37af.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libwinapi-05975613c8de37af.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_native-43d4e4e23a19653b.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_native-43d4e4e23a19653b.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libraw_cpuid-053f169126b0175d.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libraw_cpuid-053f169126b0175d.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libbitflags-56af03412bcadad9.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libbitflags-56af03412bcadad9.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_object-718f8b46d6a235ba.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_object-718f8b46d6a235ba.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_module-4eadaa6046005823.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_module-4eadaa6046005823.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libanyhow-e5a2a1314f48d3ea.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libanyhow-e5a2a1314f48d3ea.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libobject-e39f5dae50c03340.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libobject-e39f5dae50c03340.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcrc32fast-11ee3bae944ed9fb.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcrc32fast-11ee3bae944ed9fb.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcfg_if-effc1151ec034212.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcfg_if-effc1151ec034212.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_codegen-367f3a8aefa14268.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_codegen-367f3a8aefa14268.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libbyteorder-4bd9e8eddba2e910.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libbyteorder-4bd9e8eddba2e910.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libregalloc-ab60fedb5c230c35.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libregalloc-ab60fedb5c230c35.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\librustc_hash-9e24eb98b7bcf6ed.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\librustc_hash-9e24eb98b7bcf6ed.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libsmallvec-627853132f5cb768.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libsmallvec-627853132f5cb768.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libgimli-409d65c42c1a823f.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libgimli-409d65c42c1a823f.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libindexmap-d6432865211316bb.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libindexmap-d6432865211316bb.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libhashbrown-5b39f445d78bb266.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libhashbrown-5b39f445d78bb266.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libtarget_lexicon-7a7b04a7b0ad8852.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libtarget_lexicon-7a7b04a7b0ad8852.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_codegen_shared-6734e0f2fe03703c.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_codegen_shared-6734e0f2fe03703c.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libthiserror-9a7bd4988fadee6a.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libthiserror-9a7bd4988fadee6a.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liblog-814010b37c6f5102.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\liblog-814010b37c6f5102.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcfg_if-6465e92117359c6a.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcfg_if-6465e92117359c6a.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_bforest-6d35a5a3b285a530.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_bforest-6d35a5a3b285a530.rlib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_entity-7d481582d4b7a513.rlib" "/WHOLEARCHIVE:C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcranelift_entity-7d481582d4b7a513.rlib" "/LIBPATH:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-sysroot\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "rustc_driver-24afc9f800d8d460.dll.lib" "/LIBPATH:E:\\rust\\build\\x86_64-pc-windows-msvc\\stage0-sysroot\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "std-1e2b149900a8c2e5.dll.lib" "C:\\Users\\ERIN~1.POW\\AppData\\Local\\Temp\\rustc5IX85x\\libcompiler_builtins-c53132d8e54c0fd9.rlib" "advapi32.lib" "cfgmgr32.lib" "kernel32.lib" "user32.lib" "psapi.lib" "shell32.lib" "ole32.lib" "uuid.lib" "advapi32.lib" "advapi32.lib" "ole32.lib" "oleaut32.lib" "advapi32.lib" "advapi32.lib" "cfgmgr32.lib" "gdi32.lib" "kernel32.lib" "msimg32.lib" "opengl32.lib" "psapi.lib" "synchronization.lib" "user32.lib" "winspool.lib" "advapi32.lib" "ws2_32.lib" "userenv.lib" "libcmt.lib" = note: Creating library E:\rust\build\x86_64-pc-windows-msvc\stage0-codegen\x86_64-pc-windows-msvc\release\deps\rustc_codegen_cranelift-009ac88bd40450d4.dll.lib and object E:\rust\build\x86_64-pc-windows-msvc\stage0-codegen\x86_64-pc-windows-msvc\release\deps\rustc_codegen_cranelift-009ac88bd40450d4.dll.exp rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.12.rcgu.o : error LNK2019: unresolved external symbol __deregister_frame referenced in function _ZN4core3ptr13drop_in_place17h0cbf025046a6d768E rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.3.rcgu.o : error LNK2001: unresolved external symbol __deregister_frame rustc_codegen_cranelift-009ac88bd40450d4.rustc_codegen_cranelift.1gc6s5km-cgu.3.rcgu.o : error LNK2019: unresolved external symbol __register_frame referenced in function _ZN23rustc_codegen_cranelift9debuginfo6unwind13UnwindContext12register_jit17h259a09e699197ceaE E:\rust\build\x86_64-pc-windows-msvc\stage0-codegen\x86_64-pc-windows-msvc\release\deps\rustc_codegen_cranelift-009ac88bd40450d4.dll : fatal error LNK1120: 2 unresolved externals
Fixed by #1170.
Dwarf debuginfo generation will need to be disabled for MSVC:
error: linking with `link.exe` failed: exit code: 1165
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.28.29333\\bin\\HostX64\\x64\\link.exe" [...]
= note: build_script_build-de97622aa2c42411.build_script_build.42ir3bpd-cgu.9.rcgu.o : error LNK2017: 'ADDR32' relocation to '.debug_abbrev' invalid without /LARGEADDRESSAWARE:NO
build_script_build-de97622aa2c42411.build_script_build.42ir3bpd-cgu.9.rcgu.o : error LNK2017: 'ADDR32' relocation to '.debug_str' invalid without /LARGEADDRESSAWARE:NO
build_script_build-de97622aa2c42411.build_script_build.42ir3bpd-cgu.9.rcgu.o : error LNK2017: 'ADDR32' relocation to '.debug_str' invalid without /LARGEADDRESSAWARE:NO
build_script_build-de97622aa2c42411.build_script_build.42ir3bpd-cgu.9.rcgu.o : error LNK2017: 'ADDR32' relocation to '.debug_str' invalid without /LARGEADDRESSAWARE:NO
build_script_build-de97622aa2c42411.build_script_build.42ir3bpd-cgu.9.rcgu.o : error LNK2017: 'ADDR32' relocation to '.debug_ranges' invalid without /LARGEADDRESSAWARE:NO
[...]
Now, Could it be used on windows? either GNU or MSVC toolchain is fine if it can work, I try to build it on Win10 but failed.
$ rustup default nightly-x86_64-pc-windows-gnu
info: using existing install for 'nightly-x86_64-pc-windows-gnu'
info: default toolchain set to 'nightly-x86_64-pc-windows-gnu'
nightly-x86_64-pc-windows-gnu unchanged - rustc 1.54.0-nightly (fe72845f7 2021-05-16)
info: note that the toolchain 'nightly-2021-05-26-x86_64-pc-windows-gnu' is currently in use (overridden by 'G:\Git-repo\rustc_codegen_cranelift\rust-toolchain')
$ cargo build --release
Compiling rustc_codegen_cranelift v0.1.0 (G:\Git-repo\rustc_codegen_cranelift)
warning: associated function is never used: `relocate_for_jit`
--> src\debuginfo\emit.rs:71:19
|
71 | pub(super) fn relocate_for_jit(mut self, jit_module: &cranelift_jit::JITModule) -> Vec<u8> {
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(dead_code)]` on by default
error: linking with `x86_64-w64-mingw32-gcc` failed: exit code: 1
= note: G:\Git-repo\rustc_codegen_cranelift\target\release\deps\rustc_codegen_cranelift.10pdpqne00tf2gqr.rcgu.o:10pdpqne00tf2gqr:(.text+0x982): undefined reference to `_Unwind_Resume'
G:\Git-repo\rustc_codegen_cranelift\target\release\deps\rustc_codegen_cranelift.11gqdvl8vhcuv9se.rcgu.o:11gqdvl8vhcuv9se:(.text+0x467): undefined reference to `_Unwind_Resume'
G:\Git-repo\rustc_codegen_cranelift\target\release\deps\rustc_codegen_cranelift.11gqdvl8vhcuv9se.rcgu.o:11gqdvl8vhcuv9se:(.text+0x8eb): undefined reference to `_Unwind_Resume'
G:\Git-repo\rustc_codegen_cranelift\target\release\deps\rustc_codegen_cranelift.136c1t4zvxe9wtqm.rcgu.o:136c1t4zvxe9wtqm:(.text+0x46d): undefined reference to `_Unwind_Resume'
G:\Git-repo\rustc_codegen_cranelift\target\release\deps\rustc_codegen_cranelift.13e4gfb0bi3c1hb3.rcgu.o:13e4gfb0bi3c1hb3:(.text+0xb9e): undefined reference to `_Unwind_Resume'
G:\Git-repo\rustc_codegen_cranelift\target\release\deps\rustc_codegen_cranelift.13irbfn73kf9gsap.rcgu.o:13irbfn73kf9gsap:(.text+0x163): more undefined references to `_Unwind_Resume' follow
collect2.exe: error: ld returned 1 exit status
error: aborting due to previous error; 1 warning emitted
error: could not compile `rustc_codegen_cranelift`
To learn more, run the command again with --verbose.
Building using both the MSVC and GNU toolchain should work fine. When compiling your own code for MSVC with cg_clif it will likely crash due to something not yet being implemented. With the GNU toolchain everything should work. Compiling code for the GNU toolchain using cg_clif is tested on CI. Compiling cg_clif itself for the MSVC toolchain worked fine in https://github.com/rust-lang/rust/pull/81746. I am not sure why it gives undefined reference to `_Unwind_Resume'
for you. That symbol is part of the exception unwinding mechanism that is used by gcc and rustc, so it should be defined.
I solved the trouble above, but when I want to translate the build.sh to buld.ps1, I found build.sh disallow building on windows
if [[ "$unamestr" == 'Linux' || "$unamestr" == "FreeBSD" ]]; then
export RUSTFLAGS='-Clink-arg=-Wl,-rpath=$ORIGIN/../lib '$RUSTFLAGS
elif [[ "$unamestr" == 'Darwin' ]]; then
export RUSTFLAGS='-Csplit-debuginfo=unpacked -Clink-arg=-Wl,-rpath,@loader_path/../lib -Zosx-rpath-install-name '$RUSTFLAGS
dylib_ext='dylib'
else
echo "Unsupported os $unamestr"
exit 1
Does it mean I can not build it on windows ? and how to use cg_clif on windows?
The build system doesn't have support for Windows yet. The main changes required to work on windows are likely to change ln target/$CHANNEL/*rustc_codegen_cranelift* "$target_dir"/lib
to have "$target_dir"/bin
as target instead of "$target_dir"/lib
and have an empty case for windows in the if statement you mentioned. Windows doesn't support rpaths, so the dll needs to be next to the binaries.
An update on the x86_64-windows-pc-msvc
target:
We've introduced TLS support for the COFF file format in cranelift (https://github.com/bytecodealliance/wasmtime/pull/4546).
The test.sh
file was also moved into y.rs
so that we can run windows tests.
Here's an update on the current status of the testsuite on MSVC (only showing failed tests):
no_sysroot
build.mini_core
Fails with: "unresolved external symbol printf"
H:C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\build\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranel
ift\\build\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\target\\out\\mini_core.dll" "/OPT:REF,NOICF" "/DLL" "/IMPLIB:C:\\Users\\Afonso\\
CLionProjects\\rustc_codegen_cranelift\\target\\out\\mini_core.dll.lib" "/DEBUG"
= note: Creating library C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\target\out\mini_core.dll.lib and object C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\target\out\mini_core.d
ll.exp
mini_core.mini_core.c16326b1-cgu.0.rcgu.o : error LNK2001: unresolved external symbol printf
C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\target\out\mini_core.dll : fatal error LNK1120: 1 unresolved externals
If I comment out printf
usages it passes!
build.example
Passes as long as we build mini_core
(i.e. disable printf
).
jit.mini_core_hello_world
Need to disable a printf
call to run.
Fails with: "can't resolve symbol _ZN9mini_core8A_STATIC17hac12203af6ca6b91E"
thread 'rustc' panicked at 'can't resolve symbol _ZN9mini_core8A_STATIC17hac12203af6ca6b91E', C:\Users\Afonso\CLionProjects\wasmtime\cranelift\jit\src\backend.rs:312:21
stack backtrace:
0: 0x7fffae9e9c5f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h22e7b784ac716ba6
1: 0x7fffaea255ba - core::fmt::write::h710985228ff64dc4
2: 0x7fffae9dcada - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h7a965e27de439674
3: 0x7fffae9ed65b - std::panicking::default_hook::h59e772df96aabd4c
4: 0x7fffae9ed287 - std::panicking::default_hook::h59e772df96aabd4c
5: 0x7fff82a76b81 - <rustc_session[9ee3cdee11a5ff9c]::options::WasiExecModel as rustc_session[9ee3cdee11a5ff9c]::config::dep_tracking::DepTrackingHash>::hash
6: 0x7fffae9ee03c - std::panicking::rust_panic_with_hook::h38636381814ab6ea
7: 0x7fffae9eddbd - <std::panicking::begin_panic_handler::StrPanicPayload as core::panic::BoxMeUp>::get::haeca514280bcf18e
8: 0x7fffae9ea957 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h22e7b784ac716ba6
9: 0x7fffae9eda90 - rust_begin_unwind
10: 0x7fffaea5b485 - core::panicking::panic_fmt::h30a9aaedd2e91939
11: 0x7fffae43bca3 - cranelift_jit::backend::JITModule::get_address::h79eaafe65aed6ccd
12: 0x7fffae440b7a - cranelift_jit::compiled_blob::CompiledBlob::perform_relocations::h2d3dd9b12c37a6cc
13: 0x7fffae43c59d - cranelift_jit::backend::JITModule::finalize_definitions::h1bad446e1d195205
14: 0x7fffae41d692 - rustc_codegen_cranelift::driver::jit::run_jit::h8585bd81e007a5e3
15: 0x7fffae363b8f - <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::h0da6af42230e73fb
16: 0x7fff804b18a0 - rustc_interface[6c72882eac342bcd]::passes::analysis
17: 0x7fff804a3ce3 - <rustc_interface[6c72882eac342bcd]::passes::LintStoreExpandImpl as rustc_expand[6695f8eb6e16e84d]::base::LintStoreExpand>::pre_expansion_lint
18: 0x7fff80490a5c - <rustc_interface[6c72882eac342bcd]::queries::Queries>::ongoing_codegen
19: 0x7fff80447030 - <unknown>
20: 0x7fff8047e937 - rustc_driver[197bfed8d57a407b]::args::arg_expand_all
21: 0x7fff80467cf9 - <unknown>
22: 0x7fff804687fd - <rustc_middle[d6f72711bda4db03]::ty::SymbolName as core[9a2c4b0c2bb38f26]::fmt::Display>::fmt
23: 0x7fffae9ff15c - std::sys::windows::thread::Thread::new::hec2508d69eebdd0a
24: 0x7ff832ac7034 - BaseThreadInitThunk
25: 0x7ff833722651 - RtlUserThreadStart
error: internal compiler error: unexpected panic
aot.mini_core_hello_world
LNK1181: cannot open input file 'pthread.lib
error: linking with `link.exe` failed: exit code: 1181
|
= note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\Afonso\\AppData\\Local\\Temp\\rustckiFHhD
\\symbols.o" "C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\target\\out\\mini_core_hello_world.mini_core_hello_world.65fa8a3a-cgu.0.rcgu.o" "C:\\Users\\Afonso\\CLionProjects\\rustc_codege
n_cranelift\\target\\out\\mini_core_hello_world.mini_core_hello_world.65fa8a3a-cgu.1.rcgu.o" "C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\target\\out\\mini_core_hello_world.mini_core_he
llo_world.65fa8a3a-cgu.2.rcgu.o" "/LIBPATH:C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\target\\out" "/LIBPATH:C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\build\\lib\\rust
lib\\x86_64-pc-windows-msvc\\lib" "pthread.lib" "C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\target\\out\\libmini_core.rlib" "msvcrt.lib" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Afonso\\CLionP
rojects\\rustc_codegen_cranelift\\build\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\Afonso\\CLionProjects\\rustc_codegen_cranelift\\target\\out\\mini_core_hello_world.exe" "/OPT:REF,N
OICF" "/DEBUG"
= note: LINK : fatal error LNK1181: cannot open input file 'pthread.lib'
Commenting out pthread
usages makes this test pass!
base_sysroot
jit.std_example
thread 'rustc' panicked at 'can't resolve symbol _ZN42_$LT$$u21$$u20$as$u20$core..fmt..Debug$GT$3fmt17h1451c1c2a910bac2E'
thread 'rustc' panicked at 'can't resolve symbol _ZN42_$LT$$u21$$u20$as$u20$core..fmt..Debug$GT$3fmt17h1451c1c2a910bac2E', C:\Users\Afonso\CLionProjects\wasmtime\cranelift\jit\src\backend.rs:312:21
stack backtrace:
0: 0x7fffae9e9c5f - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h22e7b784ac716ba6
1: 0x7fffaea255ba - core::fmt::write::h710985228ff64dc4
2: 0x7fffae9dcada - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h7a965e27de439674
3: 0x7fffae9ed65b - std::panicking::default_hook::h59e772df96aabd4c
4: 0x7fffae9ed287 - std::panicking::default_hook::h59e772df96aabd4c
5: 0x7fff82a76b81 - <rustc_session[9ee3cdee11a5ff9c]::options::WasiExecModel as rustc_session[9ee3cdee11a5ff9c]::config::dep_tracking::DepTrackingHash>::hash
6: 0x7fffae9ee03c - std::panicking::rust_panic_with_hook::h38636381814ab6ea
7: 0x7fffae9eddbd - <std::panicking::begin_panic_handler::StrPanicPayload as core::panic::BoxMeUp>::get::haeca514280bcf18e
8: 0x7fffae9ea957 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h22e7b784ac716ba6
9: 0x7fffae9eda90 - rust_begin_unwind
10: 0x7fffaea5b485 - core::panicking::panic_fmt::h30a9aaedd2e91939
11: 0x7fffae43bca3 - cranelift_jit::backend::JITModule::get_address::h79eaafe65aed6ccd
12: 0x7fffae440b7a - cranelift_jit::compiled_blob::CompiledBlob::perform_relocations::h2d3dd9b12c37a6cc
13: 0x7fffae43c59d - cranelift_jit::backend::JITModule::finalize_definitions::h1bad446e1d195205
14: 0x7fffae41d692 - rustc_codegen_cranelift::driver::jit::run_jit::h8585bd81e007a5e3
15: 0x7fffae363b8f - <rustc_codegen_cranelift::CraneliftCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::h0da6af42230e73fb
16: 0x7fff804b18a0 - rustc_interface[6c72882eac342bcd]::passes::analysis
17: 0x7fff804a3ce3 - <rustc_interface[6c72882eac342bcd]::passes::LintStoreExpandImpl as rustc_expand[6695f8eb6e16e84d]::base::LintStoreExpand>::pre_expansion_lint
18: 0x7fff80490a5c - <rustc_interface[6c72882eac342bcd]::queries::Queries>::ongoing_codegen
19: 0x7fff80447030 - <unknown>
20: 0x7fff8047e937 - rustc_driver[197bfed8d57a407b]::args::arg_expand_all
21: 0x7fff80467cf9 - <unknown>
22: 0x7fff804687fd - <rustc_middle[d6f72711bda4db03]::ty::SymbolName as core[9a2c4b0c2bb38f26]::fmt::Display>::fmt
23: 0x7fffae9ff15c - std::sys::windows::thread::Thread::new::hec2508d69eebdd0a
24: 0x7ff832ac7034 - BaseThreadInitThunk
25: 0x7ff833722651 - RtlUserThreadStart
error: internal compiler error: unexpected panic
aot.std_example
LNK2001: unresolved external symbol fabsf
= note: msvcrt.lib(exe_main.obj) : warning LNK4078: multiple '.CRT' sections found with different attributes (40400040)
std_example.std_example.03190124-cgu.15.rcgu.o : error LNK2001: unresolved external symbol fabsf
C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\target\out\std_example.exe : fatal error LNK1120: 1 unresolved externals
extended_sysroot
test.rust-random/rand
Illegal instruction when building `getrandom`, `libm` and `num-traits`
Compiling num-traits v0.2.15
[build_script_build : codegen mono items] start
[build_script_build : codegen mono items] end time: 13.4684ms
error: failed to run custom build command for `getrandom v0.1.16`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\rand\target\debug\build\getrandom-ae9cbaf4035dfeb9\build-script-build` (exit code: 0xc000001d, STATUS_ILLEGAL
_INSTRUCTION)
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `libm v0.2.2`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\rand\target\debug\build\libm-7d775bc88a95dcd8\build-script-build` (exit code: 0xc000001d, STATUS_ILLEGAL_INST
RUCTION)
error: failed to run custom build command for `num-traits v0.2.15`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\rand\target\debug\build\num-traits-77597371f412c10a\build-script-build` (exit code: 0xc000001d, STATUS_ILLEGA
L_INSTRUCTION)
--- stdout
[probe0 : codegen mono items] start
[probe0 : codegen mono items] end time: 922.2µs
[probe1 : codegen mono items] start
[probe1 : codegen mono items] end time: 840.7µs
[serde : codegen mono items] start
[serde : codegen mono items] end time: 225.6096ms
test.libcore
Illegal instruction when building `getrandom`
error: failed to run custom build command for `getrandom v0.1.16`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\build_sysroot\sysroot_src\library\core\tests\target\debug\build\getrandom-ae9cbaf4035dfeb9\build-script-build
` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
test.regex-shootout-regex-dna
Builds successfully, but fails when running shootout-regex-dna.exe
Finished dev [unoptimized + debuginfo] target(s) in 0.10s
Running `target\x86_64-pc-windows-msvc\debug\examples\shootout-regex-dna.exe`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: -1073741822, kind: Uncategorized, message: "OS Error -1073741822 (FormatMessageW() returned error 317)" }', examples\
shootout-regex-dna.rs:18:42
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\x86_64-pc-windows-msvc\debug\examples\shootout-regex-dna.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
thread '<unnamed>
test.regex
Fails to build with illegal instruction
error: failed to run custom build command for `winapi v0.3.9`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\regex\target\debug\build\winapi-4fa2ba29c6d2280e\build-script-build` (exit code: 0xc000001d, STATUS_ILLEGAL_I
NSTRUCTION)
warning: build failed, waiting for other jobs to finish...
error: failed to run custom build command for `rand_pcg v0.1.2`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\regex\target\debug\build\rand_pcg-bb69e9857a3d383b\build-script-build` (exit code: 0xc000001d, STATUS_ILLEGAL
_INSTRUCTION)
error: failed to run custom build command for `rand_chacha v0.1.1`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\regex\target\debug\build\rand_chacha-743ffc42347a8cb3\build-script-build` (exit code: 0xc000001d, STATUS_ILLE
GAL_INSTRUCTION)
error: failed to run custom build command for `rand v0.6.5`
Caused by:
process didn't exit successfully: `C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\regex\target\debug\build\rand-be94e9473ad495f2\build-script-build` (exit code: 0xc000001d, STATUS_ILLEGAL_INS
TRUCTION)
test.portable-simd
LNK2001: unresolved external symbol fabsf
= note: msvcrt.lib(exe_main.obj) : warning LNK4078: multiple '.CRT' sections found with different attributes (40400040)
f32_ops-12918a2a6d68f6ed.4bstrdpwoxpm0wzh.rcgu.o : error LNK2001: unresolved external symbol fabsf
C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\portable-simd\target\x86_64-pc-windows-msvc\debug\deps\f32_ops-12918a2a6d68f6ed.exe : fatal error LNK1120: 1 unresolved externals
error: could not compile `core_simd` due to previous error
cc https://github.com/bjorn3/rustc_codegen_cranelift/pull/1254
Once https://github.com/bytecodealliance/wasmtime/pull/4747 lands, we are in pretty good shape for windows support. If anyone wants to test it out in the mean time, this branch enables pretty much everything that we need.
As mentioned in https://github.com/bjorn3/rustc_codegen_cranelift/issues/1249#issuecomment-1221358262 we are still missing JIT support, and its currently disabled in the testsuite.
I had a go at enabling the JIT tests, but it fails in jit.mini_core_hello_world
.
It panics with: thread 'rustc' panicked at 'can't resolve symbol _ZN9mini_core8A_STATIC17hc53ef79cc689fdd5E'
, and it looks like its because the object
crate does not enumerate dll exports so no symbols are ever registered. (this also looks like what is reported in #1197)
I checked with dumpbin.exe
and the symbol is exported in the dll, so we should be good in that regard.
Edit: Tried to run the objdump
example from the object
crate in the current master
branch, and it detects the symbols! But it looks like it uses file.symbols()
instead of file.dynamic_symbols()
like we use in the JIT.
Edit2: Opened https://github.com/gimli-rs/object/issues/457
https://github.com/bytecodealliance/wasmtime/pull/4747 Is merged! 🎉 . With that I think we should remove the MSVC check on y.rs
and enable inline stackprobing for Windows once cranelift 0.88 lands (CC #1276 I guess?).
Additionally on my TODO list is adding MSVC to CI.
From here, follow up work is the following:
- Testing
test_bootstrap.sh
- Testing
test_rustc_tests.sh
- The JIT needs some love, its crashing in
std_example
(see: https://github.com/bjorn3/rustc_codegen_cranelift/pull/1273#issue-1353291888)
Although I'm quite busy now so I might not get to these anytime soon.
This should be done now thanks to @afonso360.