Tested with USE=-lto and it works fine, but with USE=+lto I get: Thread 1 "wireshark" received signal SIGSEGV, Segmentation fault. doActivate<false> (sender=0x0, signal_index=9, argv=argv@entry=0x7fffffffd000) 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=0x7fffffffd000) at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qobject.cpp:3768 #1 0x00007fffefd38d68 in QMetaObject::activate (sender=<optimized out>, m=m@entry=0x7ffff057cfa0 <QGuiApplication::staticMetaObject>, local_signal_index=local_signal_index@entry=1, argv=argv@entry=0x7fffffffd000) at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qobject.cpp:3946 #2 0x00007ffff00ea0f2 in QGuiApplication::screenAdded (this=<optimized out>, _t1=<optimized out>, _t1@entry=0x555555d632e0) at .moc/moc_qguiapplication.cpp:389 #3 0x00007ffff00da26c in QWindowSystemInterface::handleScreenAdded (ps=ps@entry=0x555555d5be60, 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 0x00007fffeb637fe0 in QXcbConnection::initializeScreens (this=this@entry=0x555555d2dff0) 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 0x00007fffeb612d40 in QXcbConnection::QXcbConnection (this=0x555555d2dff0, 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 0x00007fffeb615b72 in QXcbIntegration::QXcbIntegration (this=0x555555d2df00, parameters=..., argc=@0x7fffffffd7cc: 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 0x00007ffff7fc84b8 in QXcbIntegrationPlugin::create (this=<optimized out>, system=..., argv=0x7fffffffdb08, argc=@0x7fffffffd7cc: 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=@0x7fffffffd7cc: 1, argv=0x7fffffffdb08) 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 0x00007ffff00e2f9b in QPlatformIntegrationFactory::create (platform=..., paramList=..., argc=@0x7fffffffd7cc: 1, argv=<optimized out>, argv@entry=0x7fffffffdb08, 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 0x00007ffff00ed9cd in init_platform (argv=<optimized out>, argc=@0x7fffffffd7cc: 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=0x555555d1fee0) at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qguiapplication.cpp:1481 #12 0x00007ffff00ef198 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 0x00007fffefd156b6 in QCoreApplicationPrivate::init (this=this@entry=0x555555d1fee0) at /usr/src/debug/dev-qt/qtcore-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/corelib/kernel/qcoreapplication.cpp:834 #14 0x00007ffff00f1ad4 in QGuiApplicationPrivate::init (this=this@entry=0x555555d1fee0) at /usr/src/debug/dev-qt/qtgui-5.15.1-r1/qtbase-everywhere-src-5.15.1/src/gui/kernel/qguiapplication.cpp:1527 #15 0x00007ffff0baedf9 in QApplicationPrivate::init (this=0x555555d1fee0) at /usr/src/debug/dev-qt/qtwidgets-5.15.1/qtbase-everywhere-src-5.15.1/src/widgets/kernel/qapplication.cpp:513 #16 0x0000555555853b3e in WiresharkApplication::WiresharkApplication (this=<optimized out>, argc=<optimized out>, argv=<optimized out>, this=<optimized out>, argc=<optimized out>, argv=<optimized out>) at /usr/src/debug/net-analyzer/wireshark-3.4.0/wireshark-3.4.0/ui/qt/wireshark_application.cpp:616 #17 0x00005555556594d1 in main (argc=<optimized out>, qt_argv=0x7fffffffdb08) at /usr/src/debug/net-analyzer/wireshark-3.4.0/wireshark-3.4.0/ui/qt/main.cpp:600 Reproducible: Always Portage 3.0.9 (python 3.7.9-final-0, default/linux/amd64/17.1/desktop/plasma, gcc-10.2.0, glibc-2.32-r2, 5.9.1-gentoo x86_64) ================================================================= System Settings ================================================================= System uname: Linux-5.9.1-gentoo-x86_64-AMD_Ryzen_7_2700_Eight-Core_Processor-with-gentoo-2.7 KiB Mem: 57406060 total, 780024 free KiB Swap: 134217724 total, 87240648 free Timestamp of repository gentoo: Wed, 11 Nov 2020 12:15:01 +0000 Head commit of repository gentoo: e47c9f3f3402650d0cfcded164c7db248e33d94c Head commit of repository gridcoin: f40c860bd0dcc9aeb82b9f24c32656497f4c86f4 Head commit of repository steam-overlay: 32203d28a724a74a1fa14720129f95b97a90efcd sh bash 5.0_p18 ld GNU ld (Gentoo 2.35.1 p1) 2.35.1 ccache version 4.0 [enabled] app-shells/bash: 5.0_p18::gentoo dev-java/java-config: 2.3.1::gentoo dev-lang/perl: 5.30.3-r1::gentoo dev-lang/python: 2.7.18-r4::gentoo, 3.7.9::gentoo, 3.8.6::gentoo, 3.9.0::gentoo dev-util/ccache: 4.0::gentoo dev-util/cmake: 3.18.4::gentoo dev-util/pkgconfig: 0.29.2::gentoo sys-apps/baselayout: 2.7::gentoo sys-apps/openrc: 0.42.1::gentoo sys-apps/sandbox: 2.20::gentoo sys-devel/autoconf: 2.13-r1::gentoo, 2.69-r5::gentoo sys-devel/automake: 1.16.2::gentoo sys-devel/binutils: 2.35.1::gentoo sys-devel/gcc: 10.2.0-r3::gentoo sys-devel/gcc-config: 2.3.2::gentoo sys-devel/libtool: 2.4.6-r6::gentoo sys-devel/make: 4.3::gentoo sys-kernel/linux-headers: 5.9::gentoo (virtual/os-headers) sys-libs/glibc: 2.32-r2::gentoo Repositories: gentoo location: /usr/portage sync-type: rsync sync-uri: rsync://rsync.europe.gentoo.org/gentoo-portage priority: -1000 sync-rsync-verify-max-age: 24 sync-rsync-extra-opts: sync-rsync-verify-jobs: 1 sync-rsync-verify-metamanifest: yes local location: /usr/local/portage masters: gentoo priority: 0 gridcoin location: /usr/local/portage/gridcoin-overlay sync-type: git sync-uri: https://github.com/nethershaw/gridcoin.git masters: gentoo priority: 50 steam-overlay location: /usr/local/portage/steam-overlay sync-type: git sync-uri: https://github.com/anyc/steam-overlay.git masters: gentoo priority: 50 Installed sets: @games, @kde ACCEPT_KEYWORDS="amd64 ~amd64" ACCEPT_LICENSE="* -@EULA google-chrome AdobeFlash-11.x AMD-GPU-PRO-EULA RAR ms-teams-pre" CBUILD="x86_64-pc-linux-gnu" CFLAGS="-march=native -ggdb3 -O2 -pipe -fdiagnostics-color" CHOST="x86_64-pc-linux-gnu" CONFIG_PROTECT="/etc /usr/share/config /usr/share/gnupg/qualified.txt" CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo" CXXFLAGS="-march=native -ggdb3 -O2 -pipe -fdiagnostics-color" DISTDIR="/usr/portage/distfiles" EMERGE_DEFAULT_OPTS="--with-bdeps y" ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR" FCFLAGS="-O2 -pipe" FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs buildpkg ccache cgroup clean-logs compressdebug config-protect-if-modified distlocks ebuild-locks fixlafiles installsources ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch parallel-install pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms splitdebug strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr" FFLAGS="-O2 -pipe" GENTOO_MIRRORS="http://mirrors.evowise.com/gentoo/ http://ftp.romnet.org/gentoo/ http://distfiles.gentoo.org" LANG="ro_RO.UTF-8" LC_ALL="en_US.UTF-8" LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,-z,now" LINGUAS="ro ro_RO en eo" MAKEOPTS="-j8 -l16" PKGDIR="/usr/portage/packages" PORTAGE_CONFIGROOT="/" PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git" PORTAGE_TMPDIR="/var/tmp" USE="7zip X a52 aac aacplus aalib acl acpi activities alsa amd64 amr autoipd avahi bash-completion berkdb branding btrfs bzip2 cacert cairo caps cdda cdr cgroups clang cli client cmake cpufreq_bench crypt cups curl cxx dbus debug-frame declarative demos designer discover dolphin dos dot dri dts dvd dvdr egl elogind emboss emoji encode equalizer evdev exif extra fbcondecor feedback ffmpeg firmware flac flatpak fortran gcrypt gd gdbm gif git gles gles2 glslang gmp gnutls google gpg gpm grub gssapi gui haptic highlight htmlthumbs http http2 hunspell hwloc ibus iconv icu idn io-uring ipv6 jadetex jpeg jpeg2k jumbo-build kde kerberos kipi kwallet lcms libcaca libdrm libglvnd libidn2 libkms libplacebo libtirpc libudev lm-sensors lm_sensors lto lzma mad mdnsresponder-compat metalink midi mikmod mng mod mp3 mp4 mpeg mtp multilib multimedia ncat ncurses nettle networkmanager nls nptl ntp numpy nvme offensive office offload ogg openal opencl openconnect opencv opengl openmp openssl opus pam pango pcap pch pcntl pcre pdf pgo phonon pim pkcs7 plasma plotutils plymouth pm-utils png policykit postproc ppds pulseaudio qml qrcode qt5 qtmedia rar readline rtmp samba sasl scanner schroedinger screencast script scripttools sdk sdl sdl-image sdl2 seccomp semantic-desktop sms sndfile sound source-highlight speech speex spell spice split-usr sqlite ssl startup-notification streaming svg symlink system-bootstrap system-libs system-snappy systemtap taglib tcpd telemetry textures theora threads tiff timidity tinfo tracepath truetype udev udisks uefi unicode unwind upnp upower usb user-session utils vaapi valgrind vdpau videos virgl virt-network vlc voice vorbis vpx vulkan vulkan-overlay wayland webengine webp widgets winbind x264 x265 xattr xcb xml xrandr xv xvfb xvid xz yahoo zeroconf zip zlib zstd" ABI_X86="64 32" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sha sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="efi-64 pc" INPUT_DEVICES="evdev joystick libinput roccat_kovaplus" KERNEL="linux" L10N="ro en eo" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LLVM_TARGETS="AMDGPU" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-2 php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_7" PYTHON_TARGETS="python2_7 python3_7" QEMU_SOFTMMU_TARGETS="aarch64 x86_64" QEMU_USER_TARGETS="aarch64 aarch64_be" RUBY_TARGETS="ruby25 ruby26" SANE_BACKENDS="pixma" USERLAND="GNU" VIDEO_CARDS="amdgpu radeonsi" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account" Unset: CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS ================================================================= Package Settings ================================================================= net-analyzer/wireshark-3.4.0::gentoo was built with the following: USE="capinfos captype dftest dumpcap editcap filecaps http2 kerberos mergecap minizip netlink opus pcap plugins qt5 randpkt randpktdump reordercap sharkd ssl text2pcap tshark udpdump zlib zstd -androiddump -bcg729 -brotli -ciscodump -doc -dpauxmon -ilbc -libxml2 -lto -lua -lz4 -maxminddb -plugin-ifdemo -sbc -sdjournal (-selinux) -smi -snappy -spandsp -sshdump -test -tfshark" ABI_X86="(64)" CXXFLAGS="-march=native -ggdb3 -O2 -pipe -fdiagnostics-color -fPIC -DPIC" FEATURES="distlocks qa-unresolved-soname-deps xattr multilib-strict splitdebug sfperms ebuild-locks ipc-sandbox preserve-libs buildpkg fixlafiles usersandbox pid-sandbox binpkg-logs network-sandbox binpkg-docompress userpriv unknown-features-warn sandbox unmerge-orphans parallel-fetch unmerge-logs parallel-install binpkg-dostrip userfetch installsources compressdebug ccache news assume-digests config-protect-if-modified cgroup strict merge-sync protect-owned clean-logs usersync"
gdb will be helpful here (see https://wiki.gentoo.org/wiki/Debugging, we want debugging symbols on Wireshark, probably qtcore, glibc can be useful too) but I anticipate this being an upstream bug. It's unlikely to be specific to how we package Wireshark in Gentoo.
Dying when passing things into Qt is weird: https://gitlab.com/wireshark/wireshark/-/blob/release-3.4/ui/qt/wireshark_application.cpp#L616. I suggest you report this upstream because it's unlikely to be related to how we package Wireshark in Gentoo. Did you use any command like arguments?
Confirmed. 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 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. So later on QCoreApplication::instance() 's this is a null pointer, resulting in the crash.
I'm seeing the exact same crash with =app-admin/keepassxc-2.6.2. (with qt-5.15.2) Stacktrace is effectively the same as the posted trace from wireshark. Disabling LTO on both fixes both.
I am getting the same crash with Wireshark 3.4.2.
(In reply to Andrew Udvare from comment #5) > I am getting the same crash with Wireshark 3.4.2. Please report the issue and link it here as I can’t reproduce it right now.
Thank you so much for pointing out that it works with USE="-lto". I was desperate why wireshark works on my desktop machine but won't start on my laptop!
As per the keepassxc comment, the real problem might be that dev-qt/qtcore is not prepared to handle its library variables being replaced by the executable. Because they are. This is reproduced if the final executable (wireshark/keepassxc) uses all of -flto and -fPIE linker flags, because replacing -fPIE with -fPIC uses the exported symbol from the library. So maybe qtcore -flto is linked with -fPIE instead of -fPIC too? (while being a library, so this would be very wrong)
I can confirm this builds a working wireshark on gentoo unstable: USE=-lto emerge =net-analyzer/wireshark-3.4.3 Thanks for the tip.
(In reply to Gary E. Miller from comment #9) > I can confirm this builds a working wireshark on gentoo unstable: > > USE=-lto emerge =net-analyzer/wireshark-3.4.3 Can confirm this, too. And that I get a crash in doActivate() with USE=lto.
(CC from upstream comment) This issue is not specific to Wireshark, it can be triggered by the following simple code: #include <QApplication> #include <QDebug> int main(int argc, char **argv) { QApplication app(argc, argv); qDebug() << qApp->styleSheet(); } (note that even bugs aside, `app.styleSheet()` would be more appropriate than `qApp->styleSheet()`) and a sample qmake `.pro` file (for brevity, CMakeLists.txt would be way longer, but this shows the absolute minimal setup needed, and should be readable anyway) QT += gui widgets SOURCES += qtlto.cc QMAKE_CXXFLAGS += -flto QMAKE_LFLAGS += -pie -fPIE Removing any of the flags above results in a working executable (printing ""). so this might be a linker bug (lto1 bug) here, a compiler bug in compiling Qt (cc1plus/lto1 bug), or Qt compilation flags misconfiguration (Gentoo bug).
(In reply to Arusekk from comment #11) > (CC from upstream comment) > > This issue is not specific to Wireshark, it can be triggered by the > following simple code: > > #include <QApplication> > #include <QDebug> > > int main(int argc, char **argv) > { > QApplication app(argc, argv); > qDebug() << qApp->styleSheet(); > } > > (note that even bugs aside, `app.styleSheet()` would be more appropriate > than `qApp->styleSheet()`) > > and a sample qmake `.pro` file (for brevity, CMakeLists.txt would be way > longer, but this shows the absolute minimal setup needed, and should be > readable anyway) > > QT += gui widgets > SOURCES += qtlto.cc > QMAKE_CXXFLAGS += -flto > QMAKE_LFLAGS += -pie -fPIE > > Removing any of the flags above results in a working executable (printing > ""). > > so this might be a linker bug (lto1 bug) here, a compiler bug in compiling > Qt (cc1plus/lto1 bug), or Qt compilation flags misconfiguration (Gentoo bug). This project generates equivalent of: $ g++ -c -flto -fPIC qtlto.cc $ g++ -pie -fPIE qtlto.o -o qtlto Note that lto merges all the flags from all the translation units to a single set as much as it can. I think -fPIC gets overridden by -fPIE based on documented rule from 'man gcc': -flto[=n] ... The following options -fPIC, -fpic, -fpie and -fPIE are combined based on the following scheme: B<-fPIC> + B<-fpic> = B<-fpic> B<-fPIC> + B<-fno-pic> = B<-fno-pic> B<-fpic/-fPIC> + (no option) = (no option) B<-fPIC> + B<-fPIE> = B<-fPIE> B<-fpic> + B<-fPIE> = B<-fpie> B<-fPIC/-fpic> + B<-fpie> = B<-fpie> Which combines towards stricter requirements assuming bytecode already applied some optimisations based on preprocessor values. I see that Qt normally disallows anything to be built without -fPIC (at least in Gentoo): /usr/include/qt5/QtCore/qglobal.h:1286:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (and not with -fPIE)." I think wireshark's CMakeLists.txt imposes -fPIE and effectively throws away -fPIC at: set(CMAKE_POSITION_INDEPENDENT_CODE ON) Gentoo's toolchain already uses -fPIE where appropriate without explicit flags. I'd say wireshark would have to avoid -fPIE. I think ideal state for wireshark would be to do -fPIC + -pie.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=22aba2f719c9f40e1d9285bba7173091b2b77125 commit 22aba2f719c9f40e1d9285bba7173091b2b77125 Author: Sam James <sam@gentoo.org> AuthorDate: 2021-04-09 22:44:07 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2021-04-09 22:51:16 +0000 profiles/base: mask net-analyzer/wireshark[lto] for now Crashes at runtime. Bug: https://bugs.gentoo.org/754021 Signed-off-by: Sam James <sam@gentoo.org> profiles/base/package.use.mask | 7 +++++++ 1 file changed, 7 insertions(+)
Reproducible with Wireshark 4.0.0 (GCC 13.1) + dev-qt/qtcore-5.15.0. Seems there is no bug report on the subject for dev-qt/qtcore. Disabling LTO for Wireshark does not trigger the segfault.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a2494b77d21f70b6e1fef71496e23740b550116e commit a2494b77d21f70b6e1fef71496e23740b550116e Author: Sam James <sam@gentoo.org> AuthorDate: 2023-06-17 16:09:03 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2023-06-17 16:09:03 +0000 net-analyzer/wireshark: add missing filter-lto for USE=-lto Note that USE=lto is masked right now too. Bug: https://bugs.gentoo.org/754021 Signed-off-by: Sam James <sam@gentoo.org> net-analyzer/wireshark/wireshark-3.6.13.ebuild | 2 ++ net-analyzer/wireshark/wireshark-3.6.14.ebuild | 2 ++ net-analyzer/wireshark/wireshark-4.0.5.ebuild | 2 ++ net-analyzer/wireshark/wireshark-4.0.6.ebuild | 2 ++ net-analyzer/wireshark/wireshark-9999.ebuild | 2 ++ 5 files changed, 10 insertions(+)
FAILED: run/plugins/4.3/epan/wimax.so : && /usr/bin/x86_64-pc-linux-gnu-gcc -fPIC -fvisibility=hidden -Wall -Wextra -Wpointer-arith -Wformat-security -fno-strict-overflow -fexcess-precision=fast -Wvla -Wattributes -Wpragmas -Wredundant-decls -Wunreachable-code -Wlogical-op -Wno-error=stringop-overflow= -Wno-error=deprecated-declarations -Wframe-larger-than=32768 -Wno-format-truncation -fdiagnostics-color=always -Wshadow -Wold-style-definition -Wstrict-prototypes -Wno-pointer-sign -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -fmacro-prefix-map="/var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999/"= -fmacro-prefix-map="/var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999_build/"= -Wl,-O1 -Wl,--as-needed -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wl,--defsym=__gentoo_check_ldflags__=0 -Wl,--as-needed -shared -o run/plugins/4.3/epan/wimax.so plugins/epan/wimax/CMakeFiles/wimax.dir/plugin.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/packet-m2m.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/packet-wmx.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_ffb_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_fch_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_pdu_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_cdma_code_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_hack_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_phy_attributes_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/mac_hd_generic_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/mac_hd_type1_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/mac_hd_type2_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/mac_mgmt_msg_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dcd.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_ucd.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dlmap.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_ulmap.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_rng_req.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_rng_rsp.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_reg_req.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_reg_rsp.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dreg.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dsa.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dsc.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dsd.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_arq.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_sbc.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_pkm.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_aas_fbck.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_fpc.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_pmc.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_prc_lt_ctrl.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_aas_beam.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_res_cmd.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_rep.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_clk_cmp.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/msg_dsx_rvd.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_harq_map_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_compact_dlmap_ie_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_compact_ulmap_ie_decoder.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_utils.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/crc.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/crc_data.c.o plugins/epan/wimax/CMakeFiles/wimax.dir/wimax_tlv.c.o -Wl,-rpath,"\$ORIGIN/../../../:" run/libwireshark.so.0.0.0 run/libwsutil.so.0.0.0 /usr/lib64/libglib-2.0.so -Wl,-rpath-link,/var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999_build/run && : /var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999/plugins/epan/wimax/packet-wmx.c:36:14: error: type of ‘include_cor2_changes’ does not match original declaration [-Werror=lto-type-mismatch] 36 | extern bool include_cor2_changes; | ^ /var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999/plugins/epan/wimax/mac_hd_generic_decoder.c:54:10: note: type ‘gboolean’ should match type ‘_Bool’ 54 | gboolean include_cor2_changes; | ^ /var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999/plugins/epan/wimax/mac_hd_generic_decoder.c:54:10: note: ‘include_cor2_changes’ was previously declared here /var/tmp/portage/net-analyzer/wireshark-9999/work/wireshark-9999/plugins/epan/wimax/mac_hd_generic_decoder.c:54:10: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used lto1: some warnings being treated as errors lto-wrapper: fatal error: /usr/bin/x86_64-pc-linux-gnu-gcc returned 1 exit status compilation terminated. It doesn't build fine either at the moment. :P
https://gitlab.com/wireshark/wireshark/-/commit/489c0a69e8305d2f3e6a85d9af803bb19f5ffb17 It appears that per the OpenSSF "harden ur software" recommendations, wireshark has decided to add these flags: > -fno-strict-overflow -fno-strict-aliasing also > -U_FORTIFY_SOURCE # Run-time buffer overflow detection Much wow, very hardened. Shall we also assume that LTO should be disabled "for hardening"?
Closing this one in favor of #941890 *** This bug has been marked as a duplicate of bug 941890 ***
I don't think it's a dupe, it's a separate problem which is hopefully obsolete.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=71a7e7c01404fe221bb9763dd3d4f58f5a701984 commit 71a7e7c01404fe221bb9763dd3d4f58f5a701984 Author: Holger Hoffstätte <holger@applied-asynchrony.com> AuthorDate: 2025-04-17 09:59:39 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-04-17 13:02:45 +0000 net-analyzer/wireshark: drop py3.10, allow LTO again in -9999 Bug: https://bugs.gentoo.org/754021 Bug: https://bugs.gentoo.org/941890 Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com> Closes: https://github.com/gentoo/gentoo/pull/41627 Signed-off-by: Sam James <sam@gentoo.org> net-analyzer/wireshark/wireshark-9999.ebuild | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=271d5459ef4a511414f2f968afe4c728fa5664b7 commit 271d5459ef4a511414f2f968afe4c728fa5664b7 Author: Holger Hoffstätte <holger@applied-asynchrony.com> AuthorDate: 2025-04-17 09:53:02 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-04-17 13:02:35 +0000 net-analyzer/wireshark: add 4.4.6, drop py3.10, allow LTO again Bug: https://bugs.gentoo.org/754021 Closes: https://bugs.gentoo.org/941890 Signed-off-by: Holger Hoffstätte <holger@applied-asynchrony.com> Signed-off-by: Sam James <sam@gentoo.org> net-analyzer/wireshark/Manifest | 2 + net-analyzer/wireshark/wireshark-4.4.6.ebuild | 328 ++++++++++++++++++++++++++ 2 files changed, 330 insertions(+)
Created attachment 925143 [details] build.log-4.4.6.xz I get some test failures with crashes like: ``` (gdb) bt #0 0x00007ff40e529cf0 in QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::get (this=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/tools/qscopedpointer.h:112 #1 qGetPtrHelper<QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > > (ptr=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/global/qtclasshelpermacros.h:128 #2 QObject::d_func (this=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject.h:108 #3 QObjectPrivate::get (o=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject_p.h:150 #4 doActivate<false> (sender=0x0, signal_index=9, argv=argv@entry=0x7ffe59a73c30) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject.cpp:4003 #5 0x00007ff40e4d2809 in QMetaObject::activate (sender=<optimized out>, m=m@entry=0x7ff40f44f6c0 <QGuiApplication::staticMetaObject>, local_signal_index=local_signal_index@entry=1, argv=argv@entry=0x7ffe59a73c30) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject.cpp:4183 #6 0x00007ff40ead5676 in QGuiApplication::screenAdded (this=<optimized out>, _t1=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3_build/src/gui/Gui_autogen/include/moc_qguiapplication.cpp:420 #7 0x00007ff4101245e0 in QMinimalIntegrationPlugin::create (this=<optimized out>, system=<optimized out>, paramList=...) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/plugins/platforms/minimal/main.cpp:23 #8 QMinimalIntegrationPlugin::create (this=<optimized out>, system=<optimized out>, paramList=...) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/plugins/platforms/minimal/main.cpp:20 #9 0x00007ff40eadb046 in init_platform (pluginNamesWithArguments=..., platformPluginPath=..., platformThemeName=..., argc=@0x7ffe59a745dc: 9, argv=argv@entry=0x7ffe59a749a8) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/gui/kernel/qguiapplication.cpp:1291 #10 0x00007ff40eadeaeb in QGuiApplicationPrivate::createPlatformIntegration (this=0x55ef38019920) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/gui/kernel/qguiapplication.cpp:1580 #11 0x00007ff40eadf698 in QGuiApplicationPrivate::createEventDispatcher (this=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/gui/kernel/qguiapplication.cpp:1599 #12 0x00007ff40e578e4d in QCoreApplicationPrivate::init (this=this@entry=0x55ef38019920) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qcoreapplication.cpp:936 #13 0x00007ff40eae5c4c in QGuiApplicationPrivate::init (this=0x55ef38019920) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/gui/kernel/qguiapplication.cpp:1627 #14 0x00007ff40fb94ac9 in QApplicationPrivate::init (this=0x55ef38019920) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/widgets/kernel/qapplication.cpp:474 #15 QApplication::QApplication (this=0x7ffe59a74740, argc=@0x7ffe59a745dc: 9, argv=0x7ffe59a749a8) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/widgets/kernel/qapplication.cpp:462 #16 0x000055eef968f588 in MainApplication::MainApplication (this=0x7ffe59a74740, argc=@0x7ffe59a745dc: 9, argv=0x7ffe59a749a8) at /var/tmp/portage/net-analyzer/wireshark-4.4.6/work/wireshark-4.4.6/ui/qt/main_application.cpp:661 #17 WiresharkApplication::WiresharkApplication (this=0x7ffe59a74740, argc=@0x7ffe59a745dc: 9, argv=0x7ffe59a749a8) at /var/tmp/portage/net-analyzer/wireshark-4.4.6/work/wireshark-4.4.6/ui/qt/wireshark_application.cpp:15 #18 main (argc=<optimized out>, qt_argv=0x7ffe59a749a8) at /var/tmp/portage/net-analyzer/wireshark-4.4.6/work/wireshark-4.4.6/ui/qt/main.cpp:723 ``` Looks like the same signature as the original issue.
(In reply to Sergei Trofimovich (RETIRED) from comment #12) > (In reply to Arusekk from comment #11) > > (CC from upstream comment) > > > > This issue is not specific to Wireshark, it can be triggered by the > > following simple code: > > > > #include <QApplication> > > #include <QDebug> > > > > int main(int argc, char **argv) > > { > > QApplication app(argc, argv); > > qDebug() << qApp->styleSheet(); > > } > > > > (note that even bugs aside, `app.styleSheet()` would be more appropriate > > than `qApp->styleSheet()`) > > > > and a sample qmake `.pro` file (for brevity, CMakeLists.txt would be way > > longer, but this shows the absolute minimal setup needed, and should be > > readable anyway) > > > > QT += gui widgets > > SOURCES += qtlto.cc > > QMAKE_CXXFLAGS += -flto > > QMAKE_LFLAGS += -pie -fPIE > > > > Removing any of the flags above results in a working executable (printing > > ""). > > > > so this might be a linker bug (lto1 bug) here, a compiler bug in compiling > > Qt (cc1plus/lto1 bug), or Qt compilation flags misconfiguration (Gentoo bug). > > This project generates equivalent of: > $ g++ -c -flto -fPIC qtlto.cc > $ g++ -pie -fPIE qtlto.o -o qtlto > > Note that lto merges all the flags from all the translation units to a > single set as much as it can. I think -fPIC gets overridden by -fPIE based > on documented rule from 'man gcc': > > -flto[=n] > ... > The following options -fPIC, -fpic, -fpie and -fPIE are combined > based on the following scheme: > B<-fPIC> + B<-fpic> = B<-fpic> > B<-fPIC> + B<-fno-pic> = B<-fno-pic> > B<-fpic/-fPIC> + (no option) = (no option) > B<-fPIC> + B<-fPIE> = B<-fPIE> > B<-fpic> + B<-fPIE> = B<-fpie> > B<-fPIC/-fpic> + B<-fpie> = B<-fpie> > > Which combines towards stricter requirements assuming bytecode already > applied some optimisations based on preprocessor values. > > I see that Qt normally disallows anything to be built without -fPIC (at > least in Gentoo): > > /usr/include/qt5/QtCore/qglobal.h:1286:4: error: #error "You must build > your code with position independent code if Qt was built with > -reduce-relocations. " "Compile your code with -fPIC (and not with -fPIE)." > > I think wireshark's CMakeLists.txt imposes -fPIE and effectively throws away > -fPIC at: > set(CMAKE_POSITION_INDEPENDENT_CODE ON) > > Gentoo's toolchain already uses -fPIE where appropriate without explicit > flags. I'd say wireshark would have to avoid -fPIE. > > I think ideal state for wireshark would be to do -fPIC + -pie. In /usr/include/qt6/QtCore/qcompilerdetection.h, I see: ``` #if defined(QT_BOOTSTRAPPED) || defined(QT_USE_PROTECTED_VISIBILITY) || !defined(__ELF__) || defined(__PIC__) // this is fine #elif defined(__PIE__) # error "-fPIE is not sufficient if Qt was configured with the -DFEATURE_reduce_relocations=ON "\ "CMake option. Compile your code with -fPIC and without -fPIE or compile Qt with "\ "-DFEATURE_no_direct_extern_access=ON." #elif defined(QT_REDUCE_RELOCATIONS) # error "You must build your code with position independent code if Qt was configured with the "\ "-DFEATURE_reduce_relocations=ON CMake option. Compile your code with -fPIC and "\ "without -fPIE or compile Qt with -DFEATURE_no_direct_extern_access=ON." #endif ``` I think the Qt sanity check doesn't fire because at the time of preprocessing, it was indeed fine (when building that earlier object). I agree that dropping CMAKE_POSITION_INDEPENDNET_CODE is therefore the right thing to do. It'll then add -pie still because of the bits at https://gitlab.com/wireshark/wireshark/-/blob/master/CMakeLists.txt#L1240.
Created attachment 925144 [details] build log of 4.4.6 with gcc-14, bfd and LTO enabled
See https://bugs.gentoo.org/933110#c2 too.
Created attachment 925172 [details, diff] 0001-net-analyzer-wireshark-fix-crash-with-LTO.patch Attached a WIP patch. It's not quite right as we've just discovered when looking to cleanup the -fPIC the ebuild adds. We still want to add -fPIC to the libraries and not all of them pick up the one from the Qt interface parts. Holger's looking at that now (thank you!)
Some further findings: - all this only affects the main wireshark executable with QT GUI, not the other headless tool binaries. - the "if use gui; then append-cxxflags -fPIC -DPIC" block is an old remnant to work around the problem we're discussing here, though it probably should have been added in cmake. It can be removed.. - ..however only when Sam's WIP patch is NOT being used, otherwise wireshark's shared libraries will fail to link since their objects are no longer built with PIC at all. - instead it seems all we need to do is to prevent linking with -fPIE, so simply disabling the PIE checks from https://gitlab.com/wireshark/wireshark/-/blob/master/CMakeLists.txt#L1256 like e.g.: sed -i 's/include(CheckPIESupported)/#&/' CMakeLists.txt || die sed -i 's/check_pie_supported/#&/' CMakeLists.txt || die in src_configure (or more properly _prepare) prevents the wireshark executable from being linked with "-fPIE -pie", and the resulting lto-enabled binary works fine against gcc/bfd built QT, whereas it would repeatably crash before. For reasons which I don't understand there are still many occurrences of -fPIE in the build log, but those do not seem to matter: everything is built with LTO and all executables incl. the utilities work fine. - the CheckPIE cmake module mentions: set_property(TARGET wireshark PROPERTY POSITION_INDEPENDENT_CODE FALSE) so I thought I'd add that with a simple patch: --- a/CMakeLists.txt~ 2025-04-18 00:32:25.000000000 +0200 +++ b/CMakeLists.txt 2025-04-18 00:50:43.218528502 +0200 @@ -2871,6 +2871,7 @@ if(BUILD_wireshark AND QT_FOUND) endif() set(PROGLIST ${PROGLIST} wireshark) set_target_properties(wireshark PROPERTIES + POSITION_INDEPENDENT_CODE FALSE LINK_FLAGS "${WS_LINK_FLAGS}" FOLDER "Executables" INSTALL_RPATH "${EXECUTABLE_INSTALL_RPATH}" This results in -no-pie being added to the wireshark executable link command, and as expected it works. \o/
Thanks, that sounds right. I'll redo the patch later with that change instead (and tweak the commit message slightly accordingly).
(FWIW, I'm not completely sure if we want it to pass -no-pie to the linker, see the last part of https://bugs.gentoo.org/754021#c12, but I think it's also.. probably fine?)
(In reply to Sam James from comment #28) > (FWIW, I'm not completely sure if we want it to pass -no-pie to the linker, > see the last part of https://bugs.gentoo.org/754021#c12, but I think it's > also.. probably fine?) "Works on my machine" :D But you can also try to mutilate WS_LINK_FLAGS (used right below in the patch context), it's being built/configured throughout the cmake file.
(In reply to Holger Hoffstätte from comment #29) > (In reply to Sam James from comment #28) > > (FWIW, I'm not completely sure if we want it to pass -no-pie to the linker, > > see the last part of https://bugs.gentoo.org/754021#c12, but I think it's > > also.. probably fine?) > > "Works on my machine" :D > But you can also try to mutilate WS_LINK_FLAGS (used right below in the > patch context), it's being built/configured throughout the cmake file. Works but not PIE ;)
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=fad8ff8a45afc83559f8df695cf96dfec51d3e8a commit fad8ff8a45afc83559f8df695cf96dfec51d3e8a Author: Sam James <sam@gentoo.org> AuthorDate: 2025-04-18 04:21:42 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-04-18 04:23:01 +0000 net-analyzer/wireshark: fix runtime with LTO Qt's qcompilerdetection.h currently checks for whether -fPIE is being used along with QT_USE_PROTECTED_VISIBILITY ("reduce relocations", which Qt automatically uses if supported). It bails out if -fPIE is used, as -fPIC is required instead. If LTO is used, when one does something like: (1) g++ -c -flto -fPIC qtlto.cc (2) g++ -pie -fPIE qtlto.o -o qtlto At point (1), the Qt check in the headers fires, and everything is fine, because we're indeed using -fPIC, and GCC doesn't automatically add -fPIE when built with --enable-default-pie if -fPIC is present on the command line. GCC may apply optimisations at this point given Qt is using -mno-direct-extern-access and it was built with -fPIC not -fPIE. Later, at point (2), -fPIE is passed. This happens in Wireshark because `CMAKE_POSITION_INDEPENDENT_CODE` gets set in CMakeLists.txt. With LTO, there's no opportunity for the Qt sanity check in headers to fire again, as everything is already long-preprocessed and GCC will have applied some optimisations already assuming the -fPIC code model in (1). But as slyfox says at https://bugs.gentoo.org/754021#c12, GCC merges -fPIC -fPIE to -fPIE at LTO-time (-fPIC coming from the earlier LTO object in (1), and -fPIE was just-passed on the command line). qtlto (or Wireshark) then crashes. For Wireshark, this looks like: ``` #0 0x00007ff40e529cf0 in QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> >::get (this=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/tools/qscopedpointer.h:112 #1 qGetPtrHelper<QScopedPointer<QObjectData, QScopedPointerDeleter<QObjectData> > > (ptr=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/global/qtclasshelpermacros.h:128 #2 QObject::d_func (this=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject.h:108 #3 QObjectPrivate::get (o=<optimized out>) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject_p.h:150 #4 doActivate<false> (sender=0x0, signal_index=9, argv=argv@entry=0x7ffe59a73c30) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject.cpp:4003 #5 0x00007ff40e4d2809 in QMetaObject::activate (sender=<optimized out>, m=m@entry=0x7ff40f44f6c0 <QGuiApplication::staticMetaObject>, local_signal_index=local_signal_index@entry=1, argv=argv@entry=0x7ffe59a73c30) at /usr/src/debug/dev-qt/qtbase-6.8.3/qtbase-everywhere-src-6.8.3/src/corelib/kernel/qobject.cpp:4183 #6 0x00007ff40ead5676 in QGuiApplication::screenAdded (this=<optimized out>, _t1=<optimized out>) [...] ``` We need to drop -fPIE somehow at link-time accordingly. There's a few ways of doing this but I've gone for not calling `check_pie_supported()` (see (7) below). (Analysis on fixing this in other packages may depend on whether any static libraries *installed* by CMake where -fPIC was no longer passed for those, we would have a problem. I'd tried to use POSITION_INDEPENDENT_CODE at first but then -fPIC gets dropped as well everywhere, and setting the target property to false for just the Wireshark executable also doesn't work because it'll pass -no-pie which isn't what we want.) There are some questions: (3) Why doesn't this happen with Clang, given that Clang has -fno-direct-access-external-data (equivalent to GCC's -mno-direct-extern-access), even when Qt is built with bfd (not lld)? The answer seems to be that Clang doesn't implement the optimisation yet to avoid copy-relocations where possible. GCC implemented that in 5.x in r5-5573-g77ad54d911dd7c. (4) Why doesn't this (seem to) happen in other distributions? nextcloud-client suffers from the same issue analysed here, see https://bugs.gentoo.org/933110. The upstream bug at https://github.com/nextcloud/desktop/issues/2790 was reported by a Debian developer (cgzones), so it's a reasonable assumption that it can happen on Debian. Debian is one of few distributions (we're another) to use --enable-default-pie in GCC rather than just passing it to all package builds in the package manager: it's possible that some distros are just disabling -fPIE or adding a workaround like we did for https://bugs.gentoo.org/552440. Not many distros build with LTO either. Debian also stopped building Wireshark with LTO because of a bug in Wireshark itself (https://bugs.gentoo.org/941890), so I guess they disabled LTO and didn't notice this crash. (This is enough for me to be more confident in my analysis, anyway.) (5) Could Qt communicate this somehow automatically? I think it might be able to if statically linking Qt and Qt was built with LTO. Otherwise, I think the only option would be an ELF .note. pkg-config could maybe work but you can't assume all Qt consumers use that... See the discussion around <https://bugreports.qt.io/browse/QTBUG-45755?focusedId=282483&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-282483>: > Thiago Macieira added a comment - 22 May '15 17:11 > There aren't that many autoconf-based Qt5 builds and we've never exported the flag anyway. (It might be worth bringing this .note idea up to Thiago and/or H.J. but I'm not sure yet if it'll work.) On the Qt side, -fPIC gets passed in to various places before because Qt's CMake config files have INTERFACE_COMPILE_OPTIONS w/ -fPIC. Maybe the answer is for Qt packages to never use CMAKE_POSITION_INDEPENDENT_CODE instead. This came up in https://gitlab.kitware.com/cmake/cmake/-/issues/15570. (6) Could we just disable "reduce relocations" in Qt itself, given that the workaround here will need to be applied in various Qt consumers? This would significantly impact startup times of applications using Qt and there don't seem to be too many applications doing this (only 2 known so far in Gentoo: Wireshark and nextcloud-client). (7) Is the mechanism used to fix this brittle? Yes, we're relying on a CMake bug/feature for now at https://gitlab.kitware.com/cmake/cmake/-/issues/25588 so it doesn't try to enable *or* disable PIE at link-time and we can just rely on our toolchain defaults. Thanks to Arusekk for producing a minimal example and reporting it upstream to Wireshark, thanks to slyfox for analysing the interaction with LTO, thanks to Holger for the discussion around it and testing, and thanks to Eli for reviewing the commit message. Bug: https://bugs.gentoo.org/552440 Bug: https://bugs.gentoo.org/754021 Bug: https://bugs.gentoo.org/933110 Bug: https://bugs.gentoo.org/941890 Bug: https://gitlab.kitware.com/cmake/cmake/-/issues/15570 Bug: https://gitlab.kitware.com/cmake/cmake/-/issues/25588 Bug: https://gitlab.kitware.com/cmake/cmake/-/issues/23980 Bug: https://gitlab.com/wireshark/wireshark/-/issues/17040 Bug: https://bugreports.qt.io/browse/QTBUG-45755 Bug: https://bugreports.qt.io/browse/QTBUG-47942 Bug: https://gcc.gnu.org/PR65248 Bug: https://gcc.gnu.org/PR65886 Thanks-to: Arusekk <arek_koz@o2.pl> Thanks-to: Sergei Trofimovich <slyfox@gentoo.org> Thanks-to: Holger Hoffstätte <holger@applied-asynchrony.com> Thanks-to: Eli Schwartz <eschwartz@gentoo.org> Signed-off-by: Sam James <sam@gentoo.org> net-analyzer/wireshark/files/4.4.6-lto.patch | 164 +++++++++++++++++++++ ...hark-4.4.6.ebuild => wireshark-4.4.6-r1.ebuild} | 11 +- net-analyzer/wireshark/wireshark-9999.ebuild | 11 +- 3 files changed, 175 insertions(+), 11 deletions(-)
Hopefully fixed. I need to understand better what's happening. Corrections are welcome if anyone has them too. Thank you all!
https://maskray.me/blog/2021-01-09-copy-relocations-canonical-plt-entries-and-protected seems to be a great writeup.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=2a8e6203ce276dd4ead7fa789ba671477dba3fba commit 2a8e6203ce276dd4ead7fa789ba671477dba3fba Author: Sam James <sam@gentoo.org> AuthorDate: 2025-04-18 04:53:57 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-04-18 04:54:03 +0000 net-analyzer/wireshark: tweak attribution in patch Bug: https://bugs.gentoo.org/754021 Signed-off-by: Sam James <sam@gentoo.org> net-analyzer/wireshark/files/4.4.6-lto.patch | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Also, an upstreamable patch which I may attempt at some point would look like: * dropping CMAKE_POSITION_INDEPENDENT_CODE (as it implies more than we want) * adding -fPIC to individual targets * adding something to pass -pie at link-time if supported (not -fPIE) I think.
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=496ea7aeecbf417f6b3030d07af3164c19135ee4 commit 496ea7aeecbf417f6b3030d07af3164c19135ee4 Author: Ionen Wolkens <ionen@gentoo.org> AuthorDate: 2025-04-23 13:11:05 +0000 Commit: Ionen Wolkens <ionen@gentoo.org> CommitDate: 2025-04-23 13:24:30 +0000 dev-qt/qtbase: allow auto-detecting -mno-direct-extern-access (ask Sam if want the reasoning, haven't read much on this topic) Not really tested beside checking that the option is passed. Note that this won't be "fully" used unless also rebuild all of dev-qt/* after upgrade to qtbase-6.9.0-r1 given the option is passed by the qtbase defautls to each Qt modules. Part of why not adding it to 6.8.3 as it'll be difficult to guarantee what the users actually have without bunch of revbumps (not so bad for 6.9.0 given mask), will propagate properly when add 6.9.1 unmasked. Unsure if a better way than a patch to drop autodetect like a =AUTO option or so (want to let the test do its thing). Imagine Qt will revert this as well eventually so it won't be there forever. Bug: https://bugs.gentoo.org/754021 Signed-off-by: Ionen Wolkens <ionen@gentoo.org> dev-qt/qtbase/files/qtbase-6.9.0-no-direct-extern-access.patch | 9 +++++++++ dev-qt/qtbase/{qtbase-6.9.0.ebuild => qtbase-6.9.0-r1.ebuild} | 1 + dev-qt/qtbase/qtbase-6.9.9999.ebuild | 1 + dev-qt/qtbase/qtbase-6.9999.ebuild | 1 + 4 files changed, 12 insertions(+)
The bug has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=36d4028db62cee4a64ea56c0b3273528957a0c4e commit 36d4028db62cee4a64ea56c0b3273528957a0c4e Author: Sam James <sam@gentoo.org> AuthorDate: 2025-05-03 05:27:03 +0000 Commit: Sam James <sam@gentoo.org> CommitDate: 2025-05-03 05:27:03 +0000 qt5-build.eclass: disable reduce-relocations For Qt 5, it's best to just disable reduce-relocations, because it doesn't (unlike Qt 6) support -mno-direct-extern-access, which means CMake applications building against Qt 5 are prone to all the issues mentioned in the bug. Bug: https://bugs.gentoo.org/754021 Signed-off-by: Sam James <sam@gentoo.org> eclass/qt5-build.eclass | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)