zephyr: Build of picolibc module with LTO fails
Describe the bug Building a minimal example with the picolibc module and LTO fails with a bunch of undefined references.
To Reproduce CMakeLists.txt:
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(lto)
target_sources(app PRIVATE
src/main.c)
prj.conf:
CONFIG_COMPILER_OPT="-Wall -Werror"
CONFIG_DEBUG_OPTIMIZATIONS=y
CONFIG_LOG=y
CONFIG_ISR_TABLES_LOCAL_DECLARATION=y
CONFIG_LTO=y
CONFIG_PICOLIBC_USE_MODULE=y
main.c:
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
int main(void)
{
LOG_INF("Hello!");
return 0;
}
Expected behavior It should be possible to build the picolibc module with LTO.
Impact It is not possible to use the picolibc module in combination with LTO.
Logs and console output
west build -p auto -b nucleo_f746zg -d build/lto lto
[0/1] Re-running CMake...
Loading Zephyr default modules (Zephyr base (cached)).
-- Application: .../zephyr_playground/lto
-- CMake version: 3.28.3
-- Cache files will be written to: /home/bschmidt/.cache/zephyr
-- Zephyr version: 4.0.99 (.../zephyr_playground/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: nucleo_f746zg, qualifiers: stm32f746xx
-- Found host-tools: zephyr 0.16.1 (/home/bschmidt/zephyr-sdk-0.16.1)
-- Found toolchain: zephyr 0.16.1 (/home/bschmidt/zephyr-sdk-0.16.1)
-- Found BOARD.dts: .../zephyr_playground/zephyr/boards/st/nucleo_f746zg/nucleo_f746zg.dts
-- Generated zephyr.dts: .../zephyr_playground/build/lto/zephyr/zephyr.dts
-- Generated pickled edt: .../zephyr_playground/build/lto/zephyr/edt.pickle
-- Generated zephyr.dts: .../zephyr_playground/build/lto/zephyr/zephyr.dts
-- Generated devicetree_generated.h: .../zephyr_playground/build/lto/zephyr/include/generated/zephyr/devicetree_generated.h
-- Including generated dts.cmake file: .../zephyr_playground/build/lto/zephyr/dts.cmake
Parsing .../zephyr_playground/zephyr/Kconfig
Loaded configuration '.../zephyr_playground/zephyr/boards/st/nucleo_f746zg/nucleo_f746zg_defconfig'
Merged configuration '.../zephyr_playground/lto/prj.conf'
Configuration saved to '.../zephyr_playground/build/lto/zephyr/.config'
Kconfig header saved to '.../zephyr_playground/build/lto/zephyr/include/generated/zephyr/autoconf.h'
-- Using ccache: /usr/bin/ccache
-- Looking for xtensa/config/core-isa.h
-- Looking for xtensa/config/core-isa.h - not found
-- Configuring done (6.1s)
-- Generating done (0.1s)
-- Build files have been written to: .../zephyr_playground/build/lto
[1092/1097] Linking C executable zephyr/zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map .../zephyr_playground/build/lto/zephyr/zephyr_pre0.map
: && ccache /home/bschmidt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -gdwarf-4 -flto=auto -fno-ipa-sra -ffunction-sections -fdata-sections -gdwarf-4 -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=.../zephyr_playground/build/lto/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/mpu/libarch__arm__core__mpu.a zephyr/lib/libc/picolibc/liblib__libc__picolibc.a zephyr/lib/libc/common/liblib__libc__common.a zephyr/drivers/interrupt_controller/libdrivers__interrupt_controller.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/console/libdrivers__console.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a zephyr/drivers/reset/libdrivers__reset.a zephyr/drivers/serial/libdrivers__serial.a zephyr/drivers/timer/libdrivers__timer.a modules/hal_stm32/stm32cube/lib..__modules__hal__stm32__stm32cube.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a -L.../zephyr_playground/build/lto/zephyr zephyr/arch/common/libisr_tables.a -mcpu=cortex-m7 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft -fuse-ld=bfd -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 -L"/home/bschmidt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v7e-m/nofp" .../zephyr_playground/build/lto/modules/picolibc/libc.a -lgcc && cd .../zephyr_playground/build/lto/zephyr && /usr/bin/cmake -E true
/home/bschmidt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/ccXfOQ2f.ltrans0.ltrans.o: in function `z_tls_copy':
.../zephyr_playground/zephyr/kernel/include/kernel_tls.h:50: undefined reference to `memset'
/home/bschmidt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/ccXfOQ2f.ltrans0.ltrans.o: in function `cbvprintf':
.../zephyr_playground/zephyr/lib/libc/picolibc/cbprintf.c:30: undefined reference to `vfprintf'
/home/bschmidt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/ccXfOQ2f.ltrans0.ltrans.o: in function `log_output_dropped_process':
.../zephyr_playground/zephyr/subsys/logging/log_output.c:764: undefined reference to `snprintf'
/home/bschmidt/zephyr-sdk-0.16.1/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: /tmp/ccXfOQ2f.ltrans0.ltrans.o: in function `z_early_memset':
.../zephyr_playground/zephyr/kernel/init.c:197: undefined reference to `memset'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build .../zephyr_playground/build/lto
make: *** [Makefile:345: build/lto/zephyr/zephyr.elf] Error 1
Environment Zephyr Version 6843240196356e7e287ff08a4aec502483f57c91
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (15 by maintainers)
Commits related to this issue
- picolibc: Disable LTO while building picolibc bits The compiler requires that much of the C library be built without using LTO so that various symbols are available for use by generated code, includi... — committed to keith-packard/zephyr by keith-packard 2 years ago
- picolibc: Disable LTO while building picolibc bits The compiler requires that much of the C library be built without using LTO so that various symbols are available for use by generated code, includi... — committed to tiacsys/zephyr by keith-packard 2 years ago
- picolibc: Disable LTO while building picolibc bits The compiler requires that much of the C library be built without using LTO so that various symbols are available for use by generated code, includi... — committed to Devansh0210/zephyr by keith-packard 2 years ago
Changing the prj.conf to
CONFIG_PICOLIBC_USE_MODULE=nresolves the issue, so the trigger is definitely the combination of LTO with the module version of picolibc. The testcases where LTO is used (samples/bluetooth/hci_ipc,tests/kernel/common,tests/kernel/interrupt) do not use the module version of picolibc.