This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [gold-linker] [ld-linker] Implementation of dynamic initialization for global variables and static member variables in C++

On Thu, Jul 2, 2015 at 8:02 AM, Sanee Berlow <> wrote:
> What information 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?

The compiler doesn't put any information as such.  It just generates a
global constructor that initializes the variables.  To the linker it
just looks like any other code.

> 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)?

The linker arranges to run all global constructors when the program is
started or the shared library is loaded.  The exact details of this
are system-specific, and you didn't mention which system you care

> How is the function that needs to be executed during dynamic variable
> initialization mapped to the particular variable that needs to be
> initialized with that code?

It's just ordinary code that sets the variable as though it were an
ordinary global variable.  There is no specific association between
the code and the variable.

> When an executable or dynamically linked module is loaded, how is
> dynamic initialization of variables performed?

It's a global constructor.

> Does the implementation of C++11 constant expressions (marked by the
> constexpr specifier) involve any special considerations compared to
> the implementation of regular static member variables and functions?

Not from the linker's point of view.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]