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

C++: Boot fails with global STL objects #75853

Closed
elazar-vayyar opened this issue Jul 14, 2024 · 0 comments · Fixed by #75915
Closed

C++: Boot fails with global STL objects #75853

elazar-vayyar opened this issue Jul 14, 2024 · 0 comments · Fixed by #75915
Assignees
Labels
area: C++ bug The issue is a bug, or the PR is fixing a bug platform: ESP32 Espressif ESP32 priority: low Low impact/importance bug

Comments

@elazar-vayyar
Copy link

elazar-vayyar commented Jul 14, 2024

Describe the bug
For a C++ app (main.cpp), when declaring a global variable of an STL class, e.g., std::string, the app fails to boot (even the boot banner is not shown on the UART console).
It seems like this problem is related to static construction of STL objects.

This happens since I upgraded to Zephyr v3.7.0-rc*. I did not experience this with v3.6.0, so it looks like a regression.

Zephyr version: v3.7.0-rc3 (commit: fd0e46506fabd4c0c91ecb336a39cb6a6aa2b270)
Zephyr SDK: 0.16.8
C++ implementation: CONFIG_GLIBCXX_LIBCPP=y
Target: esp32_devkitc_wroom/esp32/procpu

To Reproduce

  1. Apply the following patch to samples/cpp/cpp_synchronization
    diff --git a/samples/cpp/cpp_synchronization/prj.conf b/samples/cpp/cpp_synchronization/prj.conf
    index c6b0deca74d..8d9aaba6271 100644
    --- a/samples/cpp/cpp_synchronization/prj.conf
    +++ b/samples/cpp/cpp_synchronization/prj.conf
    @@ -1,2 +1,3 @@
     CONFIG_CPP=y
    +CONFIG_GLIBCXX_LIBCPP=y
     CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=128
    diff --git a/samples/cpp/cpp_synchronization/src/main.cpp b/samples/cpp/cpp_synchronization/src/main.cpp
    index 3ccf39bbb28..1c7db919e76 100644
    --- a/samples/cpp/cpp_synchronization/src/main.cpp
    +++ b/samples/cpp/cpp_synchronization/src/main.cpp
    @@ -23,6 +23,9 @@
     #include <zephyr/arch/cpu.h>
     #include <zephyr/sys/printk.h>
     
    +#include <string>
    +std::string foo;
    +
     /**
      * @class semaphore the basic pure virtual semaphore class
      */
    
    
  2. cd samples/cpp/cpp_synchronization
  3. west build -b "esp32_devkitc_wroom/esp32/procpu"
  4. west flash
  5. west espressif monitor

Expected behavior
Successful sample app boot that starts with the boot banner:

*** Booting Zephyr OS build v3.7.0-rc3 ***
Create semaphore 0x3ffb2934
Create semaphore 0x3ffb2920
main: Hello World!
coop_thread_entry: Hello World!
...

Actual behavior
The bootloader stops after setting up memory segments and does not reach the boot banner stage.

Impact
Cannot run C++ applications with global/static STL objects.
In addition, cannot declare initialized STL rvalue in functions, for example, declaring the following function would also reproduce this problem (probably since it actually creates a static const object as rvalue to return):

std::string foo_func()
{
    return std::string("bar");
}

Logs and console output
UART console log output of samples/cpp/cpp_synchronization when declaring global STL object as suggested in the reproduction steps given above:

$ west espressif monitor
Serial port /dev/ttyUSB0
Connecting.....
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting......
Detecting chip type... ESP32
--- idf_monitor on /dev/ttyUSB0 115200 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
ets Jun  8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3ffb0000,len:6016
load:0x40080000,len:33520
0x40080000: _WindowOverflow4 at /home/user/zephyrproject/zephyr/arch/xtensa/core/window_vectors.S:56

entry 0x40083bf8
0x40083bf8: __start at /home/user/zephyrproject/zephyr/soc/espressif/common/loader.c:229

