Finding static constructors with possible out-of-order initialization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Sheer

    Finding static constructors with possible out-of-order initialization


    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:



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

    -paul


  • Dave Townsend

    #2
    Re: Finding static constructors with possible out-of-order initialization

    (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




    Comment

    • Paul Sheer

      #3
      Re: Finding static constructors with possible out-of-order initialization


      hmmmm - this is a good idea

      thanx

      -paul
      [color=blue]
      >
      > 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
      > [...][/color]


      Comment

      Working...