Skip to content

include/string.h: mark memset and memcpy as used_code#17444

Open
raiden00pl wants to merge 1 commit intoapache:masterfrom
raiden00pl:memset_lto
Open

include/string.h: mark memset and memcpy as used_code#17444
raiden00pl wants to merge 1 commit intoapache:masterfrom
raiden00pl:memset_lto

Conversation

@raiden00pl
Copy link
Member

@raiden00pl raiden00pl commented Dec 7, 2025

Summary

Mark memset and memcpy 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

@github-actions github-actions bot added Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small labels Dec 7, 2025
@raiden00pl raiden00pl mentioned this pull request Dec 7, 2025
1 task
@raiden00pl
Copy link
Member Author

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

@pkarashchenko
Copy link
Contributor

pkarashchenko commented Dec 7, 2025

Alternative way is to add -u memset to LDFLAGS

@jerpelea jerpelea changed the title libs/libc/string/lib_memset.c: mark memset as used_code libs/libc/string: mark memset as used_code Dec 19, 2025
@raiden00pl raiden00pl force-pushed the memset_lto branch 2 times, most recently from de9d837 to 6cbdc52 Compare December 20, 2025 16:53
Mark memset and memcpy 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.

Signed-off-by: raiden00pl <raiden00@railab.me>
@raiden00pl raiden00pl changed the title libs/libc/string: mark memset as used_code include/string.h: mark memset and memcpy as used_code Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: XS The size of the change in this PR is very small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants