Open PPed72 opened 3 years ago
What is LTO? Either way I fixed this error in upcoming autotype refactor.
Link-time optimisation I suppose. The current Linux Auto-Type module is particularly vulnerable to such kind of optimisation.
Can be reproduced by adding -flto
to CXXFLAGS
Adding the following change
diff --git a/src/autotype/CMakeLists.txt b/src/autotype/CMakeLists.txt
index 6b9b8b67..fc8ae063 100644
--- a/src/autotype/CMakeLists.txt
+++ b/src/autotype/CMakeLists.txt
@@ -1,4 +1,6 @@
if(WITH_XC_AUTOTYPE)
+ # https://github.com/keepassxreboot/keepassxc/issues/5801
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-lto")
if(UNIX AND NOT APPLE AND NOT HAIKU)
find_package(X11)
find_package(Qt5X11Extras 5.2)
makes the build succeed but breaks test suite quite a bit:
82% tests passed, 7 tests failed out of 38
Total Test time (real) = 9.99 sec
The following tests FAILED:
1 - testgroup (SEGFAULT)
3 - testkdbx3 (SEGFAULT)
4 - testkdbx4 (SEGFAULT)
7 - testentrymodel (Subprocess aborted)
13 - testdeletedobjects (SEGFAULT)
14 - testkeepass1reader (SEGFAULT)
22 - testmerge (SEGFAULT)
and keepassxc segfaults on start. So I suggest to globally disable LTO by adding -fno-lto
somewhere.
The better solution of course would be to find the breaking code and fix it so LTO does not break anything but I suppose that's a very low priority issue. :smiley:
I got similar error report when I enable LTO:
[451/542] : && /usr/bin/g++ -fPIC -pipe -Wno-error -fstack-protector-strong --param=ssp-buffer-size
=4 -fexceptions -ggdb -O2 -fomit-frame-pointer -march=x86-64 -mtune=sandybridge -msse2
-fira-loop-pressure -fira-hoist-pressure -ftree-vectorize -specs=/usr/lib/gcc/specs/hardened-cc1
-flto=auto -ggdb -fpermissive -fdeclone-ctor-dtor -ftree-vectorize -fno-common -
Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibili
ty=hidden -fvisibility-inlines-hidden -fstack-protector-strong -fno-exceptions -fno-rtti -Wnon-virtu
al-dtor -Wold-style-cast -Woverloaded-virtual -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Werror=format-s
ecurity -Wcast-align -pie -fPIE -std=c++11 -fsized-deallocation -Wno-deprecated-declarations -O2 -g
-DNDEBUG -Wl,-O1,--sort-common,--as-needed -Wl,-build-id=sha1 -Wl,-z,relro -Wl,-z,now -specs=/usr
/lib/gcc/specs/hardened-ld -flto -fuse-linker-plugin -Wl,--no-add-needed -Wl,--as-needed -Wl,-z,
relro,-z,now -shared -o src/autotype/xcb/libkeepassx-autotype-xcb.so src/autotype/xcb/CMakeFiles/ke
epassx-autotype-xcb.dir/keepassx-autotype-xcb_autogen/mocs_compilation.cpp.o src/autotype/xcb/CMakeF
iles/keepassx-autotype-xcb.dir/AutoTypeXCB.cpp.o src/libkeepassx_core.a /usr/lib/libQt5X11Extras.s
o.5.15.2 /usr/lib/libX11.so /usr/lib/libXi.so /usr/lib/libXtst.so src/libautotype.a src/browser
/libkeepassxcbrowser.a src/qrcode/libqrcode.a /usr/lib/libQt5Svg.so.5.15.2 /usr/lib/libqrencode.s
o src/fdosecrets/libfdosecrets.a /usr/lib/libQt5Concurrent.so.5.15.2 /usr/lib/libsodium.so /usr/
lib/libyubikey.so /usr/lib/libykpers-1.so src/libzxcvbn.a /usr/lib/libargon2.so /usr/lib/libz.so
src/sshagent/libsshagent.a /usr/lib/libQt5Network.so.5.15.2 src/keeshare/libkeeshare.a /usr/lib
/libQt5Widgets.so.5.15.2 src/crypto/ssh/libcrypto_ssh.a /usr/lib/libquazip5.so /usr/lib/libQt5DBu
s.so.5.15.2 -lX11 /usr/lib/libgcrypt.so /usr/lib/libgpg-error.so /usr/lib/libQt5Gui.so.5.15.2 /
usr/lib/libQt5Core.so.5.15.2 && :
FAILED: src/autotype/xcb/libkeepassx-autotype-xcb.so
: && /usr/bin/g++ -fPIC -pipe -Wno-error -fstack-protector-strong --param=ssp-buffer-size=4 -fexce
ptions -ggdb -O2 -fomit-frame-pointer -march=x86-64 -mtune=sandybridge -msse2 -fira-lo
op-pressure -fira-hoist-pressure -ftree-vectorize -specs=/usr/lib/gcc/specs/hardened-cc1 -flto=aut
o -ggdb -fpermissive -fdeclone-ctor-dtor -ftree-vectorize -fno-common -Wall -Wext
ra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden
-fvisibility-inlines-hidden -fstack-protector-strong -fno-exceptions -fno-rtti -Wnon-virtual-dtor -W
old-style-cast -Woverloaded-virtual -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -Werror=format-security -W
cast-align -pie -fPIE -std=c++11 -fsized-deallocation -Wno-deprecated-declarations -O2 -g -DNDEBUG
-Wl,-O1,--sort-common,--as-needed -Wl,-build-id=sha1 -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/gcc/s
pecs/hardened-ld -flto -fuse-linker-plugin -Wl,--no-add-needed -Wl,--as-needed -Wl,-z,relro,-z,n
ow -shared -o src/autotype/xcb/libkeepassx-autotype-xcb.so src/autotype/xcb/CMakeFiles/keepassx-aut
otype-xcb.dir/keepassx-autotype-xcb_autogen/mocs_compilation.cpp.o src/autotype/xcb/CMakeFiles/keepa
ssx-autotype-xcb.dir/AutoTypeXCB.cpp.o src/libkeepassx_core.a /usr/lib/libQt5X11Extras.so.5.15.2
/usr/lib/libX11.so /usr/lib/libXi.so /usr/lib/libXtst.so src/libautotype.a src/browser/libkeepas
sxcbrowser.a src/qrcode/libqrcode.a /usr/lib/libQt5Svg.so.5.15.2 /usr/lib/libqrencode.so src/fdo
secrets/libfdosecrets.a /usr/lib/libQt5Concurrent.so.5.15.2 /usr/lib/libsodium.so /usr/lib/libyub
ikey.so /usr/lib/libykpers-1.so src/libzxcvbn.a /usr/lib/libargon2.so /usr/lib/libz.so src/ssha
gent/libsshagent.a /usr/lib/libQt5Network.so.5.15.2 src/keeshare/libkeeshare.a /usr/lib/libQt5Wid
gets.so.5.15.2 src/crypto/ssh/libcrypto_ssh.a /usr/lib/libquazip5.so /usr/lib/libQt5DBus.so.5.15.
2 -lX11 /usr/lib/libgcrypt.so /usr/lib/libgpg-error.so /usr/lib/libQt5Gui.so.5.15.2 /usr/lib/li
bQt5Core.so.5.15.2 && :
/usr/bin/ld: /tmp/libkeepassx-autotype-xcb.so.wfIqBk.ltrans0.ltrans.o: warning: relocation against `
_ZN9QHashData11shared_nullE@@Qt_5' in read-only section `.text'
/usr/bin/ld: /tmp/libkeepassx-autotype-xcb.so.wfIqBk.ltrans0.ltrans.o: relocation R_X86_64_PC32 agai
nst symbol `_ZTV12AutoTypeChar' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
I notice that the small different place is: relocation R_X86_64_PC32 against symbol `_ZTV12AutoTypeChar' in my case while requires dynamic R_X86_64_PC32 reloc against '_ZN16AutoTypeExecutor9execDelayEP13AutoTypeDelay' which may overflow at runtime in yours.
OS: Linux (AOSC OS, it's said that Fedora and openSUSE also encounter this problem) KeePassXC Version 2.6.6, Revision: 9c108b9 Desktop Environment: KDE Xorg session
I find that attaching -fPIC
flag all the time can fix this LTO problem, but actually KeePassXC has set CMAKE_POSITION_INDEPENDENT_CODE
as true. It's confused that why the latter doesn't work well ...
UPDATED: Sorry...... CMakeLists.txt of version 2.6.6 doesn't include CMAKE_POSITION_INDEPENDENT_CODE
yet, nerver mind this.
Building with thin-lto works on my machine (using gentoo). But if lto is used and I try to use my yubikey, keepassxc crashes.
Overview
keepassxc-2.6.[12] does not compile on my Gentoo system with LTO enabled
Steps to Reproduce
emerge -1 app-admin/keepassxc
Expected Behavior
Successful package build
Actual Behavior
[306/504] /usr/bin/x86_64-pc-linux-gnu-g++ -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_DBUS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_NO_CAST_TO_ASCII -DQT_NO_DEBUG -DQT_NO_DEPRECATED_WARNINGS -DQT_NO_EXCEPTIONS -DQT_STRICT_ITERATORS -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_X11EXTRAS_LIB -DWITH_APP_BUNDLE -Dkeepassx_autotype_xcb_EXPORTS -Isrc/autotype/xcb/keepassx-autotype-xcb_autogen/include -I/var/tmp/portage/app-admin/keepassxc-2.6.2/work/keepassxc-2.6.2/src -Isrc -I/var/tmp/portage/app-admin/keepassxc-2.6.2/work/keepassxc-2.6.2/src/zxcvbn -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtCore -isystem /usr/lib64/qt5/mkspecs/linux-g++ -isystem /usr/include/qt5/QtWidgets -isystem /usr/include/qt5/QtGui -isystem /usr/include/qt5/QtConcurrent -isystem /usr/include/qt5/QtNetwork -isystem /usr/include/qt5/QtSvg -isystem /usr/include/qt5/QtDBus -isystem /usr/include/qt5/QtX11Extras -O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6 -fno-common -Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden -fvisibility-inlines-hidden -fstack-protector-strong -fno-exceptions -fno-rtti -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Werror=format-security -Wcast-align -pie -fPIE -std=c++11 -fsized-deallocation -Wno-deprecated-declarations -fPIC -fPIC -MD -MT src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/AutoTypeXCB.cpp.o -MF src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/AutoTypeXCB.cpp.o.d -o src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/AutoTypeXCB.cpp.o -c /var/tmp/portage/app-admin/keepassxc-2.6.2/work/keepassxc-2.6.2/src/autotype/xcb/AutoTypeXCB.cpp [307/504] : && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6 -fno-common -Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden -fvisibility-inlines-hidden -fstack-protector-strong -fno-exceptions -fno-rtti -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Werror=format-security -Wcast-align -pie -fPIE -std=c++11 -fsized-deallocation -Wno-deprecated-declarations -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -flto=6 -Wl,--no-add-needed -Wl,--as-needed -Wl,-z,relro,-z,now -shared -o src/autotype/xcb/libkeepassx-autotype-xcb.so src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/keepassx-autotype-xcb_autogen/mocs_compilation.cpp.o src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/AutoTypeXCB.cpp.o src/libkeepassx_core.a /usr/lib64/libQt5X11Extras.so.5.15.1 /usr/lib64/libX11.so /usr/lib64/libXi.so /usr/lib64/libXtst.so src/libautotype.a src/browser/libkeepassxcbrowser.a src/qrcode/libqrcode.a /usr/lib64/libQt5Svg.so.5.15.1 /usr/lib64/libqrencode.so src/fdosecrets/libfdosecrets.a /usr/lib64/libQt5Concurrent.so.5.15.1 /usr/lib64/libsodium.so src/libzxcvbn.a /usr/lib64/libargon2.so -lz src/sshagent/libsshagent.a /usr/lib64/libQt5Widgets.so.5.15.1 /usr/lib64/libQt5Network.so.5.15.1 src/crypto/ssh/libcrypto_ssh.a /usr/lib64/libQt5DBus.so.5.15.1 -lX11 /usr/lib64/libgcrypt.so /usr/lib64/libgpg-error.so /usr/lib64/libQt5Gui.so.5.15.1 /usr/lib64/libQt5Core.so.5.15.1 && : FAILED: src/autotype/xcb/libkeepassx-autotype-xcb.so : && /usr/bin/x86_64-pc-linux-gnu-g++ -fPIC -O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6 -fno-common -Wall -Wextra -Wundef -Wpointer-arith -Wno-long-long -Wformat=2 -Wmissing-format-attribute -fvisibility=hidden -fvisibility-inlines-hidden -fstack-protector-strong -fno-exceptions -fno-rtti -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Werror=format-security -Wcast-align -pie -fPIE -std=c++11 -fsized-deallocation -Wno-deprecated-declarations -Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -flto=6 -Wl,--no-add-needed -Wl,--as-needed -Wl,-z,relro,-z,now -shared -o src/autotype/xcb/libkeepassx-autotype-xcb.so src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/keepassx-autotype-xcb_autogen/mocs_compilation.cpp.o src/autotype/xcb/CMakeFiles/keepassx-autotype-xcb.dir/AutoTypeXCB.cpp.o src/libkeepassx_core.a /usr/lib64/libQt5X11Extras.so.5.15.1 /usr/lib64/libX11.so /usr/lib64/libXi.so /usr/lib64/libXtst.so src/libautotype.a src/browser/libkeepassxcbrowser.a src/qrcode/libqrcode.a /usr/lib64/libQt5Svg.so.5.15.1 /usr/lib64/libqrencode.so src/fdosecrets/libfdosecrets.a /usr/lib64/libQt5Concurrent.so.5.15.1 /usr/lib64/libsodium.so src/libzxcvbn.a /usr/lib64/libargon2.so -lz src/sshagent/libsshagent.a /usr/lib64/libQt5Widgets.so.5.15.1 /usr/lib64/libQt5Network.so.5.15.1 src/crypto/ssh/libcrypto_ssh.a /usr/lib64/libQt5DBus.so.5.15.1 -lX11 /usr/lib64/libgcrypt.so /usr/lib64/libgpg-error.so /usr/lib64/libQt5Gui.so.5.15.1 /usr/lib64/libQt5Core.so.5.15.1 && : /usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: /var/tmp/portage/app-admin/keepassxc-2.6.2/temp/libkeepassx-autotype-xcb.so.RFKUG5.ltrans0.ltrans.o: requires dynamic R_X86_64_PC32 reloc against '_ZN16AutoTypeExecutor9execDelayEP13AutoTypeDelay' which may overflow at runtime; recompile with -fPIC collect2: error: ld returned 1 exit status ninja: build stopped: subcommand failed.
Context
If I disable LTO everything builds and works fine.
KeePassXC - Version 2.6.1 (same happens with 2.6.2) Revision: 9a35bba
Operating System: Linux Desktop Env: KDE Windowing System: either X11 or Wayland