QString Constructor segfault ; qshaderdescription.cpp corruption

Viewed 30

A few function calls past our main function a QString gets constructed and segfaults with the following stack trace

(gdb) bt
#0  0x000000000044d60b in int QAtomicOps<int>::loadRelaxed<int>(std::atomic<int> const&) ()
#1  0x000000000044ceb8 in QBasicAtomicInteger<int>::loadRelaxed() const ()
#2  0x000000000044c46e in QtPrivate::RefCount::ref() ()
#3  0x000000000044ca67 in QString::QString(QString const&) ()
...
...
...

I assumed that our project was doing something unsafe with memory and recompiled with libefence so that I could figure out what was causing the problem.

(gdb) bt
#0  QString::fromLatin1_helper (str=str@entry=0x7ffff5b6562b "float", size=size@entry=5) at text/qstring.cpp:5462
#1  0x00007ffff563ac75 in QString::QString (aLatin1=..., this=0x7ffff5e7d7c0 <typeTab>)
    at ../../include/QtCore/../../src/corelib/text/qstring.h:1067
#2  __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at rhi/qshaderdescription.cpp:666
#3  _GLOBAL__sub_I_qshaderdescription.cpp(void) () at rhi/qshaderdescription.cpp:1513
#4  0x00007ffff7de3e0a in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffdbd8, env=env@entry=0x7fffffffdbe8)
    at dl-init.c:72
#5  0x00007ffff7de3f0a in call_init (env=0x7fffffffdbe8, argv=0x7fffffffdbd8, argc=1, l=<optimized out>) at dl-init.c:30
#6  _dl_init (main_map=0x7ffff7ffe1f0, argc=1, argv=0x7fffffffdbd8, env=0x7fffffffdbe8) at dl-init.c:119
#7  0x00007ffff7dd501a in _dl_start_user () from /lib64/ld-linux-x86-64.so.2

This suggests that the problem is the result of a static variable in the gui/rhi component using QStrings as static variables before they're ready. Checking git I found that these keys were changed to const char* and this change/fix should be live in recent versions of Qt 6.

Apart from upgrading our entire software to Qt 6 is there anything I can do to make this work? I feel like if the issue should be experienced by more Linux developers since as far as I know we're not actually using any of the features in RHI directly. We currently have software working with Qt 5.15.2 on Windows but struggling with the Linux port.

0 Answers
Related