Swatantra-66 opened a new pull request, #22317:
URL: https://github.com/apache/nuttx/pull/22317

   ## Summary
   
   Addresses Issue [#20414](https://github.com/apache/nuttx/issues/20414) 
([HELP] Improve NuttX bloated size)
   
   NuttX libc provides three printf profiles (`Minimal`, `Default`, and 
`Full`), documented in `Documentation/os/libs/libc/printf.rst`. Currently, the 
profile choice unconditionally defaults to `LIBC_PRINTF_DEFAULT` for all 
targets.
   
   This patch changes the profile choice in `libs/libc/stdio/Kconfig` to 
default to `LIBC_PRINTF_MINIMAL` when `CONFIG_DEFAULT_SMALL=y`:
   
   ```kconfig
   choice
        prompt "printf profile"
        default LIBC_PRINTF_MINIMAL if DEFAULT_SMALL
        default LIBC_PRINTF_DEFAULT
   ```
   
   On memory-constrained targets, `Minimal` omits unnecessary conversions and 
flags that are rarely required in resource-constrained firmware:
   - Disables `%lld` / 64-bit integer division on 32-bit CPUs (unless 
`SYSLOG_TIMESTAMP` or `FS_PROCFS` is enabled).
   - Disables alternate form (`#` flag for `%#x`, `%#o`).
   - Disables integer precision (e.g. `%.3d`).
   - Automatically defaults `CONFIG_STREAM_OUT_BUFFER_SIZE` to `0` in 
`libs/libc/stream/Kconfig`, saving 64 bytes of stack frame on `dprintf()` and 
`vdprintf()` calls and omitting `lib_bufferedoutstream.c`.
   
   Standard configurations (`!DEFAULT_SMALL`) continue to default to 
`LIBC_PRINTF_DEFAULT` with zero impact. Targets needing specific printf 
features can still enable them individually or select `Default`/`Full` in 
menuconfig.
   
   ### Size Impact
   
   Measured across multiple architectures with `-Os`:
   
   | Architecture | Target Configuration | Before (`Default`) | After 
(`Minimal`) | Flash Savings |
   | :--- | :--- | :---: | :---: | :---: |
   | **ARM Cortex-M3** | `stm32f103-minimum:nsh` | 53,255 B | 52,815 B | **-440 
B** |
   | **ARM Cortex-M0** | `nucleo-f072rb:nsh` | 46,792 B | 46,460 B | **-332 B** 
|
   | **32-bit RISC-V** | `rv-virt:nsh` | 231,490 B | 228,166 B | **-3,324 B 
(-3.3 KB)** |
   | **ARM64** | `qemu-armv8a:nsh` | 329,564 B | 325,844 B | **-3,720 B (-3.7 
KB)** |
   
   ## Impact
   
   - **Is new feature added?**: No.
   - **Is existing feature changed?**: Yes, defaults printf profile to 
`LIBC_PRINTF_MINIMAL` on `DEFAULT_SMALL=y`.
   - **Impact on user**: Memory-constrained targets save flash and stack. 
Format conversions remain safe (any omitted conversion safely prints `?` and 
consumes arguments correctly).
   - **Impact on build**: None. No defconfigs set `CONFIG_LIBC_PRINTF_*`, so 
defconfig normalization is 100% clean.
   - **Impact on hardware**: Flash savings on all `DEFAULT_SMALL` boards.
   - **Impact on documentation**: Updated 
`Documentation/os/libs/libc/printf.rst`.
   
   ## Testing
   
   Build host: Linux container (`nuttx-builder`) with `arm-none-eabi-gcc` 
10.3.1.
   Target board: `stm32f103-minimum:nsh`.
   
   ### 1. Style & Verification
   - `git diff --check`: PASSED (0 whitespace errors).
   - Documentation updated and verified.
   
   ### 2. Build & Size Comparison Logs
   
   **Before (`CONFIG_LIBC_PRINTF_DEFAULT=y`):**
   ```
   CP: nuttx.bin
      text         data     bss     dec     hex filename
     53255          332    3136   56723    dd93 nuttx
   ```
   
   **After (`CONFIG_LIBC_PRINTF_MINIMAL=y` via `DEFAULT_SMALL`):**
   ```
   CP: nuttx.bin
      text         data     bss     dec     hex filename
     52815          332    3136   56283    dbdb nuttx
   ```
   Total flash reduction on `stm32f103-minimum:nsh`: **-440 bytes**.
   


-- 
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]

Reply via email to