[cfe-dev] Implementation of C++ dynamic initialization (compiler output and linking)

Richard Pennington rich at pennware.com
Sun Jul 5 13:09:55 PDT 2015


On 07/05/2015 11:53 AM, Sanee Berlow wrote:
> 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:
> http://stackoverflow.com/questions/31137260/implementation-of-dynamic-initialization-for-global-variables-and-static-member
>
> 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

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



More information about the cfe-dev mailing list