zephyr: Usage Fault with CONFIG_NO_OPTIMIZATIONS even on samples/hello_world

Describe the bug Zephyr crashes with a usage fault before getting to main() if CONFIG_NO_OPTIMIZATIONS is passed in. BOARD=cc1352r1_launchxl using samples/hello_world (custom application exhibits the same behaviour)

CONFIG_NO_OPTIMIZATIONS is required in order to see values other than optimized out through JTAG / gdb (see screenshot).

More info on CONFIG_NO_OPTIMIZTIONS.

To Reproduce Steps to reproduce the behavior:

  1. echo 'CONFIG_NO_OPTIMIZATIONS=y' >> samples/hello_world/prj.conf
  2. west build --pristine -b cc1352r1_launchxl samples/hello_world
  3. west debug
  4. See error

Expected behavior

Aside from being able to debug inspect variables and not see ‘value optimized out’, I would expect this:

***** Booting Zephyr OS build v2.0.0-rc1-265-gc4d2e173a42c *****
Hello World! cc1352r1_launchxl        

Impact

For my purposes, this is a bit of a showstopper, as I was hoping to get application-level code tested over UART before moving it to BLE in time for the Linux Plumbers Conference.

Without the ability to inspect all variables through JTAG, it makes debugging via JTAG only slightly more useful than printf debugging, but not by much. I’ve found it often takes at least 3x as long to debug applications when having to rely on printed debugging.

However, in my case, I am using the UART for my application (i.e. cannot use printf debugging), and so it makes debugging effectively impossible.

Screenshots or console output

Backtrace:

Program received signal SIGINT, Interrupt.
k_cpu_idle () at /home/cfriedt/workspace/zephyrproject/zephyr/arch/arm/core/cpu_idle.S:99
99		bx lr
bt
#0  k_cpu_idle () at /home/cfriedt/workspace/zephyrproject/zephyr/arch/arm/core/cpu_idle.S:99
#1  0x0000466a in z_arch_system_halt (reason=0) at /home/cfriedt/workspace/zephyrproject/zephyr/kernel/fatal.c:29
#2  0x000023ca in k_sys_fatal_error_handler (reason=0, esf=0x20000910 <_interrupt_stack+2016>) at /home/cfriedt/workspace/zephyrproject/zephyr/kernel/fatal.c:42
#3  0x000024d4 in z_fatal_error (reason=0, esf=0x20000910 <_interrupt_stack+2016>) at /home/cfriedt/workspace/zephyrproject/zephyr/kernel/fatal.c:121
#4  0x00003cd4 in z_arm_fatal_error (reason=0, esf=0x20000910 <_interrupt_stack+2016>) at /home/cfriedt/workspace/zephyrproject/zephyr/arch/arm/core/fatal.c:50
#5  0x0000188e in _Fault (esf=0x20000910 <_interrupt_stack+2016>, exc_return=42) at /home/cfriedt/workspace/zephyrproject/zephyr/arch/arm/core/cortex_m/fault.c:867
#6  0x00001322 in __usage_fault () at /home/cfriedt/workspace/zephyrproject/zephyr/arch/arm/core/fault_s.S:161
#7  <signal handler called>
#8  0x0000be00 in ?? ()
#9  <signal handler called>
#10 z_errno () at /home/cfriedt/workspace/zephyrproject/zephyr/lib/os/fdtable.c:146
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Console:

**FATAL: ***** USAGE FAULT *****                                                                                 
FATAL:   Illegal use of the EPSR                                                                                 
FATAL: r0/a1:  0x40001000  r1/a2:  0x0000002a  r2/a3:  0xe4000000                                                
FATAL: r3/a4:  0x40001000 r12/ip:  0x00000000 r14/lr:  0xfffffffd                                                
FATAL:  xpsr:  0x8000000f                                                                                        
FATAL: Faulting instruction address (r15/pc): 0x0000be00                                                         
FATAL: >>> ZEPHYR FATAL ERROR 0: CPU exception                                                                   
FATAL: Current thread: 0x20000028 (unknown)                                                                      
FATAL: Halting system       

Here is a screenshot of me attempting to inspect variables without the CONFIG_NO_OPTIMIZATION option. Likely, the default optimization level is -O2 or -Os.

optimized-out

Environment (please complete the following information):

  • OS: Ubuntu Bionic
  • Toolchain: GNU ARM Embedded 2019 Q3 (but presumably affects all gcc variants)
  • Commit: 0906671a7b17d7218c7f3acf0bcd991712dafd35

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 21 (18 by maintainers)

Most upvoted comments

Thanks @cfriedt for the PRs.

Does Zephyr’s linker script have a convenient way to do that?

At the SoC level you can do it like this.

Directly in the main linker script you can do it like this.

Also take a look at this commit that moved the vector relay code to be CMake-handled, maybe it can serve as inspiration as well.

@cfriedt also, please note that the right name of this Kconfig option is CONFIG_NO_OPTIMIZATIONS (note the S at the end). In your description you seem to have misspelled it.