Repository navigation
libs/libc/tls: disable TLS_EMUTLS by default on DEFAULT_SMALL - #22055
Merged
xiaoxiang781216 merged 1 commit intoNov 20, 2026
Merged
xiaoxiang781216 merged 1 commit into
xiaoxiang781216 merged 1 commit into
Conversation
Swatantra-66
requested review from
GUIDINGLI,
Ouss4 and
xiaoxiang781216
as code owners
November 19, 2026 12:54
|
xiaoxiang781216
previously approved these changes
Nov 19, 2026
PR apache#20723 added CONFIG_TLS_EMUTLS with 'default y'. To support LTO, tools/Config.mk passes '-u __wrap___emutls_get_address' and '-u __wrap___emutls_register_common', unconditionally forcing tls_emutls.o and its dependencies (realloc, memmove, semaphores) into every linked image, even when __thread variables are never used. On memory-constrained targets (CONFIG_DEFAULT_SMALL=y), this wastes up to ~1.5 KB of Flash. For example, on nucleo-f302r8 (DEFAULT_SMALL=y, LTO_FULL=y): CONFIG_TLS_EMUTLS=y: 23208 B Flash, 1160 B SRAM CONFIG_TLS_EMUTLS=n: 21752 B Flash, 1120 B SRAM Difference: -1456 B Flash (-6.7%). This patch changes CONFIG_TLS_EMUTLS to default to !DEFAULT_SMALL, saving Flash across small configurations while keeping emulated TLS enabled by default on standard configurations. Targets requiring per-thread __thread emulation can still explicitly enable it in their defconfig. Related to apache#20414 Fixes flash bloat reported in apache#20723 Assisted-by: Claude:claude-opus-4.6 Signed-off-by: Swatantra Yadav <[email protected]>
Swatantra-66
force-pushed
the
fix/libc-tls-emutls-default-small
branch
from
November 19, 2026 17:32
3854acf to
b121b65
Compare
raiden00pl
approved these changes
Nov 19, 2026
xiaoxiang781216
approved these changes
Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Change
CONFIG_TLS_EMUTLSto default to!DEFAULT_SMALL.In PR #20723,
CONFIG_TLS_EMUTLSwas added withdefault yfor toolchains using emulated TLS. To support LTO,tools/Config.mkpasses-u __wrap___emutls_get_addressand-u __wrap___emutls_register_common, unconditionally forcingtls_emutls.oand its dependencies (realloc,memmove, semaphores) into every linked image, even when no__threadvariables are used.On memory-constrained targets (
CONFIG_DEFAULT_SMALL=y), this wastes up to ~1.5 KB of Flash.Before & After Comparison Table
nucleo-f302r8:cansock(DEFAULT_SMALL=y,LTO_FULL=y)CONFIG_TLS_EMUTLSdefault onDEFAULT_SMALL=yy(enabled)n(disabled)CONFIG_TLS_EMUTLSdefault on standard targetsy(enabled)y(enabled)-u __wrap___emutls_get_address-u __wrap___emutls_register_commontls_emutls.opulled into small LTO imagesBy making
CONFIG_TLS_EMUTLSdefault to!DEFAULT_SMALL, small/minimal configurations avoid this bloat, while standard/large systems continue to have emulated TLS enabled by default. Configurations that explicitly require per-thread__threadsupport can still enableCONFIG_TLS_EMUTLS=yin their defconfig.Also updates
Documentation/guides/concurrency/thread_local_storage.rstto document the new default.Related to #20414
Fixes flash bloat reported in #20723
Impact
CONFIG_TLS_EMUTLSdefault changed onDEFAULT_SMALL=y)__threadcan still explicitly enableCONFIG_TLS_EMUTLS=y.thread_local_storage.rst.Testing
I confirm that changes are verified on local setup and works as intended:
arm-none-eabi-gcc)stm32f103-minimum:nsh(CONFIG_DEFAULT_SMALL=y),nucleo-f302r8:cansock(CONFIG_DEFAULT_SMALL=y,CONFIG_LTO_FULL=y)Size Comparison:
nucleo-f302r8:cansockTesting logs before change:
stm32f103-minimum:nsh(master withdefault y):CONFIG_TLS_EMUTLS=ywas enabled by default on small targets, passing-u __wrap___emutls_get_addressto the linker.nucleo-f302r8:cansock(CONFIG_DEFAULT_SMALL=y,CONFIG_LTO_FULL=y, master 8a282a5):Testing logs after change:
stm32f103-minimum:nsh(withdefault !DEFAULT_SMALL):CONFIG_TLS_EMUTLSis now cleanly disabled by default on small configurations without manual intervention.nucleo-f302r8:cansockwithCONFIG_TLS_EMUTLS=n:Difference: -1,456 B (-6.7%) Flash saved, -40 B SRAM saved.