esp-rs / rust

Rust for the xtensa architecture. Built in targets for the ESP32 and ESP8266
https://www.rust-lang.org
Other
742 stars 39 forks source link

size_of::<Self>() causes SIGSEGV #243

Open i404788 opened 1 week ago

i404788 commented 1 week ago

Code

This commit fixes it in the project I originally used it in: https://github.com/i404788/embassy/commit/3b540cf24559f4ba6236db4167c443bd7224851f

Unfortunately my attempts to reproduce it at smaller scale in non-esp rust so far have failed, for now I'm assuming it's esp specific. I'll continue trying to find the root cause minimal example, if found to be in mainline rust, I'll move the issue over there.

This seems to be allowed in >1.80 without import, but in release mode can cause an rustc/LLVM SIGSEGV. Changing it to an explicit import fixes this.

Meta

This is the version I originally found it in but it identical errors occurs in 1.80.0.

rustc --version --verbose:

$ rustc +esp --version --verbose
rustc 1.82.0-nightly (a87c0551c 2024-10-30) (1.82.0.3)
binary: rustc
commit-hash: a87c0551c68304e5e845cab1523db1134eb0a765
commit-date: 2024-10-30
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.2

Error output

error: rustc interrupted by SIGSEGV, printing backtrace

/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x3865086)[0x7f5945465086]
/usr/lib/libc.so.6(+0x3f8c0)[0x7f59418fc8c0]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x5ddd520)[0x7f59479dd520]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x5ddea0d)[0x7f59479dea0d]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x5de5513)[0x7f59479e5513]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x5dd0f12)[0x7f59479d0f12]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x5daa76e)[0x7f59479aa76e]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x5c3ac84)[0x7f594783ac84]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x6f9f6fa)[0x7f5948b9f6fa]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x6f9f884)[0x7f5948b9f884]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x6fa0284)[0x7f5948ba0284]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(LLVMRustWriteOutputFile+0x468)[0x7f594588e928]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x3b88be9)[0x7f5945788be9]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x3b8d8bc)[0x7f594578d8bc]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x3b17173)[0x7f5945717173]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x3b0c015)[0x7f594570c015]
/home/null/.rustup/toolchains/esp/lib/librustc_driver-6c3b01745bae83eb.so(+0x3b1a2dd)[0x7f594571a2dd]
/home/null/.rustup/toolchains/esp/lib/libstd-4b39eaf6f4d1afd7.so(rust_metadata_std_514176f0421ff3ff+0xe2a6b)[0x7f5941b89a6b]
/usr/lib/libc.so.6(+0x8c962)[0x7f5941949962]
/usr/lib/libc.so.6(+0x107b08)[0x7f59419c4b08]

note: we would appreciate a report at https://github.com/rust-lang/rust
help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216
warning: `robolabel` (bin "test-controller") generated 54 warnings (run `cargo fix --bin "test-controller"` to apply 1 suggestion)
error: could not compile `robolabel` (bin "test-controller"); 54 warnings emitted

