build: Use Link Time Optimization for Qt code on Linux #25542

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:220705-ltcg changing 2 files +4 −0
  1. hebasto commented at 10:05 am on July 5, 2022: member

    See: https://www.qt.io/blog/2019/01/02/qt-applications-lto

    bitcon-qt unstripped size:

    host master (31c6309cc60ae3fee2d3ecc2aff9576596fb98ac) this PR, depends built with LTO=1
    x86_64-pc-linux-gnu 42 MB 35 MB
    arm-linux-gnueabihf 31 MB 26 MB
    aarch64-linux-gnu 41 MB 32 MB
    powerpc64-linux-gnu 51 MB 41 MB
    powerpc64le-linux-gnu 48 MB 39 MB
    riscv64-linux-gnu 35 MB 29 MB

    Based on the first commit from bitcoin/bitcoin#25391.

    Using LTO for macOS and Windows hosts has some issues which could be addressed in follow ups.

    x86_64 build: image

  2. fanquake commented at 10:36 am on July 5, 2022: member
    Last I checked this basically didn’t work for anything other than x86_64 Linux, but if that’s no-longer the case, that could be handy.
  3. DrahtBot added the label Build system on Jul 5, 2022
  4. kristapsk commented at 11:14 pm on July 6, 2022: contributor

    Last I checked this basically didn’t work for anything other than x86_64 Linux, but if that’s no-longer the case, that could be handy.

    I tthink this could be useful even if it works only for x86_64 Linux.

  5. in depends/packages/qt.mk:44 in d5278cb7c0 outdated
    39@@ -40,6 +40,7 @@ $(package)_config_opts += -bindir $(build_prefix)/bin
    40 $(package)_config_opts += -c++std c++17
    41 $(package)_config_opts += -confirm-license
    42 $(package)_config_opts += -hostprefix $(build_prefix)
    43+$(package)_config_opts += -ltcg
    


    fanquake commented at 12:00 pm on July 13, 2022:

    I think this could be a good starting point, assuming our configure checks also work. I haven’t tested yet.

     0--- a/depends/packages/qt.mk
     1+++ b/depends/packages/qt.mk
     2@@ -159,6 +159,9 @@ $(package)_config_opts_x86_64_linux = -xplatform linux-clang-libc++
     3 else
     4 $(package)_config_opts_x86_64_linux = -xplatform linux-g++-64
     5 endif
     6+ifneq ($(LTO),)
     7+$(package)_config_opts_x86_64_linux += -ltcg
     8+endif
     9 $(package)_config_opts_aarch64_linux = -xplatform linux-aarch64-gnu-g++
    10 $(package)_config_opts_powerpc64_linux = -platform linux-g++ -xplatform bitcoin-linux-g++
    11 $(package)_config_opts_powerpc64le_linux = -platform linux-g++ -xplatform bitcoin-linux-g++
    
  6. hebasto force-pushed on Jul 13, 2022
  7. hebasto renamed this:
    build: Use Link Time Optimization for Qt code
    build: Use Link Time Optimization for Qt code on Linux
    on Jul 14, 2022
  8. hebasto marked this as ready for review on Jul 14, 2022
  9. hebasto force-pushed on Jul 14, 2022
  10. hebasto requested review from fanquake on Jul 14, 2022
  11. build: pass -fno-lto when building expat
    Otherwise it's autoconf endianess check will fail to determine what the
    endianess is..
    ebce66e532
  12. build: Use Link Time Optimization for Qt code on Linux
    See: https://www.qt.io/blog/2019/01/02/qt-applications-lto
    3442865360
  13. in depends/packages/qt.mk:156 in 7c5d7dc780 outdated
    150@@ -152,6 +151,11 @@ $(package)_config_opts_linux += -fontconfig
    151 $(package)_config_opts_linux += -no-opengl
    152 $(package)_config_opts_linux += -no-feature-vulkan
    153 $(package)_config_opts_linux += -dbus-runtime
    154+ifneq ($(LTO),)
    155+# See https://wiki.qt.io/Performance_Tip_Startup_Time
    156+$(package)_config_opts_linux += -reduce-relocations
    


    fanquake commented at 1:17 pm on July 15, 2022:

    I think we should keep this as $(package)_config_opts_x86_64_linux for now. I’m still seeing build issues for all other Linux HOSTS. i.e for aarch64:

     0Trying source 1 (type inline) of library xcb_xinput ...
     1+ cd /home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/config.tests/xcb_xinput && PKG_CONFIG_SYSROOT_DIR=/ PKG_CONFIG_LIBDIR=/home/ubuntu/bitcoin/depends/aarch64-linux-gnu/lib/pkgconfig /home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/qtbase/bin/qmake "CONFIG -= qt debug_and_release app_bundle lib_bundle" "CONFIG += static warn_off console single_arch" -early "CONFIG += cross_compile" 'QMAKE_USE += xcb_xinput' 'QMAKE_LIBS_XCB_XINPUT = -lxcb-xinput' 'QMAKE_DEPENDS_XCB_XINPUT_CC = XCB' 'QMAKE_DEPENDS_XCB_XINPUT_LD = XCB' 'QMAKE_LIBS_XCB = -L//home/ubuntu/bitcoin/depends/aarch64-linux-gnu/lib -lxcb' 'QMAKE_INCDIR_XCB = //home/ubuntu/bitcoin/depends/aarch64-linux-gnu/include' /home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/config.tests/xcb_xinput
     2+ cd /home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/config.tests/xcb_xinput && MAKEFLAGS= /usr/bin/gmake
     3> gmake[1]: Entering directory '/home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/config.tests/xcb_xinput'
     4> aarch64-linux-gnu-g++ -c -pipe -pipe -std=c++17 -flto -O2 -I/home/ubuntu/bitcoin/depends/aarch64-linux-gnu/include -O2 -w -fPIC  -I. -I/home/ubuntu/bitcoin/depends/aarch64-linux-gnu/include -I/home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/qtbase/mkspecs/linux-aarch64-gnu-g++ -o main.o main.cpp
     5> aarch64-linux-gnu-g++ -flto -L/home/ubuntu/bitcoin/depends/aarch64-linux-gnu/lib -Wl,-O1 -o xcb_xinput main.o   -lxcb-xinput -L//home/ubuntu/bitcoin/depends/aarch64-linux-gnu/lib -lxcb   
     6> /usr/lib/gcc-cross/aarch64-linux-gnu/11/../../../../aarch64-linux-gnu/bin/ld: cannot find -lxcb-xinput: No such file or directory
     7> collect2: error: ld returned 1 exit status
     8> gmake[1]: *** [Makefile:67: xcb_xinput] Error 1
     9> gmake[1]: Leaving directory '/home/ubuntu/bitcoin/depends/work/build/aarch64-linux-gnu/qt/5.15.3-4ca304a51a3/config.tests/xcb_xinput'
    10 => source failed verification.
    11test config.qtbase_gui.libraries.xcb_xinput FAILED
    

    hebasto commented at 0:56 am on July 16, 2022:

    Changing of the -reduce-relocations flag dropped from this PR for now.

    More details available in https://bugreports.qt.io/browse/QTBUG-36129

  14. hebasto force-pushed on Jul 15, 2022
  15. fanquake approved
  16. fanquake commented at 9:38 am on July 18, 2022: member

    ACK 3442865360b18b757aee718de585c31e28c457ce

    I’ve tested this branch + #25391 + a change to allow for additional symbol exports for bitcoin-qt, and the Guix + LTO Linux builds are working. I have not tested or run bitcoin-qt.

  17. fanquake merged this on Jul 18, 2022
  18. fanquake closed this on Jul 18, 2022

  19. hebasto deleted the branch on Jul 18, 2022
  20. sidhujag referenced this in commit 040c573317 on Jul 18, 2022
  21. kittywhiskers referenced this in commit 85e4bf0cdf on Jul 3, 2023
  22. kittywhiskers referenced this in commit 1e4beea85f on Jul 3, 2023
  23. kittywhiskers referenced this in commit e333806200 on Jul 4, 2023
  24. bitcoin locked this on Jul 18, 2023

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-07-03 10:13 UTC

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