Git Product home page Git Product logo

esp-rs / rust Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rust-lang/rust

730.0 22.0 35.0 1.33 GB

Rust for the xtensa architecture. Built in targets for the ESP32 and ESP8266

Home Page: https://www.rust-lang.org

License: Other

Rust 97.11% Python 0.40% Makefile 0.27% Dockerfile 0.11% Shell 0.50% C 0.05% HTML 0.36% Roff 0.02% CSS 0.09% XSLT 0.01% Batchfile 0.01% JavaScript 0.45% C++ 0.20% RenderScript 0.02% Assembly 0.02% Pascal 0.01% Puppet 0.01% CMake 0.01% RPC 0.01% Fluent 0.39%

rust's Introduction

The Rust Programming Language for Espressif chips

This fork enables projects to be built for the Xtensa-based ESP32, ESP32-SXX and ESP8266 using Espressif's llvm fork. (RiscV chips like ESP32-CXX are already supported in stock Rust.)

Moreover, this fork enables Rust STD support (networking, threads, and filesystem) for all chips in the ESP32 family (Xtensa and RiscV), by optionally linking with the ESP-IDF framework.

The esp-rs organization has been formed to develop runtime, pac and hal crates for the Espressif chips (bare-metal as well as ESP-IDF based).

Join in on the discussion: https://matrix.to/#/#esp-rs:matrix.org!

Installation

Please see the most up to date instructions in the esp rust book.

Building from source

If you wish to build this fork from source, the instructions are almost identical to the ones upstream (follow here), however before beginning the build, run the following ./configure command:

./configure --experimental-targets=Xtensa --release-channel=nightly --enable-extended --tools=clippy,cargo,rustfmt --enable-lld

License

Rust is primarily distributed under the terms of both the MIT license and the Apache License (Version 2.0), with portions covered by various BSD-like licenses.

See LICENSE-APACHE, LICENSE-MIT, and COPYRIGHT for details.

rust's People

Contributors

alexcrichton avatar bjorn3 avatar bors avatar brson avatar catamorphism avatar centril avatar cjgillot avatar compiler-errors avatar dylan-dpc avatar eddyb avatar estebank avatar flip1995 avatar graydon avatar guillaumegomez avatar johntitor avatar kennytm avatar manishearth avatar mark-simulacrum avatar matklad avatar matthiaskrgr avatar nikomatsakis avatar nnethercote avatar nrc avatar oli-obk avatar pcwalton avatar petrochenkov avatar ralfjung avatar steveklabnik avatar topecongiro avatar veykril avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust's Issues

Still alive?

I would like to contribute in the weekends on my free to get some projects working

Not supported instr error

I have the following snippet:

pub enum Enum<'a> {
    A(&'a str),
    B { ptr: usize, len: usize },
    C(&'a [u8]),
    D(u8),
}

impl Enum<'_> {
    pub(crate) fn foo(&self, tmp: &mut Vec<u8>) {
        match self {
            Self::A(_) => tmp.push(0),
            Enum::B { .. } => tmp.push(1),
            Enum::C(_) => tmp.push(2),
            Enum::D(_) => tmp.push(3),
        }
    }
}

pub struct B<'a> {
    slice: &'a [Enum<'a>],
}
impl B<'_> {
    pub fn foo(&self, tmp: &mut Vec<u8>) {
        for e in self.slice {
            e.foo(tmp);
        }
    }
}

Trying to compile it, the build fails with: LLVM ERROR: Not supported instr: <MCInst 271 <MCOperand Reg:42>>. Slight modifications of this example can halt the compiler in a (seemingly, I got bored after 15 minutes of waiting) infinite loop.

This is a minimized repro. What's especially interesting is that deleting the D variant causes the code to compile. However, on the original code, having the A-B-C variants still fails.

I am trying to build for an ESP32 using the 1.56.0.1 rustc version. Build fails both locally (version below) and on a freshly set-up ubuntu GHA runner.

❯ rustc +esp -vV
rustc 1.56.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-pc-windows-msvc
release: 1.56.0-dev
LLVM version: 12.0.1

ESP8266 build regression

Hi,

After today's update, I started getting this compilation error of 'quickstart' project:

$ cargo xbuild      
<...>
LLVM ERROR: Error while trying to spill A8 from class AR: Cannot scavenge register without an emergency spill slot!
error: could not compile `core`.

...and another error when building with xargo:

$ xargo build
error: cannot produce bin for `esp32-test v0.1.0 (/Users/vmark/dev/emb/xtensa-rust-quickstart)` as the target `xtensa-esp8266-none-elf` does not support these crate types

Rustc info:

rustc 1.44.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-apple-darwin
release: 1.44.0-dev
LLVM version: 9.0

Note: for xtensa-esp32-none-elf target the project compiles successfully.

Should I report the issue on espressif's LLVM fork?

LLVM ERROR: Error while trying to spill A9 from class AR

Got this error while building num-rational.

warning: Patch `getrandom v0.1.16 (https://github.com/ivmarkov/getrandom.git?branch=0.1#d942e06a)` was not used in the crate graph.
Patch `polling v2.1.0 (https://github.com/ivmarkov/polling#260dded7)` was not used in the crate graph.
Patch `socket2 v0.4.2 (https://github.com/ivmarkov/socket2#7217ebe8)` was not used in the crate graph.
Check that the patched package version and available features are compatible
with the dependency requirements. If the patch has a different version from
what is locked in the Cargo.lock file, run `cargo update` to use the new
version. This may also occur with an optional dependency that is not enabled.
    Blocking waiting for file lock on build directory
   Compiling num-rational v0.3.2
   Compiling atat v0.13.1
   Compiling esp-idf-hal v0.21.0
   Compiling num v0.3.1
   Compiling embedded-time v0.11.0
   Compiling esp-idf-svc v0.26.0
LLVM ERROR: Error while trying to spill A9 from class AR: Cannot scavenge register without an emergency spill slot!
error: could not compile `num-rational`

ICE on 1.51 when building esp32-hal's alloc example

Built rust-xtensa from c4c02e8. Using esp32-hal https://github.com/esp-rs/esp32-hal/tree/94dc49fed351246ee57e9c3a4a28fe662b11165d and building with:

cargo xbuild --release --features='mem,rt,alloc' --example alloc

I get:

error: internal compiler error: compiler/rustc_mir/src/monomorphize/collector.rs:826:9: no MIR available for DefId(8:1581 ~ esp32_hal[a18f]::alloc::DEFAULT_HEAP)

thread 'rustc' panicked at 'Box<Any>', /home/brian/src/esp32-rust/rust-xtensa/library/std/src/panic.rs:59:5
stack backtrace:
   0:     0x778d6a92bf5c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h92f05c32d34e55b1
   1:     0x778d6a9e65ff - core::fmt::write::habc01af56514e184
   2:     0x778d6a92aae6 - std::io::Write::write_fmt::h786298d3493045df
   3:     0x778d6a94cb65 - std::panicking::default_hook::{{closure}}::h9f81f29c173dd1ba
   4:     0x778d6a94c733 - std::panicking::default_hook::h29961f4fed4671b5
   5:     0x778d6b3f35b4 - rustc_driver::report_ice::h62b7dd6e3311caf9
   6:     0x778d62e6b7f6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hdb2823b27ceaf625
                               at /home/brian/src/esp32-rust/rust-xtensa/library/alloc/src/boxed.rs:1535:9
   7:     0x778d62e69019 - proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}::he8834c1ed5f8ce0d
                               at /home/brian/src/esp32-rust/rust-xtensa/library/proc_macro/src/bridge/client.rs:320:21
   8:     0x778d6a94d2ca - std::panicking::rust_panic_with_hook::h8508dce83d0c4d0e
   9:     0x778d70becfbd - std::panicking::begin_panic::{{closure}}::he4d98f1dc0eef9ed
  10:     0x778d70bec4e6 - std::sys_common::backtrace::__rust_end_short_backtrace::hb6db84595d50ab6f
  11:     0x778d70bc6b5f - std::panicking::begin_panic::he1006c7b8d50deed
  12:     0x778d70bf848d - std::panic::panic_any::h730abc2446882085
  13:     0x778d70bfe9f5 - rustc_errors::HandlerInner::bug::h94fd4ed00a59c29a
  14:     0x778d70bfd130 - rustc_errors::Handler::bug::hfa492ecff8df8ec3
  15:     0x778d7064f17d - rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}::h01a25b32ddfce489
  16:     0x778d70649c0b - rustc_middle::ty::context::tls::with_opt::{{closure}}::hffd33416f2fe257f
  17:     0x778d706496d2 - rustc_middle::ty::context::tls::with_opt::hcbf9ecbe823a5213
  18:     0x778d7064f0a3 - rustc_middle::util::bug::opt_span_bug_fmt::hdc326236b8dcf6d5
  19:     0x778d7064f015 - rustc_middle::util::bug::bug_fmt::h2c5e53dec68bdf1e
  20:     0x778d6f0aced1 - rustc_mir::monomorphize::collector::should_codegen_locally::h2ecb295070b6c359
  21:     0x778d6f0aeb58 - rustc_mir::monomorphize::collector::collect_miri::h2fdad49e50385172
  22:     0x778d6f0a9ee2 - rustc_mir::monomorphize::collector::collect_items_rec::h35a4e3f6b96ff7b2
  23:     0x778d6f3f24e1 - rustc_session::utils::<impl rustc_session::session::Session>::time::h639d283fc3e9aa39
  24:     0x778d6f0a8e2a - rustc_mir::monomorphize::collector::collect_crate_mono_items::h6749e3d27b803dd5
  25:     0x778d6f1de637 - rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items::h2e9f893f2a32a691
  26:     0x778d6b7fe962 - rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_and_partition_mono_items>::compute::h187cc8aed29e59f3
  27:     0x778d6b7204be - rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps::hc22bd7ec540ef31e
  28:     0x778d6b89cbef - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl::hb201ace3ced09119
  29:     0x778d6b7bfdc6 - rustc_data_structures::stack::ensure_sufficient_stack::hfba4598167b79f32
  30:     0x778d6b83b65a - rustc_query_system::query::plumbing::force_query_with_job::h2f88a763e5fb37b8
  31:     0x778d6b816521 - rustc_query_system::query::plumbing::get_query_impl::h1a4b12822e21fec3
  32:     0x778d6b810729 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::haa0696e63f406593
  33:     0x778d6b61b89d - rustc_interface::passes::QueryContext::enter::h81c882d5ed9ca0aa
  34:     0x778d6b66c633 - rustc_interface::queries::Queries::ongoing_codegen::h5e1d85538a562eab
  35:     0x778d6b4186eb - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::hc8eb60c36b7135e8
  36:     0x778d6b3f77be - rustc_span::with_source_map::h4e873b7fc2994ddf
  37:     0x778d6b419b1b - rustc_interface::interface::create_compiler_and_run::h6b6b3cbc7bad9a01
  38:     0x778d6b3f8870 - rustc_span::with_session_globals::h23089b9f3c681cae
  39:     0x778d6b41b880 - std::sys_common::backtrace::__rust_begin_short_backtrace::h098db73ee66fea81
  40:     0x778d6b44448a - core::ops::function::FnOnce::call_once{{vtable.shim}}::he83ff58da95d651c
  41:     0x778d6a95bdf8 - std::sys::unix::thread::Thread::new::thread_start::h9e66dc0481aecb2f
  42:     0x778d6a679ea7 - start_thread
  43:     0x778d6a7b5def - clone
  44:                0x0 - <unknown>

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (c4c02e837 2021-04-15) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C link-arg=-nostartfiles -C link-arg=-Wl,-Tlink.x --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error

