Swatantra-66 opened a new pull request, #22055:
URL: https://github.com/apache/nuttx/pull/22055
## Summary
Change `CONFIG_TLS_EMUTLS` to default to `!DEFAULT_SMALL`.
In PR #20723, `CONFIG_TLS_EMUTLS` was added with `default y` for toolchains
using emulated TLS. 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 no `__thread`
variables are used.
On memory-constrained targets (`CONFIG_DEFAULT_SMALL=y`), this wastes up to
~1.5 KB of Flash.
### Before & After Comparison Table
| Target / Build | Flash Before (master) | Flash After (this PR) | Flash
Delta | SRAM Before | SRAM After | SRAM Delta |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| `nucleo-f302r8:cansock` (`DEFAULT_SMALL=y`, `LTO_FULL=y`) | 23,208 B |
21,752 B | **-1,456 B (-6.7%)** | 1,160 B | 1,120 B | **-40 B** |
| Minimal Cortex-M (no console, no files, LTO) | 10.1 KB | 8.8 KB | **-1.3
KB (-12.8%)** | - | - | - |
| Configuration Attribute | Before (master) | After (this PR) |
| :--- | :--- | :--- |
| `CONFIG_TLS_EMUTLS` default on `DEFAULT_SMALL=y` | `y` (enabled) | **`n`
(disabled)** |
| `CONFIG_TLS_EMUTLS` default on standard targets | `y` (enabled) | `y`
(enabled) |
| Forced linker symbols on small targets | `-u
__wrap___emutls_get_address`<br>`-u __wrap___emutls_register_common` | **None**
|
| `tls_emutls.o` pulled into small LTO images | Yes (unconditional) | **No**
(completely excluded) |
By making `CONFIG_TLS_EMUTLS` default 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 `__thread` support can still enable `CONFIG_TLS_EMUTLS=y` in their
defconfig.
Also updates `Documentation/guides/concurrency/thread_local_storage.rst` to
document the new default.
Related to #20414
Fixes flash bloat reported in #20723
## Impact
* Is new feature added? No
* Is existing feature changed? Yes (`CONFIG_TLS_EMUTLS` default changed on
`DEFAULT_SMALL=y`)
* Impact on user: Saves ~1.5 KB Flash on small systems. Any small board
needing `__thread` can still explicitly enable `CONFIG_TLS_EMUTLS=y`.
* Impact on build: None.
* Impact on hardware: Preserves valuable Flash space on memory-constrained
microcontrollers.
* Impact on documentation: Updated `thread_local_storage.rst`.
* Impact on security: None.
* Impact on compatibility: Compatible with existing defconfigs; standard
systems remain unaffected.
## Testing
I confirm that changes are verified on local setup and works as intended:
* Build Host(s): Linux (Ubuntu 22.04 container via Docker), GCC 10.3.1
(`arm-none-eabi-gcc`)
* Target(s): `stm32f103-minimum:nsh` (`CONFIG_DEFAULT_SMALL=y`),
`nucleo-f302r8:cansock` (`CONFIG_DEFAULT_SMALL=y`, `CONFIG_LTO_FULL=y`)
### Size Comparison:
| Target | Flash (Before) | Flash (After) | Flash Delta | SRAM (Before) |
SRAM (After) | SRAM Delta |
| :--- | :--- | :--- | :--- | :--- | :--- | :--- |
| `nucleo-f302r8:cansock` | 23,208 B | 21,752 B | **-1,456 B (-6.7%)** |
1,160 B | 1,120 B | **-40 B** |
### Testing logs before change:
1. **Kconfig configuration on `stm32f103-minimum:nsh` (master with `default
y`):**
```text
$ ./tools/configure.sh -l stm32f103-minimum:nsh
$ grep -E "DEFAULT_SMALL|TLS_EMUTLS" .config
CONFIG_DEFAULT_SMALL=y
CONFIG_TLS_EMUTLS=y
```
`CONFIG_TLS_EMUTLS=y` was enabled by default on small targets, passing `-u
__wrap___emutls_get_address` to the linker.
2. **Size measurement on `nucleo-f302r8:cansock` (`CONFIG_DEFAULT_SMALL=y`,
`CONFIG_LTO_FULL=y`, master 8a282a5):**
```text
$ size nuttx
text data bss dec hex filename
23208 0 1160 24368 5f30 nuttx
```
---
### Testing logs after change:
1. **Kconfig configuration on `stm32f103-minimum:nsh` (with `default
!DEFAULT_SMALL`):**
```text
$ ./tools/configure.sh -l stm32f103-minimum:nsh
$ grep -E "DEFAULT_SMALL|TLS_EMUTLS" .config
CONFIG_DEFAULT_SMALL=y
# CONFIG_TLS_EMUTLS is not set
```
`CONFIG_TLS_EMUTLS` is now cleanly disabled by default on small
configurations without manual intervention.
2. **Size measurement on `nucleo-f302r8:cansock` with
`CONFIG_TLS_EMUTLS=n`:**
```text
$ size nuttx
text data bss dec hex filename
21752 0 1120 22872 5958 nuttx
```
**Difference: -1,456 B (-6.7%) Flash saved, -40 B SRAM saved.**
3. **Checkpatch and commit message verification:**
```text
$ ./tools/checkpatch.sh -r -g HEAD~1..HEAD
✔️ All checks pass.
$ git log -1 --format=%B | ./tools/checkpatch.sh -m -g --stdin
✔️ All checks pass.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]