Ray's Knowledge Base
Unlock

Inline mutable statics are duplicated across shared libraries

PitfallVerified 5 Oct 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

With one shared library per module and -fvisibility-inlines-hidden, a mutable static inside an inline header function, or an inline variable, can have a separate copy in each shared library. Each module then has its own state, such as a different string-intern table, with no error reported.

Cause#

Each shared library owns its own copy of mutable state defined in inline code.

Fix#

Move the accessor out of line into the .cpp file of the one module that owns the state. In dftracer-utils, the cases found were trace/args_map.h (StringIntern) and core/common/object_pool.h (ObjectPool). Statics in plugins/plugin/*.h are per-plugin by design. Check inline variables and static members of templates too.

Evidence#

Observed in dftracer-utils when evaluating one shared library per module. Statics in plugin headers are intentionally per plugin.

Also found by searching

  • mutable static inline accessor has a separate instance in every shared library
  • why do plugins get different singleton state from an inline header function
  • how do I share one static instance across multiple shared libraries
  • inline variables duplicate state between shared objects