Implementation of C++ dynamic initialization (compiler output and linking)

I have a few general questions about the implementation of a C++
linker feature and I noticed that there is a linker (the lld linker)
being worked on as part of the LLVM project. I'm hoping that there is
therefore someone knowledgeable about linkers who is willing to spare
a few moments to help me out.

I'm a CS student working on a small linker for C++ programs, mostly
for self-learning purposes. I've hit a feature I'm having difficulty
puzzling out and I can't find any information about it on the
internet.

I've put the full question here:

To summarize the problem, I would like to know:

What information (sections, symbols) does the compiler place into a
generated object file relating to dynamic initialization of global
variables and static member variables for the linker to use?

What information does the linker place into the final linked module
during the linking process so that the OS module loader is able to
correctly initialize all variables (including dynamically initialized
global/static member variables that make calls to functions as part of
initialization)?

I'm happy to know this information as it relates specifically to
clang's output (in MSVC mode or GCC compliant mode) since clang is my
primary compiler.

I would greatly appreciate any help I'm given with this.

Thanks a lot for your time,
Sanee

Hi Sanee,

The quick answer is that the compiler generates code for initialization and arranges to have the run-time system call the code it has generated to do the initializations. I added an answer to your stackoverflow question that I hope will be helpful to you.

-Rich