Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linking with avr-gcc failed #580

Open
xphoniex opened this issue Feb 9, 2023 · 15 comments
Open

linking with avr-gcc failed #580

xphoniex opened this issue Feb 9, 2023 · 15 comments

Comments

@xphoniex
Copy link

xphoniex commented Feb 9, 2023

trying to compile this crate for avr target and after adding alloc and implementing a dummy allocator, I'm getting:

error: linking with `avr-gcc` failed: exit status: 1
  |
  = note: "avr-gcc" "-mmcu=atmega328p" "-Wl,--as-needed" "/arduino-lib-rs/target/avr-atmega328p/debug/deps/arduino_lib-eba03eb7ff231966.secp256k1-39ff10e3da6aca26.secp256k1.20a321c8-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/arduino-lib-rs/target/avr-atmega328p/debug/deps" "-L" "/arduino-lib-rs/target/debug/deps" "-L" "/arduino-lib-rs/target/avr-atmega328p/debug/build/secp256k1-sys-3814b449d734bc91/out" "-L" "/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/avr-atmega328p/lib" "-Wl,-Bstatic" "/tmp/rustcbzOoYn/libsecp256k1_sys-3a3f6b652e34c422.rlib" "/arduino-lib-rs/target/avr-atmega328p/debug/deps/libcompiler_builtins-7aa2be695e3a21ba.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-znoexecstack" "-L" "/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/avr-atmega328p/lib" "-o" "/arduino-lib-rs/target/avr-atmega328p/debug/deps/arduino_lib-eba03eb7ff231966.elf" "-Wl,--gc-sections"
  = note: /tmp/rustcbzOoYn/libsecp256k1_sys-3a3f6b652e34c422.rlib: error adding symbols: File format not recognized
          collect2: error: ld returned 1 exit status

I tried RUSTFLAGS="--cfg=rust_secp_no_symbol_renaming" too, doesn't work.

anyone knows why I'm getting this error? is it even possible to link this for avr without extra work/config?

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 9, 2023

It looks like you're trying to link your project with a Rust library using gcc instead of rustc.

@xphoniex
Copy link
Author

xphoniex commented Feb 9, 2023

hm... I'm following the template from Rahix/avr-hal and it works when importing other no_std crates, you can see an exmaple here.

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 9, 2023

I think it could be unimplemented in the cc crate. There's no mention of AVR in issues, PRs or code. Did you try any other C-wrapping library which uses the CC crate?

@xphoniex
Copy link
Author

xphoniex commented Feb 9, 2023

It compiles fine if I remove the alloc feature with secp256k1 crate, not sure if that counts?

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 9, 2023

Oh that's really surprising. The feature should only affect which functions are available, not how linking is performed. Could you try to compile both cases with verbose flag and compare what's different?

@xphoniex
Copy link
Author

xphoniex commented Feb 9, 2023

made a mistake, the reason it was linking without alloc feature was because no code from secp256k1 was being used.

here's the verbose output:

       Fresh core v0.0.0 (/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
       Fresh unicode-ident v1.0.6
       Fresh cc v1.0.41
       Fresh rustc-std-workspace-core v1.99.0 (/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
       Fresh compiler_builtins v0.1.73
       Fresh proc-macro2 v1.0.51
       Fresh alloc v0.0.0 (/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc)
       Fresh quote v1.0.23
       Fresh rustversion v1.0.11
       Fresh proc-macro-hack v0.5.20+deprecated
       Fresh paste v1.0.11
       Fresh syn v1.0.107
       Fresh nb v1.0.0
       Fresh void v1.0.2
       Fresh ufmt-write v0.1.0
       Fresh vcell v0.1.3
       Fresh cfg-if v1.0.0
       Fresh bare-metal v1.0.0
       Fresh cfg-if v0.1.10
       Fresh embedded-storage v0.2.0
       Fresh secp256k1-sys v0.8.0
       Fresh panic-halt v0.2.0
       Fresh ufmt-macros v0.2.0
       Fresh nb v0.1.3
       Fresh avr-device-macros v0.5.0
       Fresh secp256k1 v0.26.0
       Fresh embedded-hal v0.2.7
       Fresh ufmt v0.1.2
       Fresh avr-device v0.5.0
       Fresh avr-hal-generic v0.1.0 (https://github.com/rahix/avr-hal?rev=4c9c44c314eb061ee20556ef10d45dea36e75ee4#4c9c44c3)
       Fresh atmega-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4c9c44c314eb061ee20556ef10d45dea36e75ee4#4c9c44c3)
       Fresh arduino-hal v0.1.0 (https://github.com/rahix/avr-hal?rev=4c9c44c314eb061ee20556ef10d45dea36e75ee4#4c9c44c3)
   Compiling arduino-lib v0.1.0 (/arduino-lib-rs)
     Running `rustc --crate-name arduino_lib --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --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=4fc5e0f08d0e8413 -C extra-filename=-4fc5e0f08d0e8413 --out-dir /arduino-lib-rs/target/avr-atmega328p/debug/deps --target /arduino-lib-rs/avr-atmega328p.json -C incremental=/arduino-lib-rs/target/avr-atmega328p/debug/incremental -L dependency=/arduino-lib-rs/target/avr-atmega328p/debug/deps -L dependency=/arduino-lib-rs/target/debug/deps --extern 'noprelude:alloc=/arduino-lib-rs/target/avr-atmega328p/debug/deps/liballoc-6657415c07dc6074.rlib' --extern arduino_hal=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libarduino_hal-ab70d292f4898b57.rlib --extern 'noprelude:compiler_builtins=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libcompiler_builtins-7aa2be695e3a21ba.rlib' --extern 'noprelude:core=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libcore-5992387ffdde5367.rlib' --extern panic_halt=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libpanic_halt-c807d160b6ac4a90.rlib --extern secp256k1=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libsecp256k1-3da03d9a855cade0.rlib -Z unstable-options -L native=/arduino-lib-rs/target/avr-atmega328p/debug/build/secp256k1-sys-71731f20ca02ee1b/out`
WARN rustc_codegen_ssa::back::link Linker does not support -no-pie command line option. Retrying without.
error: linking with `avr-gcc` failed: exit status: 1
  |
  = note: "avr-gcc" "-mmcu=atmega328p" "-Wl,--as-needed" "/arduino-lib-rs/target/avr-atmega328p/debug/deps/arduino_lib-4fc5e0f08d0e8413.secp256k1-3da03d9a855cade0.secp256k1.96b2e4ee-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/arduino-lib-rs/target/avr-atmega328p/debug/deps" "-L" "/arduino-lib-rs/target/debug/deps" "-L" "/arduino-lib-rs/target/avr-atmega328p/debug/build/secp256k1-sys-71731f20ca02ee1b/out" "-L" "/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/avr-atmega328p/lib" "-Wl,-Bstatic" "/tmp/rustcDNjnWV/libsecp256k1_sys-78f272f5c76a5ef9.rlib" "/arduino-lib-rs/target/avr-atmega328p/debug/deps/libcompiler_builtins-7aa2be695e3a21ba.rlib" "-Wl,-Bdynamic" "-lgcc" "-Wl,-znoexecstack" "-L" "/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/avr-atmega328p/lib" "-o" "/arduino-lib-rs/target/avr-atmega328p/debug/deps/arduino_lib-4fc5e0f08d0e8413.elf" "-Wl,--gc-sections"
  = note: /tmp/rustcDNjnWV/libsecp256k1_sys-78f272f5c76a5ef9.rlib: error adding symbols: File format not recognized
          collect2: error: ld returned 1 exit status


error: could not compile `arduino-lib` due to previous error

Caused by:
  process didn't exit successfully: `rustc --crate-name arduino_lib --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --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=4fc5e0f08d0e8413 -C extra-filename=-4fc5e0f08d0e8413 --out-dir /arduino-lib-rs/target/avr-atmega328p/debug/deps --target /arduino-lib-rs/avr-atmega328p.json -C incremental=/arduino-lib-rs/target/avr-atmega328p/debug/incremental -L dependency=/arduino-lib-rs/target/avr-atmega328p/debug/deps -L dependency=/arduino-lib-rs/target/debug/deps --extern 'noprelude:alloc=/arduino-lib-rs/target/avr-atmega328p/debug/deps/liballoc-6657415c07dc6074.rlib' --extern arduino_hal=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libarduino_hal-ab70d292f4898b57.rlib --extern 'noprelude:compiler_builtins=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libcompiler_builtins-7aa2be695e3a21ba.rlib' --extern 'noprelude:core=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libcore-5992387ffdde5367.rlib' --extern panic_halt=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libpanic_halt-c807d160b6ac4a90.rlib --extern secp256k1=/arduino-lib-rs/target/avr-atmega328p/debug/deps/libsecp256k1-3da03d9a855cade0.rlib -Z unstable-options -L native=/arduino-lib-rs/target/avr-atmega328p/debug/build/secp256k1-sys-71731f20ca02ee1b/out` (exit status: 1)

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 10, 2023

So it looks like I'm correct in guessing AVR is not supported by cc?

@xphoniex
Copy link
Author

xphoniex commented Feb 10, 2023

I don't see cc being used, can you point me to the line? Instead it's using avr-gcc which should support avr?

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 10, 2023

I mean the crate.

@xphoniex
Copy link
Author

if by crate you mean secp256k1, well that's basically my question.

I want to know if it supports avr and if not why, what needs to be changed?

@apoelstra
Copy link
Member

By crate he means the cc crate, which appears not to support AVR ... or at least, has no evidence that anyone has tried to use it with AVR until now.

I'm happy to leave this open because I think libsecp-on-AVR is pretty cool...but I think the fix is going to have to happen in the cc crate and that there's not much we can do hree.

@xphoniex
Copy link
Author

ah, I think I get it now.

my lib calls rust-secp256k1 which calls cc, that's why we're getting:

error adding symbols: File format not recognized

correct?

this file has to be changed for avr to work.

@apoelstra
Copy link
Member

Yep, exactly. And I don't know how/if we can change that file to support AVR; the cc crate is the standard way to "call a C compiler for any platform you might support" so if it doesn't support AVR I worry that nothing will.

If it worked for you, I'd be willing to accept an ad-hoc change that did something like if cfg!(target = "avr") { /* explicitly call avr-gcc with std::process::Command or something */; return Ok(()); }. But I won't be able to make such a change, or test it. I can just verify that it won't affect non-AVR users and accept it on those grounds :P.

@xphoniex
Copy link
Author

sounds fair, will check if I can get it to work once I find some time.

@Kixunil
Copy link
Collaborator

Kixunil commented Feb 10, 2023

If you can, I think your time would be better spent on making a PR to the cc crate, since that'll benefit many more users.
I also think AVR is cool and even have some Arduinos around but sadly, I don't have time to help you much. So I can only wish you good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants