Skip to content

Conversation

fanquake
Copy link
Member

In packages where we are passing -std=c++11 switch to -std=c++17, or, -std=c++1z in the case of Qt.

This PR also contains a commit that improves debug output when building Qt for debugging (DEBUG=1).

Now we'll get output like this:

g++ -c -pipe -ffunction-sections -O2 -fPIC -std=c++11 -fno-exceptions <lots more> ../../corelib/kernel/qcoreapplication.cpp

rather than just:

compiling ../../corelib/kernel/qcoreapplication.cpp

Note that when you look at the DEBUG output for these changes when building Qt, you'll see objects being compiled with a mix of C++11 and C++17. The breakdown is roughly:

  1. qmake built with -std=c++11:
Creating qmake...
make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase/qmake'
g++ -c -o project.o   -std=c++11 -ffunction-sections -O2 -g <trim> <trim>/qt/5.9.8-4110fa99945/qtbase/qmake/project.cpp

# when qmake, Qt also builds some of it's corelib, such as corelib/global/qmalloc.cpp
g++ -c -o qmalloc.o   -std=c++11 -ffunction-sections -O2 -g <trim> <trim>/qt/5.9.8-4110fa99945/qtbase/src/corelib/global/qmalloc.cpp
  1. qmake is run, and passed our build options, including -c++std:
make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase'
<trim>qt/5.9.8-4110fa99945/qtbase/bin/qmake -o Makefile qtbase.pro -- -bindir <trim>/native/bin -c++std c++1z -confirm-license <trim>
  1. After some cleaning and configuring, we actually start to build Qt, as well as it's tools and internal libs:
Building qt...
make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase/src'

# build libpng, zlib etc
gcc -c -m64 -pipe -pipe -O1 <trim> -o .obj/png.o png.c

# build libQt5Bootstrap, using C++11, which again compiles qmalloc.cpp
make[2]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase/src/tools/bootstrap'
g++ -c -pipe -ffunction-sections -O2 -fPIC -std=c++11 <trim> -o .obj/qmalloc.o ../../corelib/global/qmalloc.cpp

# build a bunch of tools like moc, rcc, uic, qfloat16-tables, qdbuscpp2xml, using C++11
g++ -c -pipe -O2 -std=c++11 -fno-exceptions -Wall -W <trim> -o .obj/rcc.o rcc.cpp

# from here, Qt is compiled with -std=c++1z, including qmalloc.cpp, for the third and final time:
g++ -c -include .pch/Qt5Core <trim> -g -Og -fPIC -std=c++1z -fvisibility=hidden <trim> -o .obj/qmalloc.o global/qmalloc.cpp
  1. Finally, build tools like lrelease, lupdate, etc, but back to using -std=c++11
make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qttools/src/linguist/lrelease'
g++ -c -pipe -O2 -std=c++11 -fno-exceptions -Wall -W <trim> -o .obj/translator.o ../shared/translator.cpp

If you dump the debug info from the built Qt libs, they should also tell you that they were compiled with C++17:

objdump -g bitcoin/depends/x86_64-pc-linux-gnu/lib/libQt5Core.a
GNU C++17 9.3.0 -m64 -mtune=generic -march=x86-64 -g -O1 -Og -std=c++17 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection

This means we'll get build output like this when building with DEBUG=1:

g++ -c -pipe -ffunction-sections -O2 -fPIC -std=c++11 -fno-exceptions <lots more> ../../corelib/kernel/qcoreapplication.cpp

rather than just:

compiling ../../corelib/kernel/qcoreapplication.cpp
@maflcko
Copy link
Member

maflcko commented Nov 24, 2020

Is this needed for anything or does this change anything about the binaries? I presume it is needed for qt5.15?

@laanwj
Copy link
Member

laanwj commented Nov 24, 2020

I think it's safer with regard to ABI to compile them with the same standard as the application, definitely for boost. We've seen some problems in that regard in the past.

And especially building with an older C++XX than the application itself could cause some things to be missing that are conditional on the C++XX version.

Note that when you look at the DEBUG output for these changes when building Qt, you'll see objects being compiled with a mix of C++11 and C++17. The breakdown is roughly:

