Skip to content

fix(ldf): avoid self-selecting Teensy framework libraries and their global state #1094

Description

@zackees

Regression

A Teensy 4.1 Blink sketch that only includes FastLED still has framework Audio, SD, SdFat, and SerialFlash selected by fbuild lib-select, even after FastLED removes its Audio.h LDF hint and all source includes of Audio.h / SD.h.

fbuild lib-select .build/pio/teensy41 -e teensy41 --explain reports:

  • Audio triggered by the framework's own libraries/Audio/AudioControl.h
  • SD triggered by the framework's own libraries/SD/src/SD.cpp
  • SdFat triggered by the framework's own libraries/SdFat/src/DigitalIO/DigitalPin.h
  • SerialFlash selected transitively

This is a self-discovery cycle: once the resolver reaches library sources/headers, headers in that same library appear to be treated as new roots. The result is all of the library sources being compiled. SD.cpp contains the global SDClass SD, which survives LTO and contributes 1,236 B .bss to Blink.

Reproduction

  1. Check out FastLED branch implementing #3696 (no <Audio.h> in src/platforms/arm/teensy/ldf_headers.h).
  2. bash compile teensy41 --examples Blink
  3. fbuild lib-select .build/pio/teensy41 -e teensy41 --explain
  4. fbuild symbols .build/pio/teensy41/.fbuild/build/release/firmware.elf --top 100 --no-graph

Expected: only libraries reachable from the sketch/FastLED roots are selected; no Audio/SD/SdFat/SerialFlash for Blink.

Actual: the resolver selects 11 libraries including Audio (91 sources), SD, SdFat (46 sources), and SerialFlash. The linked ELF retains SD (1,236 B) and DMAChannel::begin despite the sketch not using any of them.

Acceptance

  • Do not use a library's own transitive headers/sources as a root that selects that same library.
  • A fresh resolver run for FastLED Blink on teensy41 does not select Audio, SD, SdFat, or SerialFlash.
  • The resulting Blink ELF contains none of their symbols/global state.
  • Preserve selection when the sketch or FastLED actually includes a feature-specific header.

Related: FastLED/FastLED#3696; historical fbuild #204 and #1088.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions