Skip to content

Linker errors when compiling for ATmega2560 with recent rust compiler (>2022-10-22) #388

Closed
@arnemileswinter

Description

@arnemileswinter

Hello!

I'm pretty new to cross-compiling.

I created a nix environment in which i can compile the .ELF file for some targets.

For example, the target avr-atmega328p.json works:

bash-5.1$ cargo build --target avr-specs/avr-atmega328p.json 
   Compiling compiler_builtins v0.1.85
   Compiling core v0.0.0 (/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/src/rust/library/core)
   Compiling avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a7
   [..... i am skipping some lines ....]
   Compiling helloworld v0.1.0 (/home/arne/Projects/hobby/rust-arduino-led-blink)
    Finished dev [optimized + debuginfo] target(s) in 20.01s

And i get target/avr-atmega328p/debug/helloworld.elf.

But the arduino that i have at my disposal is the atmega2560, i get the following output:

bash-5.1$ cargo build --target avr-specs/avr-atmega2560.json --verbose
       Fresh core v0.0.0 (/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/src/rust/library/core)
       Fresh rustc-std-workspace-core v1.99.0 (/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/src/rust/library/rustc-std-workspace-core)
       Fresh unicode-ident v1.0.6
       Fresh compiler_builtins v0.1.85
       Fresh proc-macro2 v1.0.49
       Fresh quote v1.0.23
       Fresh nb v1.0.0
       Fresh syn v1.0.107
       Fresh proc-macro-hack v0.5.20+deprecated
       Fresh rustversion v1.0.11
       Fresh ufmt-macros v0.2.0
       Fresh avr-device-macros v0.4.0
       Fresh nb v0.1.3
       Fresh ufmt-write v0.1.0
       Fresh bare-metal v1.0.0
       Fresh cfg-if v0.1.10
       Fresh void v1.0.2
       Fresh vcell v0.1.3
       Fresh ufmt v0.1.2
       Fresh paste v1.0.11
       Fresh embedded-hal v0.2.7
       Fresh avr-device v0.4.0
       Fresh cfg-if v1.0.0
       Fresh avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a773)
       Fresh panic-halt v0.2.0
       Fresh atmega-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a773)
       Fresh arduino-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4170a773d4d76cc93433d2455ed8b14e573ebe70#4170a773)
   Compiling helloworld v0.1.0 (/home/arne/Projects/hobby/rust-arduino-led-blink)
     Running `rustc --crate-name helloworld --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type bin --emit=dep-info,link -C opt-level=s -C panic=abort -C lto -C debuginfo=2 -C debug-assertions=on -C metadata=fbe7e5f7c81a8527 -C extra-filename=-fbe7e5f7c81a8527 --out-dir /home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps --target /home/arne/Projects/hobby/rust-arduino-led-blink/avr-specs/avr-atmega2560.json -C incremental=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/incremental -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/debug/deps --extern arduino_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libarduino_hal-b20db3fb6d901e6a.rlib --extern 'noprelude:compiler_builtins=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcompiler_builtins-03a22ee3553a16ba.rlib' --extern 'noprelude:core=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcore-8e43a845006832d0.rlib' --extern embedded_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libembedded_hal-2eda8d6ea831d148.rlib --extern nb=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libnb-1af58d0fb3475ee9.rlib --extern panic_halt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libpanic_halt-d2460f22359f919f.rlib --extern ufmt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libufmt-a9534496297e0ed1.rlib -Z unstable-options`