Update to newer compiler version.

@MabezDev Your repo is still based on rustc v1.33.0 but your patches apply without any complications on stable rustc v1.37.0 (maybe even current beta or nightly).

What do you think about rebasing or merging onto a newer version? Especially as rustc v1.36.0 stabilized the alloc crate which means that any no_std crate which calls extern crate alloc without the #[feature(alloc)] flag can't get compiled with the current state.

I did a few tests locally with an updated version and couldn't trigger any issues. Is there anything related to llvm-xtensa which would require to stay on an older version?

Atomic operation caused IllegalInstruction on esp32s2

I tried this code:

let a = AtomicUsize::new(1);
a.compare_and_swap(3, 3, Ordering::Release);

and this triggered a panic:

Guru Meditation Error: Core  0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x40087540: c192280c 130c8000 a100e982
0x40087540: esprs::executor::Executor<T>::run at ??:?

This issue makes it impossible to use Arc on esp32.

Are atomic operations supported in this implementation?

Thank you!

Compilation fails because of missing esp32 linker(gcc) when esp8266 target selected

Hi @MabezDev

I found the following issue:
Compilation fails with error for xtensa-esp8266-none-elf target because of missing xtensa-esp32-elf-gcc executable.

Expected result:
Rust uses xtensa-lx106-elf-gcc from official toolchain as linker parameter

Actual result:
Rust tries to find xtensa-esp32-elf-gcc and fails

Temporary solution:
Manually set correct linker by adding "-C linker=" to the RUSTFLAGS variable

New targets for esp32s2 and esp32s3

Given that for these MCUs Espressif provides separate toolchains, perhaps we need separate targets too. At the very least, the linker field in TargetOptions as well as the cpu should be different.

Also: shall we create a target for esp32c3? I get it that it is not really 'xtensa', but it needs the same changes. Possibly based on some of the existing "riscv-" targets?

LLVM ERROR: Not supported instr: <MCInst 237 <MCOperand Reg:42>>

I am trying to build rust, on Windows 10 21h1, using both the default llvm-project and a custom llvm-project but am getting:-

LLVM ERROR: Not supported instr: <MCInst 237 >

Did not run successfully: exit code: 101
"C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2\bin\rustc.exe" "--crate-name" "term" "--edition=2018" "library\term\src\lib.rs" "--error-format=json" "--json=diagnostic-rendered-ansi" "--crate-type" "lib" "--emit=dep-info,metadata,link" "-C" "opt-level=3" "-C" "embed-bitcode=no" "-C" "debuginfo=0" "-C" "metadata=9ae1ecb98b4816ad" "-C" "extra-filename=-9ae1ecb98b4816ad" "--out-dir" "C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2-std\xtensa-esp32-espidf\release\deps" "--target" "xtensa-esp32-espidf" "-C" "linker=xtensa-esp32-elf-cc" "-C" "incremental=C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2-std\xtensa-esp32-espidf\release\incremental" "-L" "dependency=C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2-std\xtensa-esp32-espidf\release\deps" "-L" "dependency=C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2-std\release\deps" "--extern" "core=C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2-std\xtensa-esp32-espidf\release\deps\libcore-d0f410522e28d1f8.rmeta" "--extern" "std=C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2-std\xtensa-esp32-espidf\release\deps\libstd-5d6c47f019a00a49.rlib" "-Zmacro-backtrace" "-Clink-args=-Wl,-rpath,$ORIGIN/../lib" "-Zsave-analysis" "-Cprefer-dynamic" "-Cllvm-args=-import-instr-limit=10" "-Cembed-bitcode=yes" "-Z" "binary-dep-depinfo" "-Wrust_2018_idioms" "-Wunused_lifetimes" "-Dwarnings" "--sysroot" "C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage2" "-Z" "force-unstable-if-unmarked"

error: could not compile term

To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
command did not execute successfully: "\\?\C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage0\bin\cargo.exe" "build" "--target" "xtensa-esp32-espidf" "-Zbinary-dep-depinfo" "-j" "6" "--release" "--features" "panic-unwind backtrace" "--manifest-path" "C:\Dev\Github\rust\library/test/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
Traceback (most recent call last):
File "C:\Dev\Github\rust\x.py", line 27, in
bootstrap.main()
File "C:\Dev\Github\rust\src\bootstrap\bootstrap.py", line 1191, in main
bootstrap(help_triggered)
File "C:\Dev\Github\rust\src\bootstrap\bootstrap.py", line 1177, in bootstrap
run(args, env=env, verbose=build.verbose)
File "C:\Dev\Github\rust\src\bootstrap\bootstrap.py", line 153, in run
raise RuntimeError(err)
RuntimeError: failed to run: C:\Dev\Github\rust\build\bootstrap\debug\bootstrap build --stage 2 --verbose`

I have migrated the changes to the rust repo master branch and get:-

error: fixup value out of range

LLVM ERROR: Cannot select: 0x1e75141f3e8: f32 = fma 0x1e75141f110, 0x1e75141f1e0, 0x1e75141f380
0x1e75141f110: f32 = bitcast 0x1e75141ef08
0x1e75141ef08: i32,ch = CopyFromReg 0x1e73c8d7da8, Register:i32 %0
0x1e75141eea0: i32 = Register %0
0x1e75141f1e0: f32 = bitcast 0x1e75141f0a8
0x1e75141f0a8: i32,ch = CopyFromReg 0x1e73c8d7da8, Register:i32 %2
0x1e75141f040: i32 = Register %2
0x1e75141f380: f32 = fma 0x1e75141f318, 0x1e75141f178, 0x1e75141f178
0x1e75141f318: f32 = fneg 0x1e75141f110
0x1e75141f110: f32 = bitcast 0x1e75141ef08
0x1e75141ef08: i32,ch = CopyFromReg 0x1e73c8d7da8, Register:i32 %0
0x1e75141eea0: i32 = Register %0
0x1e75141f178: f32 = bitcast 0x1e75141efd8
0x1e75141efd8: i32,ch = CopyFromReg 0x1e73c8d7da8, Register:i32 %1
0x1e75141ef70: i32 = Register %1
0x1e75141f178: f32 = bitcast 0x1e75141efd8
0x1e75141efd8: i32,ch = CopyFromReg 0x1e73c8d7da8, Register:i32 %1
0x1e75141ef70: i32 = Register %1
In function: ZN3std3f3221$LT$impl$u20$f32$GT$4lerp17hd25dd7f6def92bafE
error: could not compile std

To learn more, run the command again with --verbose.
command did not execute successfully: "\\?\C:\Dev\Github\rust\build\x86_64-pc-windows-msvc\stage0\bin\cargo.exe" "build" "--target" "xtensa-esp32-espidf" "-Zbinary-dep-depinfo" "-j" "6" "--release" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "C:\Dev\Github\rust\library/test/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101
failed to run: C:\Dev\Github\rust\build\bootstrap\debug\bootstrap build --stage 2

Anyone point this newbie in a direction to troubleshoot this?

Build the core crate in the CI

Hi there,

It would be nice, if the CI that builds Rust compiler for Xtensa also build and distribute the core crate for Xtensa arch.

I know that in the embedded world it's usual case to build the core crate with specific optimizations (debug vs release) that required in particular case. But in my daily work I never touch or rebuild the core crate.

Thanks in advance!

Having issues compiling with the latest pull (9b05fc7)

Hi there,

Recently I have been having issue with compiling, and I tried different platforms and methods, all rebuilding the compiler exactly as per instructions, but all of them produce the follower error:

error: failed to resolve patches for `https://github.com/rust-lang/crates.io-index`

Caused by:
  failed to load source for dependency `rustc-std-workspace-core`

Caused by:
  Unable to update /build/rust-xtensa/src/rustc-std-workspace-core

Caused by:
  failed to read `/build/rust-xtensa/src/rustc-std-workspace-core/Cargo.toml`

Caused by:
  No such file or directory (os error 2)
