Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Linking error when using rand::thread_rng() #23

Closed
arnauorriols opened this issue Aug 12, 2021 · 4 comments
Closed

Linking error when using rand::thread_rng() #23

arnauorriols opened this issue Aug 12, 2021 · 4 comments

Comments

@arnauorriols
Copy link

I'm using this example as boilerplate for a PoC I'm conducting. I'm compiling with the docker image georgikrocks/esp-idf-rust:latest (2e95100a412d). When my Rust code calls rand::thread_rng(), compilation fails with

FAILED: streams-embedded-transport-example.elf 
: && /opt/xtensa-esp32-elf-clang/bin/xtensa-esp32-elf-g++ -mlongcalls -Wno-frame-address  CMakeFiles/streams-embedded-transport-example.elf.dir/project_elf_src_esp32.c.obj -o streams-embedded-transport-example.elf  esp-idf/esp_ringbuf/libesp_ringbuf.a  esp-idf/efuse/libefuse.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/driver/libdriver.a  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/app_update/libapp_update.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/espcoredump/libespcoredump.a  esp-idf/esp_phy/libesp_phy.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/tcpip_adapter/libtcpip_adapter.a  esp-idf/esp_netif/libesp_netif.a  esp-idf/esp_event/libesp_event.a  esp-idf/wpa_supplicant/libwpa_supplicant.a  esp-idf/esp_wifi/libesp_wifi.a  esp-idf/lwip/liblwip.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/soc/libsoc.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/xtensa/libxtensa.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_timer/libesp_timer.a  esp-idf/freertos/libfreertos.a  esp-idf/newlib/libnewlib.a  esp-idf/cxx/libcxx.a  esp-idf/app_trace/libapp_trace.a  esp-idf/asio/libasio.a  esp-idf/cbor/libcbor.a  esp-idf/unity/libunity.a  esp-idf/cmock/libcmock.a  esp-idf/coap/libcoap.a  esp-idf/console/libconsole.a  esp-idf/nghttp/libnghttp.a  esp-idf/esp-tls/libesp-tls.a  esp-idf/esp_adc_cal/libesp_adc_cal.a  esp-idf/esp_hid/libesp_hid.a  esp-idf/tcp_transport/libtcp_transport.a  esp-idf/esp_http_client/libesp_http_client.a  esp-idf/esp_http_server/libesp_http_server.a  esp-idf/esp_https_ota/libesp_https_ota.a  esp-idf/esp_lcd/libesp_lcd.a  esp-idf/protobuf-c/libprotobuf-c.a  esp-idf/protocomm/libprotocomm.a  esp-idf/mdns/libmdns.a  esp-idf/esp_local_ctrl/libesp_local_ctrl.a  esp-idf/sdmmc/libsdmmc.a  esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a  esp-idf/esp_websocket_client/libesp_websocket_client.a  esp-idf/expat/libexpat.a  esp-idf/wear_levelling/libwear_levelling.a  esp-idf/fatfs/libfatfs.a  esp-idf/freemodbus/libfreemodbus.a  esp-idf/jsmn/libjsmn.a  esp-idf/json/libjson.a  esp-idf/libsodium/liblibsodium.a  esp-idf/mqtt/libmqtt.a  esp-idf/openssl/libopenssl.a  esp-idf/perfmon/libperfmon.a  esp-idf/spiffs/libspiffs.a  esp-idf/ulp/libulp.a  esp-idf/wifi_provisioning/libwifi_provisioning.a  esp-idf/main/libmain.a  esp-idf/clib/libclib.a  esp-idf/rustlib/librustlib.a  -Wl,--cref -Wl,--Map=/opt/streams/build/streams-embedded-transport-example.map  -Wl,--gc-sections  -fno-rtti  -fno-lto  esp-idf/asio/libasio.a  esp-idf/cbor/libcbor.a  esp-idf/cmock/libcmock.a  esp-idf/unity/libunity.a  esp-idf/coap/libcoap.a  esp-idf/esp_adc_cal/libesp_adc_cal.a  esp-idf/esp_hid/libesp_hid.a  esp-idf/esp_lcd/libesp_lcd.a  esp-idf/esp_local_ctrl/libesp_local_ctrl.a  esp-idf/esp_websocket_client/libesp_websocket_client.a  esp-idf/expat/libexpat.a  esp-idf/fatfs/libfatfs.a  esp-idf/wear_levelling/libwear_levelling.a  esp-idf/freemodbus/libfreemodbus.a  esp-idf/jsmn/libjsmn.a  esp-idf/libsodium/liblibsodium.a  esp-idf/mqtt/libmqtt.a  esp-idf/openssl/libopenssl.a  esp-idf/perfmon/libperfmon.a  esp-idf/spiffs/libspiffs.a  esp-idf/wifi_provisioning/libwifi_provisioning.a  esp-idf/protocomm/libprotocomm.a  esp-idf/protobuf-c/libprotobuf-c.a  esp-idf/mdns/libmdns.a  esp-idf/console/libconsole.a  esp-idf/json/libjson.a  esp-idf/rustlib/target/xtensa-esp32-espidf/release/librustlib.a  esp-idf/clib/libclib.a  esp-idf/esp_ringbuf/libesp_ringbuf.a  esp-idf/efuse/libefuse.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/driver/libdriver.a  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/app_update/libapp_update.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/espcoredump/libespcoredump.a  esp-idf/esp_phy/libesp_phy.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/tcpip_adapter/libtcpip_adapter.a  esp-idf/esp_netif/libesp_netif.a  esp-idf/esp_event/libesp_event.a  esp-idf/wpa_supplicant/libwpa_supplicant.a  esp-idf/esp_wifi/libesp_wifi.a  esp-idf/lwip/liblwip.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/soc/libsoc.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/xtensa/libxtensa.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_timer/libesp_timer.a  esp-idf/freertos/libfreertos.a  esp-idf/newlib/libnewlib.a  esp-idf/cxx/libcxx.a  esp-idf/app_trace/libapp_trace.a  esp-idf/nghttp/libnghttp.a  esp-idf/esp-tls/libesp-tls.a  esp-idf/tcp_transport/libtcp_transport.a  esp-idf/esp_http_client/libesp_http_client.a  esp-idf/esp_http_server/libesp_http_server.a  esp-idf/esp_https_ota/libesp_https_ota.a  esp-idf/sdmmc/libsdmmc.a  esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a  esp-idf/ulp/libulp.a  esp-idf/mbedtls/mbedtls/library/libmbedtls.a  esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a  esp-idf/mbedtls/mbedtls/library/libmbedx509.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcoexist.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcore.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libespnow.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libmesh.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libnet80211.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libpp.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libsmartconfig.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libwapi.a  esp-idf/esp_ringbuf/libesp_ringbuf.a  esp-idf/efuse/libefuse.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/driver/libdriver.a  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/app_update/libapp_update.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/espcoredump/libespcoredump.a  esp-idf/esp_phy/libesp_phy.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/tcpip_adapter/libtcpip_adapter.a  esp-idf/esp_netif/libesp_netif.a  esp-idf/esp_event/libesp_event.a  esp-idf/wpa_supplicant/libwpa_supplicant.a  esp-idf/esp_wifi/libesp_wifi.a  esp-idf/lwip/liblwip.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/soc/libsoc.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/xtensa/libxtensa.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_timer/libesp_timer.a  esp-idf/freertos/libfreertos.a  esp-idf/newlib/libnewlib.a  esp-idf/cxx/libcxx.a  esp-idf/app_trace/libapp_trace.a  esp-idf/nghttp/libnghttp.a  esp-idf/esp-tls/libesp-tls.a  esp-idf/tcp_transport/libtcp_transport.a  esp-idf/esp_http_client/libesp_http_client.a  esp-idf/esp_http_server/libesp_http_server.a  esp-idf/esp_https_ota/libesp_https_ota.a  esp-idf/sdmmc/libsdmmc.a  esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a  esp-idf/ulp/libulp.a  esp-idf/mbedtls/mbedtls/library/libmbedtls.a  esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a  esp-idf/mbedtls/mbedtls/library/libmbedx509.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcoexist.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcore.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libespnow.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libmesh.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libnet80211.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libpp.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libsmartconfig.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libwapi.a  esp-idf/esp_ringbuf/libesp_ringbuf.a  esp-idf/efuse/libefuse.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/driver/libdriver.a  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/app_update/libapp_update.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/espcoredump/libespcoredump.a  esp-idf/esp_phy/libesp_phy.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/tcpip_adapter/libtcpip_adapter.a  esp-idf/esp_netif/libesp_netif.a  esp-idf/esp_event/libesp_event.a  esp-idf/wpa_supplicant/libwpa_supplicant.a  esp-idf/esp_wifi/libesp_wifi.a  esp-idf/lwip/liblwip.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/soc/libsoc.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/xtensa/libxtensa.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_timer/libesp_timer.a  esp-idf/freertos/libfreertos.a  esp-idf/newlib/libnewlib.a  esp-idf/cxx/libcxx.a  esp-idf/app_trace/libapp_trace.a  esp-idf/nghttp/libnghttp.a  esp-idf/esp-tls/libesp-tls.a  esp-idf/tcp_transport/libtcp_transport.a  esp-idf/esp_http_client/libesp_http_client.a  esp-idf/esp_http_server/libesp_http_server.a  esp-idf/esp_https_ota/libesp_https_ota.a  esp-idf/sdmmc/libsdmmc.a  esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a  esp-idf/ulp/libulp.a  esp-idf/mbedtls/mbedtls/library/libmbedtls.a  esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a  esp-idf/mbedtls/mbedtls/library/libmbedx509.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcoexist.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcore.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libespnow.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libmesh.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libnet80211.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libpp.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libsmartconfig.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libwapi.a  esp-idf/esp_ringbuf/libesp_ringbuf.a  esp-idf/efuse/libefuse.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/driver/libdriver.a  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/app_update/libapp_update.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/espcoredump/libespcoredump.a  esp-idf/esp_phy/libesp_phy.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/tcpip_adapter/libtcpip_adapter.a  esp-idf/esp_netif/libesp_netif.a  esp-idf/esp_event/libesp_event.a  esp-idf/wpa_supplicant/libwpa_supplicant.a  esp-idf/esp_wifi/libesp_wifi.a  esp-idf/lwip/liblwip.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/soc/libsoc.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/xtensa/libxtensa.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_timer/libesp_timer.a  esp-idf/freertos/libfreertos.a  esp-idf/newlib/libnewlib.a  esp-idf/cxx/libcxx.a  esp-idf/app_trace/libapp_trace.a  esp-idf/nghttp/libnghttp.a  esp-idf/esp-tls/libesp-tls.a  esp-idf/tcp_transport/libtcp_transport.a  esp-idf/esp_http_client/libesp_http_client.a  esp-idf/esp_http_server/libesp_http_server.a  esp-idf/esp_https_ota/libesp_https_ota.a  esp-idf/sdmmc/libsdmmc.a  esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a  esp-idf/ulp/libulp.a  esp-idf/mbedtls/mbedtls/library/libmbedtls.a  esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a  esp-idf/mbedtls/mbedtls/library/libmbedx509.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcoexist.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcore.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libespnow.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libmesh.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libnet80211.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libpp.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libsmartconfig.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libwapi.a  esp-idf/esp_ringbuf/libesp_ringbuf.a  esp-idf/efuse/libefuse.a  esp-idf/esp_ipc/libesp_ipc.a  esp-idf/driver/libdriver.a  esp-idf/esp_pm/libesp_pm.a  esp-idf/mbedtls/libmbedtls.a  esp-idf/app_update/libapp_update.a  esp-idf/bootloader_support/libbootloader_support.a  esp-idf/spi_flash/libspi_flash.a  esp-idf/nvs_flash/libnvs_flash.a  esp-idf/pthread/libpthread.a  esp-idf/esp_gdbstub/libesp_gdbstub.a  esp-idf/espcoredump/libespcoredump.a  esp-idf/esp_phy/libesp_phy.a  esp-idf/esp_system/libesp_system.a  esp-idf/esp_rom/libesp_rom.a  esp-idf/hal/libhal.a  esp-idf/vfs/libvfs.a  esp-idf/esp_eth/libesp_eth.a  esp-idf/tcpip_adapter/libtcpip_adapter.a  esp-idf/esp_netif/libesp_netif.a  esp-idf/esp_event/libesp_event.a  esp-idf/wpa_supplicant/libwpa_supplicant.a  esp-idf/esp_wifi/libesp_wifi.a  esp-idf/lwip/liblwip.a  esp-idf/log/liblog.a  esp-idf/heap/libheap.a  esp-idf/soc/libsoc.a  esp-idf/esp_hw_support/libesp_hw_support.a  esp-idf/xtensa/libxtensa.a  esp-idf/esp_common/libesp_common.a  esp-idf/esp_timer/libesp_timer.a  esp-idf/freertos/libfreertos.a  esp-idf/newlib/libnewlib.a  esp-idf/cxx/libcxx.a  esp-idf/app_trace/libapp_trace.a  esp-idf/nghttp/libnghttp.a  esp-idf/esp-tls/libesp-tls.a  esp-idf/tcp_transport/libtcp_transport.a  esp-idf/esp_http_client/libesp_http_client.a  esp-idf/esp_http_server/libesp_http_server.a  esp-idf/esp_https_ota/libesp_https_ota.a  esp-idf/sdmmc/libsdmmc.a  esp-idf/esp_serial_slave_link/libesp_serial_slave_link.a  esp-idf/ulp/libulp.a  esp-idf/mbedtls/mbedtls/library/libmbedtls.a  esp-idf/mbedtls/mbedtls/library/libmbedcrypto.a  esp-idf/mbedtls/mbedtls/library/libmbedx509.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcoexist.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libcore.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libespnow.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libmesh.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libnet80211.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libpp.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libsmartconfig.a  /opt/esp/idf/components/esp_wifi/lib/esp32/libwapi.a  -Wl,--wrap=mbedtls_mpi_exp_mod  -u esp_app_desc  -u pthread_include_pthread_impl  -u pthread_include_pthread_cond_impl  -u pthread_include_pthread_local_storage_impl  -L /opt/esp/idf/components/esp_phy/lib/esp32  -lphy  esp-idf/esp_phy/libesp_phy.a  -lphy  esp-idf/esp_phy/libesp_phy.a  -lphy  -lrtc  -u ld_include_highint_hdl  -u start_app  -u start_app_other_cores  -L /opt/streams/build/esp-idf/esp_system/ld  -T memory.ld  -T sections.ld  -u __ubsan_include  -L /opt/esp/idf/components/esp_rom/esp32/ld  -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  -Wl,--wrap=longjmp  -u __assert_func  -u vfs_include_syscalls_impl  -L /opt/esp/idf/components/esp_wifi/lib/esp32  -L /opt/esp/idf/components/soc/esp32/ld  -T esp32.peripherals.ld  /opt/esp/idf/components/xtensa/esp32/libxt_hal.a  -Wl,--undefined=uxTopUsedPriority  -u app_main  -lm  esp-idf/newlib/libnewlib.a  -u newlib_include_heap_impl  -u newlib_include_syscalls_impl  -u newlib_include_pthread_impl  -Wl,--wrap=_Unwind_SetEnableExceptionFdeSorting  -Wl,--wrap=__register_frame_info_bases  -Wl,--wrap=__register_frame_info  -Wl,--wrap=__register_frame  -Wl,--wrap=__register_frame_info_table_bases  -Wl,--wrap=__register_frame_info_table  -Wl,--wrap=__register_frame_table  -Wl,--wrap=__deregister_frame_info_bases  -Wl,--wrap=__deregister_frame_info  -Wl,--wrap=_Unwind_Find_FDE  -Wl,--wrap=_Unwind_GetGR  -Wl,--wrap=_Unwind_GetCFA  -Wl,--wrap=_Unwind_GetIP  -Wl,--wrap=_Unwind_GetIPInfo  -Wl,--wrap=_Unwind_GetRegionStart  -Wl,--wrap=_Unwind_GetDataRelBase  -Wl,--wrap=_Unwind_GetTextRelBase  -Wl,--wrap=_Unwind_SetIP  -Wl,--wrap=_Unwind_SetGR  -Wl,--wrap=_Unwind_GetLanguageSpecificData  -Wl,--wrap=_Unwind_FindEnclosingFunction  -Wl,--wrap=_Unwind_Resume  -Wl,--wrap=_Unwind_RaiseException  -Wl,--wrap=_Unwind_DeleteException  -Wl,--wrap=_Unwind_ForcedUnwind  -Wl,--wrap=_Unwind_Resume_or_Rethrow  -Wl,--wrap=_Unwind_Backtrace  -Wl,--wrap=__cxa_call_unexpected  -Wl,--wrap=__gxx_personality_v0  -u __cxa_guard_dummy  -lstdc++  esp-idf/pthread/libpthread.a  -lgcc  esp-idf/cxx/libcxx.a  -u __cxx_fatal_exception  esp-idf/app_trace/libapp_trace.a  -lgcov  esp-idf/app_trace/libapp_trace.a  -lgcov  -lc && :
/opt/xtensa-esp32-elf-clang/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: esp-idf/rustlib/target/xtensa-esp32-espidf/release/librustlib.a(rustlib-8ed1900ea86a6c48.rand-4de7581c8c2fb914.rand.5x8vszn4-cgu.15.rcgu.o.rcgu.o):(.literal._ZN3std4sync4once4Once9call_once28_$u7b$$u7b$closure$u7d$$u7d$17hd74d63aeb634a063E.llvm.12770143606975383821+0x4): undefined reference to `pthread_atfork'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

I noticed ESP-IDF pthread.c implementation does not implement pthread_atfork. Am I right in assuming there's nothing I can do ATM? Is it a bug, pending implementation, or can't be implemented?

In any case, this should probably be caught at compile time rather than link time. If you could point me to the right repository to where report this issue I'd appreciated it.

@georgik
Copy link
Collaborator

georgik commented Aug 12, 2021

@arnauorriols thank you fore reporting the issue.

Our team made initial analysis with following result:
pthread_atfork as indeed not implemented in IDF. Since IDF can't implement fork. At to why this is a linker error not compiler error, I think the answer is the function is declared somewhere in lib, and we haven't made it unavailable for newlib/idf.

Some pointers to source code:
pthread_atfork declared here: https://github.com/rust-lang/libc/blob/ca93b20b8435d238ceeb75fd09eaddee133c4147/src/unix/newlib/mod.rs#L692-L696

used here: https://github.com/rust-random/rand/blob/6d236fd8efddc063d1312de00792ba100fe083de/src/rngs/adapter/reseeding.rs#L282-L317

@igrr
Copy link
Member

igrr commented Aug 12, 2021

Thanks for reporting this @arnauorriols!
I've looked into this for a bit, so leaving a couple links that may be useful.
pthread_atfork is declared here in libc crate: https://github.com/rust-lang/libc/blob/ca93b20b8435d238ceeb75fd09eaddee133c4147/src/unix/newlib/mod.rs#L692-L696
and called here in rand crate: https://github.com/rust-random/rand/blob/6d236fd8efddc063d1312de00792ba100fe083de/src/rngs/adapter/reseeding.rs#L282-L317.
I think meaningful implementation of pthread_fork is not possible in IDF, since IDF cannot implement fork. However since fork never happens, we can either implement a dummy pthread_atfork in ESP-IDF (do nothing, return 0). Alternatively, we can make the declaration of pthread_atfork (and other process-related functions) conditional on #[cfg(not(target_os = "espidf"))], then submit a PR to rand crate to handle target_os = "espidf" same way as at handles target_os = "emscripten".

As to your comment that this should be a compile time rather than link time error — I think while being correct this would put us further away from reaching the desired state where everything works as expected. To make all such situations compile time errors, we would need to get a real list of posix/unix APIs implemented in ESP-IDF, and exclude everything that's not implemented in libc crate. Then, realize that half of them actually can be implemented or stubbed out, make the changes in IDF, and then un-exclude them in libc. The latter will probably take more time. I think once we do the initial pass of implementing the missing things in IDF, we can look at the list of functions declared in libc and compare it to the list of functions extern'ed by IDF. Then, exclude the missing ones in libc crate. But doing this at the current point is premature, in my opinion.

(sorry, have crossed posts with @georgik!)

arnauorriols added a commit to arnauorriols/streams that referenced this issue Aug 12, 2021
espidf targets have libstd available through ESP-IDF framework.
This framework provides most but not all of the POSIX standard API.
In particular, ESP-IDF does not provide a means to fork threads, and
cannot implement `pthread_atfork` (see
espressif/rust-esp32-example#23).
This means `rand::thread_rng()` is not available on those targets,
as it is based on storing the rng in the thread-local storage, accessed
through a thread handle.

For these targets, this commit specializes the random_key and
random_nonce generators to use `StdRng::from_entropy()` instead.
In practice, given the coldness of these 2 functions, the same level
of security and performance is to be expected.

Note that currently `getrandom` does not support `espidf` targets
and requires a small patch.
arnauorriols added a commit to arnauorriols/streams that referenced this issue Aug 12, 2021
espidf targets have libstd available through ESP-IDF framework.
This framework provides most but not all of the POSIX standard API.
In particular, ESP-IDF does not provide a means to fork threads, and
cannot implement `pthread_atfork` (see
espressif/rust-esp32-example#23).
This means `rand::thread_rng()` is not available on those targets,
as it is based on storing the rng in the thread-local storage, accessed
through a thread handle.

For these targets, this commit specializes the random_key and
random_nonce generators to use `StdRng::from_entropy()` instead.
In practice, given the coldness of these 2 functions, the same level
of security and performance is to be expected.

Note that currently `getrandom` does not support `espidf` targets
and requires a small patch.
@georgik
Copy link
Collaborator

georgik commented Oct 12, 2021

@igrr Is this issue still relevant with 1.55 and installation instructions from https://github.com/esp-rs/rust-build project?

@arnauorriols
Copy link
Author

Thanks @georgik @igrr for your explanations, very helpful and informative! From my side, this issue can be closed

@georgik georgik closed this as completed Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants