[Webkit-unassigned] [Bug 20511] New: Remove static initializers on Windows (StaticConstructors.h)

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Aug 25 07:34:28 PDT 2008


https://bugs.webkit.org/show_bug.cgi?id=20511

           Summary: Remove static initializers on Windows
                    (StaticConstructors.h)
           Product: WebKit
           Version: 526+ (Nightly build)
          Platform: PC
        OS/Version: Mac OS X 10.5
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: Platform
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: danceoffwithyourpantsoff at gmail.com


StaticConstructors.h does some really ugly macro replacements, to allow you to
declare something an object than is global, but to have the construct run when
you choose.  This is done by declaring the variable as a void*[], and later
filling it in with placement new.  This won't link with MSVC, because they
types aren't correct, you're expecting to link against a FooType, and you're
getting a void*[].  Overall, this is approach is a super ugly hack, and I think
the system should just be fixed.  Can we not just make these function calls
(lazy initialized singletons?), or structure with a pointer that is NULL, and
then gets initialized in the init routines?  I realize this would require
changing a bunch of accessing code, but I think it is the correct solution.

In the mean time, I have a hacky working solution in MSVC (although, it's less
hacky then the current code).  The problem is that in order to make it work,
AVOID_STATIC_CONSTRUCTORS must actually be undefined, which will require either
fixing the whole system, or leaving it undefined, even when we really are
avoiding static constructors...

If you drop this in StaticConstructors.h, it will avoid static initialization
under MSVC:

// This is a hack.  For MSVC, AVOID_STATIC_CONSTRUCTORS will not
// be set in config.h, because it's not supported.  The problem is that, we
// need to take a bunch of the paths that !AVOID_STATIC_CONSTRUCTORS takes
// this is the easiest thing to do:
// - Leave AVOID_STATIC_CONSTRUCTORS undefined, if we define it, the variables
//   will not be extern'd and we won't be able to link.  Also, we need the
//   default empty constructor for QualifiedName that we only get if
//   AVOID_STATIC_CONSTRUCTORS is undefined.
// - Assume that all includes of this header want ALL of their static
//   initializers ignored.  This is currently the case.  This means that if
//   a .cc includes this header (or it somehow gets included), all static
//   initializers after the include will be ignored.
// - We do this with a pragma, so that all of the static initializer pointers
//   go into our own section, and the CRT won't call them.  Eventually it would
//   be nice if the section was discarded, because we don't want the pointers.
//   See: http://msdn.microsoft.com/en-us/library/7977wcck(VS.80).aspx
#ifndef AVOID_STATIC_CONSTRUCTORS
#if COMPILER(MSVC)
#pragma warning(disable:4075)
#pragma init_seg(".unwantedstaticinits")
#endif
#endif


-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.



More information about the webkit-unassigned mailing list