I (29) boot: ESP Simple boot
I (29) boot: compile time Jul 14 2024 12:04:40
W (30) boot: Unicore bootloader
I (30) spi_flash: detected chip: generic
I (32) spi_flash: flash io: dio
I (35) boot: chip revision: v1.0
I (38) boot.esp32: SPI Speed      : 40MHz
I (42) boot.esp32: SPI Mode       : DIO
I (46) boot.esp32: SPI Flash Size : 4MB
I (49) boot: Enabling RNG early entropy source...
[esp32] [INF] DRAM: lma 0x00001020 vma 0x3ffb0000 len 0x1780   (6016)
[esp32] [INF] IRAM: lma 0x000027a8 vma 0x40080000 len 0x82f0   (33520)
0x40080000: _WindowOverflow4 at /home/user/zephyrproject/zephyr/arch/xtensa/core/window_vectors.S:56

[esp32] [INF] padd: lma 0x0000aaa8 vma 0x00000000 len 0x5550   (21840)
[esp32] [INF] IMAP: lma 0x00010000 vma 0x400d0000 len 0x869c   (34460)
0x400d0000: _image_irom_vaddr at ??:?

[esp32] [INF] padd: lma 0x000186a4 vma 0x00000000 len 0x7954   (31060)
[esp32] [INF] DMAP: lma 0x00020000 vma 0x3f400000 len 0x138e4  (80100)
[esp32] [INF] Image with 6 segments
[esp32] [INF] DROM segment: paddr=00020000h, vaddr=3f410000h, size=038E4h ( 14564) map
[esp32] [INF] IROM segment: paddr=00010000h, vaddr=400d0000h, size=0869Ch ( 34460) map

(output stops after the last line quoted above - no boot banner or any other output)

Environment:

  • OS: Linux - Ubuntu 22.04.4 LTS
  • Toolchain: Zephyr SDK 0.16.8
  • Target board: esp32_devkitc_wroom/esp32/procpu
  • C++ implementation (for STL): CONFIG_GLIBCXX_LIBCPP
  • Commit SHA or Version used: v3.7.0-rc3 (fd0e46506fabd4c0c91ecb336a39cb6a6aa2b270)
@elazar-vayyar elazar-vayyar added the bug The issue is a bug, or the PR is fixing a bug label Jul 14, 2024
@sylvioalves sylvioalves self-assigned this Jul 16, 2024
@sylvioalves sylvioalves added the platform: ESP32 Espressif ESP32 label Jul 16, 2024
sylvioalves added a commit to sylvioalves/zephyr that referenced this issue Jul 16, 2024
cplusplus-rom linker initialization was wrongly placed
in RAM area when it should be in ROM area.

Fixes zephyrproject-rtos#75853

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
@nashif nashif added area: C++ priority: low Low impact/importance bug labels Jul 16, 2024
nashif pushed a commit that referenced this issue Aug 6, 2024
cplusplus-rom linker initialization was wrongly placed
in RAM area when it should be in ROM area.

Fixes #75853

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
zephyrbot pushed a commit that referenced this issue Aug 6, 2024
cplusplus-rom linker initialization was wrongly placed
in RAM area when it should be in ROM area.

Fixes #75853

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
(cherry picked from commit c374d31)
nashif pushed a commit that referenced this issue Aug 7, 2024
cplusplus-rom linker initialization was wrongly placed
in RAM area when it should be in ROM area.

Fixes #75853

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
(cherry picked from commit c374d31)
topisani pushed a commit to topisani/zephyr that referenced this issue Aug 28, 2024
cplusplus-rom linker initialization was wrongly placed
in RAM area when it should be in ROM area.

Fixes zephyrproject-rtos#75853

Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
(cherry picked from commit c374d31)
Chenhongren pushed a commit to Chenhongren/zephyr that referenced this issue Aug 29, 2024
cplusplus-rom linker initialization was wrongly placed
in RAM area when it should be in ROM area.

Fixes zephyrproject-rtos#75853

(cherry picked from commit c374d31)

Original-Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
GitOrigin-RevId: c374d31
Cr-Build-Id: 8740269368881080913
Cr-Build-Url: https://cr-buildbucket.appspot.com/build/8740269368881080913
Copybot-Job-Name: zephyr-main-copybot-downstream
Change-Id: I6570e43f0389302d902a7996f746a67d3a4f2653
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5769425
Tested-by: Jeremy Bettis <jbettis@chromium.org>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C++ bug The issue is a bug, or the PR is fixing a bug platform: ESP32 Espressif ESP32 priority: low Low impact/importance bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants