esp-rs / esp-idf-template

A "Hello, world!" template of a Rust binary crate for the ESP-IDF framework.
372 stars 43 forks source link

.rlib file format not recognized when linking #210

Closed keredson closed 1 month ago

keredson commented 1 month ago

Bug description

Adding and using the library libssh-rs leads to the linker throwing .rlib: error adding symbols: file format not recognized.

To Reproduce

Steps to reproduce the behavior:

  1. start a project:
    $ cargo install espup
    $ espup install
    $ . $HOME/export-esp.sh
    $ cargo generate esp-rs/esp-idf-template
    ⚠️   Favorite `esp-rs/esp-idf-template` not found in config, using it as a git repository: https://github.com/esp-rs/esp-idf-template.git
    ✔ 🤷   Which template should be expanded? · cargo
    🤷   Project Name: test-linking
    ✔ 🤷   Which MCU to target? · esp32
    ✔ 🤷   Configure advanced template options? · false
    ✨   Done! New project created /tmp/test-linking
  2. add the dep:
    $ cargo add libssh-rs
  3. enable cross compiling in .cargo/config.toml:
    [env]
    PKG_CONFIG_ALLOW_CROSS = "1"
  4. this will build!
    $ cargo build
    Compiling libssh-rs-sys v0.2.4
    Compiling openssl-sys v0.9.102
    Compiling libssh-rs v0.3.3
    Finished dev [optimized + debuginfo] target(s) in 6.62s
  5. but try to use it by adding the following to src/main.rs
    use libssh_rs::{Session};
    let mut session = Session::new().unwrap();

    (obviously the second line goes in the main function)

  6. and you get:
    
    = note: [ldproxy] Running ldproxy
    Error: Linker /tmp/test-linking/.embuild/espressif/tools/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc failed: exit status: 1
    STDERR OUTPUT:
    /tmp/test-linking/.embuild/espressif/tools/xtensa-esp32-elf/esp-12.2.0_20230208/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/12.2.0/../../../../xtensa-esp32-elf/bin/ld: /tmp/test-linking/target/xtensa-esp32-espidf/debug/deps/liblibssh_rs_sys-ba33b208cf49f79d.rlib: error adding symbols: file format not recognized


## Expected behavior

No linking error.

## Environment

- OS: Ubuntu 24.04
- How did you install the environment: recent espup

## Additional context

Same in esp-idf v4 and v5 (enabled in advanced template options).
keredson commented 1 month ago

$ objdump -d /tmp/test-linking-idfv4/target/xtensa-esp32-espidf/debug/deps/liblibssh_rs_sys-ba33b208cf49f79d.rlib looks OK, but admittedly i'm out of my depth here.

keredson commented 1 month ago

actually the start of objdump contains:

In archive /tmp/test-linking-idfv4/target/xtensa-esp32-espidf/debug/deps/liblibssh_rs_sys-ba33b208cf49f79d.rlib:
lib.rmeta:     file format elf32-little
libssh_rs_sys-ba33b208cf49f79d.libssh_rs_sys.f63cc42efaec27b7-cgu.0.rcgu.o:     file format elf32-little
1fa44eb5313ef680-agent.o:     file format elf64-x86-64

it prob. shouldn't contain elf64-x86-64 objects? no clue if this i related, but thought i'd note.

ivmarkov commented 1 month ago

actually the start of objdump contains:

In archive /tmp/test-linking-idfv4/target/xtensa-esp32-espidf/debug/deps/liblibssh_rs_sys-ba33b208cf49f79d.rlib:
lib.rmeta:     file format elf32-little
libssh_rs_sys-ba33b208cf49f79d.libssh_rs_sys.f63cc42efaec27b7-cgu.0.rcgu.o:     file format elf32-little
1fa44eb5313ef680-agent.o:     file format elf64-x86-64

it prob. shouldn't contain elf64-x86-64 objects? no clue if this i related, but thought i'd note.

Of course it is. The lib likely has some x86 assembly hard-coded. Not sure all of this is a problem with the esp idf crates.