bugQtLua script engine for Qt - Bugs: bug #49931, Global Initialization Order


bug #49931: Global Initialization Order

Submitted by:  None
Submitted on:  Mon 26 Dec 2016 02:05:13 AM UTC  
Category:  None Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 26 Dec 2016 02:05:13 AM UTC, original submission:  

Just discovered a bug with initialization of globals in QtLua 2.1 that prevents most of QtLua from working. After some debugging I think I found the problem, although I admit I do not fully understand it:

qtluaqtlib.cc:103 defines a static variable qt_meta, calling the QMetaObjectTable::QMetaObjectTable() constructor that loops over meta_object_table. meta_object_table itself is defined as a global in qtluaqmetaobjecttable.cc. Now, when QMetaObjectTable::QMetaObjectTable() executes, most of the _mo pointers inside meta_object_table are NULL. I suspect that this is because meta_object_table is not yet fully initialized when the constructor is called (static initialization order between different module files is undefined in C/C++!). This leads to the loop inside the constructor aborting prematurely.

I'm not entirely sure what's going on, because SOME of the _mo pointers (in particular, all of the QtLua::*::staticMetaObject ones) are valid. It's only the Qt builtin ones that are not. Also, when I loop over meta_object_table at a later time in my program, the values ARE valid, just not at the time that QMetaObjectTable::QMetaObjectTable() is called.

A quick and dirty fix for this that works only with GCC is to use _attribute_((init_priority(XXX))) for the meta_object_table and qt_meta globals, forcing meta_object_table to be initialized first. It might be best though to move those two globals into the same .cc file, so that their initialization order is well defined for all compilers.

Tested it on QtLua 2.1, Qt 5.7.1 with MinGW-W64 GCC 5.3.0 on Windows. Maybe a bug that shows only on recent compilers because their initialization order has changed?



(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

Attached Files
file #39312:  libqtlua-2.1-initorder-gcc.patch added by None (1KiB - application/octet-stream - The quick and dirty fix I talked about. Only works with GCC!)


Depends on the following items: None found

Items that depend on this one: None found


CC list is empty


Do you think this task is very important?
If so, you can add your encouragement to it.
This task has 0 encouragements so far.

Only logged-in users can vote.




Follows 1 latest change.

Date Changed by Updated Field Previous Value => Replaced by
2016-12-26 None Attached File- => Added libqtlua-2.1-initorder-gcc.patch, #39312

Back to the top

Powered by Savane 3.7