Glad you got it to work eventually to build the library with C++17. It doesn't matter that the intermediate tools are built with C++11. It's a bit strange though that it seems to resist being built with C++17 at every step.

Would this be solved by upgrading Qt?

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 24, 2020

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@practicalswift
Copy link
Contributor

Concept ACK for the reasons given by @laanwj

@fanquake
Copy link
Member Author

Would this be solved by upgrading Qt?

It doesn't look like it. #19716 (Qt 5.15.2) still behaves in the same way when built in c++1z mode.

@laanwj
Copy link
Member

laanwj commented Nov 25, 2020

It doesn't look like it. #19716 (Qt 5.15.2) still behaves in the same way when built in c++1z mode.

OK, good to know. That should be in for 0.22 anyway. I suppose for that version we can also just use c++17 in not need the 1z temporary name.

Code review ACK 2f5dfe4

@fanquake
Copy link
Member Author

I suppose for that version we can also just use c++17 in not need the 1z temporary name.

Yep, we will be able to. 5.15.x understands -c++std c++17.

@hebasto
Copy link
Member

hebasto commented Nov 25, 2020

Concept ACK.

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2f5dfe4, I have reviewed the code and it looks OK, I agree it can be merged.

@practicalswift
Copy link
Contributor

cr ACK 2f5dfe4: patch looks correct

@DrahtBot
Copy link
Contributor

Guix builds

File commit afdfd3c
(master)
commit b76f624
(master and this pull)
*-aarch64-linux-gnu-debug.tar.gz 321e361023e8ea7b... 9da9c1f62c371d60...
*-aarch64-linux-gnu.tar.gz b054d1129516836e... 3e3d8bba7451f10d...
*-arm-linux-gnueabihf-debug.tar.gz cdd6185a356e7a80... a2cf788ddeb262a0...
*-arm-linux-gnueabihf.tar.gz 4db9b1126b6601b7... 0d437227eb7d4c8d...
*-riscv64-linux-gnu-debug.tar.gz df4a6eb0267f7140... ef06c5f32f589def...
*-riscv64-linux-gnu.tar.gz 3ff6d83bd5983e2b... d21af7048218cd49...
*-win-unsigned.tar.gz 0dbc83ed5f22a4db... ab0c761f0ed98d6f...
*-win64-debug.zip 539b210aa13b56bc... 48a47fabb87385a8...
*-win64-setup-unsigned.exe 5ff779deff3db721... ae0cd605e85aa4e9...
*-win64.zip 4e50c84031e8b116... 812b84470b2be3fb...
*-x86_64-linux-gnu-debug.tar.gz 345daa571d3557b0... 9c6ea737387d490d...
*-x86_64-linux-gnu.tar.gz 60655c6fb26e8633... 8005e3e97e21aa4c...
*.tar.gz 0ddcf17cb856ed92... aaa4ca0f4fa2267d...
guix_build.log 6670400b0a6511d0... 366fb8ef0ebc8e02...
guix_build.log.diff e1a27f2e3a782baf...

@fjahr
Copy link
Contributor

fjahr commented Nov 29, 2020

Code review ACK 2f5dfe4

@DrahtBot
Copy link
Contributor

Gitian builds

