Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-56620

Static Initialization Order Fiasco With a Static Build

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P2: Important P2: Important
    • None
    • 5.7.0
    • None
    • INTEGRITY OS
      Green Hills Software Compiler

      Static constant variables get initialized before the core containers on a static build. This behaviour was observed on the INTEGRITY OS when using the GHS tool chain to produce a static build of QT 5.7.

      One specific example is the following:
      The statement Q_DECLARE_METATYPE(QMatrix2x2) in qgenericmatrix.h leads to the creation of a variable:

      const int newId = qRegisterMetaType< QMatrix2x2 >("QMatrix2x2",
      reinterpret_cast< QMatrix2x2 *>(quintptr(-1)));

      This variable is instantiated in qgenericmatrix.cpp.
      At the same time the qRegisterMetaType function call leads to a call to QMetaType::registerNormalizedType, which requires that QArrayData::shared_null is initialized.

      QArrayData::shared_null is instantiated in qarraydata.cpp as:
      const QArrayData QArrayData::shared_null[2] = {

      { Q_REFCOUNT_INITIALIZE_STATIC, 0, 0, 0, sizeof(QArrayData) }

      , // shared null
      /* zero initialized terminator */};

      Both these variables are constant and reside in different compilation units and hence the C++ standard does not define the order in which the static initialization occurs.

      This is currently only reproducible with the GHS toolchain.

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            thiago Thiago Macieira
            nvelinov Nikola Velinov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes