nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

libs/libc/string/lib_memset.c: mark memset as used_code

Open raiden00pl opened this issue 3 weeks ago • 2 comments

Summary

Mark memset as used_code to fix issues with GCC LTO and CMake which throws many "undefined reference to memset" errors. used_code force the compiler to emit the memset symbol under LTO.

Example error for libcxxabi:

/usr/lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld: /tmp/ccFKUV08.ltrans1.ltrans.o: in function `__dynamic_cast.constprop.0':
external/nuttx/libs/libxx/libcxxabi/libcxxabi/src/private_typeinfo.cpp:655:(.text.__dynamic_cast.constprop.0+0x20): undefined reference to `memset'
/usr/lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld: external/nuttx/libs/libxx/libcxxabi/libcxxabi/src/private_typeinfo.cpp:736:(.text.__dynamic_cast.constprop.0+0x4e): undefined reference to `memset'
/usr/lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld: /tmp/ccFKUV08.ltrans1.ltrans.o: in function `__cxxabiv1::__class_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const':
external/nuttx/libs/libxx/libcxxabi/libcxxabi/src/private_typeinfo.cpp:236:(.text._ZNK10__cxxabiv117__class_type_info9can_catchEPKNS_16__shim_type_infoERPv+0x28): undefined reference to `memset'
/usr/lib/gcc/arm-none-eabi/14.2.0/../../../../arm-none-eabi/bin/ld: /tmp/ccFKUV08.ltrans1.ltrans.o: in function `__cxxabiv1::__pointer_type_info::can_catch(__cxxabiv1::__shim_type_info const*, void*&) const':
external/nuttx/libs/libxx/libcxxabi/libcxxabi/src/private_typeinfo.cpp:434:(.text._ZNK10__cxxabiv119__pointer_type_info9can_catchEPKNS_16__shim_type_infoERPv+0x12c): undefined reference to `memset'

Impact

fix LTO compilation

Testing

local build with LTO enabled

raiden00pl avatar Dec 07 '25 17:12 raiden00pl

I'm not sure if we should mark all memset implementations with used_code

raiden00pl avatar Dec 07 '25 17:12 raiden00pl

Alternative way is to add -u memset to LDFLAGS

pkarashchenko avatar Dec 07 '25 20:12 pkarashchenko