File commit e2ff5e7
(master)
commit 68f7a5a
(master and this pull)
bitcoin-core-linux-22-res.yml 44e52af36236879f... 77a2fc07bd68d2a6...
bitcoin-core-osx-22-res.yml 71d5fb0e6642d6b0... ae6c70bc0ad8d2d0...
bitcoin-core-win-22-res.yml 0148a2f5e7295184... 4f7dec9db3ccf145...
*-aarch64-linux-gnu-debug.tar.gz 383e84aaa96f342a... 66a5b3246caffba3...
*-aarch64-linux-gnu.tar.gz 3558211891c0484a... 7b103e2df103f0ad...
*-arm-linux-gnueabihf-debug.tar.gz 5ebbb475a590480a... 673dd40fac20ae5a...
*-arm-linux-gnueabihf.tar.gz 60951d893e2688b6... 73c0f0cd908a56ba...
*-osx-unsigned.dmg 7cba6edda598c96c... 815a84ed2581b08f...
*-osx64.tar.gz ea2ab5c893780a2e... 3307b01251079806...
*-riscv64-linux-gnu-debug.tar.gz 0c20a43923efcd5f... b63971f914f260c2...
*-riscv64-linux-gnu.tar.gz 8d3632d81c77eff1... 36291e1691bc7eeb...
*-win64-debug.zip 72c35e133cf9a0db... d633c76c2989b5fd...
*-win64-setup-unsigned.exe 55c17bfff54273e5... 2e09afb90ef49085...
*-win64.zip f7bf6737c7f741c3... 4a493666259a77e0...
*-x86_64-linux-gnu-debug.tar.gz abf91baef5c44686... 9e9cdb28b5876893...
*-x86_64-linux-gnu.tar.gz 75fda490174df335... 131a16fd7423e578...
*.tar.gz 793a2c7af39452d5... 9d6a50076e1ceeb1...
linux-build.log 9c5461a914e1f4c0... e21e0db664dfb49f...
osx-build.log 5adaf67afbaf00fc... 9e059e1e692cca81...
win-build.log 756101ecccffabf0... 2dd93bcee2b46dfd...
bitcoin-core-linux-22-res.yml.diff 38fea8873446f606...
bitcoin-core-osx-22-res.yml.diff 27f413453571eba2...
bitcoin-core-win-22-res.yml.diff dad9947bdcba36eb...
linux-build.log.diff 532c1e5988509e79...
osx-build.log.diff c3201f7816e04e86...
win-build.log.diff 8d907cadd7fbbced...

@fanquake fanquake merged commit 2e1336d into bitcoin:master Nov 30, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 30, 2020
2f5dfe4 depends: build qt in c++17 mode (fanquake)
104e859 builds: don't pass -silent to qt when building in debug mode (fanquake)
e2c5006 depends: build zeromq with -std=c++17 (fanquake)
2374f2f depends: build Boost with -std=c++17 (fanquake)
2dde557 depends: build bdb with -std=c++17 (fanquake)

Pull request description:

  In packages where we are passing `-std=c++11` switch to `-std=c++17`, or, `-std=c++1z` in the case of Qt.

  This PR also contains a [commit](bitcoin@104e859) that improves debug output when building Qt for debugging (`DEBUG=1`).

  Now we'll get output like this:
  ```bash
  g++ -c -pipe -ffunction-sections -O2 -fPIC -std=c++11 -fno-exceptions <lots more> ../../corelib/kernel/qcoreapplication.cpp
  ```
  rather than just:
  ```bash
  compiling ../../corelib/kernel/qcoreapplication.cpp
  ```

  Note that when you look at the DEBUG output for these changes when building Qt, you'll see objects being compiled with a mix of C++11 and C++17. The breakdown is roughly:

  1. `qmake` built with `-std=c++11`:
  ```bash
  Creating qmake...
  make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase/qmake'
  g++ -c -o project.o   -std=c++11 -ffunction-sections -O2 -g <trim> <trim>/qt/5.9.8-4110fa99945/qtbase/qmake/project.cpp

  # when qmake, Qt also builds some of it's corelib, such as corelib/global/qmalloc.cpp
  g++ -c -o qmalloc.o   -std=c++11 -ffunction-sections -O2 -g <trim> <trim>/qt/5.9.8-4110fa99945/qtbase/src/corelib/global/qmalloc.cpp
  ```

  2. `qmake` is run, and passed our build options, including `-c++std`:
  ```bash
  make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase'
  <trim>qt/5.9.8-4110fa99945/qtbase/bin/qmake -o Makefile qtbase.pro -- -bindir <trim>/native/bin -c++std c++1z -confirm-license <trim>
  ```

  3. After some cleaning and configuring, we actually start to build Qt, as well as it's tools and internal libs:
  ```bash
  Building qt...
  make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase/src'

  # build libpng, zlib etc
  gcc -c -m64 -pipe -pipe -O1 <trim> -o .obj/png.o png.c

  # build libQt5Bootstrap, using C++11, which again compiles qmalloc.cpp
  make[2]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qtbase/src/tools/bootstrap'
  g++ -c -pipe -ffunction-sections -O2 -fPIC -std=c++11 <trim> -o .obj/qmalloc.o ../../corelib/global/qmalloc.cpp

  # build a bunch of tools like moc, rcc, uic, qfloat16-tables, qdbuscpp2xml, using C++11
  g++ -c -pipe -O2 -std=c++11 -fno-exceptions -Wall -W <trim> -o .obj/rcc.o rcc.cpp

  # from here, Qt is compiled with -std=c++1z, including qmalloc.cpp, for the third and final time:
  g++ -c -include .pch/Qt5Core <trim> -g -Og -fPIC -std=c++1z -fvisibility=hidden <trim> -o .obj/qmalloc.o global/qmalloc.cpp
  ```

  4.  Finally, build tools like `lrelease`, `lupdate`, etc, but back to using -std=c++11
  ```bash
  make[1]: Entering directory '<trim>/qt/5.9.8-4110fa99945/qttools/src/linguist/lrelease'
  g++ -c -pipe -O2 -std=c++11 -fno-exceptions -Wall -W <trim> -o .obj/translator.o ../shared/translator.cpp
  ```

  If you dump the debug info from the built Qt libs, they should also tell you that they were compiled with `C++17`:
  ```bash
  objdump -g bitcoin/depends/x86_64-pc-linux-gnu/lib/libQt5Core.a
  GNU C++17 9.3.0 -m64 -mtune=generic -march=x86-64 -g -O1 -Og -std=c++17 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -fasynchronous-unwind-tables -fstack-protector-strong -fstack-clash-protection -fcf-protection
  ```

