Skip to content

glibc lint for c++ #4832

Closed as not planned
Closed as not planned

Description

@zackees

FastLED fights with glibc

https://github.com/FastLED/FastLED/pull/4830/files

and the work arounds are getting rediculus and now pulling in stdlib

what we need is linting for glibc name collisions. fl::memcpy -> fl_memcpy

fl::malloc -> fl_malloc

then machine to enforce this via a linter.

Activity

  1. zackees commented on Oct 13, 2026

    @zackees
    MemberAuthor

    Investigation: what's involved

    Why this keeps happening

    Since 3.10.4 CRGB lives in fl. Any unqualified call with an fl type argument (CRGB*, palettes, fl::vector, …) therefore also searches fl through argument-dependent lookup (ADL). If fl declares a function with the same name and signature as libc (memset(void*, int, size_t) and so on), the call is ambiguous. User sketches hit this as memset(leds, 0, sizeof(leds)) and free(buf) (#4827). #4830 works around it with template demotion (making fl::memcpy a template <typename = void> so libc wins a tie) plus <string.h>/<stdlib.h> in the stub Arduino.h. Renaming the mirrors removes the collision at the root, and the template trick, the stub includes and the linter allowlist entries in #4830 can then be reverted.

    Names in scope (current master)

    Header Names that collide with libc
    fl/stl/cstring.h memchr memcmp memcpy memmove memset strcat strchr strcmp strcpy strcspn strerror strlen strncat strncmp strncpy strpbrk strrchr strspn strstr strtok
    fl/stl/malloc.h malloc calloc realloc free
    fl/stl/cstdlib.h aligned_alloc atoi atol getenv qsort strtod strtol strtoul rand

    Not in scope:

    • memcopy, aligned_alloc_via_malloc, aligned_free_via_malloc and aligned_free already have names that don't collide.
    • Math functions (abs, sqrt, sin, floor, pow, …) take arithmetic types, so ADL never pulls fl in. They can only collide under a using-directive for fl combined with <math.h>, which is a separate, lower-priority question.
    • fl::printf and fl::snprintf (about 970 call sites) are variadic and take const char*, so they are also outside ADL. Leave them alone unless we decide on a blanket rule.

    Migration size (rough git grep on master)

    • Qualified fl::<name>( call sites for the names above: about 1,300. The biggest are strcmp (329), memcpy (186), memset (184), strlen (119), free (86), strstr (78) and malloc (57).
    • Unqualified calls inside namespace fl that currently resolve to the mirrors: about 200 for the hot names alone. These need care, because once the mirror is renamed a bare memcpy( silently binds to ::memcpy.
    • About 205 files include fl/stl/{cstring,malloc,cstdlib}.h.

    The rename is mechanical, but it must be done with a tool that checks token boundaries, not a blind sed.

    Proposed plan

    1. Rename fl::X → fl::fl_X (or global fl_X; decide below) in the three headers and their .cpp.hpp files. Remove the libc_impl and template-demotion layer from fix: CRGB and other fl types no longer make libc/std calls ambiguous (#4827) #4830.
    2. Codemod all call sites in src/, tests/ and examples/, covering both qualified fl::X( and unqualified X( inside fl.
    3. Deprecation shim (optional, for one release): keep fl::memcpy and the others as [[deprecated]] template <typename = void> forwarders, so downstream code that calls fl::memcpy keeps compiling. Then delete them.
    4. Linter (new Rust checker in ci/lint_cpp_rs/src/checkers/, modelled on bare_legacy.rs):
      • In src/fl/** and src/platforms/**, flag any declaration of a function whose name is in a libc-reserved list (a table in lint_core/, seeded with the C standard <string.h>, <stdlib.h> and <strings.h> names) inside namespace fl or its sub-namespaces.
      • Optionally flag fl::X( calls that use a reserved name, to catch regressions in tests and examples.
      • Allowlist: none expected after the migration. Platform shims that intentionally define libc symbols in global scope (newlib stubs, for example) stay out of scope because they are not in fl.
    5. Tests: keep tests/fl/stl/adl_barrier.cpp from fix: CRGB and other fl types no longer make libc/std calls ambiguous (#4827) #4830 as the end-to-end guard (legacy memset, free and qsort on CRGB* compiling with and without a using-directive for fl).

    Open decisions

    • Naming: should it be fl::fl_memcpy (namespaced plus prefixed, which looks redundant but stays grep-friendly) or global fl_memcpy (C-style, matching the issue text)? The global form could collide with a user's fl_ symbols; the namespaced form cannot.
    • Does swap, sort and the other generic algorithms belong here? They collide with std::, not libc. fix: CRGB and other fl types no longer make libc/std calls ambiguous (#4827) #4830 handles them with fl::adl_barrier, and renaming them would be far more invasive. This plan leaves them out.
    • Should the deprecated fl::memcpy forwarders ship for one release, or should they go now?
  2. zackees commented on Oct 14, 2026

    @zackees
    MemberAuthor

    Proposed replacement: #4834 adds an exhaustive lint rule that requires every libc-named function in fl to be a force-inlined template wrapper, which keeps the #4830 fix from regressing without the ~1,300-site rename. If that lands, this issue can be closed as superseded.

  3. zackees commented on Oct 14, 2026

    @zackees
    MemberAuthor

    Superseded by #4834 / #4835: the libc_mirror lint rule now enforces that every libc-named function in fl is a force-inlined template wrapper, which keeps #4830's fix from regressing without the ~1,300-site rename.

  4. moved this from Triage to Done in FastLED Trackeron Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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