mrk-its / rust-mos

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
57 stars 7 forks source link

LLVM ERROR: unable to legalize instruction: %57:_(s128) = G_UDIV %0:_, %1:_ #29

Open cyborgyn opened 8 months ago

cyborgyn commented 8 months ago

On a fresh install for LLVM-MOS, LLVM-MOS-SDK, RUST-MOS git latest all, default branch, would have loved to try out one of your examples (pi calculations) from here: https://github.com/mrk-its/aoc2022/tree/main/pi

Compile complained for missing core, so tried to compile it:

# RUST_BACKTRACE=1 cargo build -Zbuild-std -v

Main error is:

LLVM ERROR: unable to legalize instruction: %57:_(s128) = G_UDIV %0:_, %1:_ (in function: _ZN46_$LT$u128$u20$as$u20$core..ops..arith..Div$GT$3div17hc67d425184e61060E)
error: could not compile `core` (lib)

version infos:

# llc --version
LLVM (http://llvm.org/):
  LLVM version 19.0.0git
  Optimized build.
  Default target: mos-unknown-unknown
  Host CPU: znver4

  Registered Targets:
    arm     - ARM
    armeb   - ARM (big endian)
    mos     - MOS Technologies 65xx and variants
    thumb   - Thumb
    thumbeb - Thumb (big endian)
    x86     - 32-bit X86: Pentium-Pro and above
    x86-64  - 64-bit X86: EM64T and AMD64

# rustc --print target-list | grep mos-
mos-unknown-none

# rustc --version --verbose
rustc 1.78.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.78.0-dev
LLVM version: 19.0.0

Output of:

# RUST_BACKTRACE=1 cargo build -Zbuild-std -v
    Updating git repository `https://github.com/mrk-its/compiler-builtins`
    Updating crates.io index
   Compiling core v0.0.0 (/home/cyborgyn/.rust/lib/rustlib/src/rust/library/core)
       Fresh unicode-ident v1.0.12
     Running `rustc --crate-name core --edition=2021 /home/cyborgyn/.rust/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=164 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=06099055ffadbb8c -C extra-filename=-06099055ffadbb8c --out-dir /home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps --target /home/cyborgyn/Sources/poc_c64_rust/mos-c64-none.json -Z force-unstable-if-unmarked -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/debug/deps --cap-lints allow`
       Fresh proc-macro2 v1.0.78
       Fresh quote v1.0.35
       Fresh syn v1.0.109
       Fresh ufmt-macros v0.3.0
       Fresh mos-test-macros v0.0.1
       Dirty rustc-std-workspace-core v1.99.0 (/home/cyborgyn/.rust/lib/rustlib/src/rust/library/rustc-std-workspace-core): the dependency core was rebuilt
   Compiling rustc-std-workspace-core v1.99.0 (/home/cyborgyn/.rust/lib/rustlib/src/rust/library/rustc-std-workspace-core)
     Running `rustc --crate-name rustc_std_workspace_core --edition=2021 /home/cyborgyn/.rust/lib/rustlib/src/rust/library/rustc-std-workspace-core/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=164 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=6b3fa98473dd4918 -C extra-filename=-6b3fa98473dd4918 --out-dir /home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps --target /home/cyborgyn/Sources/poc_c64_rust/mos-c64-none.json -Z force-unstable-if-unmarked -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/debug/deps --extern core=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps/libcore-06099055ffadbb8c.rmeta --cap-lints allow`
       Dirty compiler_builtins v0.1.108 (https://github.com/mrk-its/compiler-builtins?branch=mos-0.1.108#34ac1f85): the dependency core was rebuilt
   Compiling compiler_builtins v0.1.108 (https://github.com/mrk-its/compiler-builtins?branch=mos-0.1.108#34ac1f85)
       Dirty libc v0.2.153: the dependency rustc_std_workspace_core was rebuilt
   Compiling libc v0.2.153
     Running `rustc --crate-name compiler_builtins --edition=2018 /home/cyborgyn/.cargo/git/checkouts/compiler-builtins-6e48e97653cc45c3/34ac1f8/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=164 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="compiler-builtins"' --cfg 'feature="core"' --cfg 'feature="default"' --cfg 'feature="rustc-dep-of-std"' -C metadata=ca8b9e9df8d5b90b -C extra-filename=-ca8b9e9df8d5b90b --out-dir /home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps --target /home/cyborgyn/Sources/poc_c64_rust/mos-c64-none.json -Z force-unstable-if-unmarked -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/debug/deps --extern core=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps/librustc_std_workspace_core-6b3fa98473dd4918.rmeta --cap-lints allow --cfg 'feature="unstable"' --cfg 'feature="mem"'`
     Running `rustc --crate-name libc /home/cyborgyn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/libc-0.2.153/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=164 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="align"' --cfg 'feature="rustc-dep-of-std"' --cfg 'feature="rustc-std-workspace-core"' -C metadata=083516a6243abd82 -C extra-filename=-083516a6243abd82 --out-dir /home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps --target /home/cyborgyn/Sources/poc_c64_rust/mos-c64-none.json -Z force-unstable-if-unmarked -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/debug/deps --extern rustc_std_workspace_core=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps/librustc_std_workspace_core-6b3fa98473dd4918.rmeta --cap-lints allow --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_int128 --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor --cfg libc_non_exhaustive --cfg libc_long_array --cfg libc_ptr_addr_of --cfg libc_underscore_const_names --cfg libc_thread_local --cfg libc_const_extern_fn`
LLVM ERROR: unable to legalize instruction: %57:_(s128) = G_UDIV %0:_, %1:_ (in function: _ZN46_$LT$u128$u20$as$u20$core..ops..arith..Div$GT$3div17hc67d425184e61060E)
error: could not compile `core` (lib)

Caused by:
  process didn't exit successfully: `rustc --crate-name core --edition=2021 /home/cyborgyn/.rust/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=164 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=06099055ffadbb8c -C extra-filename=-06099055ffadbb8c --out-dir /home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps --target /home/cyborgyn/Sources/poc_c64_rust/mos-c64-none.json -Z force-unstable-if-unmarked -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/mos-c64-none/debug/deps -L dependency=/home/cyborgyn/Sources/poc_c64_rust/target/debug/deps --cap-lints allow` (exit status: 101)
warning: build failed, waiting for other jobs to finish...
sajattack commented 4 months ago

Seeing a similar issue here with latest rust-mos

LLVM ERROR: unable to legalize instruction: %44:_(s128) = G_UDIV %0:_, %43:_ (in function: _ZN4core3num22_$LT$impl$u20$u128$GT$6ilog1017hc5ef0d8092a2cd16E)
error: could not compile `core` (lib)
sajattack commented 4 months ago

try enabling lto, fixed it for me.