1

On Linux Debian/Sid/x86-64 for the RefPerSys GPLv3+ project using Qt5 (5.12.5 as packaged by Debian), I prefer to disable ASLR to ease debugging (and facilitate GDB watchpoints). FWIW, that project is generating C++ code on the fly at runtime, compiling it into a shared library, and is dlopen(3)-ing the obtained plugins. So using gdb is definitely useful.

So with RefPerSys git commit dae216918be51c... on gitlab compiled by g++ 9.3.0 from Debian, using make RPS_BUILD_CODGENFLAGS= (or edit the Makefile to undefine it) after both a make clean and then a make fullclean I am getting the following reproducible compiler error:

ccache g++ -std=gnu++17 -Og -g3  -Wall -Wextra -I .  -I /usr/local/include  -I /usr/include -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -I/usr/local/include -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtNetwork -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I/usr/include/x86_64-linux-gnu/qt5 -DRPS_GITID=\"dae216918be51c0c025d8d57369d186db08e4923+\"   -c -c -o refpersys.hh.gch-tmp refpersys.hh
In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qnamespace.h:43,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs.h:48,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:46,
                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QObject:1,
                 from refpersys.hh:100:
/usr/include/x86_64-linux-gnu/qt5/QtCore/qglobal.h:1187:4: error: #error "You must build your code with position independent code if Qt was built with -reduce-relocations. " "Compile your code with -fPIC (-fPIE is not enough)."
 1187 | #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
      |    ^~~~~

As the error message says, it is related to Qt5 having been built with -reduce-relocations by Debian folks. Since then You must build your code with position independent code

Is it just a matter of recompiling Qt5 from its source code, or is it more subtle than that?

More broadly:

how to use GDB watchpoints on Qt5 code compiled on Debian/Sid?

Of course I want hardware watchpoints. Typically printing some pointer under gdb - which would give for example 0x7fafb071b8 then watch *(int*) 0x7fafb071b8 inside gdb

QT bug 84159 is motivated and related to the question above. Compiling Qt from source is not that simple....

I just added a --no-aslr program option (using personality(2) hints from here to disable programmatically ASLR). That option sometimes run pmap(1) on the current process. I am observing widely different maps from one run to the next one.

PS. To reproduce the bug, after a successful make without setting RPS_BUILD_CODGENFLAGS= run twice ./refpersys --no-aslr -dGUI --display=object. The two _refpersys*Pmap*.tmp files (output of pmap) are widely different. I expected them to be similar. For coding details in may 2020, please grep for the rps_disable_aslr variable in the C++ source code, files refpersys.hh, appli_qrps.cc, and mostly main_rps.cc ....

NB: Same error appears on Mageia 7.1 installed on my laptop. So in RefPerSys we are switching to FLTK.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • 1
    There's [anecdotal evidence](https://bugzilla.redhat.com/show_bug.cgi?id=1700435#c5) that building Qt from source with `-no-reduce-relocations` will produce a library that can be linked with a non-PIC object file, at least for a small test case. – Mark Plotnick May 11 '20 at 17:54

0 Answers0