error: linking with `avr-gcc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/x86_64-unknown-linux-gnu/bin:/nix/store/g2nfbpind37b3v3y6zbszmcgfmrj5v7x-patchelf-0.15.0/bin:/nix/store/wn31i3dzwahz6ccws8bs1nwyqrpgsvj7-gcc-wrapper-11.3.0/bin:/nix/store/sxdx80lmk4zkhb51f4x5dgqvxgmx55wl-gcc-11.3.0/bin:/nix/store/s7ip867mrpnnjlppbnxlcsq10gv13x2x-glibc-2.35-224-bin/bin:/nix/store/h8gvq6r4hgpa71h44dmg9qfx03mj81sv-coreutils-9.1/bin:/nix/store/62fb427ncxaaksa2k59rhbilfg68v20x-binutils-wrapper-2.39/bin:/nix/store/frh9l9nrdysasdi2gs7i241s241ngjw2-binutils-2.39/bin:/nix/store/bzc9c4x9fqwjaxs0g45qkahabc0gv75f-avrdude-7.0/bin:/nix/store/fznym4mxp2q5r0bg6zdpska27xcq1iv3-ravedude-0.1.5/bin:/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/bin:/nix/store/88awvrn16car4z5xx516drhpbl2sp5h8-avr-stage-final-gcc-wrapper-11.3.0/bin:/nix/store/7zlcl5m0vq5cl5kcl1swb67wczms78al-avr-stage-final-gcc-11.3.0/bin:/nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/bin:/nix/store/qyrv5scy0pda6cm10mdn66nd6shh907a-avr-binutils-wrapper-2.39/bin:/nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin:/nix/store/h8gvq6r4hgpa71h44dmg9qfx03mj81sv-coreutils-9.1/bin:/nix/store/zml88vnkpm8if114qkbbqd1q7n3ypqqy-findutils-4.9.0/bin:/nix/store/49y3r0gr9m6k20d91kl6dgp4b9a6m72v-diffutils-3.8/bin:/nix/store/5dv5cq1lwvsijr9p16p2kp79g1dbajk3-gnused-4.8/bin:/nix/store/bcvccw6y9bfil6xrl5j7psza7hnd16ry-gnugrep-3.7/bin:/nix/store/l1fp0hyca54xbb85vfhppd16bskzx8dg-gawk-5.1.1/bin:/nix/store/89zbjdkb48ma61k76l2mzn3s0ra0wn2c-gnutar-1.34/bin:/nix/store/qs8qb1swpivkfq7i9yd52n0mw6z4ij81-gzip-1.12/bin:/nix/store/wwkyfg8b34xy16zzc9p6rkh59p4q37qx-bzip2-1.0.8-bin/bin:/nix/store/i0x4pzj96qwvkrm94317l6jbi53a2rdj-gnumake-4.4/bin:/nix/store/4xw8n979xpivdc46a9ndcvyhwgif00hz-bash-5.1-p16/bin:/nix/store/793iwfbjvg7wgpqq7r83a1qjl1yg02sf-patch-2.7.6/bin:/nix/store/a3mwv26f99ycsv9w6hrx0jjjjywvcb1n-xz-5.2.9-bin/bin:/nix/store/camlh5laf1wsklghk0vcaw7gvx4rpzd1-file-5.43/bin:/home/arne/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/home/arne/.cargo/bin:/home/arne/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/arne/.cabal/bin:/home/arne/.ghcup/bin:/home/arne/.yarn/bin:/home/arne/.emacs.d/bin:/home/arne/.yarn/bin:/home/arne/.emacs.d/bin" VSLANG="1033" "avr-gcc" "-mmcu=atmega2560" "-Wl,--as-needed" "/tmp/nix-shell.pCNOuF/rustcaIPZ4U/symbols.o" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/helloworld-fbe7e5f7c81a8527.arduino_hal-b20db3fb6d901e6a.arduino_hal.4ff7873c-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps" "-L" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/debug/deps" "-L" "/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/avr-atmega2560/lib" "-Wl,-Bstatic" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcompiler_builtins-03a22ee3553a16ba.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-znoexecstack" "-L" "/nix/store/r9ns07w4z808rpysvg4z84bx3q525yv7-rust-mixed/lib/rustlib/avr-atmega2560/lib" "-o" "/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/helloworld-fbe7e5f7c81a8527.elf" "-Wl,--gc-sections" "-no-pie"
  = note: /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr5/libm.a when searching for -lm
          /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr3/libm.a when searching for -lm
          /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr4/libm.a when searching for -lm
          /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr5/libc.a when searching for -lc
          /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr3/libc.a when searching for -lc
          /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: skipping incompatible /nix/store/5kh0ddszrd1d04z61kw1b2302z7mbnkp-avr-libc-avr-2.1.0/avr/lib/avr4/libc.a when searching for -lc
          /nix/store/kzjyiw72pi5d7hgyrs0l1fgqq31zj6cs-avr-binutils-2.39/bin/avr-ld: avr architecture of input file `/tmp/nix-shell.pCNOuF/rustcaIPZ4U/symbols.o' is incompatible with avr:6 output
          collect2: error: ld returned 1 exit status
          

error: could not compile `helloworld` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name helloworld --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=149 --crate-type bin --emit=dep-info,link -C opt-level=s -C panic=abort -C lto -C debuginfo=2 -C debug-assertions=on -C metadata=fbe7e5f7c81a8527 -C extra-filename=-fbe7e5f7c81a8527 --out-dir /home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps --target /home/arne/Projects/hobby/rust-arduino-led-blink/avr-specs/avr-atmega2560.json -C incremental=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/incremental -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps -L dependency=/home/arne/Projects/hobby/rust-arduino-led-blink/target/debug/deps --extern arduino_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libarduino_hal-b20db3fb6d901e6a.rlib --extern 'noprelude:compiler_builtins=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcompiler_builtins-03a22ee3553a16ba.rlib' --extern 'noprelude:core=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libcore-8e43a845006832d0.rlib' --extern embedded_hal=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libembedded_hal-2eda8d6ea831d148.rlib --extern nb=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libnb-1af58d0fb3475ee9.rlib --extern panic_halt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libpanic_halt-d2460f22359f919f.rlib --extern ufmt=/home/arne/Projects/hobby/rust-arduino-led-blink/target/avr-atmega2560/debug/deps/libufmt-a9534496297e0ed1.rlib -Z unstable-options` (exit status: 1)

I don't understand why it doesn't work for the latter target.

The repository is here: https://github.com/arnemileswinter/rust-arduino-cross-compile-nix-blinking-led
and is based on the cargo template.

Thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    compiler-bugNot a bug in avr-hal, but a bug in the rust compiler/LLVM

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions