~/talk

What C++ developers should know about globals (and the linker)

Talkat CppCon 2017 · 2017-09-24..09-29· [software-architecture]
links:none on file
slides:none on file

Demonstrates a reproducible segfault when an executable links a static library and a shared library that both provide the same global, showing the constructor runs twice on the same address and the destructor runs twice, causing double free. Uses nm and objdump to inspect symbol tables and init sections, shows linker left-to-right resolution causing the mismatch, and presents fixes: inline variables in C++17, Meyers-style static locals, and a forced static reference trick, plus warnings about SIOF and performance and destructor-timing pitfalls.

AI-written summary · about

  1. 0:00Introduction
  2. 4:58Library types
  3. 5:23Build setup
  4. 5:43Compilation commands
  5. 7:11The problem
  6. 8:16Debugging initialization
  7. 8:58Root cause analysis
  8. 9:55Linker mechanics
  9. 11:50Symbol tables
  10. 13:10Linker order
  11. 14:39Assembly investigation
  12. 15:37Double construction
  13. 18:09C++17 solution
  14. 18:36Pre-C++17 solutions
  15. 19:53Forced initialization
  16. 20:50Template tricks
  17. 22:28Static initialization order
  18. 23:31Singleton pitfalls
  19. 24:58Header definition strategy
  20. 25:52Destructor issues
  21. 26:13Dependency risks
  22. 26:59Robust headers
  23. 27:59Conclusion
  24. 28:45Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.