Skip to content

compiler optimization -O2 results in bad assembly #90703

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

Open
1 task
stef opened this issue May 27, 2025 · 0 comments
Open
1 task

compiler optimization -O2 results in bad assembly #90703

stef opened this issue May 27, 2025 · 0 comments
Labels
bug The issue is a bug, or the PR is fixing a bug

Comments

@stef
Copy link

stef commented May 27, 2025

Describe the bug

when i try to build the example samples/bluetooth/peripheral_nus for my new xiao_ble board, the build fails with the error:

Error: registers may not be the same -- `str r3,[r3,#-12]!'

Regression

  • This is a regression.

Steps to reproduce

i try to build using

% ZEPHYR_TOOLCHAIN_VARIANT=cross-compile CROSS_COMPILE=/usr/bin/arm-none-eabi- west build -p auto -b xiao_ble/nrf52840 samples/bluetooth/peripheral_nus

this fails, with the error mentioned in the previous section, see relevant output in the "log output" section.

the problem is the -O2 flag in the failing command which overrides the previous -Os flag, if i remove the -O2 flag and run this command again from the build directory it succeeds.

Relevant log output

ninja: job failed: /usr/bin/arm-none-eabi-gcc -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DNRF52840_XXAA -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -I/home/user/z/zephyr/subsys/bluetooth/controller/. -I/home/user/z/zephyr/subsys/bluetooth/controller/include -I/home/user/z/zephyr/subsys/bluetooth/controller/../crypto -I/home/user/z/zephyr/subsys/bluetooth/controller/ll_sw/nordic -I/home/user/z/zephyr/subsys/bluetooth/controller/ll_sw/nordic/hci -I/home/user/z/zephyr/build/zephyr/include/generated/zephyr -I/home/user/z/zephyr/include -I/home/user/z/zephyr/build/zephyr/include/generated -I/home/user/z/zephyr/soc/nordic -I/home/user/z/zephyr/soc/nordic/nrf52/. -I/home/user/z/zephyr/soc/nordic/common/. -I/home/user/z/zephyr/subsys/usb/device -I/home/user/z/zephyr/subsys/bluetooth/controller/ll_sw/nordic/hal/nrf5/nrfx_glue -I/home/user/z/zephyr/subsys/bluetooth -I/home/user/z/zephyr/drivers/usb/common/nrf_usbd_common/. -I/home/user/z/modules/hal/cmsis/CMSIS/Core/Include -I/home/user/z/modules/hal/cmsis_6/CMSIS/Core/Include -I/home/user/z/zephyr/modules/cmsis_6/. -I/home/user/z/modules/hal/nordic/nrfx -I/home/user/z/modules/hal/nordic/nrfx/drivers/include -I/home/user/z/modules/hal/nordic/nrfx/mdk -I/home/user/z/zephyr/modules/hal_nordic/nrfx/. -isystem /home/user/z/zephyr/lib/libc/common/include -isystem /home/user/z/zephyr/build/modules/picolibc/picolibc/include -isystem /usr/lib/gcc/arm-none-eabi/15.1.0/include -Wshadow -fno-strict-aliasing -Os -imacros /home/user/z/zephyr/build/zephyr/include/generated/zephyr/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=/usr/arm-none-eabi -imacros /home/user/z/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/user/z/zephyr/samples/bluetooth/peripheral_nus=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/user/z/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/user/z=WEST_TOPDIR -ffunction-sections -fdata-sections -std=c99 -nostdinc -O2 -MD -MT zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/mem.c.obj -MF zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/mem.c.obj.d -o zephyr/subsys/bluetooth/controller/CMakeFiles/subsys__bluetooth__controller.dir/util/mem.c.obj -c /home/user/z/zephyr/subsys/bluetooth/controller/util/mem.c
/tmp/ccoMjcik.s: Assembler messages:
/tmp/ccoMjcik.s:494: Error: registers may not be the same -- `str r3,[r3,#-12]!'

Impact

Not sure

Environment

arm-none-eabi-gcc (Alpine Linux) 15.1.0, zephyr v4.1.0

Additional Context

No response

@stef stef added the bug The issue is a bug, or the PR is fixing a bug label May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

No branches or pull requests

1 participant