Caused by:
Caused by:
  process didn't exit successfully: `~/.rustup/toolchains/esp/bin/rustc --crate-name test_controller --edition=2021 src/bin/test-controller.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=239 --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="defmt"' --check-cfg 'cfg(docsrs)' --check-cfg 'cfg(feature, values("board-v2", "default", "defmt", "dhcp"))' -C metadata=e7246ac715e73736 -C extra-filename=-e7246ac715e73736 --out-dir '~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps' --target xtensa-esp32s3-none-elf -L 'dependency=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps' -L 'dependency=~/Projects/<omitted>/target/release/deps' --extern 'noprelude:alloc=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/liballoc-90c289883ea7f0bd.rlib' --extern 'anyhow=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libanyhow-b8353654bff6355b.rlib' --extern 'btft81x_eve=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libbtft81x_eve-f6a86162ae9c4080.rlib' --extern 'noprelude:compiler_builtins=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libcompiler_builtins-7c093f2951165023.rlib' --extern 'noprelude:core=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libcore-334f21e805c9707b.rlib' --extern 'critical_section=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libcritical_section-1e864fb2825e85ca.rlib' --extern 'defmt=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libdefmt-be8ea8f841e25399.rlib' --extern 'embassy_executor=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_executor-46dd899318ae47b2.rlib' --extern 'embassy_futures=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_futures-79c287f4c33dcc5a.rlib' --extern 'embassy_net=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_net-b91208e7229a453d.rlib' --extern 'embassy_net_wiznet=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_net_wiznet-3a36e5a77ca86f31.rlib' --extern 'embassy_sync=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_sync-000fbc9cb850eed2.rlib' --extern 'embassy_time=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_time-f78acdd6ac73f59f.rlib' --extern 'embassy_usb=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_usb-a1cf32f626f892b4.rlib' --extern 'embassy_usb_driver=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembassy_usb_driver-bd579cdca77d487b.rlib' --extern 'embedded_graphics=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_graphics-b9af893bccf4f6e0.rlib' --extern 'embedded_hal=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_hal-791dffae80eb1c2b.rlib' --extern 'embedded_hal_async=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_hal_async-6e9cbe65040bce00.rlib' --extern 'embedded_hal_bus=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_hal_bus-00cc7387ea4218f2.rlib' --extern 'embedded_io_async=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_io_async-13ffd5efd0ffae40.rlib' --extern 'embedded_nal=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_nal-61bdb8974409ea3d.rlib' --extern 'embedded_sdmmc=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libembedded_sdmmc-986c6734a3bbd3f2.rlib' --extern 'esp_alloc=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libesp_alloc-d4029322b1b26dfe.rlib' --extern 'esp_backtrace=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libesp_backtrace-359782003ddc2387.rlib' --extern 'esp_flash_app_macros=~/Projects/<omitted>/target/release/deps/libesp_flash_app_macros-cd029b400f9bdf88.so' --extern 'esp_hal=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libesp_hal-dbb4ea3e69c95149.rlib' --extern 'esp_hal_embassy=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libesp_hal_embassy-8eb5c40ecba2783c.rlib' --extern 'esp_println=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libesp_println-355d05fd0de8ae48.rlib' --extern 'heapless=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libheapless-bb2227537bf20ab2.rlib' --extern 'httparse=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libhttparse-711ae320e700b877.rlib' --extern 'micromath=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libmicromath-46bdecc0f5a0270a.rlib' --extern 'modbus_core=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libmodbus_core-93029b6f82bcc29a.rlib' --extern 'postcard=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libpostcard-abe096c7b17c865d.rlib' --extern 'serde=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libserde-3ab7a32859b1bf53.rlib' --extern 'serde_json_core=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libserde_json_core-503df43988bc1042.rlib' --extern 'static_cell=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libstatic_cell-ff7a063239c17659.rlib' --extern 'tinyqoi=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libtinyqoi-e25cb701acb45145.rlib' --extern 'usbh=~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/deps/libusbh-2078aa05c46424e9.rlib' -Z unstable-options -C link-arg=-Wl,-Tlinkall.x -C link-arg=-nostartfiles -C link-arg=-Tdefmt.x -L '~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/build/defmt-8175dfa54a0fab86/out' -L '~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/build/esp-hal-e520e7b3f0aa05f0/out' -L '~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/build/esp32s3-b9dccee8de59df6b/out' -L '~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/build/xtensa-lx-e4091d354d27bb51/out' -L '~/Projects/<omitted>/target/xtensa-esp32s3-none-elf/release/build/xtensa-lx-rt-2e89930a459d1561/out'` (signal: 11, SIGSEGV: invalid memory reference)

RUST_BACKTRACE=1 has no effect

MabezDev commented 5 days ago

I'd be happy to look into this, even without a min repro, any repro will do because we have a backtrace (I'll do a local custom build of rust/LLVM with debugging symbols).

Side note: https://github.com/i404788/embassy/commit/3b540cf24559f4ba6236db4167c443bd7224851f :eyes:, you're working on a host driver in embassy!? Very cool, and very cool that you're using an s3 to develop it :D

i404788 commented 5 days ago

Thanks, I'll be submitting my PR to esp-hal when the embassy side is sorted, we are having a mini working group @ https://github.com/embassy-rs/embassy/pull/3307 to get traits & drivers across platforms aligned.

I've gotten the repro down to a managable size (https://github.com/i404788/rust-compile-crash-repro); it seems like maybe it has to do with the async_closure feature, but I've also included main.not.rs which also uses them but doesn't cause an issue (need to clean if coming from broken), Also I maybe got the wrong commit, at that point it is fixed but https://github.com/i404788/embassy/commit/df729bfcff15a091f6cd24c7da0565e10350f7d1 is the confirmed broken one, so it's possible https://github.com/i404788/embassy/commit/dd408d4e6d9d0a908d46d80b9ac6aecb492ed03a fixed it.