mrustc
mrustc copied to clipboard
Fails to bootstrap rust-1.54.0 on aarch64 / macOS 12
I'm running on a local root 2c4f89f87692f27246d1bc1e42c8d43df8514a71 ./build-1.54.0.sh
which is failed as:
> /Users/catap/src/mrustc/bin/mrustc -Z print-cfgs
(0/13) BUILDING core v0.0.0
> /Users/catap/src/mrustc/bin/mrustc rustc-1.54.0-src/library/core/src/lib.rs -o output-1.54.0/libcore.rlib --crate-name core --crate-type rlib -C emit-depfile=output-1.54.0/libcore.rlib.d --crate-tag 0_0_0 --cfg debug_assertions -O -L output-1.54.0 --edition 2018
:0: BUG:src/mir/from_hir.cpp:524: TODO: visit - asm! const
Process was terminated with signal 6
FAILING COMMAND: /Users/catap/src/mrustc/bin/mrustc rustc-1.54.0-src/library/core/src/lib.rs -o output-1.54.0/libcore.rlib --crate-name core --crate-type rlib -C emit-depfile=output-1.54.0/libcore.rlib.d --crate-tag 0_0_0 --cfg debug_assertions -O -L output-1.54.0 --edition 2018
BUILD FAILED
make: *** [output-1.54.0/libstd.rlib] Error 1
Update: Blocked mostly on my primary checkout currently being from the borrowcheck branch, and not having an aarch64 machine for testing.
@thepowersgang I do have an aarch64 machine and may easy test it in couple of days.
It's not fixed yet, just noting that I don't have a solid way of testing.
Might be fixed by the above - it compiles but can't check the gcc
invocation
@thepowersgang I've used 11a9c01119988e30ba40bab4ee5f60753c0c4b61 as local root which had failed as:
(0/13) BUILDING core v0.0.0
> /Users/catap/src/mrustc/bin/mrustc rustc-1.54.0-src/library/core/src/lib.rs -o output-1.54.0/libcore.rlib --crate-name core --crate-type rlib -C emit-depfile=output-1.54.0/libcore.rlib.d --crate-tag 0_0_0 --cfg debug_assertions -O -L output-1.54.0 --edition 2018
output-1.54.0/libcore.rlib.c:113819:23: error: unknown directive
__asm__ __volatile__(".intel_syntax; nop;\n .att_syntax; " : :);
^
<inline asm>:1:2: note: instantiated into assembly here
.intel_syntax; nop;
^
output-1.54.0/libcore.rlib.c:113819:45: error: unknown directive
__asm__ __volatile__(".intel_syntax; nop;\n .att_syntax; " : :);
^
<inline asm>:2:2: note: instantiated into assembly here
.att_syntax;
^
2 errors generated.
C Compiler failed to execute - error code 256
Process exited with non-zero exit status 1
Fixed the above mentioned error, still untested
@thepowersgang seems it is working. Trying the whole bootstrap:
catap@Kirills-mini-m1 mrustc % file output-1.54.0/rustc
output-1.54.0/rustc: Mach-O 64-bit executable arm64
catap@Kirills-mini-m1 mrustc %
Ok, it had failed on linking cargo
as:
> /Users/catap/src/mrustc/bin/mrustc -Z print-cfgs
BUILDING cargo v0.55.0
> /Users/catap/src/mrustc/bin/mrustc rustc-1.54.0-src/src/tools/cargo/src/bin/cargo/main.rs -o output-1.54.0/cargo-build/cargo --crate-name cargo --crate-type bin -C emit-depfile=output-1.54.0/cargo-build/cargo.d --crate-tag 0_55_0 --cfg debug_assertions -O -L output-1.54.0 -L output-1.54.0/cargo-build --extern cargo=output-1.54.0/cargo-build/libcargo-0_55_0.rlib --edition 2018 --extern atty=output-1.54.0/cargo-build/libatty-0_2_14.rlib --extern bytesize=output-1.54.0/cargo-build/libbytesize-1_0_1.rlib --extern cargo_platform=output-1.54.0/cargo-build/libcargo_platform-0_1_1.rlib --extern cargo_util=output-1.54.0/cargo-build/libcargo_util-0_1_0.rlib --extern crates_io=output-1.54.0/cargo-build/libcrates_io-0_33_0.rlib --extern crossbeam_utils=output-1.54.0/cargo-build/libcrossbeam_utils-0_8_5_H7.rlib --extern curl=output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib --extern curl_sys=output-1.54.0/cargo-build/libcurl_sys-0_4_42_H46.rlib --extern env_logger=output-1.54.0/cargo-build/libenv_logger-0_8_3_Hf.rlib --extern anyhow=output-1.54.0/cargo-build/libanyhow-1_0_40_H2.rlib --extern filetime=output-1.54.0/cargo-build/libfiletime-0_2_14.rlib --extern flate2=output-1.54.0/cargo-build/libflate2-1_0_20_H411.rlib --extern git2=output-1.54.0/cargo-build/libgit2-0_13_17_H7.rlib --extern git2_curl=output-1.54.0/cargo-build/libgit2_curl-0_14_1.rlib --extern glob=output-1.54.0/cargo-build/libglob-0_3_0.rlib --extern hex=output-1.54.0/cargo-build/libhex-0_4_2_H2.rlib --extern home=output-1.54.0/cargo-build/libhome-0_5_3.rlib --extern humantime=output-1.54.0/cargo-build/libhumantime-2_0_1.rlib --extern ignore=output-1.54.0/cargo-build/libignore-0_4_17.rlib --extern lazy_static=output-1.54.0/cargo-build/liblazy_static-1_4_0.rlib --extern jobserver=output-1.54.0/cargo-build/libjobserver-0_1_22.rlib --extern lazycell=output-1.54.0/cargo-build/liblazycell-1_3_0.rlib --extern libc=output-1.54.0/cargo-build/liblibc-0_2_95_H21.rlib --extern log=output-1.54.0/cargo-build/liblog-0_4_14_H20000.rlib --extern libgit2_sys=output-1.54.0/cargo-build/liblibgit2_sys-0_12_18_H1f.rlib --extern memchr=output-1.54.0/cargo-build/libmemchr-2_4_0_H6.rlib --extern num_cpus=output-1.54.0/cargo-build/libnum_cpus-1_13_0.rlib --extern opener=output-1.54.0/cargo-build/libopener-0_4_1.rlib --extern percent_encoding=output-1.54.0/cargo-build/libpercent_encoding-2_1_0.rlib --extern rustfix=output-1.54.0/cargo-build/librustfix-0_5_1.rlib --extern semver=output-1.54.0/cargo-build/libsemver-1_0_3_H3.rlib --extern serde=output-1.54.0/cargo-build/libserde-1_0_126_H1a.rlib --extern serde_ignored=output-1.54.0/cargo-build/libserde_ignored-0_1_2.rlib --extern serde_json=output-1.54.0/cargo-build/libserde_json-1_0_64_He0.rlib --extern shell_escape=output-1.54.0/cargo-build/libshell_escape-0_1_5.rlib --extern strip_ansi_escapes=output-1.54.0/cargo-build/libstrip_ansi_escapes-0_1_0.rlib --extern tar=output-1.54.0/cargo-build/libtar-0_4_35.rlib --extern tempfile=output-1.54.0/cargo-build/libtempfile-3_2_0.rlib --extern termcolor=output-1.54.0/cargo-build/libtermcolor-1_1_2.rlib --extern toml=output-1.54.0/cargo-build/libtoml-0_5_7.rlib --extern unicode_xid=output-1.54.0/cargo-build/libunicode_xid-0_2_2.rlib --extern url=output-1.54.0/cargo-build/liburl-2_2_2_H1.rlib --extern walkdir=output-1.54.0/cargo-build/libwalkdir-2_3_2.rlib --extern clap=output-1.54.0/cargo-build/libclap-2_33_3_H260b.rlib --extern unicode_width=output-1.54.0/cargo-build/libunicode_width-0_1_8.rlib --extern im_rc=output-1.54.0/cargo-build/libim_rc-15_0_0.rlib --extern itertools=output-1.54.0/cargo-build/libitertools-0_10_0_H3.rlib --extern rustc_workspace_hack=output-1.54.0/cargo-build/librustc_workspace_hack-1_0_0.rlib --extern rand=output-1.54.0/cargo-build/librand-0_8_3_H1847.rlib
ld: reference to symbol (which has not been assigned an address) _ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g in '_ZRG1cE14curl0_4_36_H224init0g' from output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.o for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
C Compiler failed to execute - error code 256
Process exited with non-zero exit status 1
FAILING COMMAND: /Users/catap/src/mrustc/bin/mrustc rustc-1.54.0-src/src/tools/cargo/src/bin/cargo/main.rs -o output-1.54.0/cargo-build/cargo --crate-name cargo --crate-type bin -C emit-depfile=output-1.54.0/cargo-build/cargo.d --crate-tag 0_55_0 --cfg debug_assertions -O -L output-1.54.0 -L output-1.54.0/cargo-build --extern cargo=output-1.54.0/cargo-build/libcargo-0_55_0.rlib --edition 2018 --extern atty=output-1.54.0/cargo-build/libatty-0_2_14.rlib --extern bytesize=output-1.54.0/cargo-build/libbytesize-1_0_1.rlib --extern cargo_platform=output-1.54.0/cargo-build/libcargo_platform-0_1_1.rlib --extern cargo_util=output-1.54.0/cargo-build/libcargo_util-0_1_0.rlib --extern crates_io=output-1.54.0/cargo-build/libcrates_io-0_33_0.rlib --extern crossbeam_utils=output-1.54.0/cargo-build/libcrossbeam_utils-0_8_5_H7.rlib --extern curl=output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib --extern curl_sys=output-1.54.0/cargo-build/libcurl_sys-0_4_42_H46.rlib --extern env_logger=output-1.54.0/cargo-build/libenv_logger-0_8_3_Hf.rlib --extern anyhow=output-1.54.0/cargo-build/libanyhow-1_0_40_H2.rlib --extern filetime=output-1.54.0/cargo-build/libfiletime-0_2_14.rlib --extern flate2=output-1.54.0/cargo-build/libflate2-1_0_20_H411.rlib --extern git2=output-1.54.0/cargo-build/libgit2-0_13_17_H7.rlib --extern git2_curl=output-1.54.0/cargo-build/libgit2_curl-0_14_1.rlib --extern glob=output-1.54.0/cargo-build/libglob-0_3_0.rlib --extern hex=output-1.54.0/cargo-build/libhex-0_4_2_H2.rlib --extern home=output-1.54.0/cargo-build/libhome-0_5_3.rlib --extern humantime=output-1.54.0/cargo-build/libhumantime-2_0_1.rlib --extern ignore=output-1.54.0/cargo-build/libignore-0_4_17.rlib --extern lazy_static=output-1.54.0/cargo-build/liblazy_static-1_4_0.rlib --extern jobserver=output-1.54.0/cargo-build/libjobserver-0_1_22.rlib --extern lazycell=output-1.54.0/cargo-build/liblazycell-1_3_0.rlib --extern libc=output-1.54.0/cargo-build/liblibc-0_2_95_H21.rlib --extern log=output-1.54.0/cargo-build/liblog-0_4_14_H20000.rlib --extern libgit2_sys=output-1.54.0/cargo-build/liblibgit2_sys-0_12_18_H1f.rlib --extern memchr=output-1.54.0/cargo-build/libmemchr-2_4_0_H6.rlib --extern num_cpus=output-1.54.0/cargo-build/libnum_cpus-1_13_0.rlib --extern opener=output-1.54.0/cargo-build/libopener-0_4_1.rlib --extern percent_encoding=output-1.54.0/cargo-build/libpercent_encoding-2_1_0.rlib --extern rustfix=output-1.54.0/cargo-build/librustfix-0_5_1.rlib --extern semver=output-1.54.0/cargo-build/libsemver-1_0_3_H3.rlib --extern serde=output-1.54.0/cargo-build/libserde-1_0_126_H1a.rlib --extern serde_ignored=output-1.54.0/cargo-build/libserde_ignored-0_1_2.rlib --extern serde_json=output-1.54.0/cargo-build/libserde_json-1_0_64_He0.rlib --extern shell_escape=output-1.54.0/cargo-build/libshell_escape-0_1_5.rlib --extern strip_ansi_escapes=output-1.54.0/cargo-build/libstrip_ansi_escapes-0_1_0.rlib --extern tar=output-1.54.0/cargo-build/libtar-0_4_35.rlib --extern tempfile=output-1.54.0/cargo-build/libtempfile-3_2_0.rlib --extern termcolor=output-1.54.0/cargo-build/libtermcolor-1_1_2.rlib --extern toml=output-1.54.0/cargo-build/libtoml-0_5_7.rlib --extern unicode_xid=output-1.54.0/cargo-build/libunicode_xid-0_2_2.rlib --extern url=output-1.54.0/cargo-build/liburl-2_2_2_H1.rlib --extern walkdir=output-1.54.0/cargo-build/libwalkdir-2_3_2.rlib --extern clap=output-1.54.0/cargo-build/libclap-2_33_3_H260b.rlib --extern unicode_width=output-1.54.0/cargo-build/libunicode_width-0_1_8.rlib --extern im_rc=output-1.54.0/cargo-build/libim_rc-15_0_0.rlib --extern itertools=output-1.54.0/cargo-build/libitertools-0_10_0_H3.rlib --extern rustc_workspace_hack=output-1.54.0/cargo-build/librustc_workspace_hack-1_0_0.rlib --extern rand=output-1.54.0/cargo-build/librand-0_8_3_H1847.rlib
BUILD FAILED
make: *** [output-1.54.0/cargo] Error 1
if I run a grep against output folder by this symbol I have:
catap@Kirills-mini-m1 mrustc % grep -irn _ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g output-1.54.0
Binary file output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.o matches
output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.c:16307:__attribute__((section("__DATA,__mod_init_func"))) union u_static_ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g{ t_ZRTFe1C0T0 val; uintptr_t raw[1]; } ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g; // static ::"curl-0_4_36_H22"::#0::INIT_CTOR : extern "C" fn() -> ()
output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.c:16366:union u_static_ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g = { .raw = {(uintptr_t)&ZRG2cE14curl0_4_36_H22B_010init_inner0g} }; // static ::"curl-0_4_36_H22"::#0::INIT_CTOR : extern "C" fn() -> () = 0010000000000000{@0x0+8 = &::"curl-0_4_36_H22"::#0::init_inner}
catap@Kirills-mini-m1 mrustc %
the only binary which contains such symbol is arm64
and nm says:
catap@Kirills-mini-m1 mrustc % nm output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.o | grep _ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g
0000000000018850 S _ZRG2cE14curl0_4_36_H22B_09INIT_CTOR0g
catap@Kirills-mini-m1 mrustc % lipo -info output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.o
Non-fat file: output-1.54.0/cargo-build/libcurl-0_4_36_H22.rlib.o is architecture: arm64
catap@Kirills-mini-m1 mrustc %
Might be some quirk with that section attribute causing the symbol to be unavailable? I'm not to experienced with the quirks of MacOS linking.
@thepowersgang on x86_64 it links fine, the issue is arm64 :(
And the section attributes are likely per-architecture.
I've created a simple c program which is similar one that is created by mrust:
#include <stdint.h>
typedef void (*my_typedef)(void);
void my_callback(void);
__attribute__((section("__DATA,__mod_init_func"))) union u_static_my_union{ my_typedef val; uintptr_t raw[1]; } my_union;
union u_static_my_union my_union = { .raw = {(uintptr_t)&my_callback} };
void my_callback(void) {
}
int main() {
my_union.val();
return 0;
}
I've used:
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
and it can't compile it with error like:
ld: reference to symbol (which has not been assigned an address) _my_union in '_main' from /var/folders/t0/n5crg2q177944y2q4tfrt3dc0000gn/T/test-d73a4d.o for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
from another hand on:
Apple clang version 14.0.0 (clang-1400.0.29.102)
Target: x86_64-apple-darwin21.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
it is compiled just fine.
Removing __attribute__((section("__DATA,__mod_init_func")))
helps to compile it on aarch64.
Yahoo! https://github.com/thepowersgang/mrustc/pull/292 allows to achieve:
catap@Mac-mini mrustc % output-1.54.0/rustc-build/rustc_main --version
rustc 1.54.0-stable-mrustc
catap@Mac-mini mrustc % output-1.54.0/cargo-build/cargo --version
cargo 1.54.0
catap@Mac-mini mrustc % file output-1.54.0/rustc-build/rustc_main
output-1.54.0/rustc-build/rustc_main: Mach-O 64-bit executable arm64
catap@Mac-mini mrustc % file output-1.54.0/cargo-build/cargo
output-1.54.0/cargo-build/cargo: Mach-O 64-bit executable arm64
catap@Mac-mini mrustc %
Just for the record. #292 successfully bootstrap rustc as:
env OPENSSL_DIR=/opt/local/libexec/openssl11 RUSTC_VERSION=1.54.0 MRUSTC_TARGET_VER=1.54 OUTDIR_SUF=-1.54.0 RUSTC_TARGET=aarch64-apple-darwin make -C run_rustc
...
Finished release [optimized] target(s) in 30.21s
[RUSTC] -o output-1.54.0/prefix/bin/hello_world
./output-1.54.0/prefix/bin/hello_world
hello, world
with expected adjustment:
diff --git a/script-overrides/stable-1.54.0-macos/build_std.txt b/script-overrides/stable-1.54.0-macos/build_std.txt
index 5c2c9ce3..1daec622 100644
--- a/script-overrides/stable-1.54.0-macos/build_std.txt
+++ b/script-overrides/stable-1.54.0-macos/build_std.txt
@@ -1,2 +1,2 @@
cargo:rustc-cfg=backtrace_in_libstd
-cargo:rustc-env=STD_ENV_ARCH=x86_64
+cargo:rustc-env=STD_ENV_ARCH=aarch64
FYI: rust was suceffuly build on arm64 on MacPorts build bots: https://ports.macports.org/port/mrustc-rust/details/
yay!