public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [gold-linker] [ld-linker] Implementation of dynamic initialization for global variables and static member variables in C++
@ 2015-07-02 15:02 Sanee Berlow
  2015-07-08 23:46 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Sanee Berlow @ 2015-07-02 15:02 UTC (permalink / raw)
  To: binutils

I have a general question about the implementation of a linker feature
that I'm addressing to the knowledgeable maintainers of the gold/ld
linkers. I hope it's not too disruptive for me to ask here; if so then
I apologize. I'm not sure where else to go to get this information.

I'm a CS student working on a small linker for C++ programs, mostly
for self-learning purposes. I've figured things out so far by trial
and error and comparing the output of different linkers, but I've hit
a feature I'm having difficulty puzzling out and I can't find any
information about it whatsoever 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 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)?

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?

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

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?

On stackoverflow I was looking for a very complete and detailed answer
thinking that it could potentially be useful for other users in the
future but I know that you guys have real issues to address and
limited time so I would be very happy to just have someone briefly
tell me the general gist of how it works and work out the details
myself from there.

I would greatly appreciate any help I'm given with this, I really want
to get this important feature working!

Thanks a lot for your time,
Sanee

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [gold-linker] [ld-linker] Implementation of dynamic initialization for global variables and static member variables in C++
  2015-07-02 15:02 [gold-linker] [ld-linker] Implementation of dynamic initialization for global variables and static member variables in C++ Sanee Berlow
@ 2015-07-08 23:46 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2015-07-08 23:46 UTC (permalink / raw)
  To: Sanee Berlow; +Cc: Binutils

On Thu, Jul 2, 2015 at 8:02 AM, Sanee Berlow <nepnepparadise@gmail.com> 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
about.


> 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.

Ian

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-08 23:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-02 15:02 [gold-linker] [ld-linker] Implementation of dynamic initialization for global variables and static member variables in C++ Sanee Berlow
2015-07-08 23:46 ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).