Bug 442695 - KWin fails to load necessary QT plugin when built with LTO
Summary: KWin fails to load necessary QT plugin when built with LTO
Status: RESOLVED UPSTREAM
Alias: None
Product: kwin
Classification: Plasma
Component: general (other bugs)
Version First Reported In: 5.22.4
Platform: Compiled Sources Linux
: NOR major
Target Milestone: ---
Assignee: KWin default assignee
URL: https://bugreports.qt.io/browse/QTBUG...
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-19 13:34 UTC by sattaxt
Modified: 2021-09-21 15:36 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description sattaxt 2021-09-19 13:34:38 UTC
SUMMARY
When KWin is compiled with Clang and Full LTO (I don't know if ThinLTO or GCC doesn't exhibit this issue, I didn't test it), kwin_wayland or any other attemps to start Plasma will fail with an error message something like this:

"qt.qta.plugin: could not load the Qt platform plugin "wayland-org.kde.kwin.qpa" in "" even though it was found.
 This application failed to start because no Qt platform plugin could be initialized. reinstalling the application may fix this problem"

This doesn't happen on the exact same machine, with the exact same software versions, if KWin is built without LTO (other optimizations such as -O3 or -march doesn't seem to affect this issue at all), it works perfectly.

STEPS TO REPRODUCE
1. Compile KWin with Clang and -flto=full
2. Attempt to start it
3. Watch as it fails to load the required QT Plugin

OBSERVED RESULT
Error message inserted above when starting KWin

EXPECTED RESULT
Kwin starting without errors

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux / KDE 5.22.5
(available in About System)
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.86.0
Qt Version: 5.15.2

ADDITIONAL INFORMATION
I selected 5.22.4 on the Component section because there is no option for 5.22.5
Comment 1 Vlad Zahorodnii 2021-09-20 09:10:18 UTC
Please remove KWinQpaPlugin.so in your filesystem.
Comment 2 Vlad Zahorodnii 2021-09-20 09:11:46 UTC
If the bug is still reproducible, please re-open the bug report.
Comment 3 sattaxt 2021-09-20 09:20:58 UTC
(In reply to Vlad Zahorodnii from comment #2)
> If the bug is still reproducible, please re-open the bug report.

I do not seem to have this file in my system,
as "fd --glob "KWinQpaPlugin.so*" /usr /lib /home /etc /dev /boot /var /lib64" returns no results.

Reopening.
Comment 4 Vlad Zahorodnii 2021-09-20 09:23:22 UTC
Okay. does plasma start if kwin is compiled without LTO?
Comment 5 Vlad Zahorodnii 2021-09-20 09:23:49 UTC
argh, nvm "if KWin is built without LTO". this seems like a bug worth reporting to Qt developers
Comment 6 Vlad Zahorodnii 2021-09-20 09:25:16 UTC
"wayland-org.kde.kwin.qpa" is a static plugin, i.e. it's compiled into kwin binary. If static plugins don't work with LTO, it's probably worth reporting to Qt developers.
Comment 7 sattaxt 2021-09-20 10:11:50 UTC
Alright, I'll do that. By QT developers, I'm assuming you mean upstream QT?
Comment 8 Vlad Zahorodnii 2021-09-20 11:27:44 UTC
Yeah, but it will help a lot to move the bug report progress forward if a minimal demo app is provided. Saying that kwin's qpa static plugin can't be loaded when kwin is compiled with LTO is fine, but it's more convenient to have a demo app.
Comment 9 David Edmundson 2021-09-20 11:35:22 UTC
Can you provide some more precise information and your command to build kwin that exhibits the issue?
Comment 10 sattaxt 2021-09-20 11:43:12 UTC
(In reply to David Edmundson from comment #9)
> Can you provide some more precise information and your command to build kwin
> that exhibits the issue?

I will provide my compiler flags and the command to actually build KWin below:

Compiler flags ="-march=native -O3 --ld-path=/usr/bin/ld.lld -feliminate-unused-debug-types -pipe -fexceptions -w -mbranches-within-32B-boundaries -lmimalloc --param=ssp-buffer-size=32 -m64 -D_FORTIFY_SOURCE=2 -fno-semantic-interposition -flto=full -fvirtual-function-elimination -fwhole-program-vtables"

Pre-build command:
  cmake -B build -S kwin-5.22.5 \
    -DCMAKE_INSTALL_LIBEXECDIR=lib \
    -DBUILD_TESTING=OFF

Build command:
cmake --build build

Packaging command:
DESTDIR="$pkgdir" cmake --install build

My long list of flags may seem suspect, but it's worth stressing they're not causing the issue. To test this, I tried a build of KWin *only* with -O2 and LTO (without any of the more advanced LTO optimizations such as virtual-function-elimination), and this issue still happened.

That's about the only additional information I can think of. There are no compiler errors, it builds just fine, but fails to start with the error message in the OP. If you need specific information, I can provide it.
Comment 11 sattaxt 2021-09-21 13:29:12 UTC
Linking the QT bug report here for reference: https://bugreports.qt.io/browse/QTBUG-96738
Comment 12 Vlad Zahorodnii 2021-09-21 15:36:33 UTC
Thanks!