Skip to content

ESP32: WiFi stack linked into Blink via esp_wifi_init in the platforms+ unity object (~3 KB flash, ~1.6 KB RAM) #4726

Closed

Description

@zackees

Symptom

ESP32 Blink links part of the WiFi stack even though it never touches the network. Measured on master 7ac9a83c6e, esp32c6 Blink, bash bloat esp32c6:

  • s_wifi_nvs 1308 B of .dram0.bss (libnet80211), plus libcoexist, libesp_event and libesp_wifi code: about 3 KB of flash and 1.6 KB of RAM in all.
  • The same symbol shows up on esp32dev (1308 B) and esp32c3 (1284 B). 3.10.3 linked none of it.

Cause

The linker map for esp32c6 Blink shows:

libesp_wifi.a(wifi_init.c.obj)
    libFastLED.a(platforms+_069c.o) (esp_wifi_init)

Two strong references to esp_wifi_init sit in the always-linked platforms+ unity object: platforms/esp/32/net/wifi_esp32.cpp.hpp (the fl::net::wifi API) and platforms/esp/32/ota/ota_impl.cpp.hpp. They pull wifi_init.c.obj out of the archive. That makes the weak esp_wifi_get_mode that NetworkDetector::isWiFiActive() (rmt_5/network_detector.cpp.hpp) checks resolve to a real function. FastLED.show(), the channel manager and the RMT driver call that function on every frame, so the WiFi code it reaches stays linked.

There is also a behaviour side effect: the "is WiFi linked?" weak-symbol check now always returns "linked", so isWiFiActive() always makes a real esp_wifi_get_mode call, even in sketches that never use WiFi.

A small related item: static fl::vector<fl::unique_ptr<EspRouteContext>> s_esp_route_contexts in fl/stl/asio/http/server.cpp.hpp is a namespace-scope object with a dynamic initializer, so its vector ops link into every ESP32 sketch (about 150 B).

Possible ways forward

Move the WiFi/OTA implementations out of the always-linked unity object, for example into their own archive member that links only when fl::net::wifi::* or the OTA API is called. Keep NetworkDetector's weak references.

Found by the pre-3.10.7 memory sweep.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions