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

error: linking with xtensa-lx106-elf-gcc failed: exit status: 1 #93

Closed
jessebraham opened this issue Nov 18, 2021 · 4 comments
Closed
Assignees

Comments

@jessebraham
Copy link
Member

jessebraham commented Nov 18, 2021

Using rustc-1.56.0.1 installed from the rust-build repository. Building for the ESP8266 in dev mode seems to result in the following error:

error: linking with `xtensa-lx106-elf-gcc` failed: exit status: 1
  |
  = note: "xtensa-lx106-elf-gcc" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/examples/blinky-e0818fc35520ce14.panic_halt-43f7212d7c513c73.panic_halt.f3fb034b-cgu.0.rcgu.o.rcgu.o" "-Wl,--as-needed" "-L" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/deps" "-L" "/Users/jesse/Work/esp8266-hal/target/debug/deps" "-L" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/build/esp8266-hal-2d03f26e6b6aa8d6/out" "-L" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/build/xtensa-lx-9a48fc8303ca0ffa/out" "-L" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/build/xtensa-lx-rt-02f5e2b7b68604e9/out" "-L" "/Users/jesse/.rustup/toolchains/esp/lib/rustlib/xtensa-esp8266-none-elf/lib" "-Wl,--start-group" "-Wl,--end-group" "-Wl,-Bstatic" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/deps/libcompiler_builtins-8b73f41dc98a2660.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/Users/jesse/.rustup/toolchains/esp/lib/rustlib/xtensa-esp8266-none-elf/lib" "-o" "/Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/examples/blinky-e0818fc35520ce14" "-Wl,--gc-sections" "-no-pie" "-nodefaultlibs" "-nostartfiles" "-Wl,-Tlink.x"
  = note: /Users/jesse/.xtensa/xtensa-lx106-elf/bin/../lib/gcc/xtensa-lx106-elf/8.4.0/../../../../xtensa-lx106-elf/bin/ld: /Users/jesse/Work/esp8266-hal/target/xtensa-esp8266-none-elf/debug/deps/libcompiler_builtins-8b73f41dc98a2660.rlib(compiler_builtins-8b73f41dc98a2660.compiler_builtins.77efb3e9-cgu.3.rcgu.o):(.literal._ZN17compiler_builtins3int19specialized_div_rem23u32_normalization_shift17h93377cdcc12e9cdcE+0x8): undefined reference to `core::panicking::panic'
          collect2: error: ld returned 1 exit status

  = help: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `esp8266-hal` due to previous error

Curiously, building in release seems to resolve the issue. This can be reproduced by executing the following:

$ git clone https://github.com/esp-rs/esp8266-hal.git
$ cd esp8266-hal/
$ cargo +esp build --example=blinky           # fails!
$ cargo +esp build --example=blinky --release # succeeds!

The Cargo.toml manifest for this repository contains the following configuration for build profiles, not sure if lto is the culprit or if it's something else:

[profile.dev]
lto = true
opt-level = 1

[profile.release]
lto = true
@jessebraham
Copy link
Member Author

jessebraham commented Nov 18, 2021

I've disabled lto for the dev profile and this seems to have resolved the linker error. Not sure why it won't work for dev but will for release.

@MabezDev
Copy link
Member

I think this is related to rust-lang/compiler-builtins#347. Doesn't look like there is a solution yet, just some work arounds & theories.

@MabezDev
Copy link
Member

Just following up on this, seems although this hasn't been fixed yet its been tracked down to rust-lang/cargo#10118 (comment). This is why it works in release, because there are no overflow checks etc.

@MabezDev
Copy link
Member

So I think this is almost certainly LTO's fault, but I think because we are using a GCC linker. I guess it is discarding some important symbols... like panic :D. I've only just come to this conclusion because I'm messing around with LTO on the STD port, and running into the same issues.

I am hoping that with LLD support tracked in espressif/llvm-project#11, these issues will go away. Closing for that reason.

@MabezDev MabezDev self-assigned this Jul 15, 2022
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

2 participants