depends: build LTO support into Apple’s ld64 #19530

pull theuni wants to merge 2 commits into bitcoin:master from theuni:darwin-lto changing 1 files +4 −3
  1. theuni commented at 8:57 pm on July 15, 2020: member

    This didn’t work for a few reasons (various toolchain compatibility issues) the last time I tested it, but after the last round of bumps it works with no apparent issues.

    Note that this does not enable LTO by default in any way, only hooks up the machinery for -flto to work correctly when specified.

    Lines were split for an easier rebase after #17919 is merged.

  2. fanquake added the label Build system on Jul 15, 2020
  3. fanquake commented at 1:00 pm on July 16, 2020: member
    Concept ACK 🚀
  4. depends: enable lto support for Apple's ld64
    Note that this does not _enable_ lto by default in any way, only hooks up the
    machinery for -flto to work correctly.
    
    enable-lto-support is explicitly used for pinned-clang because we know it
    works. It is neither enabled nor disabled in the external clang case so that
    it can be auto-detected.
    00d1ba7aaa
  5. depends: bump native_cctools for fixed lto with external clang
    https://github.com/tpoechtrager/cctools-port/pull/85 was merged upstream, which
    fixes lto detection for external clang with some Linux Distro's including
    Ubuntu.
    5962522fbc
  6. theuni force-pushed on Jul 16, 2020
  7. theuni commented at 8:06 pm on July 16, 2020: member

    Rebased after #17919 .

    Also added another commit after https://github.com/tpoechtrager/cctools-port/pull/85 was merged upstream to fix lto detection with external clang.

  8. fanquake commented at 2:44 am on July 17, 2020: member

    Checked out this branch at https://github.com/bitcoin/bitcoin/pull/19530/commits/5962522fbcb7b72c269fc271ac4463791a103918 and did a make -C depends/ -j6 HOST=x86_64-apple-darwin16. I’m seeing:

     0[ 97%] Building C object genisoimage/CMakeFiles/genisoimage.dir/endian.o
     1[ 97%] Building C object genisoimage/CMakeFiles/genisoimage.dir/sha1.o
     2[ 97%] Building C object genisoimage/CMakeFiles/genisoimage.dir/sha256.o
     3[ 98%] Building C object genisoimage/CMakeFiles/genisoimage.dir/sha512.o
     4[ 98%] Building C object genisoimage/CMakeFiles/genisoimage.dir/checksum.o
     5[100%] Linking C executable genisoimage
     6/usr/bin/ld: CMakeFiles/genisoimage.dir/apple.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
     7/usr/bin/ld: CMakeFiles/genisoimage.dir/boot.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
     8/usr/bin/ld: CMakeFiles/genisoimage.dir/desktop.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
     9/usr/bin/ld: CMakeFiles/genisoimage.dir/dvd_file.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    10/usr/bin/ld: CMakeFiles/genisoimage.dir/dvd_reader.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    11/usr/bin/ld: CMakeFiles/genisoimage.dir/eltorito.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    12/usr/bin/ld: CMakeFiles/genisoimage.dir/files.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    13/usr/bin/ld: CMakeFiles/genisoimage.dir/hash.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    14/usr/bin/ld: CMakeFiles/genisoimage.dir/ifo_read.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    15/usr/bin/ld: CMakeFiles/genisoimage.dir/joliet.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    16/usr/bin/ld: CMakeFiles/genisoimage.dir/mac_label.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    17/usr/bin/ld: CMakeFiles/genisoimage.dir/multi.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    18/usr/bin/ld: CMakeFiles/genisoimage.dir/name.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    19/usr/bin/ld: CMakeFiles/genisoimage.dir/rock.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    20/usr/bin/ld: CMakeFiles/genisoimage.dir/scsi.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    21/usr/bin/ld: CMakeFiles/genisoimage.dir/stream.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    22/usr/bin/ld: CMakeFiles/genisoimage.dir/tree.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    23/usr/bin/ld: CMakeFiles/genisoimage.dir/udf.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    24/usr/bin/ld: CMakeFiles/genisoimage.dir/volume.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    25/usr/bin/ld: CMakeFiles/genisoimage.dir/write.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    26/usr/bin/ld: CMakeFiles/genisoimage.dir/boot-alpha.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    27/usr/bin/ld: CMakeFiles/genisoimage.dir/boot-hppa.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    28/usr/bin/ld: CMakeFiles/genisoimage.dir/boot-mips.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    29/usr/bin/ld: CMakeFiles/genisoimage.dir/jte.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    30/usr/bin/ld: CMakeFiles/genisoimage.dir/rsync.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    31/usr/bin/ld: CMakeFiles/genisoimage.dir/boot-mipsel.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    32/usr/bin/ld: CMakeFiles/genisoimage.dir/checksum.o:(.bss+0x0): multiple definition of `outfile'; CMakeFiles/genisoimage.dir/genisoimage.o:(.bss+0x0): first defined here
    33collect2: error: ld returned 1 exit status
    

    Have not investigated further.

  9. fanquake added the label Needs gitian build on Jul 17, 2020
  10. theuni commented at 12:53 pm on July 17, 2020: member

    @fanquake Strange… this is fine locally, and our c-i didn’t have any trouble with it either.

    Is the problem locally reproducible?

  11. theuni commented at 3:21 pm on July 17, 2020: member

    For me, builds of bitcoind and bitcoin-qt even succeed with lto enabled for dependencies as well with the following hack:

     0diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk
     1index 6099fd4c71..c4180ac2f8 100644
     2--- a/depends/hosts/darwin.mk
     3+++ b/depends/hosts/darwin.mk
     4@@ -28,8 +28,8 @@ OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-
     5 #         https://reviews.llvm.org/D64089, we should use that instead. Read the
     6 #         differential summary there for more details.
     7 #
     8-darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin
     9-darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -stdlib=libc++ -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1
    10+darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin -flto=thin
    11+darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -stdlib=libc++ -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1 -flto=thin
    12
    13 darwin_CFLAGS=-pipe
    14 darwin_CXXFLAGS=$(darwin_CFLAGS)
    

    It’s almost suspicious how well/easily that worked. I’ll dig further to make sure it’s actually doing full lto under the hood.

  12. DrahtBot commented at 5:56 pm on July 18, 2020: member

    Gitian builds

    File commit fd59670642f511523570607b752ae409b5e04e7d(master) commit 3fa897a0ef921a446dfb46d929c22038e367b837(master and this pull)
    bitcoin-core-linux-0.21-res.yml 505c6e4b3d5cb53e... fed919dada1dd203...
    bitcoin-core-osx-0.21-res.yml 59e47553324c4d43... a61dd55ddf53cd1f...
    bitcoin-core-win-0.21-res.yml 8b4d3e18c2e7e44c... 0c74f587c29bdb8d...
    *-aarch64-linux-gnu-debug.tar.gz 8e7308cd154a8b01... 78d04b4e71c541b2...
    *-aarch64-linux-gnu.tar.gz 7c3675372886dbf7... 122ff48d3bfeda45...
    *-arm-linux-gnueabihf-debug.tar.gz 01b2ece9ca424ef4... ba155e8de4be8cf5...
    *-arm-linux-gnueabihf.tar.gz 45215523beb58f6d... c19fca4bd6375f94...
    *-osx-unsigned.dmg 314f2723be4b2f70... 918ee034b90ff53a...
    *-osx64.tar.gz c6bfc447a2ef1334... 8ad996a5c35c3d09...
    *-riscv64-linux-gnu-debug.tar.gz 124dfbac07ea1e64... 6e916f614aefa5d3...
    *-riscv64-linux-gnu.tar.gz 22bfb0fc4218d285... c8e0d75cb99273eb...
    *-win64-debug.zip 75f1b9e8e0aab430... 25f869a98d19b23b...
    *-win64-setup-unsigned.exe 3fb66c88b0126fb3... f0ec2840dbd17c09...
    *-win64.zip de89cf52803db359... 49e5fb3efd3b15b5...
    *-x86_64-linux-gnu-debug.tar.gz a587a7333cb2823b... 1e4cfb67952e009d...
    *-x86_64-linux-gnu.tar.gz 73dd22b3be507039... d121aa1d85662008...
    *.tar.gz 005ff019045bb0a4... 990f86ded9a6aff3...
    linux-build.log 6201e9df0f29f327... 13477b89192ddeb0...
    osx-build.log 83cd2a61f8a16ecb... 090d2b71ffbd54f0...
    win-build.log 49cc23d322018d48... 49d1ce2ed45e5506...
    bitcoin-core-linux-0.21-res.yml.diff 9d3d37d52750777d...
    bitcoin-core-osx-0.21-res.yml.diff 56adcd0fba885953...
    bitcoin-core-win-0.21-res.yml.diff d8d9b7eac8b6c98b...
    linux-build.log.diff 34eea87cd725d194...
    osx-build.log.diff 57bf2ca7d604d02e...
    win-build.log.diff d2b07e2dda38edf6...
  13. DrahtBot removed the label Needs gitian build on Jul 18, 2020
  14. fanquake commented at 7:28 am on July 19, 2020: member

    @fanquake Strange… this is fine locally, and our c-i didn’t have any trouble with it either. Is the problem locally reproducible?

    Yes. Turns out the issue is actually a change in defaults in GCC 10.1. See #19553. In the mean time, I’ll retest here with an earlier GCC.

  15. fanquake referenced this in commit ef3d4ce4c3 on Jul 22, 2020
  16. laanwj referenced this in commit c7b4968552 on Jul 22, 2020
  17. laanwj commented at 3:13 pm on July 22, 2020: member
    Concept ACK, even though we don’t use LTO for builds currently, if it isn’t unnecessary to disable it explicitly in the toolchain, we shouldn’t.
  18. theuni commented at 10:45 pm on July 23, 2020: member

    Continuing the conversation from #19565:

    The solution seemed to be to pass -object_path_lto through to ld64. Doing that I end up with a properly generated .dSYM:

    I think I understand what’s happening here. From the clang docs

     0  The default for :option:`-flto` is "full", in which the
     1  LLVM bitcode is suitable for monolithic Link Time Optimization (LTO), where
     2  the linker merges all such modules into a single combined module for
     3  optimization. With "thin", :doc:`ThinLTO <../ThinLTO>`
     4  compilation is invoked instead.
     5
     6  .. note::
     7
     8     On Darwin, when using :option:`-flto` along with :option:`-g` and
     9     compiling and linking in separate steps, you also need to pass
    10     ``-Wl,-object_path_lto,<lto-filename>.o`` at the linking step to instruct the
    11     ld64 linker not to delete the temporary object file generated during Link
    12     Time Optimization (this flag is automatically passed to the linker by Clang
    13     if compilation and linking are done in a single step). This allows debugging
    14     the executable as well as generating the ``.dSYM`` bundle using :manpage:`dsymutil(1)`.
    

    That’s describing us.

    The machinery to get clang to do this for you only applies when compiling and linking at the same time. Here’s a comment from elsewhere explaining why:

    0      // Add a 'dsymutil' step if necessary, when debug info is enabled and we
    1      // have a compile input. We need to run 'dsymutil' ourselves in such cases
    2      // because the debug info will refer to a temporary object file which
    3      // will be removed at the end of the compilation process.
    

    I can confirm that is working as intended with a test-case:

    $ cat lto1.cpp lto2.cpp

     0//lto1.cpp
     1void MyFunc();
     2int main(){
     3MyFunc();
     4}
     5//lto2.cpp
     6#include <stdio.h>
     7void MyFunc()
     8{
     9    printf("hello world\n");
    10}
    

    $ clang++ -target x86_64-apple-darwin16 -mmacosx-version-min=10.12 –sysroot /home/cory/dev/bitcoin2/depends/SDKs/Xcode-11.3.1-11C505-extracted-SDK-with-libcxx-headers -stdlib=libc++ -mlinker-version=530 -B/home/cory/dev/bitcoin2/depends/x86_64-apple-darwin16/native/bin -nostdinc++ -isystem /home/cory/dev/bitcoin2/depends/SDKs/Xcode-11.3.1-11C505-extracted-SDK-with-libcxx-headers/usr/include/c++/v1 -flto=thin -std=c++11 lto1.cpp lto2.cpp -v

    Which produces the following link line and calls dsymutil:

    “/home/cory/dev/bitcoin2/depends/x86_64-apple-darwin16/native/bin/x86_64-apple-darwin16-ld” -demangle -object_path_lto /tmp/thinlto-d130c2 -lto_library /home/cory/dev/llvm-project/build/lib/libLTO.so -no_deduplicate -dynamic -arch x86_64 -platform_version macos 10.12.0 0.0.0 -syslibroot /home/cory/dev/bitcoin2/depends/SDKs/Xcode-11.3.1-11C505-extracted-SDK-with-libcxx-headers -o a.out /tmp/lto1-bd26d0.o /tmp/lto2-439b81.o -lc++ -lSystem "/home/cory/dev/llvm-project/build/bin/dsymutil" -o a.out.dSYM a.out

    So, it sounds as though everything is actually working as intended. We just need to add that link flag if lto and debugging are on. But we’re getting ahead of ourselves, as we don’t have an option for lto yet :)

  19. fanquake referenced this in commit 007e15dcd7 on Jul 24, 2020
  20. naumenkogs referenced this in commit 1c73c54479 on Jul 24, 2020
  21. sidhujag referenced this in commit 26b9a95b92 on Jul 24, 2020
  22. sidhujag referenced this in commit 72a7a0e88b on Jul 24, 2020
  23. sidhujag referenced this in commit ff4a47add1 on Jul 24, 2020
  24. fanquake approved
  25. fanquake commented at 7:41 am on July 28, 2020: member
    ACK 5962522fbcb7b72c269fc271ac4463791a103918. The relevant option upstream is here.
  26. fanquake merged this on Jul 28, 2020
  27. fanquake closed this on Jul 28, 2020

  28. sidhujag referenced this in commit aad54d66aa on Jul 28, 2020
  29. zkbot referenced this in commit 2a39656e6d on Jul 30, 2020
  30. Warchant referenced this in commit 3b5baf7709 on Aug 6, 2020
  31. zkbot referenced this in commit e0692ed4df on Aug 7, 2020
  32. deadalnix referenced this in commit 9e3969ba97 on Jan 5, 2021
  33. furszy referenced this in commit 816f42d7ac on May 25, 2021
  34. PastaPastaPasta referenced this in commit 53ed3f6697 on Jun 27, 2021
  35. PastaPastaPasta referenced this in commit 22165582ec on Jun 28, 2021
  36. PastaPastaPasta referenced this in commit 19bd7eb467 on Jun 29, 2021
  37. PastaPastaPasta referenced this in commit 08a97ffed1 on Jul 1, 2021
  38. PastaPastaPasta referenced this in commit 3e33950447 on Jul 1, 2021
  39. PastaPastaPasta referenced this in commit c3a4b8ea1b on Jul 15, 2021
  40. PastaPastaPasta referenced this in commit ca2d095489 on Jul 16, 2021
  41. kittywhiskers referenced this in commit 9f97a97a11 on Aug 24, 2021
  42. kittywhiskers referenced this in commit e7a28348a0 on Aug 24, 2021
  43. kittywhiskers referenced this in commit cbe90ef8eb on Aug 24, 2021
  44. kittywhiskers referenced this in commit 0220032161 on Aug 24, 2021
  45. kittywhiskers referenced this in commit 7686acc1a5 on Aug 24, 2021
  46. kittywhiskers referenced this in commit be1b17355e on Aug 24, 2021
  47. kittywhiskers referenced this in commit b86adc79fc on Aug 25, 2021
  48. kittywhiskers referenced this in commit 1ab73d5e71 on Aug 25, 2021
  49. kittywhiskers referenced this in commit ebe5a0c20a on Aug 26, 2021
  50. kittywhiskers referenced this in commit 2ec15d3d75 on Aug 26, 2021
  51. kittywhiskers referenced this in commit 62dc66ce3d on Aug 26, 2021
  52. kittywhiskers referenced this in commit f9ba0f6995 on Aug 27, 2021
  53. kittywhiskers referenced this in commit 17e32dd03f on Aug 30, 2021
  54. kittywhiskers referenced this in commit bba2bd4b7b on Sep 1, 2021
  55. kittywhiskers referenced this in commit 66f68786c6 on Sep 1, 2021
  56. kittywhiskers referenced this in commit cc575e6f0c on Sep 2, 2021
  57. kittywhiskers referenced this in commit d3c22d9474 on Sep 3, 2021
  58. kittywhiskers referenced this in commit 9f2019b36b on Sep 3, 2021
  59. kittywhiskers referenced this in commit 9c81cd1e82 on Sep 3, 2021
  60. kittywhiskers referenced this in commit adbc5f1dde on Sep 4, 2021
  61. DrahtBot locked this on Feb 15, 2022

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-11-23 18:12 UTC

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