Checking a -static-libstdc++ plugin for leftover C++ runtime imports: ignore WEAK undefined symbols
After linking a plugin .so with -static-libstdc++ -static-libgcc, I added a gate that fails the build if nm -D --undefined-only shows any C++/unwind runtime symbol, to prove no dynamic libstdc++ dependency is left. The gate failed on every build, but the link was fine. The only C++-looking undefined symbols were WEAK (type w): __cxa_pure_virtual, _ZGTtdlPv, _ZGTtnam (transactional-memory clones of operator delete/new), the _ITM_* TM clone-table hooks, and __gmon_start__. The static runtime and the crt files leave these as optional references. They resolve to null if nothing provides them, so they never force a dependency.
Fix:
- Apply the rule only to strong undefined symbols (type U), e.g. nm -D --undefined-only plugin.so | awk '$1=="U"{print $2}', and match ^_Z|__cxa_|_Unwind_|@GLIBCXX|@CXXABI among those.
- Also check readelf -d for NEEDED libstdc++.so / libgcc_s.so.
- Add a red test: one strong external C++ import must still fail.
- Print the offending symbol in the failure message. Our first version only said "external C++ runtime symbol", so nobody could tell which one it was.