Fix Qt build on arch by setting -fPIC #6248

pull TheBlueMatt wants to merge 1 commits into bitcoin:master from TheBlueMatt:archbuild changing 1 files +2 −2
  1. TheBlueMatt commented at 7:12 pm on June 7, 2015: member
    Without -fPIC you get /usr/include/qt/QtCore/qglobal.h:1050: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).”
  2. Fix Qt build on arch by setting -fPIC c791ef4b29
  3. TheBlueMatt commented at 7:12 pm on June 7, 2015: member
    Theres probably another way to do it (I know @theuni wanted to build with different flags for release, but it would be good to at least fix build).
  4. laanwj commented at 12:14 pm on June 9, 2015: member

    We discussed this on IRC. I don’t think -fPIC should be the default, for executables -fPIE is superior option. See e.g. http://www.openbsd.org/papers/nycbsdcon08-pie/

    Though I’m fine with enabling it as a fallback if you can add a check to autoconf that PIE is broken on a platform.

  5. laanwj added the label Build system on Jun 9, 2015
  6. TheBlueMatt commented at 8:11 pm on June 9, 2015: member
    Many distros force PIC anyway, so this actually wont change anything for most builds.
  7. theuni commented at 8:16 pm on June 9, 2015: member

    After researching the issue some over the weekend, I agree with @laanwj.

    To clarify, this is an issue with gcc5 and newer clang+lto when qt is built with -reduce-relocations. Upstream GCC discussion is here.

    We have a few options:

    • Do nothing. I think I’d prefer this, reasoning below.
    • use -PIC instead for known-problematic compilers. This would mean maintaining a black-list since I don’t believe this can be easily tested.
    • Use -PIC instead only when building bitcoin-qt and using a problematic compiler and when qt was built with -reduce-relocations (this can be tested via preprocessor).
    • Default to -PIC everywhere and override with -PIE when creating release binaries.

    2 and 3 would be necessary only for building bitcoin-qt, but we’d end up having to disable PIE for bitcoind as well, to avoid building 2 sets of objects.

    I believe that the root issue here is that distros are shipping qt libs with -reduce-relocations, which is known to violate abi specs and makes assumptions about how downstreams will use their libs. That abi spec violation became a real-world issue with the latest compilers.

    So IMO, the more reasonable thing to do here would be to try to convince Arch to disable -reduce-relocations for their qt build. We can’t be the only downstream with this issue.

  8. TheBlueMatt commented at 8:29 pm on June 9, 2015: member
    OK, @theuni I filed a bug at https://bugs.archlinux.org/task/45283 lets see what the maintainers there say.
  9. laanwj commented at 6:05 am on June 10, 2015: member
    @cfields I’m ok with all those options, except “Default to -PIC everywhere and override with -PIE when creating release binaries.” Let’s not have everyone suffer because a distro builds libraries with broken options. Either we work around this specific case when it happens, or we do nothing and have Arch users provide an extra option as workaround (could be documented in build_unix.md). Would be even better if the problem could just be solved upstream.
  10. TheBlueMatt commented at 8:41 am on June 10, 2015: member

    @cfields would you mind discussing with the arch maintainer @ https://bugs.archlinux.org/task/45283#comment136231 ?

    On June 9, 2015 11:06:00 PM PDT, “Wladimir J. van der Laan” notifications@github.com wrote:

    @cfields I’m ok with all those options, except “Default to -PIC everywhere and override with -PIE when creating release binaries.” Let’s not have everyone suffer because a distro builds libraries with broken options. Either we work around this specific case when it happens, or we do nothing and have Arch users provide an extra option as workaround (could be documented in build_unix.md). Would be even better if the problem could just be solved upstream.


    Reply to this email directly or view it on GitHub: #6248 (comment)

  11. welshjf referenced this in commit b452d27341 on Jun 12, 2015
  12. welshjf referenced this in commit db57fdfe77 on Jun 13, 2015
  13. welshjf referenced this in commit 4227ff3c6e on Jun 14, 2015
  14. welshjf referenced this in commit aad5ee759a on Jun 14, 2015
  15. welshjf referenced this in commit 609e372bf1 on Jun 20, 2015
  16. dankeder commented at 1:01 pm on June 27, 2015: none
    This issue is present on Fedora 22 as well.
  17. theuni commented at 2:29 pm on June 27, 2015: member
    I have a fix for this in the works. I’ll try to push it up in the next few days.
  18. TheBlueMatt commented at 11:14 pm on July 17, 2015: member
    Arch changed their build settings and this is no longer an issue there, is it still on Fedora? Can we file a bug there? @dankeder
  19. dankeder commented at 6:32 pm on July 20, 2015: none

    Yes, the problem is still present on F22:

    In my bitcoin repo (checkout tag v0.10.2):

     0$ ./configure --prefix=/home/dan/programs/bitcoin-0.10.2 --with-gui=qt5 --with-pic --disable-shared --disable-tests
     1(...)
     2$ make                     
     3Making all in src
     4make[1]: Entering directory '/home/dan/tmp/src/bitcoin/src'
     5make[2]: Entering directory '/home/dan/tmp/src/bitcoin/src'
     6  CXX      qt/qt_bitcoin_qt-bitcoin.o
     7In file included from /usr/include/qt5/QtGui/qwindowdefs.h:37:0,
     8                 from /usr/include/qt5/QtWidgets/qwidget.h:37,
     9                 from /usr/include/qt5/QtWidgets/qframe.h:37,
    10                 from /usr/include/qt5/QtWidgets/qlabel.h:37,
    11                 from /usr/include/qt5/QtWidgets/QLabel:1,
    12                 from qt/bitcoingui.h:14,
    13                 from qt/bitcoin.cpp:9:
    14/usr/include/qt5/QtCore/qglobal.h:1052: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)."
    15 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
    16    ^
    17Makefile:5494: recipe for target 'qt/qt_bitcoin_qt-bitcoin.o' failed
    18make[2]: *** [qt/qt_bitcoin_qt-bitcoin.o] Error 1
    19make[2]: Leaving directory '/home/dan/tmp/src/bitcoin/src'
    20Makefile:6246: recipe for target 'all-recursive' failed
    21make[1]: *** [all-recursive] Error 1
    22make[1]: Leaving directory '/home/dan/tmp/src/bitcoin/src'
    23Makefile:568: recipe for target 'all-recursive' failed
    24make: *** [all-recursive] Error 1
    

    I have these QT5 packages:

    0$ rpm -qa | grep qt5-qtbase 
    1qt5-qtbase-gui-5.4.2-2.fc22.x86_64
    2qt5-qtbase-5.4.2-2.fc22.x86_64
    3qt5-qtbase-devel-5.4.2-2.fc22.x86_64
    4qt5-qtbase-common-5.4.2-2.fc22.noarch
    
  20. laanwj added the label Upstream on Jul 22, 2015
  21. theuni commented at 10:31 pm on July 22, 2015: member
    I’m unsure what to do here. I have a rather complicated patch that changes around the PIC flags for qt objects if it was built with -reduce-locations, but since Arch elected to quit doing that, I’m somewhat hopeful that we can lobby the other distros to do the same. That really is the correct fix.
  22. dankeder commented at 1:37 pm on July 23, 2015: none

    I asked a friend who is a contributor to the Fedora Project what he thinks about this issue.

    His opinion is that bitcoin build logic shouldn’t set compiler options on its own, it should rather make use of qmake to get the flags of the particular platform. Also, it seems that -fPIC is set as the default directly in qt build scripts. So if you think that the flags need to be changed, they should be changed upstream, not in each and every Linux distribution that has this problem.

  23. laanwj commented at 9:01 am on August 25, 2015: member

    We’re setting custom compiler options because of --enable-hardening, which sets some (relatively) obscure options to improve worst-case security. With --disable-hardening this problem it just uses the suggested flags and I don’t think this problem exists.

    I do like having hardening enabled by default, though. @theuni Can we add a test to configure that detects this problem, and disables or falls back to other options if it fails?

  24. jgarzik commented at 3:12 pm on September 16, 2015: contributor
    Well, reviewing PIE vs. PIC, no immediate security issue jumps out (via hardening) at the introduction of PIC. It’s just a bit slower. Capturing the flags from qmake seems reasonable?
  25. itoffshore commented at 4:05 pm on September 16, 2015: contributor
  26. itoffshore commented at 1:55 pm on September 18, 2015: contributor
    In Alpine Linux qt5 is built with -no-reduce-relocations &bitcoin / bitcoin-qt are still built with -fPIE
  27. laanwj commented at 12:30 pm on October 6, 2015: member

    Use -PIC instead only when building bitcoin-qt and using a problematic compiler and when qt was built with -reduce-relocations (this can be tested via preprocessor).

    Right, detecting this would be the right way to solve this. Although the logic is quite ugly, it’s not that much worse than other auto* checks.

    And agree it would be even better if -reduce-relocations was not provided to the Qt build upstream. That’s the root issue, not PIE versus PIC.

    Still NACK on setting -fPIC by default, so going to close this.

  28. laanwj closed this on Oct 6, 2015

  29. laanwj reopened this on Nov 2, 2015

  30. laanwj commented at 2:58 pm on November 2, 2015: member
    Bleh, getting the same on Ubuntu 15.10 now. Seems a lot of distributions are compiling Qt with that awful option. We do need to detect it somehow in configure. @theuni can you take a look at this?
  31. laanwj added this to the milestone 0.12.0 on Nov 3, 2015
  32. laanwj commented at 2:32 pm on November 10, 2015: member
    Closing in favor of #6978
  33. laanwj closed this on Nov 10, 2015

  34. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-10-06 16:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me