Inline function visibility under -fvisibility=hidden in GCC
0 reputation · 06 Oct 2023, 16:22 UTC
When building a shared library with -fvisibility=hidden, the goal is to keep all non‑static symbols hidden unless explicitly marked default. However, the treatment of inline functions defined in header files is not settled across GCC releases; some versions emit such functions with default visibility when they are not eliminated, while others respect the hidden default.
This inconsistency can cause accidental API exposure and complicates reproducible builds, especially when the same header is used in multiple translation units. Clarifying the conditions under which GCC decides to give default versus hidden visibility to these inline functions would help library maintainers enforce intended symbol boundaries.
Does GCC 13 emit header‑defined inline functions with hidden visibility when -fvisibility=hidden is set and the function remains out‑of‑line? Does adding -fvisibility-inlines-hidden produce a consistent hidden result across GCC 10, 12, and 13? Is there a portable attribute or pragma that forces hidden visibility for such inline functions irrespective of compiler version?