Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt connect not work with mold #352

Closed
alphaonex86 opened this issue Feb 18, 2022 · 18 comments
Closed

Qt connect not work with mold #352

alphaonex86 opened this issue Feb 18, 2022 · 18 comments

Comments

@alphaonex86
Copy link

Hi,
If I try compile my Qt software (here catchchallenger https://github.com/alphaonex86/CatchChallenger/ ) with mold (work with all other linker), QObject::connect don't found the method.
Cheers,

@rui314
Copy link
Owner

rui314 commented Feb 19, 2022

Can you copy-paste the failure log?

@alphaonex86
Copy link
Author

image

@rui314
Copy link
Owner

rui314 commented Feb 19, 2022

It looks like your program crashed. Doesn't it crash if you link with others linker?

@alphaonex86
Copy link
Author

alphaonex86 commented Feb 19, 2022

With other linker, normal linker, gold linker, lld linker: work
The problem is only with mold linker

@rui314
Copy link
Owner

rui314 commented Feb 19, 2022

Does it fail reliably? How can I build this program on my machine to reproduce the issue?

@alphaonex86
Copy link
Author

alphaonex86 commented Feb 19, 2022

Hi, always occur.
download https://github.com/alphaonex86/CatchChallenger/ + qt for dev and qt creator
cd CatchChallenger/client
qmake catchchallenger.pro
make

@rui314
Copy link
Owner

rui314 commented Feb 20, 2022

It looks like I can't build it due to missing dependencies:

ruiu@blue:~/CatchChallenger/client$ qmake catchchallenger.pro
Project ERROR: Unknown module(s) in QT: websockets qml quick

Can you debug your program a little bit? It looks like it calls abort because connect failed. What did connect return? You should be able to get the error message by calling strerror(errno) immediately after connect failure.

@BenBE
Copy link

BenBE commented Feb 20, 2022

NB: Note that the connect function in Qt should not be confused with the ::connect system call used to establish a socket connection. Instead the Qt connect function tries to add a signal handler (4th parameter) on an instance (3rd parameter) to an event provided in the first and second parameter. The relevant pieces for mold are thus the second and fourth argument to this call. Not checked, but IIRC the call errors out, when any of the arguments is NULL or it can't find the second argument in some metadata table it generated for the second argument. HTH.

@alphaonex86
Copy link
Author

Project ERROR: Unknown module(s) in QT: websockets

apt-get install libqt5websockets5-dev qtdeclarative5-dev

QObject::connect is not unix fonction, I try but errno is not set (remain to 0, unchanged).

@mheimlich
Copy link

mheimlich commented Mar 8, 2022

I'm experiencing the same issue within a larger codebase. Unfortunately I have not been able to create a minimal example that triggers the issue. Anyway, the issue occurs only with the QObject::connect() overloads that takes the address of a Qt signal function() (https://doc.qt.io/qt-5/qobject.html#connect-4). When using the old macro based syntax the signal is found.

The signal functions that trigger the behaviour are those from the Qt Base Classes within the QWidgets shared library. I have not experienced it with functions defined within our own classes.

@mheimlich
Copy link

mheimlich commented Mar 8, 2022

I have attached the following minimal test case: testmold_qt.zip

The issue occurs once the main executable links the same symbol from Qt that is also used within a shared library that uses the symbols address within connect().

Hope this helps you tracking down this issue.

@mxmlnkn
Copy link

mxmlnkn commented Apr 1, 2022

I also have problems when linking with mold in a larger project. I'm using mold --run ninja .... Linking works but when running the applications, I get hundreds of warnings:

[Warning] QObject::connect: signal not found in QCheckBox
[Warning] QObject::connect: signal not found in QComboBox
[Warning] QObject::connect: signal not found in QLineEdit
[Warning] QObject::connect: signal not found in QWidget
[Warning] QObject::connect: signal not found in QStackedWidget
[Warning] QObject::connect: signal not found in QPushButton
[Warning] QObject::connect: signal not found in QWidget

Note that these warnings will not appear in release builds even if the connect fails.

This project almost only uses the newer function pointer connect style not the old one with string names.

The closest other issue I could find is this one. Could it be that mold turns on LTO (or symbolic-functions?) by default?

I have attached the following minimal test case: testmold_qt.zip

This does not work for me. Even without using mold, I get QWidget: Must construct a QApplication before a QWidget.

Unfortunately, I'm also having trouble creating a minimal non-working example from scratch. I tried some examples from the Qt examples folder shipping with the installation but all of them worked without problems. I tried reducing the main function of that big project to a minimal widget and could still reproduce the warnings albeit of course only the few in the minimal widget. However, as soon as I try to remove the as of the above change unused CMake targets by the smallest possible step (which is still quite large because of mismanaged cross-dependencies), the warnings disappear. Note that the resulting binary shrinks from 268 MiB to 101 MiB. Maybe it is a bug only happening with large executables?

Or maybe some of the CMake targets behave weirdly. All kinds of CMake target types like interface targets, static targes, shared libraries are used in this project. However, it really is only the final linking step that is the problem. I used ninja -v to print that step and I can only rerun this step with mold --run or without and the warnings appear and disappear. That link command line is nothing fancy, it looks something like this:

/usr/lib/ccache/clang++-13 \
    -g3 -Og -static-libgcc -static-libstdc++ \
    <a lot of object files>.o \
    <a lot of static libraries>.a \
    /usr/lib/x86_64-linux-gnu/libz.so \
    <further object files and static libraries> \
    ../lib/liblz4.a \
    /opt/Qt6.2.2/6.2.2/gcc_64/lib/libQt6Svg.so.6.2.2  \
    /opt/Qt6.2.2/6.2.2/gcc_64/lib/libQt6Widgets.so.6.2.2  \
    /opt/Qt6.2.2/6.2.2/gcc_64/lib/libQt6Gui.so.6.2.2  \
    /usr/lib/x86_64-linux-gnu/libGL.so  \
    /opt/Qt6.2.2/6.2.2/gcc_64/lib/libQt6DBus.so.6.2.2  \
    /opt/Qt6.2.2/6.2.2/gcc_64/lib/libQt6Core.so.6.2.2  \
    /usr/lib/x86_64-linux-gnu/libcrypto.so \
    -ldl

I don't see any LTO or symbolic functions being explicitly turned on.

Adding -fPIC does not help either.

@mheimlich
Copy link

I've modified the example such that it does not crash when not linked with mold.
testmold_qt2.zip

@rui314 rui314 closed this as completed in e0bc74a Apr 5, 2022
@rui314
Copy link
Owner

rui314 commented Apr 5, 2022

Thank you guys for reporting the details of the issue. In particular, thank you @mheimlich for sharing the archive to reproduce the issue. With that, I could reproduce the issue on my machine, and I believe the above commit fixed it. Can you test again to see if it works for you guys? Thanks!

@mheimlich
Copy link

Awesome, I can confirm that this now also works in my original project! Thanks for looking into this!

@alphaonex86
Copy link
Author

Work here too! Thanks

@rui314
Copy link
Owner

rui314 commented Apr 5, 2022

Nice. Feel free to file a new bug if you find any. Thanks!

@bugwelle
Copy link

Awesome! I had mold 1.1.1 installed. After updating to 1.4.2, linking my Qt project works (i.e. no runtime warnings anymore). Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants