-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Description
Describe the bug
When compiling my project with LTO enabled
CONFIG_LTO=y
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
CONFIG_NEWLIB_LIBC=y
i get a linker error for a number of standard functions to be not found (undefined reference to `_close' and related functions). Depending on project configuration, the missing functions vary. adding CONFIG_NEWLIB_LIBC_NANO=y doesn't fix the problem.
Regression
- This is a regression.
Steps to reproduce
add the following lines to the posix env example: samples/posix/env/prj.conf
CONFIG_LTO=y
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
CONFIG_NEWLIB_LIBC=y
compile the example
west build -p=always -b frdm_mcxn947/mcxn947/cpu0 samples/posix/env
Relevant log output
[230/235] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /home/user/project/build/zephyr/zephyr_pre0.map
: && ccache /opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -gdwarf-4 -Os -flto=auto -fno-ipa-sra -ffunction-sections -fdata-sections zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -T zephyr/linker_zephyr_pre0.cmd -Wl,-Map,/home/user/project/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/libarch__arm__core.a zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a zephyr/arch/arch/arm/core/cortex_m/cmse/libarch__arm__core__cortex_m__cmse.a zephyr/arch/arch/arm/core/mpu/libarch__arm__core__mpu.a zephyr/lib/libc/newlib/liblib__libc__newlib.a zephyr/lib/libc/common/liblib__libc__common.a zephyr/lib/posix/eventfd/liblib__posix__eventfd.a zephyr/lib/posix/c_lib_ext/liblib__posix__c_lib_ext.a zephyr/lib/posix/shell/liblib__posix__shell.a zephyr/lib/posix/options/liblib__posix__options.a zephyr/lib/os/zvfs/liblib__os__zvfs.a zephyr/boards/nxp/frdm_mcxn947/libboards__nxp__frdm_mcxn947.a zephyr/subsys/fs/libsubsys__fs.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/hwinfo/libdrivers__hwinfo.a zephyr/drivers/mfd/libdrivers__mfd.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/hal_nxp/libmodules__hal_nxp.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L/home/user/project/build/zephyr zephyr/arch/common/libisr_tables.a -fuse-ld=bfd -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn -Wl,-no-pie -Wl,--undefined=_sw_isr_table -Wl,--undefined=_irq_vector_table -L"/opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi"/lib/thumb/v8-m.main/nofp -specs=nano.specs -L"/opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp" -lm -lc -lgcc -lc && cd /home/user/project/build/zephyr && /usr/bin/cmake -E true
/opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libc_nano.a(lib_a-closer.o): in function `_close_r':
closer.c:(.text._close_r+0xc): undefined reference to `_close'
/opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libc_nano.a(lib_a-lseekr.o): in function `_lseek_r':
lseekr.c:(.text._lseek_r+0x10): undefined reference to `_lseek'
/opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libc_nano.a(lib_a-readr.o): in function `_read_r':
readr.c:(.text._read_r+0x10): undefined reference to `_read'
/opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /opt/zephyr-sdk-0.17.4/arm-zephyr-eabi/arm-zephyr-eabi/lib/thumb/v8-m.main/nofp/libc_nano.a(lib_a-fstatr.o): in function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/user/project/buildImpact
Annoyance – Minor irritation; no significant impact on usability or functionality.
Environment
OS: Debian 13
SDK: zephyr 0.17.4
Zephyr: ab09c94
Additional Context
to me this looks like #81674, just for newlib instead of picolib. I've tried adding the fix (zephyr_library_compile_options(-fno-lto)) lib/newlib/CMakeList.txt, but that didn't fix the problem.