From 2b70e62df5b63662051d3e17e59b18cf740bca2c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 1 Feb 2026 12:48:21 +0100 Subject: [PATCH] tweak --- .../esp8266/remove_float_scanf.py.script | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/esphome/components/esp8266/remove_float_scanf.py.script b/esphome/components/esp8266/remove_float_scanf.py.script index f88e753140..b1d03a4d46 100644 --- a/esphome/components/esp8266/remove_float_scanf.py.script +++ b/esphome/components/esp8266/remove_float_scanf.py.script @@ -1,21 +1,28 @@ # pylint: disable=E0602 Import("env") # noqa -# Remove float scanf support from linker flags -# The Arduino ESP8266 framework unconditionally adds: -# -u _printf_float -u _scanf_float -# ESPHome doesn't use scanf with %f, so _scanf_float is not needed. +# Remove forced scanf linkage to allow garbage collection of unused code # -# Savings: -# - _scanf_float: ~1.3KB -# - _strtod_l: ~3.7KB (string-to-double, only needed by scanf float) -# - Related float parsing helpers +# The ESP8266 Arduino framework unconditionally adds: +# -u _printf_float -u _scanf_float +# +# The -u flag forces symbols to be linked even if unreferenced, which pulls +# in the entire scanf family (~7-8KB). ESPHome doesn't use scanf at all +# (verified by CI check in PR #13657), so this is pure dead weight. +# +# By removing -u _scanf_float, --gc-sections can eliminate: +# - scanf family functions (~7KB) +# - _strtod_l (~3.7KB) +# - Related parsing infrastructure +# +# We keep -u _printf_float because components still use %f in logging. def remove_scanf_float_flag(source, target, env): """Remove -u _scanf_float from linker flags. - This is called as a pre-action before the link step. + This is called as a pre-action before the link step, after the + Arduino framework has added its default flags. """ linkflags = env.get("LINKFLAGS", []) new_linkflags = [] @@ -26,7 +33,7 @@ def remove_scanf_float_flag(source, target, env): if flag == "-u" and i + 1 < len(linkflags): next_flag = linkflags[i + 1] if next_flag == "_scanf_float": - print("ESPHome: Removing float scanf support (_scanf_float)") + print("ESPHome: Removing _scanf_float (saves ~8KB flash)") i += 2 # Skip both -u and the symbol continue new_linkflags.append(flag)