Finding static constructors with possible out-of-order initialization

P

Paul Sheer

How do I find all static global objects and thereby
all initializors called before main()? The source I
work on is too large for this to be obvious. I would
like to search for *any* possible out-of-order
initializers in a large body of code.

I have tried looking at the assembly and nm output,
but it is not obvious (to me) in C++ how exactly
the linker groups all constructors into something
that would be called before main(). (assuming this
is how it works.)

Is it possible to get this information using nm,
objdump, etc. from the executable?

Note again that the source is far to large to
be able perform any kind of manual modifications
or searches.

The URL:

http://www.parashift.com/c++-faq-lite/ctors.html

explains the "static initialization order fiasco"
that I am trying to find instances of.

-paul
 
D

Dave Townsend

(excuse a possible duplicate post, my mail is misbehaving...)

Paul,

just an idea, you will need to fill in some blanks.

Add your own static object into the code and put a breakpoint in
the constructor. Run the debugger and wait for the break. This works
on VC++, you can see the call stack. I believe C++ implementations generate
a list of statically initialized objects and these are processed before you
get
to the main() function call. You should be able to see the function names
which
trigger the processing of this list. You'll have to do a bit of detective
work now,
and figure out how to step through this code, you might need to link in with
a
special debug enabled library, depending on the platform you are working
with.
I'm more familar with VC++, I've debugged a similar problem in my past ok.

hope that helps.

dave
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top