Alternative fix for #6248 (qt+fPIE) #6978

pull theuni wants to merge 2 commits into bitcoin:master from theuni:qt-pie changing 7 files +93 −27
  1. theuni commented at 2:25 am on November 10, 2015: member

    Rather than setting -fPIC wholesale, only set it for the qt objects.

    The first commit restructures to move the fPIE flag out, the second is the actual change.

    Note that -fPIC is used for testing qt until we get to the actual fPIE test. That’s to prevent us from bombing out early due to qt’s header yelling about PIE before we actually want to test it.

  2. theuni force-pushed on Nov 10, 2015
  3. build: Split hardening/fPIE options out
    This allows for fPIE to be used selectively.
    17c4d9d164
  4. build: Use fPIC rather than fPIE for qt objects.
    But only if qt was built with reduced relocations.
    69d0513436
  5. laanwj added the label Build system on Nov 10, 2015
  6. laanwj commented at 10:21 am on November 10, 2015: member
    Great work, utACK (will test later)
  7. MarcoFalke commented at 11:22 am on November 10, 2015: member

    Thanks, Concept ACK.

    Can confirm default settings ($ ./autogen.sh ;./configure ;make) work again with 69d0513 on latest fedora. (You may want to put “closes #6248” in the OP)

  8. jonasschnelli commented at 11:41 am on November 10, 2015: contributor
    Nice! utACK. Gitian build for all three platform works: https://bitcoin.jonasschnelli.ch/pulls/6978/
  9. laanwj commented at 4:19 pm on November 10, 2015: member

    On Ubuntu 15.10 this gives:

    0checking whether -fPIE can be used with this Qt config... no
    

    Which is correct. However on On Ubuntu 14.04 I also get:

    0checking whether -fPIE can be used with this Qt config... no
    

    While I know in fact that that does work. Error in config.log is:

    0configure:23385: g++ -c -fPIE -g -O2 -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -Wno-self-assign -I/usr/include/qt5/QtCore -I/usr/include/qt5 -I/usr/include/qt5/QtGui -I/usr/include/qt5/QtNetwork -I/usr/include/qt5/QtWidgets    -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS conftest.cpp >&5
    1conftest.cpp: In function 'int main()':
    2conftest.cpp:67:15: error: 'choke' was not declared in this scope
    3               choke;
    4               ^
    5At global scope:
    

    Strange. QT_REDUCE_RELOCATIONS is indeed enabled:

    0./qt5/QtCore/qconfig.h:#define QT_REDUCE_RELOCATIONS
    

    However it just works with fPIE. Gcc version issue?

  10. theuni commented at 8:14 pm on November 10, 2015: member

    @laanwj I believe it’s a Qt issue. They tightened the requirements with newer qt versions, -fPIE used to compile fine. But -fPIE + gcc5 + older Qt will still likely cause problems regardless if it does compile.

    So the real issue is -fPIE + newer gcc regardless of when qt tightened the error. I think it makes sense to always fall back to -fPIC any time that reduce_relocations was used. The alternative would be a blacklist/whitelist for compilers, which i was trying to avoid.

  11. laanwj commented at 8:27 pm on November 10, 2015: member
    Wouldn’t compiling+linking an example program w/ -fPIE and Qt be the most sure way to check? Or is there a specific reason you didn’t go that route?
  12. theuni commented at 8:31 pm on November 10, 2015: member
    @laanwj It compiles/links fine with the busted config. So there’s no point in linking if we’re not going to run it, and a run-test is a no-go because it doesn’t work with cross.
  13. theuni commented at 8:33 pm on November 10, 2015: member
    The alternative would be compiling a stub object with fPIE and objdump to check for relocations.
  14. laanwj commented at 8:48 pm on November 10, 2015: member
    Huh are we talking about the same issue? On at least ubuntu 15.10 this fPIE/freduced-relocations conflict causes a build-time issue, not a run-time isue.
  15. laanwj commented at 9:07 pm on November 10, 2015: member

    This is the error I get (one for every executable that uses qt):

    0In file included from /usr/include/x86_64-linux-gnu/qt5/QtCore/qnamespace.h:37:0,
    1                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs.h:41,
    2                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/qobject.h:40,
    3                 from /usr/include/x86_64-linux-gnu/qt5/QtCore/QObject:1,
    4                 from qt/test/uritests.h:8,
    5                 from qt/test/test_main.cpp:10:
    6/usr/include/x86_64-linux-gnu/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)."
    7 #  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
    8    ^
    
  16. theuni commented at 9:15 pm on November 10, 2015: member

    @laanwj Sorry for being unclear. To summarize the issue:

    Qt build can enable -Bsymbolic-functions via the reduce-relocations config option. The qt devs assumed that -fPIC or -fPIE would disable copy-relocations, but gcc5 changed that behavior and allows copy-relocs with -fPIE. So -fPIC is the only way to guarantee that -Bsymbolic-functions will work as intended.

    Source: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65886#c16

    When Qt discovered this issue (somewhere around 5.4), they added the check in qconfig.h so that compilation would fail in this QT_REDUCE_RELOCATIONS+-fPIE case. Prior to that, the check looked like this:

    0#if !defined(QT_BOOTSTRAPPED) && defined(QT_REDUCE_RELOCATIONS) && defined(__ELF__) && !defined(__PIC__) && !defined(__PIE__)
    1#  error "You must build your code with position independent code if Qt was built with -reduce-relocations. "\
    2         "Compile your code with -fPIC or -fPIE."
    3#endif
    

    Just because compiling succeeds in versions with the old check, that does not mean that it’s safe to build/run with gcc5+. So testing to see if something builds against qt+-fPIE is not enough, as older versions weren’t aware of the problem.

  17. laanwj commented at 9:17 pm on November 10, 2015: member
    Ok, fair enough
  18. laanwj merged this on Nov 11, 2015
  19. laanwj closed this on Nov 11, 2015

  20. laanwj referenced this in commit 3ac7060934 on Nov 11, 2015
  21. laanwj commented at 11:55 am on November 11, 2015: member
    Tested ACK.
  22. luke-jr referenced this in commit 90de0e1c2f on Nov 18, 2015
  23. luke-jr referenced this in commit 5c0b357bf6 on Nov 18, 2015
  24. luke-jr referenced this in commit 65cf1b5108 on Nov 27, 2015
  25. luke-jr referenced this in commit f016923570 on Dec 8, 2015
  26. luke-jr referenced this in commit d6fc10cdc0 on Dec 8, 2015
  27. anontahoe commented at 6:29 pm on March 19, 2016: none
    pardon me for necroing this thread but if -fPIC weakens PaX/Grsec patches then i wonder if silently using it as a fallback option is the right way to solve this. maybe a clear warning can be shown and more effort undertaken to convince upstream or package maintainers to ship Qt without reduce-relocations?
  28. zkbot referenced this in commit 75604363cc on Dec 1, 2017
  29. zkbot referenced this in commit 6aef4033a7 on Dec 1, 2017
  30. zkbot referenced this in commit 83af270002 on Dec 15, 2017
  31. kotodev referenced this in commit c8a979fc92 on Jan 25, 2018
  32. renium9 referenced this in commit 23640da445 on Feb 6, 2018
  33. DrahtBot 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