Segmentation fault when built with lto
Summary
If wireshark is built with link-time optimizations (-flto
gcc option, -DENABLE_LTO=...
cmake option), it reliably crashes every time it is launched.
Steps to reproduce
Just launch the GUI.
What is the current bug behavior?
It crashes.
What is the expected correct behavior?
It should show some GUI.
Sample capture file
N/A
Relevant logs and/or screenshots
Any invocation of wireshark that instantiates QCoreApplication is crashing (e.g. wireshark
crashes, but wireshark --help
does not).
Crash happens because wireshark somehow defines QCoreApplication::self
(a singleton static member) multiple times:
gdb -nx -ex 'b /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qcoreapplication.cpp:773' -ex r wireshark
(gdb) p &QCoreApplication::self
$1 = (QCoreApplication **) 0x555555cc8020 <QCoreApplication::self>
(gdb) disassemble /s $rip,+8
Dump of assembler code from 0x7fffefda9b73 to 0x7fffefda9b7b:
/usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qcoreapplication.cpp:
772 Q_ASSERT_X(!QCoreApplication::self, "QCoreApplication", "there should be only one application object");
773 QCoreApplication::self = q;
=> 0x00007fffefda9b73 <_ZN23QCoreApplicationPrivate4initEv+51>: lea 0x2b7b2e(%rip),%rax # 0x7ffff00616a8
0x00007fffefda9b7a <_ZN23QCoreApplicationPrivate4initEv+58>: mov %rbx,(%rax)
End of assembler dump.
(gdb) c
Continuing.
[New Thread 0x7fffeb9b8640 (LWP 15813)]
Thread 1 "wireshark" received signal SIGSEGV, Segmentation fault.
doActivate<false> (sender=0x0, signal_index=9, argv=argv@entry=0x7fffffffcc60)
at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qobject.cpp:3768
3768 QObjectPrivate *sp = QObjectPrivate::get(sender);
(gdb) bt
#0 doActivate<false> (sender=0x0, signal_index=9, argv=argv@entry=0x7fffffffcc60)
at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qobject.cpp:3768
#1 0x00007fffefdcd0c0 in QMetaObject::activate (sender=<optimized out>, m=m@entry=0x7ffff059eac0 <QGuiApplication::staticMetaObject>,
local_signal_index=local_signal_index@entry=1, argv=argv@entry=0x7fffffffcc60)
at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qobject.cpp:3946
#2 0x00007ffff016c2d2 in QGuiApplication::screenAdded (this=<optimized out>, _t1=<optimized out>, _t1@entry=0x555555d39ed0) at .moc/moc_qguiapplication.cpp:389
#3 0x00007ffff015c8bc in QWindowSystemInterface::handleScreenAdded (ps=ps@entry=0x555555d2d550, isPrimary=<optimized out>)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qwindowsysteminterface.cpp:827
#4 0x00007fffebbd1ce0 in QXcbConnection::initializeScreens (this=this@entry=0x555555d1cdf0)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/plugins/platforms/xcb/qxcbconnection_screens.cpp:411
#5 0x00007fffebbada10 in QXcbConnection::QXcbConnection (this=0x555555d1cdf0, nativeInterface=<optimized out>, canGrabServer=<optimized out>,
defaultVisualId=<optimized out>, displayName=<optimized out>)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/plugins/platforms/xcb/qxcbconnection.cpp:103
#6 0x00007fffebbb0682 in QXcbIntegration::QXcbIntegration (this=0x555555d1cd00, parameters=..., argc=@0x7fffffffd43c: 1, argv=<optimized out>)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/plugins/platforms/xcb/qxcbintegration.cpp:199
#7 0x00007ffff7fc9478 in QXcbIntegrationPlugin::create (this=<optimized out>, system=..., argv=0x7fffffffd778, argc=@0x7fffffffd43c: 1, parameters=...)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/plugins/platforms/xcb/qxcbmain.cpp:56
#8 QXcbIntegrationPlugin::create (this=<optimized out>, system=..., parameters=..., argc=@0x7fffffffd43c: 1, argv=0x7fffffffd778)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/plugins/platforms/xcb/qxcbmain.cpp:53
#9 0x00007ffff01653db in QPlatformIntegrationFactory::create (platform=..., paramList=..., argc=@0x7fffffffd43c: 1, argv=<optimized out>,
argv@entry=0x7fffffffd778, platformPluginPath=...)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qplatformintegrationfactory.cpp:71
#10 0x00007ffff016fa2d in init_platform (argv=<optimized out>, argc=@0x7fffffffd43c: 1, platformThemeName=..., platformPluginPath=..., pluginNamesWithArguments=...)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qguiapplication.cpp:1223
#11 QGuiApplicationPrivate::createPlatformIntegration (this=0x555555d0e620)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qguiapplication.cpp:1481
#12 0x00007ffff01711b0 in QGuiApplicationPrivate::createEventDispatcher (this=<optimized out>)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qguiapplication.cpp:1498
#13 0x00007fffefdaa5f6 in QCoreApplicationPrivate::init (this=this@entry=0x555555d0e620)
at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qcoreapplication.cpp:834
#14 0x00007ffff0173a94 in QGuiApplicationPrivate::init (this=0x555555d0e620)
at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qguiapplication.cpp:1527
#15 0x00007ffff0bc6eb9 in QApplicationPrivate::init() () from /usr/lib64/libQt5Widgets.so.5
#16 0x0000555555848ace in ?? ()
#17 0x00005555556592b1 in main ()
So later on QCoreApplication::instance() 's this is a null pointer, resulting in the crash.
This most likely has a connection to subclassing QApplication.
Build information
Wireshark 3.4.0 (Git commit 9733f173ea5e)
Copyright 1998-2020 Gerald Combs <gerald@wireshark.org> and contributors.
License GPLv2+: GNU GPL version 2 or later <https://www.gnu.org/licenses/gpl-2.0.html>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Compiled (64-bit) with Qt 5.15.1, with libpcap, with POSIX capabilities (Linux),
with libnl 3, with GLib 2.66.2, with zlib 1.2.11, without SMI, with c-ares
1.16.1, with Lua 5.1.5, with GnuTLS 3.6.15, with Gcrypt 1.8.7, without Kerberos,
without MaxMind DB resolver, without nghttp2, without brotli, with LZ4, with
Zstandard, without Snappy, without libxml2, with QtMultimedia, without automatic
updates, with SpeexDSP (using system library).
Running on Linux 5.9.8-gentoo, with Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
(with SSE4.2), with 7689 MB of physical memory, with locale pl_PL.utf8, with
libpcap version 1.10.0-PRE-GIT (with TPACKET_V3), with GnuTLS 3.6.15, with
Gcrypt 1.8.7, with zlib 1.2.11, binary plugins supported (0 loaded).
Built using gcc 10.2.0.