error: `"/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/cargo" "rustc" "-p" "alloc" "--release" "--manifest-path" "/tmp/cargo-xbuildQLyHMG/Cargo.toml" "--target" "xtensa-esp32-none-elf" "--" "-Z" "force-unstable-if-unmarked"` failed with exit code: Some(101)

I tried to duckduckgo it but I cannot find any answer that points to a clue. I wanted to try and fix it but I've been up for the majority of the night trying to fix it but I can't find it.

I found this Docker image: https://hub.docker.com/r/ncrmro/rust-extensa and it worked just fine.
I then decided to edit the Dockerfile (extracted from the image as there's no source sadly) to produce an up to date build:

FROM debian:buster
MAINTAINER Peter Willemsen <[email protected]>
CMD ["bash"]
RUN apt-get update  \
	&& apt-get install -y --no-install-recommends ca-certificates curl netbase wget  \
	&& rm -rf /var/lib/apt/lists/*
RUN set -ex; if ! command -v gpg > /dev/null; then apt-get update; apt-get install -y --no-install-recommends gnupg dirmngr ; rm -rf /var/lib/apt/lists/*; fi
RUN apt-get update  \
	&& apt-get install -y --no-install-recommends git mercurial openssh-client subversion procps  \
	&& rm -rf /var/lib/apt/lists/*
RUN set -ex; apt-get update; DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends autoconf automake bzip2 dpkg-dev file g++ gcc imagemagick libbz2-dev libc6-dev libcurl4-openssl-dev libdb-dev libevent-dev libffi-dev libgdbm-dev libglib2.0-dev libgmp-dev libjpeg-dev libkrb5-dev liblzma-dev libmagickcore-dev libmagickwand-dev libmaxminddb-dev libncurses5-dev libncursesw5-dev libpng-dev libpq-dev libreadline-dev libsqlite3-dev libssl-dev libtool libwebp-dev libxml2-dev libxslt-dev libyaml-dev make patch unzip xz-utils zlib1g-dev $( if apt-cache show 'default-libmysqlclient-dev' 2>/dev/null | grep -q '^Version:'; then echo 'default-libmysqlclient-dev'; else echo 'libmysqlclient-dev'; fi ) ; rm -rf /var/lib/apt/lists/*
ENV RUSTUP_HOME=/usr/local/rustup CARGO_HOME=/usr/local/cargo PATH=/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN set -eux; url="https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init"; wget "$url"; chmod +x rustup-init; ./rustup-init -y --no-modify-path --default-toolchain nightly; rm rustup-init; chmod -R a+w $RUSTUP_HOME $CARGO_HOME; rustup --version; cargo --version; rustc --version;
WORKDIR /build
RUN git clone --depth 1 --recurse-submodules --shallow-submodules https://github.com/MabezDev/rust-xtensa /build/rust-xtensa
RUN apt update  \
	&& apt install -y build-essential cmake libssl-dev python ninja-build
RUN /build/rust-xtensa/configure --experimental-targets=Xtensa
RUN /build/rust-xtensa/x.py build --stage 2
ENV XARGO_RUST_SRC=/build/rust-xtensa/src
ENV RUSTC=/build/build/x86_64-unknown-linux-gnu/stage2/bin/rustc
RUN cargo install cargo-xbuild
RUN apt-get install git wget make libncurses-dev flex bison gperf python python-pip python-serial -y
RUN wget https://github.com/espressif/crosstool-NG/releases/download/esp-2020r2/xtensa-esp32-elf-gcc8_2_0-esp-2020r2-linux-amd64.tar.gz -O extensa-esp32.tar.gz
RUN tar xvzf extensa-esp32.tar.gz  \
	&& rm extensa-esp32.tar.gz
ENV PATH=/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/build/xtensa-esp32-elf/bin
RUN pip install esptool
WORKDIR /app

Sadly, again, it producded the same error above, making me believe something has broken about the latest release.
Do you know what's going on? Thanks a lot, in the meantime I will just downgrade using the Docker image as I sadly lost my old working build 🤭.

Edit: I made a better looking and more simple Dockerfile trying to compile the commit that I saw others had success with building (#48) but it still failed with the following error:

error: couldn't read library/std/src/../../stdarch/crates/std_detect/src/mod.rs: No such file or directory (os error 2)
   --> library/std/src/lib.rs:543:1
    |
543 | mod std_detect;
    | ^^^^^^^^^^^^^^^

error: aborting due to previous error

error: could not compile `std`

To learn more, run the command again with --verbose.
command did not execute successfully: "/build/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "12" "--release" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/build/rust-xtensa/library/test/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit code: 101

Dockerfile is at: https://github.com/peterwilli/Lightwatch/blob/af390a669c583699953bd21ad41446adb4832740/extras/docker/Dockerfile

Edit 2: I just found maybe the issue: peterwilli/Lightwatch@93afc05 I saw that the submodules were still at the latest commit. At least it's building now, I have to go to bed tho, so I can't check until I wake up, it's taking too long. I'll let you know tomorrow.

UdpSocket::bind cannot be linked

I tried to use the std library for rust on esp32 but I am running to problems when compiling code that should bind a udp socket. I get an error about undefined reference to bind. If I comment out the networking work (which leaves me with a mostly empty program), the code compiles.

I tried both with TcpListener and UdpSocket and both fail on the linking phase.

I am sorry if I am making something wrong because I can see that https://github.com/ivmarkov/rust-esp32-std-hello makes use of bind, but when I use that feature there, the linker fails with the same error.

I tried this code:

    let socket = UdpSocket::bind("127.0.0.1:0").unwrap();

I expected to see this happen: explanation

Instead, this happened:

Running ldproxy
          Error: Linker C:\Users\name\.platformio\packages\toolchain-xtensa32\bin\xtensa-esp32-elf-gcc.EXE failed: exit code: 1
          STDERR OUTPUT:
          c:/users/name/.platformio/packages/toolchain-xtensa32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: C:\Users\name\project\target\xtensa-esp32-espidf\debug\deps\libstd-eb631c2455bb8cbc.rlib(std-eb631c2455bb8cbc.std.66ojinsg-cgu.12.rcgu.o):(.literal._ZN3std10sys_common3net9UdpSocket4bind17hb79019ec8f516013E+0x18): undefined reference to `bind'
          collect2.exe: error: ld returned 1 exit status

Meta

rustc --version --verbose:

rustc 1.54.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-pc-windows-msvc
release: 1.54.0-dev
LLVM version: 11.0.0

OS: Windows 10

I am using the esp toolchain, installation according to https://github.com/espressif/rust-esp32-example/blob/main/docs/rust-on-xtensa-installation-x86_64-pc-windows-msvc.md
I'm targeting xtensa-esp32-espidf

Backtraces in Rust on ESP-IDF

Background:

Rust has a very useful utility called backtraces. Unlike Rust panics which are an abnormal situation - but still unwind the stack on big iron; for embedded, usually the panic_abort strategy is chosen -
backtraces are invoked programmatically, and allow one to capture programmatically and possibly display the stack of the thread which invoked the backtracing logic.

Usually, this is used in combination with Rust error handling, where some of the error libs, like the popular anyhow crate can be instructed to capture backtraces on first anyhow error construction.
(Backtrace capturing is not (yet?) enabled for standard Rust STD error types though.)

Enhancement:

Ideally, we should be working on filing a PR against the backtrace-rs Rust crate (also used as a GIT submodule in Rust STD) to support IP-based backtraces under ESP-IDF. (While symbolization of backtrace IP pointers to function names and source file directly by the ESP-IDF flashed firmware is not practical due to size constraints, these can be decoded later with UART monitor filter that has access to the ELF file.)
Couple of issues with that:

  • Xtensa
  • Q: While programmatic capturing of backtrace is supported with esp_backtrace_get_start and esp_backtrace_get_next_frame, the logic seems to capture "ghost" Rust IPs, which surely do not belong to the current call stack. Could it be that these are only reliable for C/GCC-generated code?
  • RiscV
    • The situation here seems to be unclear in that the above calls are not supported, and given that GCC (and Rust) compile code for RiscV targets without frame pointer support (FP) by default, reliable capture of backtrace IPs might never be possible (that is, since the eh_frame-based ESP-IDF configuration is advised not to be used in production due to huge code size of the flash binary)
    • Q: Would a programmatic invocation of stack memory capture (as used currently during pancis on RiscV) be a feasible replacement? The stack memory can be later decoded with - say - GDB?
    • Q: Given that RiscV in ESP-IDF master now also has core-dump support, what is the future of the "stack memory dump" approach? Would it become a dump of a minimal elf in coredump format which only contains the stack memory? So that the "gdb server" hack in ESP-IDF Monitor can be retired?

Dangerous allocation linker error when using custom allocators

I have faced the issues with the "dangerous relocation" linker errors when compiling the rust library and linking it to the main ESP8266 project (IDF-style ESP8266 RTOS SDK v3.3).

I have tried to overcome this issue with solution proposed by @lexxvir in the comment, substituting linker by the stript; Also tried to add -C link-args="-mlongcalls -Wa,--auto-lit-pools" to the RUSTFLAGS, tried to add adding the same args to the link args for IDF CMake file, but still no luck.

This issue kicks in when I try to perform any dynamic allocation after with alloc crate (e.g. boxing or pushing some data to the String)

Error output:

../../target/xtensa-esp8266-none-elf/release/libfirmware.a(firmware-5b7e9638ff0ed6ee.2qffuh8m3mnmhmu5.rcgu.o): In function `__rust_alloc':
2qffuh8m3mnmhmu5:(.text.__rust_alloc+0xb): dangerous relocation: l32r: literal target out of range (try using text-section-literals): .literal
../../target/xtensa-esp8266-none-elf/release/libfirmware.a(firmware-5b7e9638ff0ed6ee.2qffuh8m3mnmhmu5.rcgu.o): In function `__rust_dealloc':
2qffuh8m3mnmhmu5:(.text.__rust_dealloc+0xd): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal+0x4)
../../target/xtensa-esp8266-none-elf/release/libfirmware.a(firmware-5b7e9638ff0ed6ee.2qffuh8m3mnmhmu5.rcgu.o): In function `__rust_realloc':
2qffuh8m3mnmhmu5:(.text.__rust_realloc+0xf): dangerous relocation: l32r: literal target out of range (try using text-section-literals): (.literal+0x8)
collect2: error: ld returned 1 exit status

Currently, I have found a rather ugly solution, but at least it works:

I have explored the alloc crate sources and found that the allocation mechanism in rust is based on a few non-mangled functions, so I implemented them in my crate as direct calls to the custom allocator:

use idf_alloc::IdfAllocator;

use core::alloc::{GlobalAlloc, Layout};

#[global_allocator]
static GLOBAL_ALLOCATOR: IdfAllocator = IdfAllocator;

#[alloc_error_handler]
fn rust_idf_oom_error_handler(info: Layout) -> ! { panic!("Out of memory error!"); }

// The tricky part starts here

#[no_mangle]
pub unsafe fn __rust_alloc(size: usize, align: usize) -> *mut u8 {
    GLOBAL_ALLOCATOR.alloc( Layout::from_size_align_unchecked(size, align))
}

#[no_mangle]
pub unsafe fn __rust_dealloc(ptr: *mut u8, size: usize, align: usize) {
    GLOBAL_ALLOCATOR.dealloc(ptr, Layout::from_size_align_unchecked(size, align))
}

#[no_mangle]
pub unsafe fn __rust_realloc(ptr: *mut u8,
                             old_size: usize,
                             align: usize,
                             new_size: usize
) -> *mut u8 {
    GLOBAL_ALLOCATOR.realloc(ptr, Layout::from_size_align_unchecked(old_size, align), new_size)
}

#[no_mangle]
pub unsafe fn __rust_alloc_zeroed(size: usize, align: usize) -> *mut u8 {
    GLOBAL_ALLOCATOR.alloc_zeroed(Layout::from_size_align_unchecked(size, align))
}

Crash dropping `Arc`

I've had some crashes when dropping core::sync::Arc objects. After some debugging I tracked the issue down to a LLVM bug with the atomic substraction, that I reported here, but not reply yet :-(.

For now I worked around the LLVM bug with this hack:

diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs
index 8dfb19fa032..eb59616ada0 100644
--- a/src/libcore/sync/atomic.rs
+++ b/src/libcore/sync/atomic.rs
@@ -1577,7 +1577,8 @@ assert_eq!(foo.load(Ordering::SeqCst), 10);
                 #[$stable]
                 #[cfg(target_has_atomic = "cas")]
                 pub fn fetch_sub(&self, val: $int_type, order: Ordering) -> $int_type {
-                    unsafe { atomic_sub(self.v.get(), val, order) }
+                    unsafe { atomic_add(self.v.get(), val.wrapping_neg(), order) }
                 }
             }

I admit that this is not pretty, I'd rather modify atomic_sub() itself, but it is too generic to fix it easily.

target `xtensa-esp8266-none-elf` does not support [bin] crate types

Hi,

First of all, thanks for your hard work.

It seems the xtensa-esp8266-none-elf target somehow differs from the ESP32 in that I'm not able to build a bin with it; where as that build succeeds for xtensa-esp32-none-elf.

I am getting this error:

error: cannot produce bin for 'hello v0.1.0 (/path/to/project)' as the target 'xtensa-esp8266-none-elf' does not support these crate types

All the information I was able to find from the internet so far says there is a missing

"executables": true

somewhere in the source. Yes, I know I could just build a lib and link it with an empty app_main() in C. But I'm trying to do away with that if I can. I'm also using this as an opportunity to learn.

Grateful for any assistance,

Regards,

Zinahe A

Xtensa multicore: AtomicXX::swap() broken for atomics smaller than 32 bit

AtomicXX::swap() does not work correctly when the atomic is smaller than 32 bit (i.e. AtomicU16, AtomicBool, possibly AtomicU8 too).

I suspect the LLVM atomic generation code is wrong, as these work just fine on riscv32imc (esp32c3) and (I would assume) single-core Xtensa (esp32s2), where atomics are lowered to libcalls using critical sections (implemented in ESP-IDF).

Here's a repo that demonstrates the problem. I've only tested it on the esp32 target, but esp32s3 might be affected as well, as it is also multicore:

  • cargo build and then flash on esp32 - the assert_eqs commented with // This breaks?! will fail
  • cargo build --target riscv32imc-esp-espidf - code should complete up to println!("All done correctly!")

`File::metadata()?.len()` returns 0

I'm not sure where I should report issues that are either libc or std, so I hope this is either the right place or someone knows.

I'm trying to read the size of an open file. I have two options to do this:

  • fs::File::metadata()
  • a custom C implementation

The C impl looks like this:

size_t file_size_fd(int file) {
    struct stat st;

    if (fstat(file, &st) == 0) {
        return st.st_size;
    } else {
        return 0u;
    }
}

I have the following snippet:

    let size = unsafe { file_size_fd(f.as_raw_fd()) };
    let size2 = f.metadata().unwrap().len();

The C implementation returns the correct size (for example, 868 bytes), but the rust call gives me 0.

I'm using a fresh enough installation of esp-idf 4.3.1 and rust 1.56.0.1 [sic].

Structure alignment !=4 bytes

When creating structures with u8 or u16 members, these are not aligned to 4 byte boundaries.

This leads to alignment exceptions when they are stored in Flash or IRAM.

I am not certain if it can be changed via the data-layout in the rust compiler or if it needs to be addressed in llvm.

Alternative is to implemented the alignment exception handler. However this will be slow.

@MabezDev, @andreisfr Any thoughts on this?

New fork testing

Espressif has just released there new iteration of the fork, its not quite working for Rust as is because of this issue. However, I have forked and made the required changes to get it working here. #19 is the branch with changes required in this fork.

@bjoernQ @pacmancoder @rodrigorc if you'd like to try it out and see if it solves any of your issues.

@lexxvir this may mean you can remove some of your work arounds in you projects :)

Panic handler crate compilation fails in debug configuration

Hi, @MabezDev

I have the following issue:
Compilation of panic handlers (e.g. panic-abort, panic-halt) for esp8266 target fails in the debug mode with the following errors:

note: /home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s: Assembler messages:
/home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s:11: Error: CFI is not supported for this target
/home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s:12: Error: CFI is not supported for this target
/home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s:15: Error: CFI is not supported for this target
/home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s:25: Error: CFI is not supported for this target
/home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s: Error: unhandled local relocation fix BFD_RELOC_64
/home/pacmancoder/core/shelter-unicorn/firmware/target/xtensa-esp8266-none-elf/debug/deps/panic_abort-84b1cfdabd08f15b.panic_abort.5hi23ci5-cgu.0.rcgu.s: Error: unhandled local relocation fix BFD_RELOC_64

Interestingly enough, with release configuration it builds just fine 😕

I am building with the following commands/environment:

    export RUSTFLAGS="-C linker="$LINKER_PATH" -C target-cpu=esp8266 -C save-temps"
    xargo build --target xtensa-esp8266-none-elf

Link error when using some `std::fs` functions

std::fs::File.set_len/ftruncate

When using std::fs::File.set_len anywhere in the project a link error occurs referencing ftruncate:

Relevant excerpt

/home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd-d1f4638178e555e4.rlib(std-d1f4638178e555e4.std.43feb998-cgu.2.rcgu.o):(.literal._ZN3std3sys4unix5cvt_r17h6b170249ec86b082E+0x0): undefined reference to `ftruncate'
Full build output
euan@Euan-Desktop:~/esp-idf-ftruncate-link-bug-repro$ cargo build
    Blocking waiting for file lock on build directory
   Compiling bindgen v0.59.2
   Compiling embuild v0.27.1
   Compiling esp-idf-sys v0.28.3
   Compiling esp-idf-ftruncate-link-bug-repro v0.1.0 (/home/euan/esp-idf-ftruncate-link-bug-repro)
error: linking with `ldproxy` failed: exit status: 1
  |
  = note: "ldproxy" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c.1iq3gu07s860atys.rcgu.o" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c.1xhrgistnoo3vrvu.rcgu.o" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c.3p5lv2lqfhd1l9sn.rcgu.o" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c.3q5y8i7sp4xzdsye.rcgu.o" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c.4qyt2qwp1t65e50g.rcgu.o" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c.28w0hodb6thz5p10.rcgu.o" "-Wl,--as-needed" "-L" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps" "-L" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/debug/deps" "-L" "/home/euan/.rustup/toolchains/esp/lib/rustlib/xtensa-esp32-espidf/lib" "-Wl,-Bstatic" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libesp_idf_sys-c71515d603b41be1.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libmutex_trait-df9aa576e9040a2f.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libembedded_svc-2899069fe8327a24.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/liblog-bcbaccb88823ec70.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcfg_if-935bd39d9f6427e5.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libanyhow-c3305a373346a996.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libenumset-7515a396e404b77d.rlib" "-Wl,--start-group" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd-d1f4638178e555e4.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libpanic_abort-45242a1e085ac8c1.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd_detect-0d85fdf205992f33.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/librustc_demangle-09912fe574e03e88.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libhashbrown-b84fbcd507543c60.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/librustc_std_workspace_alloc-6f53877691d2c88b.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libunwind-75acfd38a7bfff04.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcfg_if-16b2675bf0230332.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/liblibc-a626876b7c2b7226.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/liballoc-5a1058ec08d59625.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/librustc_std_workspace_core-17c3abae709388e4.rlib" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcore-8f5a7b792e1e0797.rlib" "-Wl,--end-group" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcompiler_builtins-20ef2192007b875d.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/euan/.rustup/toolchains/esp/lib/rustlib/xtensa-esp32-espidf/lib" "-o" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_ftruncate_link_bug_repro-f438ed8d59ada69c" "-Wl,--gc-sections" "-no-pie" "-nodefaultlibs" "--ldproxy-linker" "/home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc" "--ldproxy-dedup-libs" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/esp_wifi/lib/esp32" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/esp_rom/esp32/ld" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/xtensa/esp32" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp32" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp32/ld" "-L/home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/esp32/ld" "-Wl,--start-group" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_pm/libesp_pm.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/asio/libasio.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/cbor/libcbor.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/unity/libunity.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/cmock/libcmock.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/coap/libcoap.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/console/libconsole.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_adc_cal/libesp_adc_cal.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_hid/libesp_hid.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/protobuf-c/libprotobuf-c.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/protocomm/libprotocomm.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mdns/libmdns.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_local_ctrl/libesp_local_ctrl.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_websocket_client/libesp_websocket_client.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/expat/libexpat.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/wear_levelling/libwear_levelling.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/fatfs/libfatfs.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/freemodbus/libfreemodbus.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/jsmn/libjsmn.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/json/libjson.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/libsodium/liblibsodium.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mqtt/libmqtt.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/openssl/libopenssl.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/spiffs/libspiffs.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/wifi_provisioning/libwifi_provisioning.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/app_trace/libapp_trace.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/app_update/libapp_update.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/bootloader_support/libbootloader_support.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/cxx/libcxx.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/driver/libdriver.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/efuse/libefuse.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp-tls/libesp-tls.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp32/libesp32.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_common/libesp_common.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_eth/libesp_eth.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_event/libesp_event.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_gdbstub/libesp_gdbstub.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_http_client/libesp_http_client.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_http_server/libesp_http_server.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_https_ota/libesp_https_ota.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_hw_support/libesp_hw_support.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_ipc/libesp_ipc.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_netif/libesp_netif.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_ringbuf/libesp_ringbuf.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_rom/libesp_rom.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_system/libesp_system.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_timer/libesp_timer.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_wifi/libesp_wifi.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/espcoredump/libespcoredump.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/freertos/libfreertos.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/hal/libhal.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/heap/libheap.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/log/liblog.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/lwip/liblwip.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/libmbedtls.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/newlib/libnewlib.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/nghttp/libnghttp.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/nvs_flash/libnvs_flash.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/perfmon/libperfmon.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/pthread/libpthread.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/sdmmc/libsdmmc.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/soc/libsoc.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/spi_flash/libspi_flash.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/tcp_transport/libtcp_transport.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/tcpip_adapter/libtcpip_adapter.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/ulp/libulp.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/vfs/libvfs.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/wpa_supplicant/libwpa_supplicant.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/xtensa/libxtensa.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/mbedtls/library/libmbedtls.a" "/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/mbedtls/library/libmbedx509.a" "-lcoexist" "-lcore" "-lespnow" "-lmesh" "-lnet80211" "-lpp" "-lsmartconfig" "-lwapi" "-lphy" "-lrtc" "-lxt_hal" "-lc" "-lm" "-lstdc++" "-lgcc" "-Wl,--end-group" "-T" "esp32_out.ld" "-u" "esp_app_desc" "-u" "pthread_include_pthread_impl" "-u" "pthread_include_pthread_cond_impl" "-u" "pthread_include_pthread_local_storage_impl" "-u" "ld_include_panic_highint_hdl" "-u" "start_app" "-u" "start_app_other_cores" "-T" "esp32.rom.ld" "-T" "esp32.rom.api.ld" "-T" "esp32.rom.libgcc.ld" "-T" "esp32.rom.newlib-data.ld" "-T" "esp32.rom.syscalls.ld" "-T" "esp32.rom.newlib-funcs.ld" "-T" "esp32.rom.newlib-time.ld" "-u" "vfs_include_syscalls_impl" "-T" "esp32.project.ld" "-T" "esp32.peripherals.ld" "-u" "call_user_start_cpu0" "-u" "app_main" "-u" "newlib_include_heap_impl" "-u" "newlib_include_syscalls_impl" "-u" "newlib_include_pthread_impl" "-u" "__cxa_guard_dummy" "-u" "__cxx_fatal_exception" "-Wl,--Map=/home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf.map" "-Wl,--cref" "-Wl,--gc-sections" "-Wl,--undefined=uxTopUsedPriority" "-Wl,--wrap=_Unwind_Backtrace" "-Wl,--wrap=_Unwind_DeleteException" "-Wl,--wrap=_Unwind_FindEnclosingFunction" "-Wl,--wrap=_Unwind_Find_FDE" "-Wl,--wrap=_Unwind_ForcedUnwind" "-Wl,--wrap=_Unwind_GetCFA" "-Wl,--wrap=_Unwind_GetDataRelBase" "-Wl,--wrap=_Unwind_GetGR" "-Wl,--wrap=_Unwind_GetIP" "-Wl,--wrap=_Unwind_GetIPInfo" "-Wl,--wrap=_Unwind_GetLanguageSpecificData" "-Wl,--wrap=_Unwind_GetRegionStart" "-Wl,--wrap=_Unwind_GetTextRelBase" "-Wl,--wrap=_Unwind_RaiseException" "-Wl,--wrap=_Unwind_Resume" "-Wl,--wrap=_Unwind_Resume_or_Rethrow" "-Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting" "-Wl,--wrap=_Unwind_SetGR" "-Wl,--wrap=_Unwind_SetIP" "-Wl,--wrap=__cxa_call_unexpected" "-Wl,--wrap=__deregister_frame_info" "-Wl,--wrap=__deregister_frame_info_bases" "-Wl,--wrap=__gxx_personality_v0" "-Wl,--wrap=__register_frame" "-Wl,--wrap=__register_frame_info" "-Wl,--wrap=__register_frame_info_bases" "-Wl,--wrap=__register_frame_info_table" "-Wl,--wrap=__register_frame_info_table_bases" "-Wl,--wrap=__register_frame_table" "-Wl,--wrap=longjmp" "-Wl,--wrap=mbedtls_mpi_exp_mod" "-Wno-frame-address" "-fno-lto" "-fno-rtti" "-mlongcalls" "-Og" "-g2" "-ggdb2"
  = note: Running ldproxy
          Error: Linker /home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc failed: exit status: 1
          STDERR OUTPUT:
          /home/euan/esp-idf-ftruncate-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /home/euan/esp-idf-ftruncate-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd-d1f4638178e555e4.rlib(std-d1f4638178e555e4.std.43feb998-cgu.2.rcgu.o):(.literal._ZN3std3sys4unix5cvt_r17h6b170249ec86b082E+0x0): undefined reference to `ftruncate'
          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 esp-idf-ftruncate-link-bug-repro due to previous error

Repro project https://github.com/Eroc33/esp-idf-ftruncate-link-bug-repro

std::fs::symlink_metadata/lstat

When using std::fs::symlink_metadata anywhere in the project a link error occurs referencing lstat:

Relevant excerpt

/home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd-d1f4638178e555e4.rlib(std-d1f4638178e555e4.std.43feb998-cgu.12.rcgu.o):(.literal._ZN3std3sys4unix2fs5lstat17ha8f4be7f0c78becbE+0x8): undefined reference to `lstat'
Full build output
euan@Euan-Desktop:~/esp-idf-lstat-link-bug-repro$ cargo build
   Compiling bindgen v0.59.2
   Compiling embuild v0.27.1
   Compiling esp-idf-sys v0.28.3
   Compiling esp-idf-lstat-link-bug-repro v0.1.0 (/home/euan/esp-idf-lstat-link-bug-repro)
error: linking with `ldproxy` failed: exit status: 1
  |
  = note: "ldproxy" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a.2o61kwgqp73kz58p.rcgu.o" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a.465x7843shr3wznz.rcgu.o" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a.4tcrsw4dvi8kmynz.rcgu.o" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a.56s06nqwa2qgwed3.rcgu.o" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a.d98uauh4eugwm4e.rcgu.o" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a.4gm7qzt072dn5wlv.rcgu.o" "-Wl,--as-needed" "-L" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps" "-L" "/home/euan/esp-idf-lstat-link-bug-repro/target/debug/deps" "-L" "/home/euan/.rustup/toolchains/esp/lib/rustlib/xtensa-esp32-espidf/lib" "-Wl,-Bstatic" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libesp_idf_sys-c71515d603b41be1.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libmutex_trait-df9aa576e9040a2f.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libembedded_svc-2899069fe8327a24.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/liblog-bcbaccb88823ec70.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcfg_if-935bd39d9f6427e5.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libanyhow-c3305a373346a996.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libenumset-7515a396e404b77d.rlib" "-Wl,--start-group" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd-d1f4638178e555e4.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libpanic_abort-45242a1e085ac8c1.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd_detect-0d85fdf205992f33.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/librustc_demangle-09912fe574e03e88.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libhashbrown-b84fbcd507543c60.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/librustc_std_workspace_alloc-6f53877691d2c88b.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libunwind-75acfd38a7bfff04.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcfg_if-16b2675bf0230332.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/liblibc-a626876b7c2b7226.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/liballoc-5a1058ec08d59625.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/librustc_std_workspace_core-17c3abae709388e4.rlib" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcore-8f5a7b792e1e0797.rlib" "-Wl,--end-group" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libcompiler_builtins-20ef2192007b875d.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/euan/.rustup/toolchains/esp/lib/rustlib/xtensa-esp32-espidf/lib" "-o" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/esp_idf_lstat_link_bug_repro-0d01fa3dfdbe1c6a" "-Wl,--gc-sections" "-no-pie" "-nodefaultlibs" "--ldproxy-linker" "/home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc" "--ldproxy-dedup-libs" "-L/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf" "-L/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug" "-L/home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/esp_wifi/lib/esp32" "-L/home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/esp_rom/esp32/ld" "-L/home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/xtensa/esp32" "-L/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp32" "-L/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp32/ld" "-L/home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/framework-espidf/components/esp32/ld" "-Wl,--start-group" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_pm/libesp_pm.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/asio/libasio.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/cbor/libcbor.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/unity/libunity.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/cmock/libcmock.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/coap/libcoap.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/console/libconsole.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_adc_cal/libesp_adc_cal.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_hid/libesp_hid.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/protobuf-c/libprotobuf-c.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/protocomm/libprotocomm.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mdns/libmdns.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_local_ctrl/libesp_local_ctrl.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_websocket_client/libesp_websocket_client.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/expat/libexpat.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/wear_levelling/libwear_levelling.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/fatfs/libfatfs.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/freemodbus/libfreemodbus.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/jsmn/libjsmn.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/json/libjson.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/libsodium/liblibsodium.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mqtt/libmqtt.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/openssl/libopenssl.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/spiffs/libspiffs.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/wifi_provisioning/libwifi_provisioning.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/app_trace/libapp_trace.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/app_update/libapp_update.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/bootloader_support/libbootloader_support.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/cxx/libcxx.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/driver/libdriver.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/efuse/libefuse.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp-tls/libesp-tls.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp32/libesp32.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_common/libesp_common.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_eth/libesp_eth.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_event/libesp_event.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_gdbstub/libesp_gdbstub.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_http_client/libesp_http_client.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_http_server/libesp_http_server.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_https_ota/libesp_https_ota.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_hw_support/libesp_hw_support.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_ipc/libesp_ipc.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_netif/libesp_netif.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_ringbuf/libesp_ringbuf.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_rom/libesp_rom.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_system/libesp_system.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_timer/libesp_timer.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/esp_wifi/libesp_wifi.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/espcoredump/libespcoredump.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/freertos/libfreertos.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/hal/libhal.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/heap/libheap.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/log/liblog.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/lwip/liblwip.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/libmbedtls.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/newlib/libnewlib.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/nghttp/libnghttp.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/nvs_flash/libnvs_flash.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/perfmon/libperfmon.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/pthread/libpthread.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/sdmmc/libsdmmc.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/soc/libsoc.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/spi_flash/libspi_flash.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/tcp_transport/libtcp_transport.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/tcpip_adapter/libtcpip_adapter.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/ulp/libulp.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/vfs/libvfs.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/wpa_supplicant/libwpa_supplicant.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/xtensa/libxtensa.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/mbedtls/library/libmbedtls.a" "/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf/mbedtls/mbedtls/library/libmbedx509.a" "-lcoexist" "-lcore" "-lespnow" "-lmesh" "-lnet80211" "-lpp" "-lsmartconfig" "-lwapi" "-lphy" "-lrtc" "-lxt_hal" "-lc" "-lm" "-lstdc++" "-lgcc" "-Wl,--end-group" "-T" "esp32_out.ld" "-u" "esp_app_desc" "-u" "pthread_include_pthread_impl" "-u" "pthread_include_pthread_cond_impl" "-u" "pthread_include_pthread_local_storage_impl" "-u" "ld_include_panic_highint_hdl" "-u" "start_app" "-u" "start_app_other_cores" "-T" "esp32.rom.ld" "-T" "esp32.rom.api.ld" "-T" "esp32.rom.libgcc.ld" "-T" "esp32.rom.newlib-data.ld" "-T" "esp32.rom.syscalls.ld" "-T" "esp32.rom.newlib-funcs.ld" "-T" "esp32.rom.newlib-time.ld" "-u" "vfs_include_syscalls_impl" "-T" "esp32.project.ld" "-T" "esp32.peripherals.ld" "-u" "call_user_start_cpu0" "-u" "app_main" "-u" "newlib_include_heap_impl" "-u" "newlib_include_syscalls_impl" "-u" "newlib_include_pthread_impl" "-u" "__cxa_guard_dummy" "-u" "__cxx_fatal_exception" "-Wl,--Map=/home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/build/esp-idf-sys-722ca5ac09ebffa5/out/esp-idf/.pio/build/debug/esp-idf.map" "-Wl,--cref" "-Wl,--gc-sections" "-Wl,--undefined=uxTopUsedPriority" "-Wl,--wrap=_Unwind_Backtrace" "-Wl,--wrap=_Unwind_DeleteException" "-Wl,--wrap=_Unwind_FindEnclosingFunction" "-Wl,--wrap=_Unwind_Find_FDE" "-Wl,--wrap=_Unwind_ForcedUnwind" "-Wl,--wrap=_Unwind_GetCFA" "-Wl,--wrap=_Unwind_GetDataRelBase" "-Wl,--wrap=_Unwind_GetGR" "-Wl,--wrap=_Unwind_GetIP" "-Wl,--wrap=_Unwind_GetIPInfo" "-Wl,--wrap=_Unwind_GetLanguageSpecificData" "-Wl,--wrap=_Unwind_GetRegionStart" "-Wl,--wrap=_Unwind_GetTextRelBase" "-Wl,--wrap=_Unwind_RaiseException" "-Wl,--wrap=_Unwind_Resume" "-Wl,--wrap=_Unwind_Resume_or_Rethrow" "-Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting" "-Wl,--wrap=_Unwind_SetGR" "-Wl,--wrap=_Unwind_SetIP" "-Wl,--wrap=__cxa_call_unexpected" "-Wl,--wrap=__deregister_frame_info" "-Wl,--wrap=__deregister_frame_info_bases" "-Wl,--wrap=__gxx_personality_v0" "-Wl,--wrap=__register_frame" "-Wl,--wrap=__register_frame_info" "-Wl,--wrap=__register_frame_info_bases" "-Wl,--wrap=__register_frame_info_table" "-Wl,--wrap=__register_frame_info_table_bases" "-Wl,--wrap=__register_frame_table" "-Wl,--wrap=longjmp" "-Wl,--wrap=mbedtls_mpi_exp_mod" "-Wno-frame-address" "-fno-lto" "-fno-rtti" "-mlongcalls" "-Og" "-g2" "-ggdb2"
  = note: Running ldproxy
          Error: Linker /home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/xtensa-esp32-elf-gcc failed: exit status: 1
          STDERR OUTPUT:
          /home/euan/esp-idf-lstat-link-bug-repro/.embuild/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: /home/euan/esp-idf-lstat-link-bug-repro/target/xtensa-esp32-espidf/debug/deps/libstd-d1f4638178e555e4.rlib(std-d1f4638178e555e4.std.43feb998-cgu.12.rcgu.o):(.literal._ZN3std3sys4unix2fs5lstat17ha8f4be7f0c78becbE+0x8): undefined reference to `lstat'
          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 esp-idf-lstat-link-bug-repro due to previous error

Repro project: https://github.com/Eroc33/esp-idf-lstat-link-bug-repro

As far as I can tell ftruncate and lstat simply don't exist in the esp-idf, so would need to be implemented there, or the libstd code that calls them would have to be implemented in terms of some other idf functions

(I saw these results when building using the pio option of embuild on WSL2/Ubuntu-20.04, but I think it should be the same on any configuration)

Can't use inline assembly

When I try to compile anything that uses an assembly macro on any xtensa target, I get this error:

error[E0472]: inline assembly is unsupported on this target

This is my .cargo/config.toml:

[target.xtensa-esp32-none-elf]
rustflags = [
    "-C", "link-arg=-nostartfiles",
]

And I compiled with:

cargo xbuild --target xtensa-esp32-none-elf

Did I compile the compiler wrong? Or did I compile the project wrong?

Missing import in `unsupported::args`

library/std/src/sys/unsupported/args.rs missing a use crate::fmt, this doesn't affect cargo xbuild because xbuild doesn't compile std. however cargo build -Z build-std will failed, and build-std did work before merge 1.53.0.

this has been fixed in rust-lang/rust@cf79c06, may be we could cherry-pick this commit?

[Compiling]: can't fine crate for 'core'

Hi, esp-rs team,

I follow the steps in ReadMe.md and configure the Rust compiling toolchain.
When I try to compile the esp32-wifi project, it reports "can't fine crate for 'core'. The log is as below:

root@HP-ProBook-650-G2:/home/***/private/esp32/esp32-wifi-master# cargo build
Compiling r0 v1.0.0
Compiling scopeguard v1.1.0
Compiling mutex-trait v0.2.0
Compiling xtensa-lx-rt v0.7.0
error[E0463]: can't find crate for core
|
= note: the xtensa-esp32-none-elf target may not be installed
= help: consider downloading the target with rustup target add xtensa-esp32-none-elf
= help: consider building the standard library from source with cargo build -Zbuild-std

For more information about this error, try rustc --explain E0463.
error: could not compile r0 due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed
root@siemens-HP-ProBook-650-G2:/home/siemens/private/esp32/esp32-wifi-master# cargo build
Compiling r0 v1.0.0
Compiling scopeguard v1.1.0
Compiling mutex-trait v0.2.0
Compiling bare-metal v1.0.0
error[E0463]: can't find crate for core
|
= note: the xtensa-esp32-none-elf target may not be installed
= help: consider downloading the target with rustup target add xtensa-esp32-none-elf
= help: consider building the standard library from source with cargo build -Zbuild-std

For more information about this error, try rustc --explain E0463.
error: could not compile r0 due to previous error
warning: build failed, waiting for other jobs to finish...
error: build failed

please help have a check and give some hints.

esp 1.54 breaks Mac M1 builds

1.54 Rust introduces a new compiler builtins version which is broken on M1 Mac's with LLVM 11.

cargo:warning=clang: error: no such file or directory: 'rust-xtensa-dev/src/llvm-project/compiler-rt/lib/builtins/aarch64/lse.S'

I believe this will be fixed once the llvm fork is updated to LLVM 12, as the file only exists in LLVM 12.

LLVM ERROR: Not supported instr: <MCInst 284 <MCOperand Reg:42>>

Hello,
I run into this error when I try to compile the crate deflate as a dependency:

cargo build --release
   Compiling deflate v0.9.1
   Compiling backtrace v0.3.63
   Compiling esp-idf-sys v0.30.1
   Compiling png v0.17.2
   Compiling anyhow v1.0.52
LLVM ERROR: Not supported instr: <MCInst 284 <MCOperand Reg:42>>
error: could not compile `deflate`
warning: build failed, waiting for other jobs to finish...
error: build failed

This dependency is needed by the png crate.
The bug only appears in the release build. Debug build runs fine.

I'm building against the default ESP32 target and tried both the stable Rustc 1.57.0.0 and the preview version Rustc 1.58.0.0.
Let me know if I need to attach more informations.
Thanks!

rustc +esp -vV
rustc 1.58.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.58.0-dev
LLVM version: 13.0.0
Operating System: openSUSE Tumbleweed 20220114
Kernel Version: 5.15.12-1-default (64-bit)

Old version of xtensa as submodule

When I build using this repo an old version of llvm is used as submodule. The git repo points to a specific commit, which is not 9.0.1

Compilation fails on `compiler_builtin` v0.1.18

It seems like the latest update of compiler_builtin to v0.1.18 got us in a situation where it is no longer possible to build for the xtensa-esp32-none-elf target.

The issue appears due to the line assert!(stack_required) of classify_arg_ty() in src/librustc_target/abi/call/xtensa.rs.

the stack trace

thread 'rustc' panicked at 'assertion failed: stack_required', src/librustc_target/abi/call/xtensa.rs:78:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_target::abi::call::xtensa::classify_arg_ty
   8: rustc_target::abi::call::xtensa::compute_abi_info
   9: <rustc_target::abi::call::FnType<'tcx, &'tcx rustc::ty::TyS<'tcx>> as rustc_codegen_llvm::abi::FnTypeExt<'tcx>>::adjust_for_abi
  10: <rustc_target::abi::call::FnType<'tcx, &'tcx rustc::ty::TyS<'tcx>> as rustc_codegen_llvm::abi::FnTypeExt<'tcx>>::new
  11: rustc_codegen_llvm::declare::<impl rustc_codegen_ssa::traits::declare::DeclareMethods<'tcx> for rustc_codegen_llvm::context::CodegenCx<'ll, 'tcx>>::declare_fn
  12: rustc_codegen_llvm::mono_item::<impl rustc_codegen_ssa::traits::declare::PreDefineMethods<'tcx> for rustc_codegen_llvm::context::CodegenCx<'ll, 'tcx>>::predefine_fn
  13: rustc_codegen_ssa::mono_item::MonoItemExt::predefine
  14: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  15: rustc::dep_graph::graph::DepGraph::with_task
  16: rustc_codegen_llvm::base::compile_codegen_unit
  17: rustc_codegen_ssa::base::codegen_crate
  18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  19: rustc::util::common::time
  20: rustc_driver::driver::phase_4_codegen
  21: <std::thread::local::LocalKey<T>>::with
  22: rustc::ty::context::TyCtxt::create_and_enter
  23: rustc_driver::driver::compile_input
  24: <scoped_tls::ScopedKey<T>>::set
  25: rustc_driver::run_compiler
  26: <scoped_tls::ScopedKey<T>>::set
  27: syntax::with_globals
  28: __rust_maybe_catch_panic
  29: <F as alloc::boxed::FnBox<A>>::call_box
  30: std::sys_common::thread::start_thread
  31: std::sys::unix::thread::Thread::new::thread_start
  32: start_thread
  33: __clone
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z force-unstable-if-unmarked -C opt-level=3 -C codegen-units=1 -C target-cpu=esp32 -C save-temps -C link-arg=-nostdlib -C link-arg=-ucall_user_start_cpu0 -C link-arg=-u__cxa_guard_dummy -C link-arg=-u__cxx_fatal_exception -C link-arg=-uld_include_panic_highint_hdl -C link-arg=-uesp_app_desc -C link-arg=-Wl,--gc-sections -C link-arg=-Wl,-static -C link-arg=-Wl,--start-group -C link-arg=-Lbuild/app_update -C link-arg=-lapp_update -C link-arg=-Lbuild/driver -C link-arg=-ldriver -C link-arg=-Lbuild/esp-tls -C link-arg=-lesp-tls -C link-arg=-Lbuild/esp32 -C link-arg=-lesp32 -C link-arg=esp-idf/components/esp32/libhal.a -C link-arg=-Lesp-idf/components/esp32/lib -C link-arg=-lcore -C link-arg=-Lesp-idf/components/esp32/ld -C link-arg=-Tesp32_out.ld -C link-arg=-Tbuild/esp32/esp32.project.ld -C link-arg=-Tesp32.rom.ld -C link-arg=-Tesp32.peripherals.ld -C link-arg=-Tesp32.rom.libgcc.ld -C link-arg=-Tesp32.rom.spiram_incompatible_fns.ld -C link-arg=-Lbuild/esp_ringbuf -C link-arg=-lesp_ringbuf -C link-arg=-Lbuild/freertos -C link-arg=-lfreertos -C link-arg=-Wl,--undefined=uxTopUsedPriority -C link-arg=-Lbuild/heap -C link-arg=-lheap -C link-arg=-Lbuild/log -C link-arg=-llog -C link-arg=esp-idf/components/newlib/lib/libc.a -C link-arg=esp-idf/components/newlib/lib/libm.a -C link-arg=-Lbuild/newlib -C link-arg=-lnewlib -C link-arg=-Lbuild/pthread -C link-arg=-lpthread -C link-arg=-Lbuild/soc -C link-arg=-lsoc -C link-arg=-Lbuild/spi_flash -C link-arg=-lspi_flash -C link-arg=-Lbuild/vfs -C link-arg=-lvfs -C link-arg=-Lbuild/xtensa-debug-module -C link-arg=-lxtensa-debug-module -C link-arg=-lgcc -C link-arg=-lstdc++ -C link-arg=-lgcov -C link-arg=-Wl,--end-group -C link-arg=-Wl,-EL --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `compiler_builtins`.

Some debug output I could inject:

[src/librustc_target/abi/call/xtensa.rs:70] arg.layout.details = LayoutDetails {
    variants: Single {
        index: 0
    },
    fields: Arbitrary {
        offsets: [
            Size {
                raw: 0
            },
            Size {
                raw: 16
            }
        ],
        memory_index: [
            0,
            1
        ]
    },
    abi: ScalarPair(
        Scalar {
            value: Int(
                I128,
                true
            ),
            valid_range: 0..=340282366920938463463374607431768211455
        },
        Scalar {
            value: Int(
                I8,
                false
            ),
            valid_range: 0..=1
        }
    ),
    align: AbiAndPrefAlign {
        abi: Align {
            pow2: 3
        },
        pref: Align {
            pow2: 3
        }
    },
    size: Size {
        raw: 24
    }
}
[src/librustc_target/abi/call/xtensa.rs:71] xlen = 32
[src/librustc_target/abi/call/xtensa.rs:72] remaining_gpr = 0
[src/librustc_target/abi/call/xtensa.rs:74] arg_size.bits() = 192
[src/librustc_target/abi/call/xtensa.rs:75] MAX_ARG_IN_REGS_SIZE = 128

NVS and `compiler_builtins` collision

Hi @MabezDev,

It is not issue of your fork, but I just want to publish my experience with NVS (Non Volatile Storage of ESP32). I think we could track it here.

ESP IDF has such component as NVS. It is key-value storage built upon flash. Any action with NVS translates to flash interactions. Because application runs also from flash, IDF internally use some locks, to prevent flash interaction until NVS operation is done. Also, NVS uses some low level functions such memcpy. Such functions in IDF marked as IRAM, so they are placed in the Internal RAM, not in flash. So, locks and IRAM functions allows NVS does things while application runs from flash.

When we compiling rust application, rust compiler implicitly add libcompiler_builtins library to the linker parameters. libcompiler_builtins also contains low level functions such as memcpy, but these functions don't marked as IRAM. Because libcompiler_builtins appears first in linker arguments, linker uses memcpy from libcompiler_builtins instead of right version from Espressif's libc.

This issue appears as Guru Meditation Error: Core N panic'ed (IllegalInstruction) when you try to call nvs_flash_init() from IDF. Unfortunately, NVS is required for normal work of builtin WiFI, it is too hard to use WiFi without NVS.

Stack overflow when sleeping on ESP32-S2 with multiple prints/HAL

I'm not sure where the bug is, and so I'm not this is the right repo to raise this.

I tried this code:

use std::thread;
use std::time::Duration;
use esp_idf_hal::prelude::*;
use esp_idf_sys;

fn main() {
    esp_idf_sys::link_patches();

    let peripherals = Peripherals::take().unwrap();
    let pins = peripherals.pins;

    let mut p18 = pins.gpio10.into_output().unwrap();

    println!("before");

    println!("mid");

    thread::sleep(Duration::from_secs(1));

    println!("after");
}

Full project at https://github.com/raybritton/esp32-rust-bug

I expected to see this happen: The execution should pause for 1 second

Instead, this happened: A stack overflow is detected and the device reboots infinitely.

If println!("mid"); or println!("before"); or let perip...put().unwrap(); is commented out the code works correctly.

Meta

rustc --version --verbose:

rustc 1.56.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-apple-darwin
release: 1.56.0-dev
LLVM version: 12.0.1

The output from monitor can be seen at https://pastebin.com/fAXsfRgj

I've tried with two ESP32-S2-Soala-1_v1.2 boards from https://eu.mouser.com/ProductDetail/espressif/esp32-s2-saola-1r and get the same results.

Measurement of a crate footprint

Story: As a user, I'd like to know footprint of a create used in my project, so that I can decide whether to use the crate or not in my embedded project.

With Rust it's easy to add dependency like std or some crate. The embedded devices has limited resources and it's important to identify impact of adding a big crate. Adding big dependency might generate application which is not possible to deploy.

Explore and identify methods for measuring footprint of the code / Rust library. Dimensions to consider: memory consumption, storage space.

@JurajSadel PTAL

Merge into main branch rust-lang/rust?

By now developers have to compile whole custom Rust toolchain to work with xtensa isa. Is there any possibility to merge xtensa instruction set support into main branch Rust? Then developers can install them easily by using rustup toolchain add command.

Verify floating point inline asm register allocation works

This is a bug in the current LLVM backend, should be fixed in the future.

Test case:

Choosing a specific register:

let _x: f32;
unsafe {
    asm!(
        "lsi f0, a0, 152", out("f0") _x
    );
};

However class based register allocation doesn't seem to work yet:

let _x: f32;
unsafe {
    asm!(
        "lsi {}, a0, 152", out(freg) _x
    );
};

Fails with

error: invalid operand for instruction
  --> src/main.rs:76:14
   |
76 |             "lsi {}, a0, 152", out(freg) _x
   |              ^
   |
note: instantiated into assembly here
  --> <inline asm>:1:6
   |
1  |     lsi a8, a0, 152
   |         ^

error: could not compile `xtensa-quickstart` due to previous error

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

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

Targets for esp32s3

Given that the ESP-IDF master branch does support esp32s3, perhaps it is time to add the two relevant targets to the compiler as well (the *-espidf one as well as the bare-metal one).

I would assume the S3 chip is supported by the Espressif LLVM fork in the meantime, right?

Default allocator doesn't guarantee allocation bigger than 4?

Allocating a type with alignment bigger than 4 bytes sometimes gets allocated on address which is not a multiple of that alignment, causing accesses to fail debug_assert! in slice::from_raw_parts_*

struct Something {
    x: f64,
    y: f32
}

fn main() -> anyhow::Result<()> {
    esp_idf_sys::link_patches();
    esp_idf_svc::log::EspLogger::initialize_default();

    log::info!("align_of::<Something>(): {}", std::mem::align_of::<Something>());
    log::info!("size_of::<Something>(): {}", std::mem::size_of::<Something>());

    loop {
        let r = rand::random::<usize>() % 100;
        let mut v = Vec::with_capacity(r);
        log::info!("pointer: 0x{:x}", v.as_ptr() as usize);
        log::info!("v.as_ptr() % std::mem::align_of::<Something>() == {}", v.as_ptr() as usize % std::mem::align_of::<Something>());
        unsafe { v.set_len(r); };

        log::info!("fill");

        for x in &mut v {
            *x = Something {
                x: 10f64,
                y: 20f32
            };
        }

        log::info!("filled");
        std::thread::sleep(std::time::Duration::from_millis(100));
    }

    Ok(())
}

Note that the alignment of Something is 8, and sometimes the pointer is not a multiple of 8, causing a panic in for x in &mut v { in debug builds.

Happens on ESP32 with Rust STD library, using https://github.com/ivmarkov/rust-esp32-std-demo

Can't read files using `fs::read` and `fs::read_to_string`

I tried reading files using the fs helper functions read and read_to_string. I was lazy to verify the actual return value, but the length of the returned data was considerably shorter (< 4 bytes) than the contents of the files.

Reading the files using File::open().read() worked as expected. Writing the files using either io::Write or std::fs::write works.

Build fails on git clone

Updating only changed submodules
Submodules updated in 0.12 seconds
    Updating git repository `https://github.com/ivmarkov/libc.git`
error: failed to get `libc` as a dependency of package `std v0.0.0 (D:\proj\rust\library\std)`

Caused by:
  failed to load source for dependency `libc`

Caused by:
  Unable to update https://github.com/ivmarkov/libc.git#b942bc82

Caused by:
  object not found - no match for id (b942bc82ac3b4104e6ce7284ceffeba8fbdc84b3); class=Odb (9); code=NotFound (-3)
failed to run: D:\proj\rust\build\x86_64-pc-windows-gnu\stage0\bin\cargo.exe build --manifest-path D:\proj\rust\src/bootstrap/Cargo.toml
Build completed unsuccessfully in 0:00:04

I'm guessing the lock.toml file references an inexisting commit for libc.

std-related patches review

(Migrated from espressif/rust repo)
@igrr Patches in https://github.com/ivmarkov/rust/commits/stable provide an std-capable environment on top of ESP-IDF.

Some of these patches work around the fact that ESP-IDF is not completely POSIX-compatible.

Here is a list of things that can be fixed in ESP-IDF to reduce the number of changes we need to make in rust:

Easy changes

  • add posix_memalign implementation — should be easy, ESP-IDF already has memalign function implemented
  • readv, writev — simple version can be wrappers around read/write
  • BSD Socket APIs: accept, bind, shutdown, getpeername, getsockname, getsockopt, setsockopt, closesocket, connect, listen, recvmsg, recv, recvfrom, sendmsg, send, sendto, socket, ioctlsocket, gethostbyname, gethostbyname_r, getaddrinfo, freeaddrinfo. These functions exist in IDF, but only as static inline functions. They need to be exported functions to be found by the linker.
    It can be done pretty easily, adding a C file with the following pattern:
    // defines an alias symbol:
    int accept_impl(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) \
         __attribute__((alias("accept"));
    
    // calls the "static inline function"
    int accept_impl(int socket, struct sockaddr *restrict address, socklen_t *restrict address_len) {
        return accept(socket, address, address_len);
    }
    (repeat for each function that is static inline and needs to be exported)
  • Define getcwd. Can simply return "/".
  • Define chdir. Can return -1 and set errno to ENOSYS.
  • Define sysconf and _SC_PAGESIZE. Can be a very simple implementation, returning constant value.
  • Process-related functions (kill, signal, exec, wait, spawn, etc) — no meaningful implementation possible, but each can return -1 and set errno to ENOSYS.
  • nanosleep — can be a wrapper around usleep

More complex changes

  • duplication of file descriptors — needs support in vfs component, not sure how complex this would be, and the semantics required by libstd.
  • PTHREAD_COND_INITIALIZER definition in IDF is non-standard:
    // The newlib definitions in libc for pthread_mutex_t and PTHREAD_MUTEX_INITIALIZER
    // are way off compared to what we have in ESP-IDF:
    // 1) ESP-IDF's pthread_mutex_t is only 4 bytes and not 40+ (because it is in fact a pointer to dynamically allocated structure)
    // 2) While the above is just a waste of space, ESP-IDF PTHREAD_MUTEX_INITIALIZER is the real issue:
    //    in libc it is defined as a series of 0s, while in ESP-IDF it is equal to 0xffffffff
    
    This might be harder to change. I don't have a concrete idea about how to solve this, yet.

No changes

These changes in the current patch set do not seem to be necessary, need to find why they were needed.

  • getrandom — it should be already supported by ESP-IDF.

igrr:
@ivmarkov here is the summary after looking at the std-related patches. Most things can be solved in IDF pretty easily.

There are probably other things in the patchset that i haven't noticed yet, please feel free to add more items.


ivmarkov:
Hi @igrr,

Thanks for all the feedback so far.

Before commenting on details, let me state something generic, which is very important:
Using an API (function) implemented in ESP-IDF from Rust STD is really a two-step process:

  1. The function should (obviously) be available in ESP-IDF
  2. The function should be declared by the libc crate

The reason why we need (2) is because currently the whole Rust STD support is based around consuming "extern C" API definitions available in the libc crate from above, which are manually defined and maintained for the various libC libraries (msvcrt, glibc, newlib, musl etc.).
Currently, Rust STD does not know about our esp-idf-sys crate and therefore about all the Bindgen bindings generated by it. Letting STD know about esp-idf-sys might increase the STD patch size and its complexity, and decrease the chances of it being accepted so far.

Therefore, I think we should stick to consuming the libc crate instead of our own autogenerated bindings in the context of Rust STD (files, threads and networking/sockets).
That would imply that we might need to file patches against libc (the newlib sub-module specifically), so that it properly reflects the status quo on ESP-IDF.

That work has already started. For example, @reitermarkus, who started the STD-on-ESP32 effort originally was able to push these changes to the libc crate, which were key for having the initial ESP32 STD support for Rust.
I think we should just continue this for riscv, as well as for all "deviations" ESP-IDF has from the standard newlib - particularly in the pthread area.

Of course not everything needs to be in the libc crate so as to be usable from Rust STD. You can always put an "inline" "extern C" definition, as I did e.g. here. It is just that these should be a minority, I feel.

One more thing: I'm not implying that there will be a huge amount of changes to the libc crate. Just that there will be some, and whenever e.g. there is an API in ESP-IDF (like posix_memalign) that does not necessarily means that it is exposed in libc/newlib.
As for the types of changes, see the riscv support here. Currently, a bit of a hack as it delegates to the "xtensa" support, even though I don't expect these to be different.


igrr:

  • Regarding your assessment of the "easy" changes: I agree completely. Before starting with those, I'm wondering, perhaps we should approach the Rust libstd maintainers with the current patchset, to get early feedback / directions. Shall I do this, or will Espressif drive it?
  • Regarding the "more complex ones":
    • FDs duplication, sematics: aren't they just expecting the POSIX semantics, whatever it is?
    • pthread*_t sizes being incorrect, and the PTHREAD_MUTEX_INITIALIZER of ESP-IDF not having the value defined in the libc crate for newlib - that might be something we have to push for fixing in the libc crate itself

igrr:
@ivmarkov Thanks for the explanation, I didn't know about newlib-specific things present in libc create, it makes a lot more sense now. I would appreciate if you could start the discussion with libstd maintainers regarding this existing patch set.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.