ACKs for top commit:
  laanwj:
    Code review ACK bitcoin@2f5dfe4
  practicalswift:
    cr ACK 2f5dfe4: patch looks correct
  fjahr:
    Code review ACK 2f5dfe4
  hebasto:
    ACK 2f5dfe4, I have reviewed the code and it looks OK, I agree it can be merged.

Tree-SHA512: fc5e9d7c7518c68349c8228fb1aead829850373efc960c9b8c079096a83d1dad19c62a9730fce5802322bf07e320960fd47851420d429eda0a87c307f4e8b03a
fanquake added a commit that referenced this pull request Dec 2, 2020
…rove explicit usage

1e62350 refactor: Improve use of explicit keyword (Fabian Jahr)
c502a6d lint: Use c++17 std in cppcheck linter (Fabian Jahr)

Pull request description:

  I found the `extended-lint-cppcheck` linter still uses `std=c++11` when reviewing #20471. The only difference in the output after this change is one line is missing:

  ```
  src/script/descriptor.cpp:159:5: warning: Struct 'PubkeyProvider' has a constructor with 1 argument that is not explicit. [noExplicitConstructor]
  ```

  After some digging, I am still not sure why this one is ignored with c++17 when 40 other`noExplicitConstructor` warnings were still appearing.

  In the second commit, I fix these warnings, adding `explicit` where appropriate and adding fixes to ignore otherwise.

ACKs for top commit:
  practicalswift:
    cr ACK 1e62350: patch looks correct!
  MarcoFalke:
    review ACK 1e62350

Tree-SHA512: dff7b324429a57160e217cf38d9ddbb6e70c6cb3d3e3e0bd4013d88e07afc2292c3df94d0acf7122e9d486322821682ecf15c8f2724a78667764c05d47f89a12
@fanquake fanquake deleted the depends_c++17 branch February 9, 2021 06:49
MarkLTZ added a commit to litecoinz-core/litecoinz that referenced this pull request Feb 16, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jul 13, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jul 15, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jul 15, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Jul 17, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 11, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 11, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 15, 2021
kwvg added a commit to kwvg/dash that referenced this pull request Sep 15, 2021
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 19, 2021
thelazier pushed a commit to thelazier/dash that referenced this pull request Sep 25, 2021
gades pushed a commit to cosanta/cosanta-core that referenced this pull request May 2, 2022
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants