rui314 / mold

Mold: A Modern Linker 🦠
MIT License
14.47k stars 473 forks source link

Get help, where can can I have example about rust riscv target. #968

Open yuyang-ok opened 1 year ago

yuyang-ok commented 1 year ago
[target.riscv64gc-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=/home/yuyang/projects/mold/build/mold -m elf64-littleriscv"]
runner = "qemu-riscv64-static -L /usr/riscv64-linux-gnu  -E RUST_LOG=trace   -E CRANELIFT_TEST_BLESS=1   -E LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib -E WASMTIME_TEST_NO_HOG_MEMORY=1"

I don't where to add the option -m.

rui314 commented 1 year ago

What was the error?

yuyang-ok commented 1 year ago

$ cargo test --target riscv64gc-unknown-linux-gnu Compiling abc-rust v0.1.0 (/home/yuyang/projects/abc-rust) error: linking with clang failed: exit status: 1 | = note: "clang" "/tmp/rustcGbrfCS/symbols.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.1nj5mg1j7iuf433k.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.1qt293379h83shyv.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.1sd3ec0l268ai3qn.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.1sdqfho18gbwgduw.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.1udrkgfj0ydp6cmg.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.1v3bzwg9lac2mr1u.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.21rvjo1ikueaagwy.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.2ely8kpbzqcv23n0.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.2fwmcu51s9ahpxtn.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.2qoydlff29covcu3.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.3u51odrv1wybxpg5.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.3zltratlgyquzo78.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.4gvvtci1c0tphrso.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.4y3u5vzxt4y1tfpg.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.5dr6im6ia1i3yukp.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.5du0i9mg1hm3oyx9.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.8spnb14xu0qg6g7.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.a1oxd6ofukpugr.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.cjny70nf2vquqqa.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.jmeojzynhco5lz2.rcgu.o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.34mn6ep9b8jgheri.rcgu.o" "-Wl,--as-needed" "-L" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps" "-L" "/home/yuyang/projects/abc-rust/target/debug/deps" "-L" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libtest-1c98fb79c7914d66.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libgetopts-e863f0b6c8e3c081.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libunicode_width-be988967b06e6937.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_std_workspace_std-7f0153d38fe37b02.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libstd-d9e823159e0c6411.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libpanic_unwind-fc6e65b9996eff8c.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libobject-cc7b575ae70a2ebb.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libmemchr-d73bc0c65032a9bf.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libaddr2line-7f7fa77188aacc20.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libgimli-c55ef8bb65940301.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_demangle-fce39a1afe3b8e70.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libstd_detect-dc3d809011ee6eee.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcfg_if-5318b5b707487619.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libhashbrown-51b1fd447b5f0859.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libminiz_oxide-45d471b7fae024ad.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libadler-f465afa5302cf997.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_std_workspace_alloc-97dcfc1eeb18b032.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libunwind-ffa05ddfec3b7b04.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcfg_if-8d354023bdea2a17.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/liblibc-f55fda3769944738.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/liballoc-bde6434e0a7a666c.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/librustc_std_workspace_core-c95ccfa0ee2535b6.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcore-15ff09b3e34b813f.rlib" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib/libcompiler_builtins-89c670e12c035edc.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/yuyang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/riscv64gc-unknown-linux-gnu/lib" "-o" "/home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs" "-fuse-ld=/home/yuyang/projects/mold/build/mold -m elf64-littleriscv" = note: clang: error: invalid linker name in argument '-fuse-ld=/home/yuyang/projects/mold/build/mold -m elf64-littleriscv'

error: could not compile abc-rust due to previous error

yuyang-ok commented 1 year ago

My old configuration is this.

[target.riscv64gc-unknown-linux-gnu]
linker = "riscv64-linux-gnu-gcc"
runner = "qemu-riscv64 -L /usr/riscv64-linux-gnu -E LD_LIBRARY_PATH=/usr/riscv64-linux-gnu/lib -E WASMTIME_TEST_NO_HOG_MEMORY=1"

But very slow. I change linker to clang ,Is that ok. mold can only work with clang ???

rui314 commented 1 year ago

So it tried to use /home/yuyang/projects/mold/build/mold -m elf64-littleriscv (including spaces, -m and elf64-littleriscv) as a linker name which obviously doesn't exist. I don't know how to pass multiple linker arguments to rustc, but it looks like just quoting everything isn't the right way to do it.

Alcaro commented 1 year ago

I think you need rustflags = ["-C", "link-arg=-fuse-ld=/home/yuyang/projects/mold/build/mold", "-C", "link-arg=-m", "-C, "link-arg="elf64-littleriscv"].

Or just rustflags = ["-C", "link-arg=-fuse-ld=/home/yuyang/projects/mold/build/mold"], iirc mold auto detects the architecture from the input files.

yuyang-ok commented 1 year ago

mold can detect the architecture but gives me a error.

 note: mold: fatal: /tmp/rustcTYAdLL/symbols.o: incompatible file type: x86_64 is expected but got riscv64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
rui314 commented 1 year ago

Can you link your program with clang but without mold?

yuyang-ok commented 1 year ago

No.

 = note: /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: Relocations in generic ELF (EM: 243)
          /usr/bin/ld: /home/yuyang/projects/abc-rust/target/riscv64gc-unknown-linux-gnu/debug/deps/abc_rust-46373540b811a4ee.16t7xw4hhdgudc5c.rcgu.o: error adding symbols: file in wrong format
          clang: error: linker command failed with exit code 1 (use -v to see invocation)
rui314 commented 1 year ago

Then you need to fix it first.

yuyang-ok commented 1 year ago

Ok,thanks I will try.

emmatebibyte commented 4 months ago

@yuyang-ok did you ever figure out the underlying issue?

siltyy commented 4 months ago

i figured out how to get this working, here's the relevant segment of my config.toml

[build]
target = "riscv64gc-unknown-none-elf"
rustflags = [
  "-Clinker=clang",  # use clang instead of rust-lld to get -fuse-ld support
  "-Clink-arg=--target=riscv64",  # ensure proper linker architecture is used
  "-Clink-arg=-fuse-ld=mold",  # force clang to use mold for linking
]