From 08650c099f70d415875221092f6e3224525ef6f5 Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Thu, 23 May 2024 14:07:42 +0800 Subject: [PATCH] add LLVM copy from nixpkgs --- flake.lock | 6 +- flake.nix | 14 +- llvm/10/clang/compiler-rt-baremetal.patch | 53 ++ llvm/10/clang/default.nix | 133 ++++ llvm/10/clang/gnu-install-dirs.patch | 248 ++++++++ llvm/10/clang/purity.patch | 30 + .../compiler-rt/X86-support-extension.patch | 23 + llvm/10/compiler-rt/armv7l.patch | 32 + llvm/10/compiler-rt/default.nix | 131 ++++ .../compiler-rt/find-darwin-sdk-version.patch | 62 ++ llvm/10/compiler-rt/gnu-install-dirs.patch | 129 ++++ llvm/10/default.nix | 284 +++++++++ llvm/10/libcxx/default.nix | 88 +++ llvm/10/libcxx/gnu-install-dirs.patch | 99 +++ llvm/10/libcxxabi/default.nix | 85 +++ llvm/10/libcxxabi/gnu-install-dirs.patch | 34 + llvm/10/libunwind/default.nix | 32 + llvm/10/libunwind/gnu-install-dirs.patch | 34 + llvm/10/lld/default.nix | 46 ++ llvm/10/lld/gnu-install-dirs.patch | 68 ++ llvm/10/lldb/gnu-install-dirs.patch | 91 +++ llvm/10/lldb/procfs.patch | 31 + llvm/10/llvm/default.nix | 355 +++++++++++ llvm/10/llvm/gnu-install-dirs-polly.patch | 106 ++++ llvm/10/llvm/gnu-install-dirs.patch | 416 ++++++++++++ llvm/10/openmp/default.nix | 37 ++ llvm/11/clang/default.nix | 138 ++++ llvm/11/clang/gnu-install-dirs.patch | 235 +++++++ llvm/11/clang/purity.patch | 28 + .../compiler-rt/X86-support-extension.patch | 23 + llvm/11/compiler-rt/armv7l.patch | 32 + llvm/11/compiler-rt/default.nix | 140 +++++ llvm/11/compiler-rt/gnu-install-dirs.patch | 129 ++++ llvm/11/compiler-rt/normalize-var.patch | 16 + llvm/11/default.nix | 299 +++++++++ llvm/11/libcxx/default.nix | 104 +++ llvm/11/libcxx/gnu-install-dirs.patch | 100 +++ llvm/11/libcxxabi/default.nix | 89 +++ llvm/11/libcxxabi/gnu-install-dirs.patch | 34 + llvm/11/libunwind/default.nix | 32 + llvm/11/libunwind/gnu-install-dirs.patch | 34 + llvm/11/lld/default.nix | 46 ++ llvm/11/lld/gnu-install-dirs.patch | 68 ++ llvm/11/lldb/gnu-install-dirs.patch | 91 +++ llvm/11/lldb/procfs.patch | 31 + llvm/11/llvm/default.nix | 363 +++++++++++ llvm/11/llvm/gnu-install-dirs-polly.patch | 106 ++++ llvm/11/llvm/gnu-install-dirs.patch | 417 ++++++++++++ llvm/11/openmp/default.nix | 47 ++ llvm/12/clang/default.nix | 132 ++++ llvm/12/clang/gnu-install-dirs.patch | 235 +++++++ llvm/12/clang/purity.patch | 28 + .../compiler-rt/X86-support-extension.patch | 21 + llvm/12/compiler-rt/armv7l.patch | 32 + llvm/12/compiler-rt/default.nix | 125 ++++ llvm/12/compiler-rt/gnu-install-dirs.patch | 129 ++++ llvm/12/compiler-rt/normalize-var.patch | 16 + llvm/12/default.nix | 300 +++++++++ llvm/12/libcxx/default.nix | 79 +++ llvm/12/libcxx/gnu-install-dirs.patch | 100 +++ llvm/12/libcxxabi/default.nix | 87 +++ llvm/12/libcxxabi/gnu-install-dirs.patch | 34 + llvm/12/libunwind/default.nix | 39 ++ llvm/12/libunwind/gnu-install-dirs.patch | 34 + llvm/12/lld/default.nix | 54 ++ llvm/12/lld/gnu-install-dirs.patch | 68 ++ llvm/12/lldb/gnu-install-dirs.patch | 91 +++ llvm/12/lldb/procfs.patch | 31 + llvm/12/lldb/resource-dir.patch | 13 + llvm/12/llvm/default.nix | 351 +++++++++++ llvm/12/llvm/fix-llvm-issue-49955.patch | 13 + llvm/12/llvm/gnu-install-dirs-polly.patch | 105 ++++ llvm/12/llvm/gnu-install-dirs.patch | 417 ++++++++++++ llvm/12/openmp/default.nix | 48 ++ llvm/13/clang/default.nix | 126 ++++ llvm/13/clang/gnu-install-dirs.patch | 235 +++++++ llvm/13/clang/purity.patch | 28 + .../revert-malloc-alignment-assumption.patch | 78 +++ .../compiler-rt/X86-support-extension.patch | 21 + llvm/13/compiler-rt/armv7l.patch | 31 + llvm/13/compiler-rt/codesign.patch | 33 + .../darwin-targetconditionals.patch | 71 +++ llvm/13/compiler-rt/default.nix | 132 ++++ llvm/13/compiler-rt/normalize-var.patch | 16 + llvm/13/default.nix | 322 ++++++++++ llvm/13/libcxx/default.nix | 92 +++ llvm/13/libcxx/gnu-install-dirs.patch | 82 +++ llvm/13/libcxxabi/default.nix | 84 +++ llvm/13/libcxxabi/gnu-install-dirs.patch | 37 ++ llvm/13/libunwind/default.nix | 33 + llvm/13/libunwind/gnu-install-dirs.patch | 36 ++ llvm/13/lld/default.nix | 55 ++ llvm/13/lld/gnu-install-dirs.patch | 68 ++ .../lldb/cpu_subtype_arm64e_replacement.patch | 12 + llvm/13/lldb/gnu-install-dirs.patch | 91 +++ llvm/13/lldb/procfs.patch | 31 + llvm/13/lldb/resource-dir.patch | 13 + llvm/13/llvm/default.nix | 313 +++++++++ llvm/13/llvm/gnu-install-dirs-polly.patch | 105 ++++ llvm/13/llvm/gnu-install-dirs.patch | 381 +++++++++++ llvm/13/openmp/default.nix | 53 ++ llvm/14/clang/default.nix | 129 ++++ llvm/14/clang/gnu-install-dirs.patch | 50 ++ llvm/14/clang/purity.patch | 28 + .../compiler-rt/X86-support-extension.patch | 21 + llvm/14/compiler-rt/armv7l.patch | 31 + llvm/14/compiler-rt/codesign.patch | 33 + .../darwin-targetconditionals.patch | 71 +++ llvm/14/compiler-rt/default.nix | 141 +++++ llvm/14/compiler-rt/gnu-install-dirs.patch | 42 ++ llvm/14/compiler-rt/normalize-var.patch | 16 + llvm/14/default.nix | 320 ++++++++++ llvm/14/libcxx/default.nix | 98 +++ llvm/14/libcxx/gnu-install-dirs.patch | 21 + llvm/14/libcxxabi/default.nix | 103 +++ llvm/14/libcxxabi/gnu-install-dirs.patch | 22 + llvm/14/libunwind/default.nix | 47 ++ llvm/14/libunwind/gnu-install-dirs.patch | 21 + llvm/14/lld/default.nix | 58 ++ llvm/14/lld/fix-root-src-dir.patch | 13 + llvm/14/lld/gnu-install-dirs.patch | 22 + .../lldb/cpu_subtype_arm64e_replacement.patch | 12 + llvm/14/lldb/gnu-install-dirs.patch | 67 ++ llvm/14/lldb/procfs.patch | 31 + llvm/14/lldb/resource-dir.patch | 13 + llvm/14/llvm/default.nix | 315 ++++++++++ llvm/14/llvm/gnu-install-dirs-polly.patch | 19 + llvm/14/llvm/gnu-install-dirs.patch | 220 +++++++ llvm/14/openmp/default.nix | 69 ++ llvm/14/openmp/gnu-install-dirs.patch | 45 ++ llvm/14/openmp/run-lit-directly.patch | 12 + llvm/15/clang/default.nix | 138 ++++ llvm/15/clang/gnu-install-dirs.patch | 105 ++++ llvm/15/clang/purity.patch | 29 + .../compiler-rt/X86-support-extension.patch | 21 + .../darwin-targetconditionals.patch | 71 +++ llvm/15/compiler-rt/default.nix | 140 +++++ llvm/15/compiler-rt/gnu-install-dirs.patch | 20 + llvm/15/compiler-rt/normalize-var.patch | 16 + llvm/15/default.nix | 403 ++++++++++++ llvm/15/libcxx/default.nix | 131 ++++ llvm/15/libcxx/gnu-install-dirs.patch | 22 + llvm/15/libcxxabi/default.nix | 113 ++++ llvm/15/libcxxabi/gnu-install-dirs.patch | 22 + llvm/15/libunwind/default.nix | 67 ++ llvm/15/libunwind/gnu-install-dirs.patch | 22 + llvm/15/lld/default.nix | 57 ++ llvm/15/lld/gnu-install-dirs.patch | 46 ++ .../lldb/cpu_subtype_arm64e_replacement.patch | 12 + llvm/15/lldb/gnu-install-dirs.patch | 23 + llvm/15/lldb/procfs.patch | 46 ++ llvm/15/lldb/resource-dir.patch | 13 + llvm/15/llvm/default.nix | 440 +++++++++++++ llvm/15/llvm/gnu-install-dirs-polly.patch | 19 + llvm/15/llvm/gnu-install-dirs.patch | 138 ++++ ...-script-runner-set-dyld-library-path.patch | 26 + .../llvm-lit-cfg-add-libs-to-dylib-path.patch | 79 +++ ...polly-lit-cfg-add-libs-to-dylib-path.patch | 24 + llvm/15/openmp/default.nix | 74 +++ llvm/15/openmp/fix-find-tool.patch | 18 + llvm/15/openmp/gnu-install-dirs.patch | 22 + llvm/15/openmp/run-lit-directly.patch | 12 + llvm/16/clang/default.nix | 133 ++++ llvm/16/clang/gnu-install-dirs.patch | 109 ++++ llvm/16/clang/purity.patch | 29 + .../compiler-rt/X86-support-extension.patch | 21 + .../darwin-targetconditionals.patch | 71 +++ llvm/16/compiler-rt/default.nix | 154 +++++ llvm/16/compiler-rt/gnu-install-dirs.patch | 20 + llvm/16/compiler-rt/normalize-var.patch | 16 + llvm/16/default.nix | 414 ++++++++++++ llvm/16/libclc/default.nix | 54 ++ llvm/16/libclc/libclc-gnu-install-dirs.patch | 10 + llvm/16/libcxx/default.nix | 118 ++++ llvm/16/libcxx/gnu-install-dirs.patch | 22 + llvm/16/libcxxabi/default.nix | 114 ++++ llvm/16/libcxxabi/gnu-install-dirs.patch | 22 + llvm/16/libunwind/default.nix | 67 ++ llvm/16/libunwind/gnu-install-dirs.patch | 22 + llvm/16/lld/add-table-base.patch | 190 ++++++ llvm/16/lld/default.nix | 58 ++ llvm/16/lld/gnu-install-dirs.patch | 46 ++ .../lldb/cpu_subtype_arm64e_replacement.patch | 12 + llvm/16/lldb/gnu-install-dirs.patch | 23 + llvm/16/lldb/procfs.patch | 46 ++ llvm/16/lldb/resource-dir.patch | 14 + llvm/16/llvm/default.nix | 428 +++++++++++++ llvm/16/llvm/gnu-install-dirs-polly.patch | 19 + llvm/16/llvm/gnu-install-dirs.patch | 161 +++++ ...-script-runner-set-dyld-library-path.patch | 17 + .../llvm-lit-cfg-add-libs-to-dylib-path.patch | 79 +++ ...polly-lit-cfg-add-libs-to-dylib-path.patch | 24 + llvm/16/openmp/default.nix | 74 +++ llvm/16/openmp/fix-find-tool.patch | 21 + llvm/16/openmp/gnu-install-dirs.patch | 22 + llvm/16/openmp/run-lit-directly.patch | 0 llvm/6/clang/default.nix | 127 ++++ llvm/6/clang/gnu-install-dirs.patch | 258 ++++++++ llvm/6/compiler-rt/armv7l.patch | 32 + llvm/6/compiler-rt/codesign.patch | 155 +++++ llvm/6/compiler-rt/default.nix | 112 ++++ llvm/6/compiler-rt/gnu-install-dirs.patch | 107 ++++ llvm/6/default.nix | 141 +++++ llvm/6/libcxx/default.nix | 85 +++ llvm/6/libcxx/gnu-install-dirs.patch | 72 +++ llvm/6/libcxxabi/default.nix | 70 +++ llvm/6/libcxxabi/gnu-install-dirs.patch | 28 + llvm/6/lld/default.nix | 46 ++ llvm/6/lld/gnu-install-dirs.patch | 68 ++ llvm/6/lldb/default.nix | 88 +++ llvm/6/lldb/gnu-install-dirs.patch | 76 +++ llvm/6/llvm/default.nix | 301 +++++++++ llvm/6/llvm/gnu-install-dirs-polly.patch | 106 ++++ llvm/6/llvm/gnu-install-dirs.patch | 386 ++++++++++++ llvm/6/openmp/default.nix | 37 ++ llvm/7/clang/HIP-use-PATH-7.patch | 68 ++ llvm/7/clang/default.nix | 139 ++++ llvm/7/clang/gnu-install-dirs.patch | 281 +++++++++ llvm/7/clang/unwindlib.patch | 227 +++++++ llvm/7/compiler-rt/armv7l.patch | 38 ++ llvm/7/compiler-rt/crtbegin-and-end.patch | 595 ++++++++++++++++++ llvm/7/compiler-rt/default.nix | 117 ++++ llvm/7/compiler-rt/gnu-install-dirs.patch | 117 ++++ llvm/7/default.nix | 288 +++++++++ llvm/7/libcxx/default.nix | 89 +++ llvm/7/libcxx/gnu-install-dirs.patch | 72 +++ llvm/7/libcxxabi/default.nix | 89 +++ llvm/7/libcxxabi/gnu-install-dirs.patch | 28 + llvm/7/libunwind/default.nix | 53 ++ llvm/7/libunwind/gnu-install-dirs.patch | 28 + llvm/7/lld/default.nix | 46 ++ llvm/7/lld/gnu-install-dirs.patch | 68 ++ llvm/7/lldb/default.nix | 95 +++ llvm/7/lldb/gnu-install-dirs.patch | 76 +++ llvm/7/llvm/default.nix | 322 ++++++++++ llvm/7/llvm/gnu-install-dirs-polly.patch | 106 ++++ llvm/7/llvm/gnu-install-dirs.patch | 386 ++++++++++++ llvm/7/openmp/default.nix | 37 ++ llvm/8/clang/HIP-use-PATH-8.patch | 80 +++ llvm/8/clang/compiler-rt-baremetal.patch | 53 ++ llvm/8/clang/default.nix | 145 +++++ llvm/8/clang/gnu-install-dirs.patch | 290 +++++++++ llvm/8/clang/static-pie.patch | 157 +++++ llvm/8/clang/unwindlib.patch | 372 +++++++++++ llvm/8/clang/xpc.patch | 41 ++ llvm/8/compiler-rt/armv7l.patch | 38 ++ llvm/8/compiler-rt/crtbegin-and-end.patch | 595 ++++++++++++++++++ llvm/8/compiler-rt/default.nix | 117 ++++ llvm/8/compiler-rt/gnu-install-dirs.patch | 117 ++++ llvm/8/default.nix | 287 +++++++++ llvm/8/libcxx/default.nix | 92 +++ llvm/8/libcxx/gnu-install-dirs.patch | 72 +++ llvm/8/libcxxabi/default.nix | 85 +++ llvm/8/libcxxabi/gnu-install-dirs.patch | 28 + llvm/8/libunwind/default.nix | 40 ++ llvm/8/libunwind/gnu-install-dirs.patch | 28 + llvm/8/lld/default.nix | 46 ++ llvm/8/lld/gnu-install-dirs.patch | 68 ++ llvm/8/lldb/default.nix | 109 ++++ llvm/8/lldb/gnu-install-dirs.patch | 120 ++++ .../lldb/lldb-gdb-remote-no-libcompress.patch | 30 + llvm/8/llvm/default.nix | 319 ++++++++++ llvm/8/llvm/gnu-install-dirs-polly.patch | 106 ++++ llvm/8/llvm/gnu-install-dirs.patch | 394 ++++++++++++ llvm/8/openmp/default.nix | 37 ++ llvm/9/clang/HIP-use-PATH-9.patch | 80 +++ llvm/9/clang/compiler-rt-baremetal.patch | 53 ++ llvm/9/clang/default.nix | 140 +++++ llvm/9/clang/gnu-install-dirs.patch | 278 ++++++++ llvm/9/clang/purity.patch | 30 + llvm/9/compiler-rt/armv7l.patch | 38 ++ llvm/9/compiler-rt/default.nix | 120 ++++ llvm/9/compiler-rt/gnu-install-dirs.patch | 117 ++++ llvm/9/default.nix | 287 +++++++++ llvm/9/libcxx/default.nix | 88 +++ llvm/9/libcxx/gnu-install-dirs.patch | 99 +++ llvm/9/libcxxabi/default.nix | 85 +++ llvm/9/libcxxabi/gnu-install-dirs.patch | 34 + llvm/9/libunwind/default.nix | 32 + llvm/9/libunwind/gnu-install-dirs.patch | 34 + llvm/9/lld/default.nix | 46 ++ llvm/9/lld/gnu-install-dirs.patch | 68 ++ llvm/9/lldb/default.nix | 117 ++++ llvm/9/lldb/gnu-install-dirs.patch | 105 ++++ .../lldb/lldb-gdb-remote-no-libcompress.patch | 17 + llvm/9/lldb/procfs.patch | 31 + llvm/9/llvm/default.nix | 334 ++++++++++ .../fix-test-on-non-x86-like-others.patch | 23 + llvm/9/llvm/gnu-install-dirs-polly.patch | 106 ++++ llvm/9/llvm/gnu-install-dirs.patch | 395 ++++++++++++ llvm/9/openmp/default.nix | 37 ++ llvm/README.md | 79 +++ llvm/TLI-musl.patch | 35 ++ llvm/aarch64.patch | 51 ++ llvm/clang-11-12-LLVMgold-path.patch | 13 + llvm/clang-6-10-LLVMgold-path.patch | 15 + llvm/common/bintools.nix | 48 ++ llvm/common/clang/5-8-purity.patch | 30 + llvm/common/clang/add-nostdlibinc-flag.patch | 18 + llvm/common/compiler-rt/7-12-codesign.patch | 33 + llvm/common/compiler-rt/armv6-mcr-dmb.patch | 75 +++ .../compiler-rt/armv6-no-ldrexd-strexd.patch | 162 +++++ .../compiler-rt/armv6-scudo-libatomic.patch | 65 ++ .../compiler-rt/armv6-scudo-no-yield.patch | 34 + .../compiler-rt/armv6-sync-ops-no-thumb.patch | 52 ++ llvm/common/compiler-rt/armv7l-15.patch | 32 + .../darwin-plistbuddy-workaround.patch | 25 + llvm/common/compiler-rt/glibc.patch | 48 ++ .../libsanitizer-no-cyclades-11.patch | 80 +++ .../libsanitizer-no-cyclades-9.patch | 80 +++ llvm/common/libcxxabi/no-threads.patch | 12 + llvm/common/libcxxabi/wasm.patch | 16 + llvm/common/lldb.nix | 196 ++++++ llvm/exegesis-force-bdver2.patch | 11 + llvm/git/clang/default.nix | 139 ++++ llvm/git/clang/gnu-install-dirs.patch | 105 ++++ llvm/git/clang/purity.patch | 29 + .../compiler-rt/X86-support-extension.patch | 21 + llvm/git/compiler-rt/codesign.patch | 33 + .../darwin-targetconditionals.patch | 71 +++ llvm/git/compiler-rt/default.nix | 139 ++++ llvm/git/compiler-rt/gnu-install-dirs.patch | 20 + llvm/git/compiler-rt/normalize-var.patch | 16 + llvm/git/default.nix | 384 +++++++++++ llvm/git/libcxx/default.nix | 123 ++++ llvm/git/libcxx/gnu-install-dirs.patch | 22 + llvm/git/libcxxabi/default.nix | 125 ++++ llvm/git/libcxxabi/gnu-install-dirs.patch | 22 + llvm/git/libunwind/default.nix | 67 ++ llvm/git/libunwind/gnu-install-dirs.patch | 22 + llvm/git/lld/default.nix | 57 ++ llvm/git/lld/gnu-install-dirs.patch | 46 ++ llvm/git/lldb/gnu-install-dirs.patch | 23 + llvm/git/lldb/procfs.patch | 40 ++ llvm/git/lldb/resource-dir.patch | 13 + llvm/git/llvm/default.nix | 423 +++++++++++++ llvm/git/llvm/gnu-install-dirs-polly.patch | 19 + llvm/git/llvm/gnu-install-dirs.patch | 138 ++++ ...-script-runner-set-dyld-library-path.patch | 26 + .../llvm-lit-cfg-add-libs-to-dylib-path.patch | 79 +++ ...polly-lit-cfg-add-libs-to-dylib-path.patch | 24 + llvm/git/openmp/default.nix | 71 +++ llvm/git/openmp/fix-find-tool.patch | 18 + llvm/git/openmp/gnu-install-dirs.patch | 22 + llvm/git/openmp/run-lit-directly.patch | 12 + llvm/libcxx-0001-musl-hacks.patch | 39 ++ llvm/llvm-7-musl.patch | 92 +++ llvm/llvm-config-link-static.patch | 12 + llvm/multi.nix | 60 ++ llvm/update-git.py | 88 +++ llvm/update.sh | 55 ++ 351 files changed, 33738 insertions(+), 6 deletions(-) create mode 100644 llvm/10/clang/compiler-rt-baremetal.patch create mode 100644 llvm/10/clang/default.nix create mode 100644 llvm/10/clang/gnu-install-dirs.patch create mode 100644 llvm/10/clang/purity.patch create mode 100644 llvm/10/compiler-rt/X86-support-extension.patch create mode 100644 llvm/10/compiler-rt/armv7l.patch create mode 100644 llvm/10/compiler-rt/default.nix create mode 100644 llvm/10/compiler-rt/find-darwin-sdk-version.patch create mode 100644 llvm/10/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/10/default.nix create mode 100644 llvm/10/libcxx/default.nix create mode 100644 llvm/10/libcxx/gnu-install-dirs.patch create mode 100644 llvm/10/libcxxabi/default.nix create mode 100644 llvm/10/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/10/libunwind/default.nix create mode 100644 llvm/10/libunwind/gnu-install-dirs.patch create mode 100644 llvm/10/lld/default.nix create mode 100644 llvm/10/lld/gnu-install-dirs.patch create mode 100644 llvm/10/lldb/gnu-install-dirs.patch create mode 100644 llvm/10/lldb/procfs.patch create mode 100644 llvm/10/llvm/default.nix create mode 100644 llvm/10/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/10/llvm/gnu-install-dirs.patch create mode 100644 llvm/10/openmp/default.nix create mode 100644 llvm/11/clang/default.nix create mode 100644 llvm/11/clang/gnu-install-dirs.patch create mode 100644 llvm/11/clang/purity.patch create mode 100644 llvm/11/compiler-rt/X86-support-extension.patch create mode 100644 llvm/11/compiler-rt/armv7l.patch create mode 100644 llvm/11/compiler-rt/default.nix create mode 100644 llvm/11/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/11/compiler-rt/normalize-var.patch create mode 100644 llvm/11/default.nix create mode 100644 llvm/11/libcxx/default.nix create mode 100644 llvm/11/libcxx/gnu-install-dirs.patch create mode 100644 llvm/11/libcxxabi/default.nix create mode 100644 llvm/11/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/11/libunwind/default.nix create mode 100644 llvm/11/libunwind/gnu-install-dirs.patch create mode 100644 llvm/11/lld/default.nix create mode 100644 llvm/11/lld/gnu-install-dirs.patch create mode 100644 llvm/11/lldb/gnu-install-dirs.patch create mode 100644 llvm/11/lldb/procfs.patch create mode 100644 llvm/11/llvm/default.nix create mode 100644 llvm/11/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/11/llvm/gnu-install-dirs.patch create mode 100644 llvm/11/openmp/default.nix create mode 100644 llvm/12/clang/default.nix create mode 100644 llvm/12/clang/gnu-install-dirs.patch create mode 100644 llvm/12/clang/purity.patch create mode 100644 llvm/12/compiler-rt/X86-support-extension.patch create mode 100644 llvm/12/compiler-rt/armv7l.patch create mode 100644 llvm/12/compiler-rt/default.nix create mode 100644 llvm/12/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/12/compiler-rt/normalize-var.patch create mode 100644 llvm/12/default.nix create mode 100644 llvm/12/libcxx/default.nix create mode 100644 llvm/12/libcxx/gnu-install-dirs.patch create mode 100644 llvm/12/libcxxabi/default.nix create mode 100644 llvm/12/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/12/libunwind/default.nix create mode 100644 llvm/12/libunwind/gnu-install-dirs.patch create mode 100644 llvm/12/lld/default.nix create mode 100644 llvm/12/lld/gnu-install-dirs.patch create mode 100644 llvm/12/lldb/gnu-install-dirs.patch create mode 100644 llvm/12/lldb/procfs.patch create mode 100644 llvm/12/lldb/resource-dir.patch create mode 100644 llvm/12/llvm/default.nix create mode 100644 llvm/12/llvm/fix-llvm-issue-49955.patch create mode 100644 llvm/12/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/12/llvm/gnu-install-dirs.patch create mode 100644 llvm/12/openmp/default.nix create mode 100644 llvm/13/clang/default.nix create mode 100644 llvm/13/clang/gnu-install-dirs.patch create mode 100644 llvm/13/clang/purity.patch create mode 100644 llvm/13/clang/revert-malloc-alignment-assumption.patch create mode 100644 llvm/13/compiler-rt/X86-support-extension.patch create mode 100644 llvm/13/compiler-rt/armv7l.patch create mode 100644 llvm/13/compiler-rt/codesign.patch create mode 100644 llvm/13/compiler-rt/darwin-targetconditionals.patch create mode 100644 llvm/13/compiler-rt/default.nix create mode 100644 llvm/13/compiler-rt/normalize-var.patch create mode 100644 llvm/13/default.nix create mode 100644 llvm/13/libcxx/default.nix create mode 100644 llvm/13/libcxx/gnu-install-dirs.patch create mode 100644 llvm/13/libcxxabi/default.nix create mode 100644 llvm/13/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/13/libunwind/default.nix create mode 100644 llvm/13/libunwind/gnu-install-dirs.patch create mode 100644 llvm/13/lld/default.nix create mode 100644 llvm/13/lld/gnu-install-dirs.patch create mode 100644 llvm/13/lldb/cpu_subtype_arm64e_replacement.patch create mode 100644 llvm/13/lldb/gnu-install-dirs.patch create mode 100644 llvm/13/lldb/procfs.patch create mode 100644 llvm/13/lldb/resource-dir.patch create mode 100644 llvm/13/llvm/default.nix create mode 100644 llvm/13/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/13/llvm/gnu-install-dirs.patch create mode 100644 llvm/13/openmp/default.nix create mode 100644 llvm/14/clang/default.nix create mode 100644 llvm/14/clang/gnu-install-dirs.patch create mode 100644 llvm/14/clang/purity.patch create mode 100644 llvm/14/compiler-rt/X86-support-extension.patch create mode 100644 llvm/14/compiler-rt/armv7l.patch create mode 100644 llvm/14/compiler-rt/codesign.patch create mode 100644 llvm/14/compiler-rt/darwin-targetconditionals.patch create mode 100644 llvm/14/compiler-rt/default.nix create mode 100644 llvm/14/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/14/compiler-rt/normalize-var.patch create mode 100644 llvm/14/default.nix create mode 100644 llvm/14/libcxx/default.nix create mode 100644 llvm/14/libcxx/gnu-install-dirs.patch create mode 100644 llvm/14/libcxxabi/default.nix create mode 100644 llvm/14/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/14/libunwind/default.nix create mode 100644 llvm/14/libunwind/gnu-install-dirs.patch create mode 100644 llvm/14/lld/default.nix create mode 100644 llvm/14/lld/fix-root-src-dir.patch create mode 100644 llvm/14/lld/gnu-install-dirs.patch create mode 100644 llvm/14/lldb/cpu_subtype_arm64e_replacement.patch create mode 100644 llvm/14/lldb/gnu-install-dirs.patch create mode 100644 llvm/14/lldb/procfs.patch create mode 100644 llvm/14/lldb/resource-dir.patch create mode 100644 llvm/14/llvm/default.nix create mode 100644 llvm/14/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/14/llvm/gnu-install-dirs.patch create mode 100644 llvm/14/openmp/default.nix create mode 100644 llvm/14/openmp/gnu-install-dirs.patch create mode 100644 llvm/14/openmp/run-lit-directly.patch create mode 100644 llvm/15/clang/default.nix create mode 100644 llvm/15/clang/gnu-install-dirs.patch create mode 100644 llvm/15/clang/purity.patch create mode 100644 llvm/15/compiler-rt/X86-support-extension.patch create mode 100644 llvm/15/compiler-rt/darwin-targetconditionals.patch create mode 100644 llvm/15/compiler-rt/default.nix create mode 100644 llvm/15/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/15/compiler-rt/normalize-var.patch create mode 100644 llvm/15/default.nix create mode 100644 llvm/15/libcxx/default.nix create mode 100644 llvm/15/libcxx/gnu-install-dirs.patch create mode 100644 llvm/15/libcxxabi/default.nix create mode 100644 llvm/15/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/15/libunwind/default.nix create mode 100644 llvm/15/libunwind/gnu-install-dirs.patch create mode 100644 llvm/15/lld/default.nix create mode 100644 llvm/15/lld/gnu-install-dirs.patch create mode 100644 llvm/15/lldb/cpu_subtype_arm64e_replacement.patch create mode 100644 llvm/15/lldb/gnu-install-dirs.patch create mode 100644 llvm/15/lldb/procfs.patch create mode 100644 llvm/15/lldb/resource-dir.patch create mode 100644 llvm/15/llvm/default.nix create mode 100644 llvm/15/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/15/llvm/gnu-install-dirs.patch create mode 100644 llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch create mode 100644 llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 llvm/15/openmp/default.nix create mode 100644 llvm/15/openmp/fix-find-tool.patch create mode 100644 llvm/15/openmp/gnu-install-dirs.patch create mode 100644 llvm/15/openmp/run-lit-directly.patch create mode 100644 llvm/16/clang/default.nix create mode 100644 llvm/16/clang/gnu-install-dirs.patch create mode 100644 llvm/16/clang/purity.patch create mode 100644 llvm/16/compiler-rt/X86-support-extension.patch create mode 100644 llvm/16/compiler-rt/darwin-targetconditionals.patch create mode 100644 llvm/16/compiler-rt/default.nix create mode 100644 llvm/16/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/16/compiler-rt/normalize-var.patch create mode 100644 llvm/16/default.nix create mode 100644 llvm/16/libclc/default.nix create mode 100644 llvm/16/libclc/libclc-gnu-install-dirs.patch create mode 100644 llvm/16/libcxx/default.nix create mode 100644 llvm/16/libcxx/gnu-install-dirs.patch create mode 100644 llvm/16/libcxxabi/default.nix create mode 100644 llvm/16/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/16/libunwind/default.nix create mode 100644 llvm/16/libunwind/gnu-install-dirs.patch create mode 100644 llvm/16/lld/add-table-base.patch create mode 100644 llvm/16/lld/default.nix create mode 100644 llvm/16/lld/gnu-install-dirs.patch create mode 100644 llvm/16/lldb/cpu_subtype_arm64e_replacement.patch create mode 100644 llvm/16/lldb/gnu-install-dirs.patch create mode 100644 llvm/16/lldb/procfs.patch create mode 100644 llvm/16/lldb/resource-dir.patch create mode 100644 llvm/16/llvm/default.nix create mode 100644 llvm/16/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/16/llvm/gnu-install-dirs.patch create mode 100644 llvm/16/llvm/lit-shell-script-runner-set-dyld-library-path.patch create mode 100644 llvm/16/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 llvm/16/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 llvm/16/openmp/default.nix create mode 100644 llvm/16/openmp/fix-find-tool.patch create mode 100644 llvm/16/openmp/gnu-install-dirs.patch create mode 100644 llvm/16/openmp/run-lit-directly.patch create mode 100644 llvm/6/clang/default.nix create mode 100644 llvm/6/clang/gnu-install-dirs.patch create mode 100644 llvm/6/compiler-rt/armv7l.patch create mode 100644 llvm/6/compiler-rt/codesign.patch create mode 100644 llvm/6/compiler-rt/default.nix create mode 100644 llvm/6/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/6/default.nix create mode 100644 llvm/6/libcxx/default.nix create mode 100644 llvm/6/libcxx/gnu-install-dirs.patch create mode 100644 llvm/6/libcxxabi/default.nix create mode 100644 llvm/6/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/6/lld/default.nix create mode 100644 llvm/6/lld/gnu-install-dirs.patch create mode 100644 llvm/6/lldb/default.nix create mode 100644 llvm/6/lldb/gnu-install-dirs.patch create mode 100644 llvm/6/llvm/default.nix create mode 100644 llvm/6/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/6/llvm/gnu-install-dirs.patch create mode 100644 llvm/6/openmp/default.nix create mode 100644 llvm/7/clang/HIP-use-PATH-7.patch create mode 100644 llvm/7/clang/default.nix create mode 100644 llvm/7/clang/gnu-install-dirs.patch create mode 100644 llvm/7/clang/unwindlib.patch create mode 100644 llvm/7/compiler-rt/armv7l.patch create mode 100644 llvm/7/compiler-rt/crtbegin-and-end.patch create mode 100644 llvm/7/compiler-rt/default.nix create mode 100644 llvm/7/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/7/default.nix create mode 100644 llvm/7/libcxx/default.nix create mode 100644 llvm/7/libcxx/gnu-install-dirs.patch create mode 100644 llvm/7/libcxxabi/default.nix create mode 100644 llvm/7/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/7/libunwind/default.nix create mode 100644 llvm/7/libunwind/gnu-install-dirs.patch create mode 100644 llvm/7/lld/default.nix create mode 100644 llvm/7/lld/gnu-install-dirs.patch create mode 100644 llvm/7/lldb/default.nix create mode 100644 llvm/7/lldb/gnu-install-dirs.patch create mode 100644 llvm/7/llvm/default.nix create mode 100644 llvm/7/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/7/llvm/gnu-install-dirs.patch create mode 100644 llvm/7/openmp/default.nix create mode 100644 llvm/8/clang/HIP-use-PATH-8.patch create mode 100644 llvm/8/clang/compiler-rt-baremetal.patch create mode 100644 llvm/8/clang/default.nix create mode 100644 llvm/8/clang/gnu-install-dirs.patch create mode 100644 llvm/8/clang/static-pie.patch create mode 100644 llvm/8/clang/unwindlib.patch create mode 100644 llvm/8/clang/xpc.patch create mode 100644 llvm/8/compiler-rt/armv7l.patch create mode 100644 llvm/8/compiler-rt/crtbegin-and-end.patch create mode 100644 llvm/8/compiler-rt/default.nix create mode 100644 llvm/8/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/8/default.nix create mode 100644 llvm/8/libcxx/default.nix create mode 100644 llvm/8/libcxx/gnu-install-dirs.patch create mode 100644 llvm/8/libcxxabi/default.nix create mode 100644 llvm/8/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/8/libunwind/default.nix create mode 100644 llvm/8/libunwind/gnu-install-dirs.patch create mode 100644 llvm/8/lld/default.nix create mode 100644 llvm/8/lld/gnu-install-dirs.patch create mode 100644 llvm/8/lldb/default.nix create mode 100644 llvm/8/lldb/gnu-install-dirs.patch create mode 100644 llvm/8/lldb/lldb-gdb-remote-no-libcompress.patch create mode 100644 llvm/8/llvm/default.nix create mode 100644 llvm/8/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/8/llvm/gnu-install-dirs.patch create mode 100644 llvm/8/openmp/default.nix create mode 100644 llvm/9/clang/HIP-use-PATH-9.patch create mode 100644 llvm/9/clang/compiler-rt-baremetal.patch create mode 100644 llvm/9/clang/default.nix create mode 100644 llvm/9/clang/gnu-install-dirs.patch create mode 100644 llvm/9/clang/purity.patch create mode 100644 llvm/9/compiler-rt/armv7l.patch create mode 100644 llvm/9/compiler-rt/default.nix create mode 100644 llvm/9/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/9/default.nix create mode 100644 llvm/9/libcxx/default.nix create mode 100644 llvm/9/libcxx/gnu-install-dirs.patch create mode 100644 llvm/9/libcxxabi/default.nix create mode 100644 llvm/9/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/9/libunwind/default.nix create mode 100644 llvm/9/libunwind/gnu-install-dirs.patch create mode 100644 llvm/9/lld/default.nix create mode 100644 llvm/9/lld/gnu-install-dirs.patch create mode 100644 llvm/9/lldb/default.nix create mode 100644 llvm/9/lldb/gnu-install-dirs.patch create mode 100644 llvm/9/lldb/lldb-gdb-remote-no-libcompress.patch create mode 100644 llvm/9/lldb/procfs.patch create mode 100644 llvm/9/llvm/default.nix create mode 100644 llvm/9/llvm/fix-test-on-non-x86-like-others.patch create mode 100644 llvm/9/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/9/llvm/gnu-install-dirs.patch create mode 100644 llvm/9/openmp/default.nix create mode 100644 llvm/README.md create mode 100644 llvm/TLI-musl.patch create mode 100644 llvm/aarch64.patch create mode 100644 llvm/clang-11-12-LLVMgold-path.patch create mode 100644 llvm/clang-6-10-LLVMgold-path.patch create mode 100644 llvm/common/bintools.nix create mode 100644 llvm/common/clang/5-8-purity.patch create mode 100644 llvm/common/clang/add-nostdlibinc-flag.patch create mode 100644 llvm/common/compiler-rt/7-12-codesign.patch create mode 100644 llvm/common/compiler-rt/armv6-mcr-dmb.patch create mode 100644 llvm/common/compiler-rt/armv6-no-ldrexd-strexd.patch create mode 100644 llvm/common/compiler-rt/armv6-scudo-libatomic.patch create mode 100644 llvm/common/compiler-rt/armv6-scudo-no-yield.patch create mode 100644 llvm/common/compiler-rt/armv6-sync-ops-no-thumb.patch create mode 100644 llvm/common/compiler-rt/armv7l-15.patch create mode 100644 llvm/common/compiler-rt/darwin-plistbuddy-workaround.patch create mode 100644 llvm/common/compiler-rt/glibc.patch create mode 100644 llvm/common/compiler-rt/libsanitizer-no-cyclades-11.patch create mode 100644 llvm/common/compiler-rt/libsanitizer-no-cyclades-9.patch create mode 100644 llvm/common/libcxxabi/no-threads.patch create mode 100644 llvm/common/libcxxabi/wasm.patch create mode 100644 llvm/common/lldb.nix create mode 100644 llvm/exegesis-force-bdver2.patch create mode 100644 llvm/git/clang/default.nix create mode 100644 llvm/git/clang/gnu-install-dirs.patch create mode 100644 llvm/git/clang/purity.patch create mode 100644 llvm/git/compiler-rt/X86-support-extension.patch create mode 100644 llvm/git/compiler-rt/codesign.patch create mode 100644 llvm/git/compiler-rt/darwin-targetconditionals.patch create mode 100644 llvm/git/compiler-rt/default.nix create mode 100644 llvm/git/compiler-rt/gnu-install-dirs.patch create mode 100644 llvm/git/compiler-rt/normalize-var.patch create mode 100644 llvm/git/default.nix create mode 100644 llvm/git/libcxx/default.nix create mode 100644 llvm/git/libcxx/gnu-install-dirs.patch create mode 100644 llvm/git/libcxxabi/default.nix create mode 100644 llvm/git/libcxxabi/gnu-install-dirs.patch create mode 100644 llvm/git/libunwind/default.nix create mode 100644 llvm/git/libunwind/gnu-install-dirs.patch create mode 100644 llvm/git/lld/default.nix create mode 100644 llvm/git/lld/gnu-install-dirs.patch create mode 100644 llvm/git/lldb/gnu-install-dirs.patch create mode 100644 llvm/git/lldb/procfs.patch create mode 100644 llvm/git/lldb/resource-dir.patch create mode 100644 llvm/git/llvm/default.nix create mode 100644 llvm/git/llvm/gnu-install-dirs-polly.patch create mode 100644 llvm/git/llvm/gnu-install-dirs.patch create mode 100644 llvm/git/llvm/lit-shell-script-runner-set-dyld-library-path.patch create mode 100644 llvm/git/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 llvm/git/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch create mode 100644 llvm/git/openmp/default.nix create mode 100644 llvm/git/openmp/fix-find-tool.patch create mode 100644 llvm/git/openmp/gnu-install-dirs.patch create mode 100644 llvm/git/openmp/run-lit-directly.patch create mode 100644 llvm/libcxx-0001-musl-hacks.patch create mode 100644 llvm/llvm-7-musl.patch create mode 100644 llvm/llvm-config-link-static.patch create mode 100644 llvm/multi.nix create mode 100755 llvm/update-git.py create mode 100755 llvm/update.sh diff --git a/flake.lock b/flake.lock index 3864623..0ec8e40 100644 --- a/flake.lock +++ b/flake.lock @@ -18,11 +18,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1715087517, - "narHash": "sha256-CLU5Tsg24Ke4+7sH8azHWXKd0CFd4mhLWfhYgUiDBpQ=", + "lastModified": 1716330097, + "narHash": "sha256-8BO3B7e3BiyIDsaKA0tY8O88rClYRTjvAp66y+VBUeU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b211b392b8486ee79df6cdfb1157ad2133427a29", + "rev": "5710852ba686cc1fd0d3b8e22b3117d43ba374c2", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index f9b44f2..d2fec36 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,14 @@ rustc = rust; cargo = rust; }); + + # https://doc.rust-lang.org/rustc/linker-plugin-lto.html#toolchain-compatibility + llvmPackages_11 = pkgs.recurseIntoAttrs (pkgs.callPackage (import ./llvm/11) ({ + inherit (pkgs.stdenvAdapters) overrideCC; + buildLlvmTools = null; + targetLlvmLibraries = null; + targetLlvm = null; + })); crosspkgs-overlay = (self: super: { pkgsCross = super.pkgsCross // { @@ -108,7 +116,7 @@ ) ./.; cargoLock = { lockFile = ./Cargo.lock; }; - nativeBuildInputs = [ cargo-xbuild pkgs.llvmPackages_14.clang-unwrapped ]; + nativeBuildInputs = [ cargo-xbuild llvmPackages_11.clang-unwrapped ]; buildPhase = '' export XARGO_RUST_SRC="${rust}/lib/rustlib/src/rust/library" export CARGO_HOME=$(mktemp -d cargo-home.XXX) @@ -153,7 +161,7 @@ hydraJobs = packages.x86_64-linux; - inherit rust rustPlatform; + inherit rust rustPlatform llvmPackages_11; devShell.x86_64-linux = pkgs.mkShell { name = "zynq-rs-dev-shell"; @@ -164,7 +172,7 @@ pkgs.openocd pkgs.gdb pkgs.openssh pkgs.rsync - pkgs.llvmPackages_14.clang-unwrapped + llvmPackages_11.clang-unwrapped (pkgs.python3.withPackages(ps: [ ps.pyftdi ])) ]; }; diff --git a/llvm/10/clang/compiler-rt-baremetal.patch b/llvm/10/clang/compiler-rt-baremetal.patch new file mode 100644 index 0000000..a4a0f21 --- /dev/null +++ b/llvm/10/clang/compiler-rt-baremetal.patch @@ -0,0 +1,53 @@ +Index: lib/Driver/ToolChains/BareMetal.cpp +=================================================================== +--- a/lib/Driver/ToolChains/BareMetal.cpp ++++ b/lib/Driver/ToolChains/BareMetal.cpp +@@ -157,7 +157,7 @@ + void BareMetal::AddLinkRuntimeLib(const ArgList &Args, + ArgStringList &CmdArgs) const { + CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" + +- getTriple().getArchName() + ".a")); ++ getTriple().getArchName())); + } + + void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, +Index: test/Driver/baremetal.cpp +=================================================================== +--- a/test/Driver/baremetal.cpp ++++ b/test/Driver/baremetal.cpp +@@ -13,7 +13,7 @@ + // CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for" +-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-C-SAME: "-o" "{{.*}}.o" + + // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -35,7 +35,7 @@ + // CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind" +-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-DEFAULTCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -48,7 +48,7 @@ + // CHECK-V6M-LIBCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind" +-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -61,7 +61,7 @@ + // CHECK-V6M-LIBSTDCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind" +-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-LIBSTDCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ diff --git a/llvm/10/clang/default.nix b/llvm/10/clang/default.nix new file mode 100644 index 0000000..ad4e913 --- /dev/null +++ b/llvm/10/clang/default.nix @@ -0,0 +1,133 @@ +{ lib, stdenv, llvm_meta, fetch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "clang" "091bvcny2lh32zy8f3m9viayyhb2zannrndni7325rl85cwgr6pr"; + + unpackPhase = '' + unpackFile $src + mv clang-${version}* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./compiler-rt-baremetal.patch + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-6-10-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace tools/extra/clangd/CMakeLists.txt \ + --replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/10/clang/gnu-install-dirs.patch b/llvm/10/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..454c818 --- /dev/null +++ b/llvm/10/clang/gnu-install-dirs.patch @@ -0,0 +1,248 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index dc1413f4b597..c173531e624f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,6 +9,8 @@ endif() + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(LLVM_CONFIG) +@@ -417,7 +419,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "*.def" +@@ -427,7 +429,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE +@@ -447,7 +449,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh) + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT bash-autocomplete) + if(NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-bash-autocomplete +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 577cc11ab015..a4f4481d8442 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -114,9 +114,9 @@ macro(add_clang_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -160,7 +160,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT LLVM_ENABLE_IDE) +@@ -175,7 +175,7 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() + + function(clang_target_link_libraries target type) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 85c3124234ad..64c48235d914 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -191,7 +191,7 @@ set_target_properties(clang-resource-headers PROPERTIES + FOLDER "Misc" + RUNTIME_OUTPUT_DIRECTORY "${output_dir}") + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${generated_files} +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index ceef4b08637c..8efad5520ca4 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index 35ecdb11253c..d77d75de0094 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index cda8e29ec5b1..0134d8ccd70b 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -19,8 +19,8 @@ clang_target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/diagtool/CMakeLists.txt b/tools/diagtool/CMakeLists.txt +index a95444be40ee..136d96d9bf5b 100644 +--- a/tools/diagtool/CMakeLists.txt ++++ b/tools/diagtool/CMakeLists.txt +@@ -21,7 +21,7 @@ clang_target_link_libraries(diagtool + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(TARGETS diagtool + COMPONENT diagtool +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-diagtool +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 973655361f71..0181002e4e3b 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -141,7 +141,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +@@ -172,7 +172,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index 28241245fcb7..d6b59f02fc2a 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -42,7 +42,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-build) + endforeach() + +@@ -56,7 +56,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) + install(PROGRAMS libexec/${LibexecFile} +- DESTINATION libexec ++ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR} + COMPONENT scan-build) + endforeach() + +@@ -84,7 +84,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) + install(FILES share/scan-build/${ShareFile} +- DESTINATION share/scan-build ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build + COMPONENT scan-build) + endforeach() + +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index 22edb974bac7..9f140a9a4538 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -22,7 +22,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-view) + endforeach() + +@@ -36,7 +36,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) + install(FILES share/${ShareFile} +- DESTINATION share/scan-view ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view + COMPONENT scan-view) + endforeach() + +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 62f2de0cb15c..6aa66825b6ec 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -10,7 +10,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) + install(PROGRAMS ${CLANG_HMAPTOOL} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT hmaptool) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) diff --git a/llvm/10/clang/purity.patch b/llvm/10/clang/purity.patch new file mode 100644 index 0000000..a6729a9 --- /dev/null +++ b/llvm/10/clang/purity.patch @@ -0,0 +1,30 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!IsStatic) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) { +- const std::string Loader = +- D.DyldPrefix + ToolChain.getDynamicLinker(Args); +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Loader)); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 + diff --git a/llvm/10/compiler-rt/X86-support-extension.patch b/llvm/10/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..f6f9336 --- /dev/null +++ b/llvm/10/compiler-rt/X86-support-extension.patch @@ -0,0 +1,23 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -301,6 +301,10 @@ if (NOT MSVC) + i386/umoddi3.S + ) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -608,6 +612,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/10/compiler-rt/armv7l.patch b/llvm/10/compiler-rt/armv7l.patch new file mode 100644 index 0000000..120cfe6 --- /dev/null +++ b/llvm/10/compiler-rt/armv7l.patch @@ -0,0 +1,32 @@ +diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 +@@ -474,6 +474,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -595,7 +596,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/10/compiler-rt/default.nix b/llvm/10/compiler-rt/default.nix new file mode 100644 index 0000000..3702509 --- /dev/null +++ b/llvm/10/compiler-rt/default.nix @@ -0,0 +1,131 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + src = fetch "compiler-rt" "1yjqjri753w0fzmxcyz687nvd97sbc9rsqrxzpq720na47hwh3fr"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ]; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./find-darwin-sdk-version.patch # don't test for macOS being >= 10.15 + ./gnu-install-dirs.patch + ../../common/compiler-rt/libsanitizer-no-cyclades-11.patch + ./X86-support-extension.patch # backported from LLVM 11 + # Fix build on armv6l + ../../common/compiler-rt/armv6-mcr-dmb.patch + ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ] ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + # See https://reviews.llvm.org/D37278 for why android exception + + lib.optionalString (stdenv.hostPlatform.isx86_32 && !stdenv.hostPlatform.isAndroid) '' + for f in $out/lib/*/*builtins-i?86*; do + ln -s "$f" $(echo "$f" | sed -e 's/builtins-i.86/builtins-i386/') + done + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; + }; +} diff --git a/llvm/10/compiler-rt/find-darwin-sdk-version.patch b/llvm/10/compiler-rt/find-darwin-sdk-version.patch new file mode 100644 index 0000000..fc16ddd --- /dev/null +++ b/llvm/10/compiler-rt/find-darwin-sdk-version.patch @@ -0,0 +1,62 @@ +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake 2020-01-25 23:13:55.000000000 +0100 ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake 2020-01-25 23:19:37.000000000 +0100 +@@ -43,41 +43,6 @@ + set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE) + endfunction() + +-function(find_darwin_sdk_version var sdk_name) +- # We deliberately don't cache the result here because +- # CMake's caching causes too many problems. +- set(result_process 1) +- if(NOT DARWIN_PREFER_PUBLIC_SDK) +- # Let's first try the internal SDK, otherwise use the public SDK. +- execute_process( +- COMMAND xcrun --sdk ${sdk_name}.internal --show-sdk-version +- RESULT_VARIABLE result_process +- OUTPUT_VARIABLE var_internal +- OUTPUT_STRIP_TRAILING_WHITESPACE +- ERROR_FILE /dev/null +- ) +- endif() +- if((NOT ${result_process} EQUAL 0) OR "" STREQUAL "${var_internal}") +- execute_process( +- COMMAND xcrun --sdk ${sdk_name} --show-sdk-version +- RESULT_VARIABLE result_process +- OUTPUT_VARIABLE var_internal +- OUTPUT_STRIP_TRAILING_WHITESPACE +- ERROR_FILE /dev/null +- ) +- endif() +- if(NOT result_process EQUAL 0) +- message(FATAL_ERROR +- "Failed to determine SDK version for \"${sdk_name}\" SDK") +- endif() +- # Check reported version looks sane. +- if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$") +- message(FATAL_ERROR +- "Reported SDK version \"${var_internal}\" does not look like a version") +- endif() +- set(${var} ${var_internal} PARENT_SCOPE) +-endfunction() +- + # There isn't a clear mapping of what architectures are supported with a given + # target platform, but ld's version output does list the architectures it can + # link for. +@@ -119,17 +84,6 @@ + foreach(flag ${DARWIN_${os}_LINK_FLAGS}) + set(os_linker_flags "${os_linker_flags} ${flag}") + endforeach() +- +- # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support +- # linking for i386 and the corresponding OS doesn't allow running macOS i386 +- # binaries. +- if ("${os}" STREQUAL "osx") +- find_darwin_sdk_version(macosx_sdk_version "macosx") +- if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15) +- message(STATUS "Disabling i386 slice for ${valid_archs}") +- list(REMOVE_ITEM archs "i386") +- endif() +- endif() + endif() + + # The simple program will build for x86_64h on the simulator because it is diff --git a/llvm/10/compiler-rt/gnu-install-dirs.patch b/llvm/10/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..db0bd00 --- /dev/null +++ b/llvm/10/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,129 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8d768a404f21..74551dc5a004 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -12,6 +12,7 @@ endif() + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + endif() +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index 35a48c6af29c..e4300f256091 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -493,7 +493,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -510,7 +510,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index 9f501a61c4b6..f9a0d92dbca0 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -440,7 +440,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index 6e672b1e1818..64999709958e 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -371,7 +371,7 @@ endfunction() + function(get_compiler_rt_install_dir arch install_dir) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + get_compiler_rt_target(${arch} target) +- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE) ++ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${target} PARENT_SCOPE) + else() + set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + endif() +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index b4b87aa53073..f1ae8668837c 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -65,11 +65,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -97,7 +97,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + set(COMPILER_RT_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + endif() + + if(APPLE) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index d47d7baeb118..507c8e5c713e 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -62,22 +62,22 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install fuzzer headers. + install(FILES ${FUZZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/fuzzer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/fuzzer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + # Install profile headers. + install(FILES ${PROFILE_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/profile) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/profile) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index 051215edbeb7..ecce1f52efb0 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -56,4 +56,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}) diff --git a/llvm/10/default.nix b/llvm/10/default.nix new file mode 100644 index 0000000..37c32e4 --- /dev/null +++ b/llvm/10/default.nix @@ -0,0 +1,284 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +}: + +let + release_version = "10.0.1"; + version = release_version; # differentiating these (variables) is important for RCs + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${release_version}/${name}-${version}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "06n1yp638rh24xdxv9v2df0qajxbjz4w59b7dd4ky36drwmpi4yh"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + # disabled until recommonmark supports sphinx 3 + #Llvm-manpages = lowPrio (tools.libllvm.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + #}); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # disabled until recommonmark supports sphinx 3 + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + src = fetch "lldb" "051p5b04y6z3g730rmc2n2v71lipbw7k69riww3a6sl74myfiaq7"; + patches = [ + ./lldb/procfs.patch + ./lldb/gnu-install-dirs.patch + ]; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/10/libcxx/default.nix b/llvm/10/libcxx/default.nix new file mode 100644 index 0000000..cc029ea --- /dev/null +++ b/llvm/10/libcxx/default.nix @@ -0,0 +1,88 @@ +{ lib, stdenv, llvm_meta, fetch, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "0v78bfr6h2zifvdqnj2wlfk4pvxzrqn3hg1v6lqk3y12bx9p9xny"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include" + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz" + postPatch = '' + substituteInPlace include/__config \ + --replace "# define _LIBCPP_USE_AVAILABILITY_APPLE" "" + ''; + + preConfigure = '' + # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package + cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR") + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + nativeBuildInputs = [ cmake ] + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) python3 + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_LIBCPPABI_VERSION=2" + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (cxxabi.pname == "libcxxabi") "-DLIBCXX_LIBCXXABI_LIB_PATH=${cxxabi}/lib" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/10/libcxx/gnu-install-dirs.patch b/llvm/10/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..4b031e9 --- /dev/null +++ b/llvm/10/libcxx/gnu-install-dirs.patch @@ -0,0 +1,99 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 60564dc96c7b..77d832ad5a44 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,6 +26,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 10.0.1) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -415,7 +417,7 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) +@@ -423,10 +425,10 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + endif() + + file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 10f100f7f0fb..95ed3978ab73 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -61,7 +61,7 @@ macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 302da8a131b4..4c6ab463f564 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -244,7 +244,7 @@ if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dir} + COMPONENT ${CXX_HEADER_TARGET} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +@@ -253,7 +253,7 @@ if (LIBCXX_INSTALL_HEADERS) + if (LIBCXX_NEEDS_SITE_CONFIG) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT ${CXX_HEADER_TARGET}) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 120505fe18da..9b8456d8405a 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -341,21 +341,21 @@ if (LIBCXX_INSTALL_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib} + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise diff --git a/llvm/10/libcxxabi/default.nix b/llvm/10/libcxxabi/default.nix new file mode 100644 index 0000000..c4eba56 --- /dev/null +++ b/llvm/10/libcxxabi/default.nix @@ -0,0 +1,85 @@ +{ lib, stdenv, llvm_meta, cmake, fetch, libcxx, libunwind, llvm, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "0yqs722y76cwvmfsq0lb917r9m3fci7bf5z3yzl71yz9n88ghzm9"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + unpackFile ${llvm.src} + cmakeFlags+=" -DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)" + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch} + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d $(ls -d llvm-*) -i ${../../common/libcxxabi/wasm.patch} + ''; + + patches = [ + ../../common/libcxxabi/no-threads.patch + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/10/libcxxabi/gnu-install-dirs.patch b/llvm/10/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..0f80ade --- /dev/null +++ b/llvm/10/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 8f9572586b4a..bf0e41dfc751 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -20,6 +20,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 10.0.1) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -214,17 +216,17 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + else() + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + endif() + + set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.") diff --git a/llvm/10/libunwind/default.nix b/llvm/10/libunwind/default.nix new file mode 100644 index 0000000..8124cf0 --- /dev/null +++ b/llvm/10/libunwind/default.nix @@ -0,0 +1,32 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, fetchpatch +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + src = fetch pname "09syx66idnm2pr46x2vmk0jn3iwdv0lkd04xy4zjbwmz3vn066bl"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/10/libunwind/gnu-install-dirs.patch b/llvm/10/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..8cea7d3 --- /dev/null +++ b/llvm/10/libunwind/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c033069ef1d0..e2846896eece 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -18,6 +18,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD) + project(libunwind) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(NOT LLVM_CONFIG_PATH) +@@ -189,17 +191,17 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + endif() + + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) diff --git a/llvm/10/lld/default.nix b/llvm/10/lld/default.nix new file mode 100644 index 0000000..d4c686a --- /dev/null +++ b/llvm/10/lld/default.nix @@ -0,0 +1,46 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "0ynzi35r4fckvp6842alpd43qr810j3728yfslc66fk2mbh4j52r"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/10/lld/gnu-install-dirs.patch b/llvm/10/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..232f5cb --- /dev/null +++ b/llvm/10/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 641f71c114ae..9d44c1463aff 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -202,7 +204,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index fa48b428d26b..e7967aad3ceb 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index a15e296e31df..654c2cfdb9c0 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -17,7 +17,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE lld-link ld.lld ld64.lld wasm-ld) diff --git a/llvm/10/lldb/gnu-install-dirs.patch b/llvm/10/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..0a7539d --- /dev/null +++ b/llvm/10/lldb/gnu-install-dirs.patch @@ -0,0 +1,91 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 573b8556989e..a12cc6f6ba77 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -17,6 +17,8 @@ set(CMAKE_MODULE_PATH + # If we are not building as part of LLVM, build LLDB as a standalone project, + # using LLVM as an external library. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ++ include(GNUInstallDirs) ++ + project(lldb) + include(LLDBStandalone) + +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index ecf0b66a41a3..6f2d97af7a11 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -107,13 +107,13 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() + # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS + install(TARGETS ${name} COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${install_dest} + ARCHIVE DESTINATION ${install_dest} + FRAMEWORK DESTINATION ${install_dest}) +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index 4a15a343ee1d..c74bbb6878d7 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -238,7 +238,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +@@ -247,7 +247,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index aff75d7db334..98a527c5e761 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -64,4 +64,4 @@ if (LLDB_ENABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index 752113b..010f187 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -62,7 +62,7 @@ endif() + + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) +-set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 OR CYGWIN) + # DLL platform -- put DLLs into bin. + set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index bf74802..1c98cae 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -222,7 +222,7 @@ if (LLDB_ENABLE_PYTHON) + if(LLDB_BUILD_FRAMEWORK) + set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python) + else() +- set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH}) ++ set(LLDB_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH}) + endif() + if (NOT CMAKE_CFG_INTDIR STREQUAL ".") + string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH}) diff --git a/llvm/10/lldb/procfs.patch b/llvm/10/lldb/procfs.patch new file mode 100644 index 0000000..b075dba --- /dev/null +++ b/llvm/10/lldb/procfs.patch @@ -0,0 +1,31 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -11,21 +11,12 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif diff --git a/llvm/10/llvm/default.nix b/llvm/10/llvm/default.nix new file mode 100644 index 0000000..c09ec67 --- /dev/null +++ b/llvm/10/llvm/default.nix @@ -0,0 +1,355 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? true +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch pname "1wydhbp9kyjp5y0rc627imxgkgqiv3dfirbqil9dgpnbaw5y7n65"; + polly_src = fetch "polly" "0nm2d8niz47yjsa3r17v3p13b70igkd338ib8191znr1dfw0pyyj"; + + unpackPhase = '' + unpackFile $src + mv llvm-${version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + patches = [ + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + ./gnu-install-dirs.patch + # On older CPUs (e.g. Hydra/wendy) we'd be getting an error in this test. + (fetchpatch { + name = "uops-CMOV16rm-noreg.diff"; + url = "https://github.com/llvm/llvm-project/commit/9e9f991ac033.diff"; + sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi"; + stripLen = 1; + }) + + # Fix missing includes for GCC 11 + (fetchpatch { + name = "headers-gcc-11.patch"; + url = "https://github.com/llvm/llvm-project/commit/b498303066a63a203d24f739b2d2e0e56dca70d1.patch"; + sha256 = "0nh123kld0dgz2h941lng331dkj3wbm5lfxm375k1f569gv83hlk"; + stripLen = 1; + }) + + # Fix invalid std::string(nullptr) for GCC 12 + (fetchpatch { + name = "nvptx-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/99e64623ec9b31def9375753491cc6093c831809.patch"; + sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; + stripLen = 1; + }) + (fetchpatch { + name = "dfaemitter-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/0841916e87a39e3c223c986e8da31e4a9a1432e3.patch"; + sha256 = "1kckghvsngs51mqm82asy0s9vr19h8aqbw43a0w44mccqw6bzrwf"; + stripLen = 1; + }) + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + + # Backport gcc-13 fixes with missing includes. + (fetchpatch { + name = "signals-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/ff1681ddb303223973653f7f5f3f3435b48a1983.patch"; + hash = "sha256-CXwYxQezTq5vdmc8Yn88BUAEly6YZ5VEIA6X3y5NNOs="; + stripLen = 1; + }) + ] ++ lib.optionals enablePolly [ + ./gnu-install-dirs-polly.patch + # Add missing isl header includess required to build LLVM 10 + Polly with clang 16. + (fetchpatch { + name = "polly-ppcg-isl-headers.patch"; + url = "https://repo.or.cz/ppcg.git/patch/098ba285306114dc71497f7b51c357f69c9b4472"; + hash = "sha256-c9L30rDROYAMbUSuaK9U/ixyFMlH/Sa1n+VgLODzSCQ="; + extraPrefix = "tools/polly/lib/External/ppcg/"; + stripLen = 1; + }) + ]; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/DebugInfo/X86/debug_addr.ll + rm test/tools/dsymutil/X86/op-convert.test + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/10/llvm/gnu-install-dirs-polly.patch b/llvm/10/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..3353058 --- /dev/null +++ b/llvm/10/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,106 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index 9939097f743e..8cc538da912a 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.4.3) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -145,14 +149,14 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 211f95512717..f9e04a4844b6 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 86de6f10686e..91f30891ccbe 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8ffd984e542b..261cc19f3238 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -274,7 +274,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/10/llvm/gnu-install-dirs.patch b/llvm/10/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..155bab3 --- /dev/null +++ b/llvm/10/llvm/gnu-install-dirs.patch @@ -0,0 +1,416 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0e85afa82c76..3e700d9c5fae 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -253,15 +253,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -527,9 +533,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -993,7 +999,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1005,7 +1011,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1020,13 +1026,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index f5a1b0d6f238..a7387224d68f 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -729,9 +729,9 @@ macro(add_llvm_library name) + + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- RUNTIME DESTINATION bin COMPONENT ${name}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -934,7 +934,7 @@ function(process_llvm_pass_plugins) + "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") + install(FILES + ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake +- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} ++ DESTINATION ${LLVM_INSTALL_CMAKE_DIR} + COMPONENT cmake-exports) + + set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") +@@ -1147,7 +1147,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1713,7 +1713,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1730,7 +1730,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1753,7 +1753,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1836,7 +1836,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -1958,9 +1959,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 554046b20edf..4d1ad980641e 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -144,9 +144,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index 2bf654b60c44..450ee45d86e6 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -78,7 +78,7 @@ function (add_sphinx_target builder project) + endif() + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index af757d6199a8..b0fb7e7705d1 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -96,13 +96,13 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") + set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") + set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}") + configure_file( +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 09fed8085c23..aa79f192abf0 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index a86ebb3a37bd..e720711e2b3c 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -516,8 +516,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -548,13 +548,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + macOS Only: If enabled CMake will generate a target named +@@ -740,9 +760,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/examples/Bye/CMakeLists.txt b/examples/Bye/CMakeLists.txt +index 3206f90d0916..1822965fc35f 100644 +--- a/examples/Bye/CMakeLists.txt ++++ b/examples/Bye/CMakeLists.txt +@@ -9,5 +9,5 @@ add_llvm_pass_plugin(Bye + BUILDTREE_ONLY + ) + +-install(TARGETS ${name} RUNTIME DESTINATION examples) ++install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + set_target_properties(${name} PROPERTIES FOLDER "Examples") +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index 1d5ca3ba92b0..026f5453c1da 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -4,5 +4,5 @@ add_subdirectory(Support) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 63cef75368b7..6295478b1f3d 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index fb12e29a36a8..dbb6c2b90332 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -358,12 +358,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = path.str(); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index b86e4abd01a7..02ce5773f17d 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -23,7 +23,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lto.exports) + add_llvm_library(LTO SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index ead73ec13a8f..250362021f17 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,7 +8,7 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) + +diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt +index e948496c603a..1f4df8a98b10 100644 +--- a/tools/remarks-shlib/CMakeLists.txt ++++ b/tools/remarks-shlib/CMakeLists.txt +@@ -11,7 +11,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Remarks.exports) + add_llvm_library(Remarks SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES}) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT Remarks) + + if (APPLE) diff --git a/llvm/10/openmp/default.nix b/llvm/10/openmp/default.nix new file mode 100644 index 0000000..012f882 --- /dev/null +++ b/llvm/10/openmp/default.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = fetch pname "0i4bn84lkpm5w3qkpvwm5z6jdj8fynp7d3bcasa1xyq4is6757yi"; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/11/clang/default.nix b/llvm/11/clang/default.nix new file mode 100644 index 0000000..f0d41a3 --- /dev/null +++ b/llvm/11/clang/default.nix @@ -0,0 +1,138 @@ +{ lib, stdenv, llvm_meta, fetch, fetchpatch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +, enablePolly ? false +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "clang" "12sm91qx2m79cvj75a9aazf2x8xybjbd593dv6v7rxficpq8i0ha"; + inherit clang-tools-extra_src; + + unpackPhase = '' + unpackFile $src + mv clang-* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals enablePolly [ + "-DWITH_POLLY=ON" + "-DLINK_POLLY_INTO_TOOLS=ON" + ]; + + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace tools/extra/clangd/CMakeLists.txt \ + --replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/11/clang/gnu-install-dirs.patch b/llvm/11/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..98ea97e --- /dev/null +++ b/llvm/11/clang/gnu-install-dirs.patch @@ -0,0 +1,235 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index bb4b801f01c8..77a8b43b22c8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,6 +9,8 @@ endif() + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to") + set(CMAKE_CXX_STANDARD_REQUIRED YES) + set(CMAKE_CXX_EXTENSIONS NO) +@@ -447,7 +449,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "*.def" +@@ -457,7 +459,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE +@@ -477,7 +479,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh) + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT bash-autocomplete) + if(NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-bash-autocomplete +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 704278a0e93b..d25c8d325c71 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -123,9 +123,9 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${lib} +@@ -170,7 +170,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT LLVM_ENABLE_IDE) +@@ -185,7 +185,7 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() + + function(clang_target_link_libraries target type) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 0692fe75a441..6f201e7207d0 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -208,7 +208,7 @@ set_target_properties(clang-resource-headers PROPERTIES + FOLDER "Misc" + RUNTIME_OUTPUT_DIRECTORY "${output_dir}") + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${generated_files} +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index ceef4b08637c..8efad5520ca4 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index 35ecdb11253c..d77d75de0094 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index cda8e29ec5b1..0134d8ccd70b 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -19,8 +19,8 @@ clang_target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 5cd9ac5cddc1..a197676fedbd 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -165,7 +165,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +@@ -196,7 +196,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index ec0702d76f18..d25d982f51da 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -47,7 +47,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-build) + endforeach() + +@@ -61,7 +61,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) + install(PROGRAMS libexec/${LibexecFile} +- DESTINATION libexec ++ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR} + COMPONENT scan-build) + endforeach() + +@@ -89,7 +89,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) + install(FILES share/scan-build/${ShareFile} +- DESTINATION share/scan-build ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build + COMPONENT scan-build) + endforeach() + +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index 22edb974bac7..9f140a9a4538 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -22,7 +22,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-view) + endforeach() + +@@ -36,7 +36,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) + install(FILES share/${ShareFile} +- DESTINATION share/scan-view ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view + COMPONENT scan-view) + endforeach() + +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 62f2de0cb15c..6aa66825b6ec 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -10,7 +10,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) + install(PROGRAMS ${CLANG_HMAPTOOL} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT hmaptool) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) diff --git a/llvm/11/clang/purity.patch b/llvm/11/clang/purity.patch new file mode 100644 index 0000000..deb230a --- /dev/null +++ b/llvm/11/clang/purity.patch @@ -0,0 +1,28 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,12 +487,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!IsStatic) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/11/compiler-rt/X86-support-extension.patch b/llvm/11/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..f6f9336 --- /dev/null +++ b/llvm/11/compiler-rt/X86-support-extension.patch @@ -0,0 +1,23 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -301,6 +301,10 @@ if (NOT MSVC) + i386/umoddi3.S + ) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -608,6 +612,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/11/compiler-rt/armv7l.patch b/llvm/11/compiler-rt/armv7l.patch new file mode 100644 index 0000000..120cfe6 --- /dev/null +++ b/llvm/11/compiler-rt/armv7l.patch @@ -0,0 +1,32 @@ +diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 +@@ -474,6 +474,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -595,7 +596,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/11/compiler-rt/default.nix b/llvm/11/compiler-rt/default.nix new file mode 100644 index 0000000..38dc7a0 --- /dev/null +++ b/llvm/11/compiler-rt/default.nix @@ -0,0 +1,140 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + isNewDarwinBootstrap = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + src = fetch "compiler-rt" "0x1j8ngf1zj63wlnns9vlibafq48qcm72p4jpaxkmkb4qw0grwfy"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isNewDarwinBootstrap) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals (!haveLibc || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM || isNewDarwinBootstrap) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + ../../common/compiler-rt/libsanitizer-no-cyclades-11.patch + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./armv7l.patch + # Fix build on armv6l + ../../common/compiler-rt/armv6-mcr-dmb.patch + ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ]; + + preConfigure = lib.optionalString stdenv.hostPlatform.isDarwin '' + cmakeFlagsArray+=("-DCMAKE_LIPO=$(command -v ${stdenv.cc.targetPrefix}lipo)") + '' + lib.optionalString (!haveLibc) '' + cmakeFlagsArray+=("-DCMAKE_C_FLAGS=-nodefaultlibs -ffreestanding") + ''; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + # See https://reviews.llvm.org/D37278 for why android exception + + lib.optionalString (stdenv.hostPlatform.isx86_32 && !stdenv.hostPlatform.isAndroid) '' + for f in $out/lib/*/*builtins-i?86*; do + ln -s "$f" $(echo "$f" | sed -e 's/builtins-i.86/builtins-i386/') + done + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + # compiler-rt requires a Clang stdenv on 32-bit RISC-V: + # https://reviews.llvm.org/D43106#1019077 + broken = stdenv.hostPlatform.isRiscV && stdenv.hostPlatform.is32bit && !stdenv.cc.isClang; + }; +} diff --git a/llvm/11/compiler-rt/gnu-install-dirs.patch b/llvm/11/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..91e2088 --- /dev/null +++ b/llvm/11/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,129 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index fa62814b635d..6328614d829e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -12,6 +12,7 @@ endif() + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + endif() +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index 7c127a93dfa7..6a95a65b70a7 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -524,7 +524,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -541,7 +541,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index be8d7e733c7a..ab256bdff26c 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -498,7 +498,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index 99b9f0e4af44..c5183ffa746e 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -375,7 +375,7 @@ endfunction() + function(get_compiler_rt_install_dir arch install_dir) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + get_compiler_rt_target(${arch} target) +- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE) ++ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${target} PARENT_SCOPE) + else() + set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + endif() +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 964dd598f102..2acaab87d349 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -66,11 +66,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -98,7 +98,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + set(COMPILER_RT_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + endif() + + if(APPLE) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index d47d7baeb118..507c8e5c713e 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -62,22 +62,22 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install fuzzer headers. + install(FILES ${FUZZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/fuzzer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/fuzzer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + # Install profile headers. + install(FILES ${PROFILE_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/profile) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/profile) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index 051215edbeb7..ecce1f52efb0 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -56,4 +56,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}) diff --git a/llvm/11/compiler-rt/normalize-var.patch b/llvm/11/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..b998691 --- /dev/null +++ b/llvm/11/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index c5183ffa746e..e4e4a007335d 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -299,8 +299,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/llvm/11/default.nix b/llvm/11/default.nix new file mode 100644 index 0000000..6ce7d86 --- /dev/null +++ b/llvm/11/default.nix @@ -0,0 +1,299 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +}: + +let + release_version = "11.1.0"; + candidate = ""; # empty or "rcN" + dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; + version = "${release_version}${dash-candidate}"; # differentiating these (variables) is important for RCs + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/${name}-${release_version}${candidate}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "18n1w1hkv931xzq02b34wglbv6zd6sd0r5kb8piwvag7klj7qw3n"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libllvm-polly = callPackage ./llvm { + inherit llvm_meta; + enablePolly = true; + }; + + llvm-polly = tools.libllvm-polly.lib // { outputSpecified = false; }; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + clang-polly-unwrapped = callPackage ./clang { + inherit llvm_meta; + inherit clang-tools-extra_src; + libllvm = tools.libllvm-polly; + enablePolly = true; + }; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # disabled until recommonmark supports sphinx 3 + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + src = fetch "lldb" "1vlyg015dyng43xqb8cg2l6r9ix8klibxsajazbfnckdnh54hwxj"; + patches = [ + ./lldb/procfs.patch + ./lldb/gnu-install-dirs.patch + ]; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if (stdenv.hostPlatform.useLLVM or false) || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) || (stdenv.hostPlatform.isRiscV && stdenv.hostPlatform.is32bit) + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if (stdenv.hostPlatform.useLLVM or false) || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) || (stdenv.hostPlatform.libc == "newlib") + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if (stdenv.hostPlatform.useLLVM or false) || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + stdenv = if (stdenv.hostPlatform.useLLVM or false) || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = if (stdenv.hostPlatform.useLLVM or false) || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/11/libcxx/default.nix b/llvm/11/libcxx/default.nix new file mode 100644 index 0000000..3e77e03 --- /dev/null +++ b/llvm/11/libcxx/default.nix @@ -0,0 +1,104 @@ +{ lib, stdenv, llvm_meta, fetch, fetchpatch, cmake, python3, llvm, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "1rgqsqpgi0vkga5d7hy0iyfsqgzfz7q1xy7afdfa1snp1qjks8xv"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + mv libcxxabi-* libcxxabi + unpackFile ${llvm.src} + mv llvm-* llvm + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + (fetchpatch { + # Backported from LLVM 12, avoids clashes with commonly used "block.h" header. + url = "https://github.com/llvm/llvm-project/commit/19bc9ea480b60b607a3e303f20c7a3a2ea553369.patch"; + sha256 = "sha256-aWa66ogmPkG0xHzSfcpD0qZyZQcNKwLV44js4eiun78="; + stripLen = 1; + }) + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz" + postPatch = '' + substituteInPlace include/__config \ + --replace "# define _LIBCPP_USE_AVAILABILITY_APPLE" "" + ''; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + + # TODO: this is a bit of a hack to cross compile to Apple Silicon. libcxx + # starting with 11 enables CMAKE_BUILD_WITH_INSTALL_NAME_DIR which requires + # platform setup for rpaths. In cmake, this is enabled when macos is newer + # than 10.5. However CMAKE_SYSTEM_VERSION is set to empty (TODO: why?) + # which prevents the conditional configuration, and configure fails. The + # value here corresponds to `uname -r`. If stdenv.hostPlatform.release is + # not null, then this property will be set via mkDerivation (TODO: how can + # we set this?). + ++ lib.optional ( + stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64 && + stdenv.hostPlatform != stdenv.buildPlatform + ) "-DCMAKE_SYSTEM_VERSION=20.1.0"; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/11/libcxx/gnu-install-dirs.patch b/llvm/11/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..2b95d6a --- /dev/null +++ b/llvm/11/libcxx/gnu-install-dirs.patch @@ -0,0 +1,100 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 910d04b54b6d..80ef692d83eb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -31,6 +31,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 11.1.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -418,7 +420,7 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) +@@ -426,11 +428,11 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_HEADER_DIR ${CMAKE_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + endif() + + file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index c5aa26739e36..8841c4a5252d 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -63,7 +63,7 @@ macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index be8141c98166..93847e5758cc 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -257,7 +257,7 @@ if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dir} + COMPONENT ${CXX_HEADER_TARGET} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +@@ -265,7 +265,7 @@ if (LIBCXX_INSTALL_HEADERS) + + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT ${CXX_HEADER_TARGET}) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 2001c09761d9..5bd11ea6b400 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -344,21 +344,21 @@ if (LIBCXX_INSTALL_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS cxx_experimental + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise diff --git a/llvm/11/libcxxabi/default.nix b/llvm/11/libcxxabi/default.nix new file mode 100644 index 0000000..8a0a18f --- /dev/null +++ b/llvm/11/libcxxabi/default.nix @@ -0,0 +1,89 @@ +{ lib, stdenv, llvm_meta, cmake, fetch, libcxx, libunwind, llvm, version +, enableShared ? !stdenv.hostPlatform.isStatic +, standalone ? stdenv.hostPlatform.useLLVM or false +, withLibunwind ? !stdenv.isDarwin && !stdenv.hostPlatform.isWasm +}: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "1azcf31mxw59hb1x17xncnm3dyw90ylh8rqx462lvypqh3nr6c8l"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + mv libcxx-* libcxx + unpackFile ${llvm.src} + mv llvm-* llvm + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d libcxx -i ${../../libcxx-0001-musl-hacks.patch} + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch} + ''; + + patches = [ + ../../common/libcxxabi/no-threads.patch + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = lib.optional withLibunwind libunwind; + + cmakeFlags = lib.optionals standalone [ + "-DLLVM_ENABLE_LIBCXX=ON" + ] ++ lib.optionals (standalone && withLibunwind) [ + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/11/libcxxabi/gnu-install-dirs.patch b/llvm/11/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..10651c1 --- /dev/null +++ b/llvm/11/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 36c6b2249e2b..a93c13ccaed9 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -24,6 +24,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 11.1.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -160,17 +162,17 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + else() + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + endif() + + set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.") diff --git a/llvm/11/libunwind/default.nix b/llvm/11/libunwind/default.nix new file mode 100644 index 0000000..462d632 --- /dev/null +++ b/llvm/11/libunwind/default.nix @@ -0,0 +1,32 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, fetchpatch +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + src = fetch pname "1vpqs2c358v8fbr1r8jmzkfqk12jllimjcfmgxga127ksq9b37nj"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/11/libunwind/gnu-install-dirs.patch b/llvm/11/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..b5b9c20 --- /dev/null +++ b/llvm/11/libunwind/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index e44a103648f9..aaf1f9555d7f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -18,6 +18,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD) + project(libunwind LANGUAGES C CXX ASM) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(NOT LLVM_CONFIG_PATH) +@@ -192,17 +194,17 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + endif() + + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) diff --git a/llvm/11/lld/default.nix b/llvm/11/lld/default.nix new file mode 100644 index 0000000..dbcd96a --- /dev/null +++ b/llvm/11/lld/default.nix @@ -0,0 +1,46 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "1kk61i7z5bi9i11rzsd2b388d42if1c7a45zkaa4mk0yps67hyh1"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/11/lld/gnu-install-dirs.patch b/llvm/11/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..19cf552 --- /dev/null +++ b/llvm/11/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 040bb2c8f6d7..f765f0096d97 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -205,7 +207,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index 23df41312403..d62372c88de7 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index e6f72fcd3488..d903609e6e4f 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -21,7 +21,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE lld-link ld.lld ld64.lld wasm-ld) diff --git a/llvm/11/lldb/gnu-install-dirs.patch b/llvm/11/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..fd49be3 --- /dev/null +++ b/llvm/11/lldb/gnu-install-dirs.patch @@ -0,0 +1,91 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index bf748020ea40..34103d2b5e1a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -17,6 +17,8 @@ set(CMAKE_MODULE_PATH + # If we are not building as part of LLVM, build LLDB as a standalone project, + # using LLVM as an external library. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ++ include(GNUInstallDirs) ++ + project(lldb) + include(LLDBStandalone) + +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 4ed5c647c5d2..89f96e710d55 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -107,13 +107,13 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() + # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS + install(TARGETS ${name} COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${install_dest} + ARCHIVE DESTINATION ${install_dest} + FRAMEWORK DESTINATION ${install_dest}) +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index 8465cfe3b7b7..01b7eae136e2 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -245,7 +245,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +@@ -254,7 +254,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index efba2f74904f..e08413b1dbb1 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -65,4 +65,4 @@ if (LLDB_ENABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index 752113b..010f187 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -62,7 +62,7 @@ endif() + + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) +-set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 OR CYGWIN) + # DLL platform -- put DLLs into bin. + set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index bf74802..1c98cae 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -222,7 +222,7 @@ if (LLDB_ENABLE_PYTHON) + if(LLDB_BUILD_FRAMEWORK) + set(LLDB_PYTHON_INSTALL_PATH ${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Resources/Python) + else() +- set(LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_RELATIVE_PATH}) ++ set(LLDB_PYTHON_INSTALL_PATH ${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH}) + endif() + if (NOT CMAKE_CFG_INTDIR STREQUAL ".") + string(REPLACE ${CMAKE_CFG_INTDIR} "\$\{CMAKE_INSTALL_CONFIG_NAME\}" LLDB_PYTHON_INSTALL_PATH ${LLDB_PYTHON_INSTALL_PATH}) diff --git a/llvm/11/lldb/procfs.patch b/llvm/11/lldb/procfs.patch new file mode 100644 index 0000000..b075dba --- /dev/null +++ b/llvm/11/lldb/procfs.patch @@ -0,0 +1,31 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -11,21 +11,12 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif diff --git a/llvm/11/llvm/default.nix b/llvm/11/llvm/default.nix new file mode 100644 index 0000000..01e6483 --- /dev/null +++ b/llvm/11/llvm/default.nix @@ -0,0 +1,363 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl) && (!stdenv.hostPlatform.isRiscV) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? false # TODO should be on by default +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch pname "199yq3a214avcbi4kk2q0ajriifkvsr0l2dkx3a666m033ihi1ff"; + polly_src = fetch "polly" "031r23ijhx7v93a5n33m2nc0x9xyqmx0d8xg80z7q971p6qd63sq"; + + unpackPhase = '' + unpackFile $src + mv llvm-${release_version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + patches = [ + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + ./gnu-install-dirs.patch + # On older CPUs (e.g. Hydra/wendy) we'd be getting an error in this test. + (fetchpatch { + name = "uops-CMOV16rm-noreg.diff"; + url = "https://github.com/llvm/llvm-project/commit/9e9f991ac033.diff"; + sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi"; + stripLen = 1; + }) + # gcc-11 compat upstream patch + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/b498303066a63a203d24f739b2d2e0e56dca70d1.patch"; + sha256 = "sha256:0nh123kld0dgz2h941lng331dkj3wbm5lfxm375k1f569gv83hlk"; + stripLen = 1; + }) + + # Fix invalid std::string(nullptr) for GCC 12 + (fetchpatch { + name = "nvptx-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/99e64623ec9b31def9375753491cc6093c831809.patch"; + sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; + stripLen = 1; + }) + (fetchpatch { + name = "dfaemitter-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/0841916e87a39e3c223c986e8da31e4a9a1432e3.patch"; + sha256 = "1kckghvsngs51mqm82asy0s9vr19h8aqbw43a0w44mccqw6bzrwf"; + stripLen = 1; + }) + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + + # Backport gcc-13 fixes with missing includes. + (fetchpatch { + name = "signals-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/ff1681ddb303223973653f7f5f3f3435b48a1983.patch"; + hash = "sha256-CXwYxQezTq5vdmc8Yn88BUAEly6YZ5VEIA6X3y5NNOs="; + stripLen = 1; + }) + (fetchpatch { + name = "base64-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/5e9be93566f39ee6cecd579401e453eccfbe81e5.patch"; + hash = "sha256-PAwrVrvffPd7tphpwCkYiz+67szPRzRB2TXBvKfzQ7U="; + stripLen = 1; + }) + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-readobj/ELF/dependent-libraries.test + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + # This is a Shared Library not tied to LLVM_ENABLE_PIC + "-DLLVM_TOOL_REMARKS_SHLIB_BUILD=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/11/llvm/gnu-install-dirs-polly.patch b/llvm/11/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..fff2d49 --- /dev/null +++ b/llvm/11/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,106 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index 9939097f743e..8cc538da912a 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.4.3) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -145,14 +149,14 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 211f95512717..f9e04a4844b6 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 86de6f10686e..91f30891ccbe 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 1039079cb49c..28b499ae1e9e 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -275,7 +275,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/11/llvm/gnu-install-dirs.patch b/llvm/11/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..29df98a --- /dev/null +++ b/llvm/11/llvm/gnu-install-dirs.patch @@ -0,0 +1,417 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 247ad36d3845..815e2c4ba955 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -269,15 +269,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -559,9 +565,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -1107,7 +1113,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1119,7 +1125,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1134,13 +1140,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index b74adc11ade9..a5aa258cde30 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -766,9 +766,9 @@ macro(add_llvm_library name) + + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- RUNTIME DESTINATION bin COMPONENT ${name}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -981,7 +981,7 @@ function(process_llvm_pass_plugins) + "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") + install(FILES + ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake +- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} ++ DESTINATION ${LLVM_INSTALL_CMAKE_DIR} + COMPONENT cmake-exports) + + set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") +@@ -1201,7 +1201,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1819,7 +1819,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1836,7 +1836,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1859,7 +1859,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1942,7 +1942,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -2064,9 +2065,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 554046b20edf..4d1ad980641e 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -144,9 +144,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index b5babb30abcf..190b1222a9f9 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -84,7 +84,7 @@ function (add_sphinx_target builder project) + endif() + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 4b8879f65fe4..f01920bcc60f 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -108,13 +108,13 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") + set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + + # Generate a default location for lit + if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 09fed8085c23..aa79f192abf0 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 1f908d3e95b1..1315e0aa40e1 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -516,8 +516,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -548,13 +548,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + macOS Only: If enabled CMake will generate a target named +@@ -752,9 +772,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/examples/Bye/CMakeLists.txt b/examples/Bye/CMakeLists.txt +index bb96edb4b4bf..678c22fb43c8 100644 +--- a/examples/Bye/CMakeLists.txt ++++ b/examples/Bye/CMakeLists.txt +@@ -14,6 +14,6 @@ if (NOT WIN32) + BUILDTREE_ONLY + ) + +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endif() +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index b46319f24fc8..2feabd1954e4 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -5,5 +5,5 @@ add_subdirectory(Frontend) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 63cef75368b7..6295478b1f3d 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 7e74b7c90816..f185e9283f83 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -358,12 +358,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = std::string(path.str()); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 2963f97cad88..69d66c9c9ca1 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -25,7 +25,7 @@ add_llvm_library(LTO SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS + intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index ead73ec13a8f..250362021f17 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,7 +8,7 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) + +diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt +index e948496c603a..1f4df8a98b10 100644 +--- a/tools/remarks-shlib/CMakeLists.txt ++++ b/tools/remarks-shlib/CMakeLists.txt +@@ -11,7 +11,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Remarks.exports) + add_llvm_library(Remarks SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES}) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT Remarks) + + if (APPLE) diff --git a/llvm/11/openmp/default.nix b/llvm/11/openmp/default.nix new file mode 100644 index 0000000..6c2dd9a --- /dev/null +++ b/llvm/11/openmp/default.nix @@ -0,0 +1,47 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, fetchpatch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = fetch pname "0bh5cswgpc79awlq8j5i7hp355adaac7s6zaz0zwp6mkflxli1yi"; + + patches = [ + # Fix compilation on aarch64-darwin, remove after the next release. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/7b5254223acbf2ef9cd278070c5a84ab278d7e5f.patch"; + sha256 = "sha256-A+9/IVIoazu68FK5H5CiXcOEYe1Hpp4xTx2mIw7m8Es="; + stripLen = 1; + }) + ]; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/12/clang/default.nix b/llvm/12/clang/default.nix new file mode 100644 index 0000000..7ecd4ef --- /dev/null +++ b/llvm/12/clang/default.nix @@ -0,0 +1,132 @@ +{ lib, stdenv, llvm_meta, fetch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "clang" "0px4gl27az6cdz6adds89qzdwb1cqpjsfvrldbz9qvpmphrj34bf"; + inherit clang-tools-extra_src; + + unpackPhase = '' + unpackFile $src + mv clang-* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + substituteInPlace $sourceRoot/tools/extra/clangd/quality/CompletionModel.cmake \ + --replace ' ''${CMAKE_SOURCE_DIR}/../clang-tools-extra' ' ''${CMAKE_SOURCE_DIR}/tools/extra' + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/12/clang/gnu-install-dirs.patch b/llvm/12/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..b834d38 --- /dev/null +++ b/llvm/12/clang/gnu-install-dirs.patch @@ -0,0 +1,235 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9e74014134a0..976e6a1757fd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.13.4) + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to") + set(CMAKE_CXX_STANDARD_REQUIRED YES) + set(CMAKE_CXX_EXTENSIONS NO) +@@ -416,7 +418,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "*.def" +@@ -425,7 +427,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE +@@ -445,7 +447,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh) + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT bash-autocomplete) + if(NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-bash-autocomplete +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 704278a0e93b..d25c8d325c71 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -123,9 +123,9 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${lib} +@@ -170,7 +170,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT LLVM_ENABLE_IDE) +@@ -185,7 +185,7 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() + + function(clang_target_link_libraries target type) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index b2c0ce8dd4a0..19e5443d8c25 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -215,7 +215,7 @@ set_target_properties(clang-resource-headers PROPERTIES + FOLDER "Misc" + RUNTIME_OUTPUT_DIRECTORY "${output_dir}") + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${generated_files} +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index ceef4b08637c..8efad5520ca4 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index 35ecdb11253c..d77d75de0094 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index cda8e29ec5b1..0134d8ccd70b 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -19,8 +19,8 @@ clang_target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 51ff2e7e1565..1ed5f8a079a1 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -166,7 +166,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +@@ -196,7 +196,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index ec0702d76f18..d25d982f51da 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -47,7 +47,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-build) + endforeach() + +@@ -61,7 +61,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) + install(PROGRAMS libexec/${LibexecFile} +- DESTINATION libexec ++ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR} + COMPONENT scan-build) + endforeach() + +@@ -89,7 +89,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) + install(FILES share/scan-build/${ShareFile} +- DESTINATION share/scan-build ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build + COMPONENT scan-build) + endforeach() + +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index dd3d33439299..fea19c12ce70 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -19,7 +19,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-view) + endforeach() + +@@ -33,7 +33,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) + install(FILES share/${ShareFile} +- DESTINATION share/scan-view ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view + COMPONENT scan-view) + endforeach() + +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 62f2de0cb15c..6aa66825b6ec 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -10,7 +10,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) + install(PROGRAMS ${CLANG_HMAPTOOL} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT hmaptool) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) diff --git a/llvm/12/clang/purity.patch b/llvm/12/clang/purity.patch new file mode 100644 index 0000000..deb230a --- /dev/null +++ b/llvm/12/clang/purity.patch @@ -0,0 +1,28 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,12 +487,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!IsStatic) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/12/compiler-rt/X86-support-extension.patch b/llvm/12/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..66742e5 --- /dev/null +++ b/llvm/12/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -345,4 +345,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -608,6 +612,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/12/compiler-rt/armv7l.patch b/llvm/12/compiler-rt/armv7l.patch new file mode 100644 index 0000000..120cfe6 --- /dev/null +++ b/llvm/12/compiler-rt/armv7l.patch @@ -0,0 +1,32 @@ +diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 +@@ -474,6 +474,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -595,7 +596,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/12/compiler-rt/default.nix b/llvm/12/compiler-rt/default.nix new file mode 100644 index 0000000..02c2001 --- /dev/null +++ b/llvm/12/compiler-rt/default.nix @@ -0,0 +1,125 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + src = fetch "compiler-rt" "1950rg294izdwkaasi7yjrmadc9mzdd5paf0q63jjcq2m3rdbj5l"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./armv7l.patch + # Fix build on armv6l + ../../common/compiler-rt/armv6-mcr-dmb.patch + ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ]; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/12/compiler-rt/gnu-install-dirs.patch b/llvm/12/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..5f02576 --- /dev/null +++ b/llvm/12/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,129 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b44ad2c2118e..d42f5664d448 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.13.4) + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + endif() +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index 361538a58e47..f0d8d9ab80f1 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -495,7 +495,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -512,7 +512,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index 456a8dcda59f..7a09e74c7c79 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -508,7 +508,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index f61d487e93a0..f1f46fb9599c 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -378,7 +378,7 @@ endfunction() + function(get_compiler_rt_install_dir arch install_dir) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + get_compiler_rt_target(${arch} target) +- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE) ++ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${target} PARENT_SCOPE) + else() + set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + endif() +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 1edab43e7c0d..1aac6b73ff82 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -65,11 +65,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -97,7 +97,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + set(COMPILER_RT_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + endif() + + if(APPLE) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index b00e8caa1ddd..0fe64e4862c9 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -69,22 +69,22 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install fuzzer headers. + install(FILES ${FUZZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/fuzzer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/fuzzer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + # Install profile headers. + install(FILES ${PROFILE_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/profile) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/profile) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index a29de8deff1b..d39ff01613d2 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -57,4 +57,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}) diff --git a/llvm/12/compiler-rt/normalize-var.patch b/llvm/12/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..135cf62 --- /dev/null +++ b/llvm/12/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index f1f46fb9599c..6f19e69507ba 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -302,8 +302,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/llvm/12/default.nix b/llvm/12/default.nix new file mode 100644 index 0000000..b976dd2 --- /dev/null +++ b/llvm/12/default.nix @@ -0,0 +1,300 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +}: + +let + release_version = "12.0.1"; + candidate = ""; # empty or "rcN" + dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; + version = "${release_version}${dash-candidate}"; # differentiating these (variables) is important for RCs + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/${name}-${release_version}${candidate}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "1r9a4fdz9ci58b5z2inwvm4z4cdp6scrivnaw05dggkxz7yrwrb5"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + # disabled until recommonmark supports sphinx 3 + #Llvm-manpages = lowPrio (tools.libllvm.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + #}); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # disabled until recommonmark supports sphinx 3 + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + inherit (libraries) libunwind; + }; + + lldb = callPackage ../common/lldb.nix { + src = fetch "lldb" "0g3pj1m3chafavpr35r9fynm85y2hdyla6klj0h28khxs2613i78"; + patches = + let + resourceDirPatch = callPackage + ({ substituteAll, libclang }: substituteAll + { + src = ./lldb/resource-dir.patch; + clangLibDir = "${libclang.lib}/lib"; + }) + { }; + in + [ + ./lldb/procfs.patch + resourceDirPatch + ./lldb/gnu-install-dirs.patch + ]; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + inherit (buildLlvmTools) llvm; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/12/libcxx/default.nix b/llvm/12/libcxx/default.nix new file mode 100644 index 0000000..40bff3c --- /dev/null +++ b/llvm/12/libcxx/default.nix @@ -0,0 +1,79 @@ +{ lib, stdenv, llvm_meta, fetch, cmake, python3, llvm, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "05cx39ldlxchck454lgfly1xj0c7x65iyx4hqhiihrlg6p6qj854"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + mv libcxxabi-* libcxxabi + unpackFile ${llvm.src} + mv llvm-* llvm + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/12/libcxx/gnu-install-dirs.patch b/llvm/12/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..1f9de00 --- /dev/null +++ b/llvm/12/libcxx/gnu-install-dirs.patch @@ -0,0 +1,100 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9bf1a02f0908..612cd4aab76c 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -28,6 +28,8 @@ set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 12.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -402,7 +404,7 @@ endif () + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) +@@ -410,11 +412,11 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_HEADER_DIR ${CMAKE_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + endif() + + file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 5d2764e870e9..bb1ec5de6ca2 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -63,7 +63,7 @@ macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 29a317b8ae9a..4747263cfd1b 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -252,7 +252,7 @@ if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +@@ -260,7 +260,7 @@ if (LIBCXX_INSTALL_HEADERS) + + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT cxx-headers) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 9965104cb5b2..9b55dbb1d822 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -352,21 +352,21 @@ if (LIBCXX_INSTALL_SHARED_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS cxx_experimental + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise diff --git a/llvm/12/libcxxabi/default.nix b/llvm/12/libcxxabi/default.nix new file mode 100644 index 0000000..78a4a68 --- /dev/null +++ b/llvm/12/libcxxabi/default.nix @@ -0,0 +1,87 @@ +{ lib, stdenv, llvm_meta, cmake, python3, fetch, libcxx, libunwind, llvm, version +, enableShared ? !stdenv.hostPlatform.isStatic +, standalone ? stdenv.hostPlatform.useLLVM or false +, withLibunwind ? !stdenv.isDarwin && !stdenv.hostPlatform.isWasm +}: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "1l4idd8npbkm168d26kqn529yv3npsd8f2dm8a7iwyknj7iyivw8"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + mv libcxx-* libcxx + unpackFile ${llvm.src} + mv llvm-* llvm + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d libcxx -i ${../../libcxx-0001-musl-hacks.patch} + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch} + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake python3 ]; + buildInputs = lib.optional withLibunwind libunwind; + + cmakeFlags = lib.optionals standalone [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/12/libcxxabi/gnu-install-dirs.patch b/llvm/12/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..b49b168 --- /dev/null +++ b/llvm/12/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 426c855288fc..a9812a994f53 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -27,6 +27,8 @@ set(LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 11.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -180,17 +182,17 @@ set(CMAKE_MODULE_PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + else() + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + endif() + + set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.") diff --git a/llvm/12/libunwind/default.nix b/llvm/12/libunwind/default.nix new file mode 100644 index 0000000..8ed2468 --- /dev/null +++ b/llvm/12/libunwind/default.nix @@ -0,0 +1,39 @@ +{ lib, stdenv, llvm_meta, version, fetch, libcxx, llvm, cmake +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + src = fetch pname "192ww6n81lj2mb9pj4043z79jp3cf58a9c2qrxjwm5c3a64n1shb"; + + postUnpack = '' + unpackFile ${libcxx.src} + mv libcxx-* libcxx + unpackFile ${llvm.src} + mv llvm-* llvm + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/12/libunwind/gnu-install-dirs.patch b/llvm/12/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..a791d6c --- /dev/null +++ b/llvm/12/libunwind/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 48cb8e004e08..fec8144fb95a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -23,6 +23,8 @@ set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD) + project(libunwind LANGUAGES C CXX ASM) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libunwind) + set(PACKAGE_VERSION 12.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -115,17 +117,17 @@ set(CMAKE_MODULE_PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + endif() + + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) diff --git a/llvm/12/lld/default.nix b/llvm/12/lld/default.nix new file mode 100644 index 0000000..01b7e41 --- /dev/null +++ b/llvm/12/lld/default.nix @@ -0,0 +1,54 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, libunwind +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "0qg3fgc7wj34hdkqn21y03zcmsdd01szhhm1hfki63iifrm3y2v9"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + substituteInPlace MachO/CMakeLists.txt --replace \ + '(''${LLVM_MAIN_SRC_DIR}/' '(' + mkdir -p libunwind/include + tar -xf "${libunwind.src}" --wildcards -C libunwind/include --strip-components=2 "libunwind-*/include/" + ''; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/12/lld/gnu-install-dirs.patch b/llvm/12/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..61e2f0e --- /dev/null +++ b/llvm/12/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index d4e561b50d8f..cfa5bdd79c2a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -179,7 +181,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index 23df41312403..d62372c88de7 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index 5cff736ff57f..64e775c771b9 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -21,7 +21,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE diff --git a/llvm/12/lldb/gnu-install-dirs.patch b/llvm/12/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..afc945c --- /dev/null +++ b/llvm/12/lldb/gnu-install-dirs.patch @@ -0,0 +1,91 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b5633e21c56a..f2f1035e9238 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -10,6 +10,8 @@ set(CMAKE_MODULE_PATH + # If we are not building as part of LLVM, build LLDB as a standalone project, + # using LLVM as an external library. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ++ include(GNUInstallDirs) ++ + project(lldb) + include(LLDBStandalone) + +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 4ed5c647c5d2..89f96e710d55 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -107,13 +107,13 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() + # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS + install(TARGETS ${name} COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${install_dest} + ARCHIVE DESTINATION ${install_dest} + FRAMEWORK DESTINATION ${install_dest}) +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index 2fdf1502d055..37364341ff8b 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -225,7 +225,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".cmake" EXCLUDE +@@ -233,7 +233,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".cmake" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 734167e51bc5..f95761b5df58 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -65,4 +65,4 @@ if (LLDB_ENABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index 752113b..010f187 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -62,7 +62,7 @@ endif() + + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) +-set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 OR CYGWIN) + # DLL platform -- put DLLs into bin. + set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b5633e2..86e4738 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -79,7 +79,7 @@ if (LLDB_ENABLE_PYTHON) + if(LLDB_BUILD_FRAMEWORK) + set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb") + else() +- set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb") ++ set(lldb_python_target_dir "${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH}/lldb") + endif() + get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR) + finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}") diff --git a/llvm/12/lldb/procfs.patch b/llvm/12/lldb/procfs.patch new file mode 100644 index 0000000..b075dba --- /dev/null +++ b/llvm/12/lldb/procfs.patch @@ -0,0 +1,31 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -11,21 +11,12 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif diff --git a/llvm/12/lldb/resource-dir.patch b/llvm/12/lldb/resource-dir.patch new file mode 100644 index 0000000..e0db80a --- /dev/null +++ b/llvm/12/lldb/resource-dir.patch @@ -0,0 +1,13 @@ +diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake +index 37364341ff8b..7f74c1a3e257 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers) + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" +- "${LLVM_BUILD_LIBRARY_DIR}" ++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") diff --git a/llvm/12/llvm/default.nix b/llvm/12/llvm/default.nix new file mode 100644 index 0000000..97d8f27 --- /dev/null +++ b/llvm/12/llvm/default.nix @@ -0,0 +1,351 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch pname "1pzx9zrmd7r3481sbhwvkms68fwhffpp4mmz45dgrkjpyl2q96kx"; + polly_src = fetch "polly" "1yfm9ixda4a2sx7ak5vswijx4ydk5lv1c1xh39xmd2kh299y4m12"; + + unpackPhase = '' + unpackFile $src + mv llvm-${release_version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = optionals (stdenv.buildPlatform == stdenv.hostPlatform) [ ncurses ] + ++ [ zlib ]; + + patches = [ + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + # Fix llvm being miscompiled by some gccs. See llvm/llvm-project#49955 + # Fix llvm being miscompiled by some gccs. See https://github.com/llvm/llvm-project/issues/49955 + ./fix-llvm-issue-49955.patch + + ./gnu-install-dirs.patch + # On older CPUs (e.g. Hydra/wendy) we'd be getting an error in this test. + (fetchpatch { + name = "uops-CMOV16rm-noreg.diff"; + url = "https://github.com/llvm/llvm-project/commit/9e9f991ac033.diff"; + sha256 = "sha256:12s8vr6ibri8b48h2z38f3afhwam10arfiqfy4yg37bmc054p5hi"; + stripLen = 1; + }) + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + + # Backport gcc-13 fixes with missing includes. + (fetchpatch { + name = "signals-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/ff1681ddb303223973653f7f5f3f3435b48a1983.patch"; + hash = "sha256-CXwYxQezTq5vdmc8Yn88BUAEly6YZ5VEIA6X3y5NNOs="; + stripLen = 1; + }) + (fetchpatch { + name = "base64-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/5e9be93566f39ee6cecd579401e453eccfbe81e5.patch"; + hash = "sha256-PAwrVrvffPd7tphpwCkYiz+67szPRzRB2TXBvKfzQ7U="; + stripLen = 1; + }) + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + # TODO: Fix failing tests: + rm test/DebugInfo/X86/vla-multi.ll + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-objcopy/MachO/universal-object.test + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-O0-defaults.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/12/llvm/fix-llvm-issue-49955.patch b/llvm/12/llvm/fix-llvm-issue-49955.patch new file mode 100644 index 0000000..b515583 --- /dev/null +++ b/llvm/12/llvm/fix-llvm-issue-49955.patch @@ -0,0 +1,13 @@ +diff --git a/lib/CodeGen/AsmPrinter/CMakeLists.txt b/lib/CodeGen/AsmPrinter/CMakeLists.txt +index eb924282..c77c140b 100644 +--- a/lib/CodeGen/AsmPrinter/CMakeLists.txt ++++ b/lib/CodeGen/AsmPrinter/CMakeLists.txt +@@ -44,3 +44,8 @@ add_llvm_component_library(LLVMAsmPrinter + Support + Target + ) ++ ++if (CMAKE_COMPILER_IS_GNUCXX) ++ set_source_files_properties(DwarfCompileUnit.cpp PROPERTIES ++ COMPILE_FLAGS -fno-strict-aliasing) ++endif() diff --git a/llvm/12/llvm/gnu-install-dirs-polly.patch b/llvm/12/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..68f3c45 --- /dev/null +++ b/llvm/12/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,105 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index ca7c04c565bb..6ed5db5dd4f8 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.13.4) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -122,13 +126,13 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 7cc129ba2e90..137be25e4b80 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8991094d92c7..178d8ad606bb 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -275,7 +275,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/12/llvm/gnu-install-dirs.patch b/llvm/12/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..da8dc14 --- /dev/null +++ b/llvm/12/llvm/gnu-install-dirs.patch @@ -0,0 +1,417 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 277d0fe54d7b..af69c8be8745 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -256,15 +256,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -567,9 +573,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -1027,7 +1033,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1038,7 +1044,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1052,13 +1058,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 97c9980c7de3..409e8b615f75 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -804,9 +804,9 @@ macro(add_llvm_library name) + + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- RUNTIME DESTINATION bin COMPONENT ${name}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -1022,7 +1022,7 @@ function(process_llvm_pass_plugins) + "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") + install(FILES + ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake +- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} ++ DESTINATION ${LLVM_INSTALL_CMAKE_DIR} + COMPONENT cmake-exports) + + set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") +@@ -1242,7 +1242,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1854,7 +1854,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1871,7 +1871,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1894,7 +1894,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1977,7 +1977,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -2100,9 +2101,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 554046b20edf..4d1ad980641e 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -144,9 +144,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index e80c3b5c1cac..482f6d715ef5 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -90,7 +90,7 @@ function (add_sphinx_target builder project) + endif() + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 505dc9a29d70..36e6c63af3f4 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -107,13 +107,13 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") + set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + + # Generate a default location for lit + if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 09fed8085c23..aa79f192abf0 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index bb821b417ad9..6a528f7c2ad3 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -550,8 +550,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -582,13 +582,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + macOS Only: If enabled CMake will generate a target named +@@ -786,9 +806,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/examples/Bye/CMakeLists.txt b/examples/Bye/CMakeLists.txt +index bb96edb4b4bf..678c22fb43c8 100644 +--- a/examples/Bye/CMakeLists.txt ++++ b/examples/Bye/CMakeLists.txt +@@ -14,6 +14,6 @@ if (NOT WIN32) + BUILDTREE_ONLY + ) + +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endif() +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index b46319f24fc8..2feabd1954e4 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -5,5 +5,5 @@ add_subdirectory(Frontend) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index ebe5b73a5c65..70c497be12f5 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 1a2f04552d13..44fa7d3eec6b 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -357,12 +357,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = std::string(path.str()); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 2963f97cad88..69d66c9c9ca1 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -25,7 +25,7 @@ add_llvm_library(LTO SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS + intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index ead73ec13a8f..250362021f17 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,7 +8,7 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) + +diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt +index 865436247270..ce1daa62f6ab 100644 +--- a/tools/remarks-shlib/CMakeLists.txt ++++ b/tools/remarks-shlib/CMakeLists.txt +@@ -19,7 +19,7 @@ if(LLVM_ENABLE_PIC) + endif() + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT Remarks) + + if (APPLE) diff --git a/llvm/12/openmp/default.nix b/llvm/12/openmp/default.nix new file mode 100644 index 0000000..6040f3d --- /dev/null +++ b/llvm/12/openmp/default.nix @@ -0,0 +1,48 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, fetchpatch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = fetch pname "14dh0r6h2xh747ffgnsl4z08h0ri04azi9vf79cbz7ma1r27kzk0"; + + patches = [ + # Fix cross. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch"; + hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A="; + }) + ]; + + patchFlags = [ "-p2" ]; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/13/clang/default.nix b/llvm/13/clang/default.nix new file mode 100644 index 0000000..a070e64 --- /dev/null +++ b/llvm/13/clang/default.nix @@ -0,0 +1,126 @@ +{ lib, stdenv, llvm_meta, src, substituteAll, cmake, libxml2, libllvm, version, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/clang"; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + # Revert of https://reviews.llvm.org/D100879 + # The malloc alignment assumption is incorrect for jemalloc and causes + # mis-compilation in firefox. + # See: https://bugzilla.mozilla.org/show_bug.cgi?id=1741454 + ./revert-malloc-alignment-assumption.patch + ../../common/clang/add-nostdlibinc-flag.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + (cd tools && ln -s ../../clang-tools-extra extra) + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/13/clang/gnu-install-dirs.patch b/llvm/13/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..b834d38 --- /dev/null +++ b/llvm/13/clang/gnu-install-dirs.patch @@ -0,0 +1,235 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9e74014134a0..976e6a1757fd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.13.4) + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to") + set(CMAKE_CXX_STANDARD_REQUIRED YES) + set(CMAKE_CXX_EXTENSIONS NO) +@@ -416,7 +418,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "*.def" +@@ -425,7 +427,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE +@@ -445,7 +447,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + add_custom_target(bash-autocomplete DEPENDS utils/bash-autocomplete.sh) + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT bash-autocomplete) + if(NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-bash-autocomplete +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 704278a0e93b..d25c8d325c71 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -123,9 +123,9 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${lib} +@@ -170,7 +170,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT LLVM_ENABLE_IDE) +@@ -185,7 +185,7 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() + + function(clang_target_link_libraries target type) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index b2c0ce8dd4a0..19e5443d8c25 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -215,7 +215,7 @@ set_target_properties(clang-resource-headers PROPERTIES + FOLDER "Misc" + RUNTIME_OUTPUT_DIRECTORY "${output_dir}") + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${generated_files} +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index ceef4b08637c..8efad5520ca4 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index 35ecdb11253c..d77d75de0094 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index cda8e29ec5b1..0134d8ccd70b 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -19,8 +19,8 @@ clang_target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 51ff2e7e1565..1ed5f8a079a1 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -166,7 +166,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +@@ -196,7 +196,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index ec0702d76f18..d25d982f51da 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -47,7 +47,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-build) + endforeach() + +@@ -61,7 +61,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) + install(PROGRAMS libexec/${LibexecFile} +- DESTINATION libexec ++ DESTINATION ${CMAKE_INSTALL_LIBEXECDIR} + COMPONENT scan-build) + endforeach() + +@@ -89,7 +89,7 @@ if(CLANG_INSTALL_SCANBUILD) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) + install(FILES share/scan-build/${ShareFile} +- DESTINATION share/scan-build ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build + COMPONENT scan-build) + endforeach() + +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index dd3d33439299..fea19c12ce70 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -19,7 +19,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) + install(PROGRAMS bin/${BinFile} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT scan-view) + endforeach() + +@@ -33,7 +33,7 @@ if(CLANG_INSTALL_SCANVIEW) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) + install(FILES share/${ShareFile} +- DESTINATION share/scan-view ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view + COMPONENT scan-view) + endforeach() + +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 62f2de0cb15c..6aa66825b6ec 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -10,7 +10,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) + install(PROGRAMS ${CLANG_HMAPTOOL} +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT hmaptool) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) diff --git a/llvm/13/clang/purity.patch b/llvm/13/clang/purity.patch new file mode 100644 index 0000000..deb230a --- /dev/null +++ b/llvm/13/clang/purity.patch @@ -0,0 +1,28 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,12 +487,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!IsStatic) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/13/clang/revert-malloc-alignment-assumption.patch b/llvm/13/clang/revert-malloc-alignment-assumption.patch new file mode 100644 index 0000000..f8e55ff --- /dev/null +++ b/llvm/13/clang/revert-malloc-alignment-assumption.patch @@ -0,0 +1,78 @@ +--- b/include/clang/Basic/TargetInfo.h ++++ a/include/clang/Basic/TargetInfo.h +@@ -612,8 +612,8 @@ + } + + /// Return the largest alignment for which a suitably-sized allocation with ++ /// '::operator new(size_t)' is guaranteed to produce a correctly-aligned ++ /// pointer. +- /// '::operator new(size_t)' or 'malloc' is guaranteed to produce a +- /// correctly-aligned pointer. + unsigned getNewAlign() const { + return NewAlign ? NewAlign : std::max(LongDoubleAlign, LongLongAlign); + } +--- b/lib/CodeGen/CGCall.cpp ++++ a/lib/CodeGen/CGCall.cpp +@@ -2048,24 +2048,6 @@ + // allows it to work on indirect virtual function calls. + if (AttrOnCallSite && TargetDecl->hasAttr()) + FuncAttrs.addAttribute(llvm::Attribute::NoMerge); +- +- // Add known guaranteed alignment for allocation functions. +- if (unsigned BuiltinID = Fn->getBuiltinID()) { +- switch (BuiltinID) { +- case Builtin::BIaligned_alloc: +- case Builtin::BIcalloc: +- case Builtin::BImalloc: +- case Builtin::BImemalign: +- case Builtin::BIrealloc: +- case Builtin::BIstrdup: +- case Builtin::BIstrndup: +- RetAttrs.addAlignmentAttr(Context.getTargetInfo().getNewAlign() / +- Context.getTargetInfo().getCharWidth()); +- break; +- default: +- break; +- } +- } + } + + // 'const', 'pure' and 'noalias' attributed functions are also nounwind. +--- b/test/CodeGen/alloc-fns-alignment.c ++++ /dev/null +@@ -1,35 +0,0 @@ +-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN16 +-// RUN: %clang_cc1 -triple x86_64-windows-msvc -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN16 +-// RUN: %clang_cc1 -triple i386-apple-darwin -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN16 +-// RUN: %clang_cc1 -triple i386-unknown-linux-gnu -emit-llvm < %s | FileCheck %s --check-prefix=ALIGN8 +-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-malloc -emit-llvm < %s | FileCheck %s --check-prefix=NOBUILTIN-MALLOC +-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-calloc -emit-llvm < %s | FileCheck %s --check-prefix=NOBUILTIN-CALLOC +-// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-builtin-realloc -emit-llvm < %s | FileCheck %s --check-prefix=NOBUILTIN-REALLOC +- +-typedef __SIZE_TYPE__ size_t; +- +-void *malloc(size_t); +-void *calloc(size_t, size_t); +-void *realloc(void *, size_t); +- +-void *malloc_test(size_t n) { +- return malloc(n); +-} +- +-void *calloc_test(size_t n) { +- return calloc(1, n); +-} +- +-void *raalloc_test(void *p, size_t n) { +- return realloc(p, n); +-} +- +-// ALIGN16: align 16 i8* @malloc +-// ALIGN16: align 16 i8* @calloc +-// ALIGN16: align 16 i8* @realloc +-// ALIGN8: align 8 i8* @malloc +-// ALIGN8: align 8 i8* @calloc +-// ALIGN8: align 8 i8* @realloc +-// NOBUILTIN-MALLOC: declare i8* @malloc +-// NOBUILTIN-CALLOC: declare i8* @calloc +-// NOBUILTIN-REALLOC: declare i8* @realloc diff --git a/llvm/13/compiler-rt/X86-support-extension.patch b/llvm/13/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..66742e5 --- /dev/null +++ b/llvm/13/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -345,4 +345,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -608,6 +612,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/13/compiler-rt/armv7l.patch b/llvm/13/compiler-rt/armv7l.patch new file mode 100644 index 0000000..6818684 --- /dev/null +++ b/llvm/13/compiler-rt/armv7l.patch @@ -0,0 +1,31 @@ +diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 +@@ -37,6 +37,6 @@ + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv8m.main armv8.1m.main) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l armv8m.main armv8.1m.main) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 +@@ -555,6 +555,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -705,7 +705,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em|armv8m.main|armv8.1m.main)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/13/compiler-rt/codesign.patch b/llvm/13/compiler-rt/codesign.patch new file mode 100644 index 0000000..065959d --- /dev/null +++ b/llvm/13/compiler-rt/codesign.patch @@ -0,0 +1,33 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc69ec95c419..9f100fdcec2f 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -366,14 +366,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} +- ) +- endif() + endif() + + set(parent_target_arg) +2.14.1 + diff --git a/llvm/13/compiler-rt/darwin-targetconditionals.patch b/llvm/13/compiler-rt/darwin-targetconditionals.patch new file mode 100644 index 0000000..425dc2a --- /dev/null +++ b/llvm/13/compiler-rt/darwin-targetconditionals.patch @@ -0,0 +1,71 @@ +diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp +--- a/lib/sanitizer_common/sanitizer_mac.cpp ++++ b/lib/sanitizer_common/sanitizer_mac.cpp +@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { + // Offset example: + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 + constexpr u16 GetOSMajorKernelOffset() { +- if (TARGET_OS_OSX) return 4; +- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; +- if (TARGET_OS_WATCH) return 13; ++#if TARGET_OS_OSX ++ return 4; ++#endif ++#if TARGET_OS_IOS || TARGET_OS_TV ++ return 6; ++#endif ++#if TARGET_OS_WATCH ++ return 13; ++#endif + } + + using VersStr = char[64]; +@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { + u16 os_major = kernel_major - offset; + + const char *format = "%d.0"; +- if (TARGET_OS_OSX) { +- if (os_major >= 16) { // macOS 11+ +- os_major -= 5; +- } else { // macOS 10.15 and below +- format = "10.%d"; +- } ++#if TARGET_OS_OSX ++ if (os_major >= 16) { // macOS 11+ ++ os_major -= 5; ++ } else { // macOS 10.15 and below ++ format = "10.%d"; + } ++#endif + return internal_snprintf(vers, sizeof(VersStr), format, os_major); + } + +@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { + // Aligned versions example: + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 + static void MapToMacos(u16 *major, u16 *minor) { +- if (TARGET_OS_OSX) +- return; +- +- if (TARGET_OS_IOS || TARGET_OS_TV) ++#if !TARGET_OS_OSX ++#if TARGET_OS_IOS || TARGET_OS_TV + *major += 2; +- else if (TARGET_OS_WATCH) ++#elif TARGET_OS_WATCH + *major += 9; +- else ++#else + UNREACHABLE("unsupported platform"); ++#endif + + if (*major >= 16) { // macOS 11+ + *major -= 5; +@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { + *minor = *major; + *major = 10; + } ++#endif + } + + static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/llvm/13/compiler-rt/default.nix b/llvm/13/compiler-rt/default.nix new file mode 100644 index 0000000..18be449 --- /dev/null +++ b/llvm/13/compiler-rt/default.nix @@ -0,0 +1,132 @@ +{ lib, stdenv, llvm_meta, version, src, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl isAarch64; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/compiler-rt"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isAarch64) [ + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + # Prevent a compilation error on darwin + ./darwin-targetconditionals.patch + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./armv7l.patch + # Fix build on armv6l + ../../common/compiler-rt/armv6-mcr-dmb.patch + ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ../../common/compiler-rt/armv6-scudo-no-yield.patch + ../../common/compiler-rt/armv6-scudo-libatomic.patch + ]; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/13/compiler-rt/normalize-var.patch b/llvm/13/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..135cf62 --- /dev/null +++ b/llvm/13/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index f1f46fb9599c..6f19e69507ba 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -302,8 +302,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/llvm/13/default.nix b/llvm/13/default.nix new file mode 100644 index 0000000..3cf7cd7 --- /dev/null +++ b/llvm/13/default.nix @@ -0,0 +1,322 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +}: + +let + release_version = "13.0.1"; + candidate = ""; # empty or "rcN" + dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; + rev = ""; # When using a Git commit + rev-version = ""; # When using a Git commit + version = if rev != "" then rev-version else "${release_version}${dash-candidate}"; + targetConfig = stdenv.targetPlatform.config; + + src = fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + rev = if rev != "" then rev else "llvmorg-${version}"; + sha256 = "06dv6h5dmvzdxbif2s8njki6h32796v368dyb5945x8gjj72xh7k"; + }; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version src buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # TODO: lldb/docs/index.rst:155:toctree contains reference to nonexisting document 'design/structureddataplugins' + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + patches = + let + resourceDirPatch = callPackage + ({ substituteAll, libclang }: substituteAll + { + src = ./lldb/resource-dir.patch; + clangLibDir = "${libclang.lib}/lib"; + }) + { }; + in + [ + ./lldb/procfs.patch + resourceDirPatch + ./lldb/gnu-install-dirs.patch + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./lldb/cpu_subtype_arm64e_replacement.patch; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version src; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else ( + # libcxx >= 13 does not build on gcc9 + if stdenv.cc.isGNU && lib.versionOlder stdenv.cc.version "10" + then pkgs.gcc10Stdenv + else stdenv + ); + }; + + libcxxabi = let + stdenv_ = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + cxx-headers = callPackage ./libcxx { + inherit llvm_meta; + stdenv = stdenv_; + headersOnly = true; + }; + in callPackage ./libcxxabi { + stdenv = stdenv_; + inherit llvm_meta cxx-headers; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/13/libcxx/default.nix b/llvm/13/libcxx/default.nix new file mode 100644 index 0000000..994ec7d --- /dev/null +++ b/llvm/13/libcxx/default.nix @@ -0,0 +1,92 @@ +{ lib, stdenv, llvm_meta, src, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation rec { + pname = if headersOnly then "cxx-headers" else "libcxx"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/libcxx"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = lib.optionals (!headersOnly) [ cxxabi ]; + + cmakeFlags = [ "-DLIBCXX_CXX_ABI=${cxxabi.pname}" ] + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + buildFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + # At this point, cxxabi headers would be installed in the dev output, which + # prevents moveToOutput from doing its job later in the build process. + postInstall = lib.optionalString (!headersOnly) '' + mv "$dev/include/c++/v1/"* "$out/include/c++/v1/" + pushd "$dev" + rmdir -p include/c++/v1 + popd + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/13/libcxx/gnu-install-dirs.patch b/llvm/13/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..744967a --- /dev/null +++ b/llvm/13/libcxx/gnu-install-dirs.patch @@ -0,0 +1,82 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b1e25358d41a..7fe1f4d85401 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,6 +26,8 @@ set(LIBCXX_BINARY_INCLUDE_DIR "${LIBCXX_BINARY_DIR}/include/c++build") + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 13.0.0git) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -412,7 +414,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH + "Path where target-agnostic libc++ headers should be installed.") +@@ -426,7 +428,7 @@ elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH + "Path where target-agnostic libc++ headers should be installed.") +@@ -436,7 +438,7 @@ else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_DIR "include/c++/v1" CACHE PATH + "Path where target-agnostic libc++ headers should be installed.") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 5a8a4a270a1a..c06bae0001aa 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -63,7 +63,7 @@ macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION include/c++/v1/${dstdir} ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 496429f3841e..1a0c9c0a3159 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -376,21 +376,21 @@ if (LIBCXX_INSTALL_SHARED_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION bin COMPONENT cxx) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION bin COMPONENT cxx) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS cxx_experimental + LIBRARY DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION bin COMPONENT cxx) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise diff --git a/llvm/13/libcxxabi/default.nix b/llvm/13/libcxxabi/default.nix new file mode 100644 index 0000000..50f0983 --- /dev/null +++ b/llvm/13/libcxxabi/default.nix @@ -0,0 +1,84 @@ +{ lib, stdenv, llvm_meta, cmake, python3, src, cxx-headers, libunwind, version +, enableShared ? !stdenv.hostPlatform.isStatic +, standalone ? stdenv.hostPlatform.useLLVM or false +, withLibunwind ? !stdenv.isDarwin && !stdenv.hostPlatform.isWasm +}: + +stdenv.mkDerivation rec { + pname = "libcxxabi"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "dev" ]; + + postUnpack = lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch} + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake python3 ]; + buildInputs = lib.optional withLibunwind libunwind; + + cmakeFlags = [ + "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + ] ++ lib.optionals standalone [ + "-DLLVM_ENABLE_LIBCXX=ON" + ] ++ lib.optionals (standalone && withLibunwind) [ + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/13/libcxxabi/gnu-install-dirs.patch b/llvm/13/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..5d562dd --- /dev/null +++ b/llvm/13/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,37 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9fb35860d483..5739d9e8af62 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -27,6 +27,8 @@ set(LIBCXXABI_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 11.0.0git) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -195,7 +197,7 @@ set(CMAKE_MODULE_PATH + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++abi libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) +@@ -204,12 +206,12 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + else() + set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + endif() + diff --git a/llvm/13/libunwind/default.nix b/llvm/13/libunwind/default.nix new file mode 100644 index 0000000..d837bc6 --- /dev/null +++ b/llvm/13/libunwind/default.nix @@ -0,0 +1,33 @@ +{ lib, stdenv, llvm_meta, version, src, cmake +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/13/libunwind/gnu-install-dirs.patch b/llvm/13/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..8cd25c5 --- /dev/null +++ b/llvm/13/libunwind/gnu-install-dirs.patch @@ -0,0 +1,36 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 81eddbc24879..e2afb2002150 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -23,6 +23,8 @@ set(LIBUNWIND_LIBCXX_PATH "${CMAKE_CURRENT_LIST_DIR}/../libcxx" CACHE PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD) + project(libunwind LANGUAGES C CXX ASM) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libunwind) + set(PACKAGE_VERSION 13.0.0git) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -116,7 +118,7 @@ set(CMAKE_MODULE_PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libunwind libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) +@@ -124,11 +126,11 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + endif() + diff --git a/llvm/13/lld/default.nix b/llvm/13/lld/default.nix new file mode 100644 index 0000000..d506f39 --- /dev/null +++ b/llvm/13/lld/default.nix @@ -0,0 +1,55 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, src +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + # On Darwin the llvm-config is perhaps not working fine as the + # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as the + # include path is not correct. + postPatch = lib.optionalString stdenv.isDarwin '' + substituteInPlace MachO/CMakeLists.txt --replace \ + '(''${LLVM_MAIN_SRC_DIR}/' '(../' + ''; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/13/lld/gnu-install-dirs.patch b/llvm/13/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..61e2f0e --- /dev/null +++ b/llvm/13/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index d4e561b50d8f..cfa5bdd79c2a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -179,7 +181,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index 23df41312403..d62372c88de7 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index 5cff736ff57f..64e775c771b9 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -21,7 +21,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE diff --git a/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch b/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 0000000..20d35c9 --- /dev/null +++ b/llvm/13/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/llvm/13/lldb/gnu-install-dirs.patch b/llvm/13/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..afc945c --- /dev/null +++ b/llvm/13/lldb/gnu-install-dirs.patch @@ -0,0 +1,91 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b5633e21c56a..f2f1035e9238 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -10,6 +10,8 @@ set(CMAKE_MODULE_PATH + # If we are not building as part of LLVM, build LLDB as a standalone project, + # using LLVM as an external library. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ++ include(GNUInstallDirs) ++ + project(lldb) + include(LLDBStandalone) + +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 4ed5c647c5d2..89f96e710d55 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -107,13 +107,13 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() + # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS + install(TARGETS ${name} COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${install_dest} + ARCHIVE DESTINATION ${install_dest} + FRAMEWORK DESTINATION ${install_dest}) +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index 2fdf1502d055..37364341ff8b 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -225,7 +225,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".cmake" EXCLUDE +@@ -233,7 +233,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".cmake" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 734167e51bc5..f95761b5df58 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -65,4 +65,4 @@ if (LLDB_ENABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index 752113b..010f187 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -62,7 +62,7 @@ endif() + + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) +-set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 OR CYGWIN) + # DLL platform -- put DLLs into bin. + set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b5633e2..86e4738 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -79,7 +79,7 @@ if (LLDB_ENABLE_PYTHON) + if(LLDB_BUILD_FRAMEWORK) + set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb") + else() +- set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb") ++ set(lldb_python_target_dir "${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH}/lldb") + endif() + get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR) + finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}") diff --git a/llvm/13/lldb/procfs.patch b/llvm/13/lldb/procfs.patch new file mode 100644 index 0000000..b075dba --- /dev/null +++ b/llvm/13/lldb/procfs.patch @@ -0,0 +1,31 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -11,21 +11,12 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif diff --git a/llvm/13/lldb/resource-dir.patch b/llvm/13/lldb/resource-dir.patch new file mode 100644 index 0000000..e0db80a --- /dev/null +++ b/llvm/13/lldb/resource-dir.patch @@ -0,0 +1,13 @@ +diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake +index 37364341ff8b..7f74c1a3e257 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers) + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" +- "${LLVM_BUILD_LIBRARY_DIR}" ++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") diff --git a/llvm/13/llvm/default.nix b/llvm/13/llvm/default.nix new file mode 100644 index 0000000..2a7c1c1 --- /dev/null +++ b/llvm/13/llvm/default.nix @@ -0,0 +1,313 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, src +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, which +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = optionals (stdenv.hostPlatform == stdenv.buildPlatform) [ ncurses ] + ++ [ zlib ]; + + nativeCheckInputs = [ which ]; + + patches = [ + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + ./gnu-install-dirs.patch + + # Fix random compiler crashes: https://bugs.llvm.org/show_bug.cgi?id=50611 + (fetchpatch { + url = "https://raw.githubusercontent.com/archlinux/svntogit-packages/4764a4f8c920912a2bfd8b0eea57273acfe0d8a8/trunk/no-strict-aliasing-DwarfCompileUnit.patch"; + sha256 = "18l6mrvm2vmwm77ckcnbjvh6ybvn72rhrb799d4qzwac4x2ifl7g"; + stripLen = 1; + }) + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + + # Backport gcc-13 fixes with missing includes. + (fetchpatch { + name = "signals-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/ff1681ddb303223973653f7f5f3f3435b48a1983.patch"; + hash = "sha256-CXwYxQezTq5vdmc8Yn88BUAEly6YZ5VEIA6X3y5NNOs="; + stripLen = 1; + }) + (fetchpatch { + name = "base64-gcc-13.patch"; + url = "https://github.com/llvm/llvm-project/commit/5e9be93566f39ee6cecd579401e453eccfbe81e5.patch"; + hash = "sha256-PAwrVrvffPd7tphpwCkYiz+67szPRzRB2TXBvKfzQ7U="; + stripLen = 1; + }) + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/13/llvm/gnu-install-dirs-polly.patch b/llvm/13/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..68f3c45 --- /dev/null +++ b/llvm/13/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,105 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index ca7c04c565bb..6ed5db5dd4f8 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.13.4) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -122,13 +126,13 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 7cc129ba2e90..137be25e4b80 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8991094d92c7..178d8ad606bb 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -275,7 +275,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/13/llvm/gnu-install-dirs.patch b/llvm/13/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..18fa5fc --- /dev/null +++ b/llvm/13/llvm/gnu-install-dirs.patch @@ -0,0 +1,381 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 135036f509d2..265c36f8211b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -270,15 +270,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -581,9 +587,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -1048,7 +1054,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1059,7 +1065,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1073,13 +1079,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 9c2b85374307..5531ceeb2eeb 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -818,9 +818,9 @@ macro(add_llvm_library name) + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- RUNTIME DESTINATION bin COMPONENT ${name}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -1036,7 +1036,7 @@ function(process_llvm_pass_plugins) + "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") + install(FILES + ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake +- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} ++ DESTINATION ${LLVM_INSTALL_CMAKE_DIR} + COMPONENT cmake-exports) + + set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") +@@ -1250,7 +1250,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1868,7 +1868,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1879,7 +1879,7 @@ function(llvm_install_library_symlink name dest type) + + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1902,7 +1902,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1985,7 +1985,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -2114,9 +2115,9 @@ function(llvm_setup_rpath name) + # Since BUILD_SHARED_LIBS is only recommended for use by developers, + # hardcode the rpath to build/install lib dir first in this mode. + # FIXME: update this when there is better solution. +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 554046b20edf..4d1ad980641e 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -144,9 +144,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index e80c3b5c1cac..482f6d715ef5 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -90,7 +90,7 @@ function (add_sphinx_target builder project) + endif() + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 51b6a4fdc284..4adc2acfc074 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,6 +1,6 @@ + include(LLVMDistributionSupport) + +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -109,13 +109,13 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") + set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + + # Generate a default location for lit + if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS) +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 3e6a2c9a2648..52e14d955c60 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -4,7 +4,7 @@ + + function(install_symlink name target outdir) + set(DESTDIR $ENV{DESTDIR}) +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index f1ac2c7d4934..c6e1469b5e13 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -202,7 +202,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + Rarely-used CMake variables + --------------------------- +@@ -551,8 +551,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_LINK_LLVM_DYLIB**:BOOL + If enabled, tools will be linked with the libLLVM shared library. Defaults +@@ -792,9 +792,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/examples/Bye/CMakeLists.txt b/examples/Bye/CMakeLists.txt +index bb96edb4b4bf..678c22fb43c8 100644 +--- a/examples/Bye/CMakeLists.txt ++++ b/examples/Bye/CMakeLists.txt +@@ -14,6 +14,6 @@ if (NOT WIN32) + BUILDTREE_ONLY + ) + +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endif() +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index b46319f24fc8..2feabd1954e4 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -5,5 +5,5 @@ add_subdirectory(Frontend) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index ebe5b73a5c65..70c497be12f5 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 1a2f04552d13..44fa7d3eec6b 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -357,12 +357,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = std::string(path.str()); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 0af29ad762c5..37b99b83e35c 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -33,7 +33,7 @@ add_llvm_library(${LTO_LIBRARY_NAME} ${LTO_LIBRARY_TYPE} INSTALL_WITH_TOOLCHAIN + ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index ead73ec13a8f..250362021f17 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,7 +8,7 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) + +diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt +index 865436247270..ce1daa62f6ab 100644 +--- a/tools/remarks-shlib/CMakeLists.txt ++++ b/tools/remarks-shlib/CMakeLists.txt +@@ -19,7 +19,7 @@ if(LLVM_ENABLE_PIC) + endif() + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT Remarks) + + if (APPLE) diff --git a/llvm/13/openmp/default.nix b/llvm/13/openmp/default.nix new file mode 100644 index 0000000..7b461df --- /dev/null +++ b/llvm/13/openmp/default.nix @@ -0,0 +1,53 @@ +{ lib +, stdenv +, llvm_meta +, src +, fetchpatch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${pname}"; + + patches = [ + # Fix cross. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5e2358c781b85a18d1463fd924d2741d4ae5e42e.patch"; + hash = "sha256-UxIlAifXnexF/MaraPW0Ut6q+sf3e7y1fMdEv1q103A="; + }) + ]; + + patchFlags = [ "-p2" ]; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + cmakeFlags = [ + "-DLIBOMPTARGET_BUILD_AMDGCN_BCLIB=OFF" # Building the AMDGCN device RTL currently fails + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/14/clang/default.nix b/llvm/14/clang/default.nix new file mode 100644 index 0000000..976ff75 --- /dev/null +++ b/llvm/14/clang/default.nix @@ -0,0 +1,129 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, substituteAll, cmake, libxml2, libllvm, version, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation (rec { + pname = "clang"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/clang-tools-extra "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + ../../common/clang/add-nostdlibinc-flag.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + (cd tools && ln -s ../../clang-tools-extra extra) + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/14/clang/gnu-install-dirs.patch b/llvm/14/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..57c54e1 --- /dev/null +++ b/llvm/14/clang/gnu-install-dirs.patch @@ -0,0 +1,50 @@ +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 9bbbfc032b7d..947bd0da865d 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -119,8 +119,8 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (NOT LLVM_ENABLE_IDE) +@@ -175,7 +175,7 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() + + function(clang_target_link_libraries target type) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 078988980c52..14b58614b40a 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -234,7 +234,7 @@ set_target_properties(clang-resource-headers PROPERTIES + FOLDER "Misc" + RUNTIME_OUTPUT_DIRECTORY "${output_dir}") + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${generated_files} +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 4e0647971ab4..68dd67fcc476 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -216,7 +216,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) diff --git a/llvm/14/clang/purity.patch b/llvm/14/clang/purity.patch new file mode 100644 index 0000000..deb230a --- /dev/null +++ b/llvm/14/clang/purity.patch @@ -0,0 +1,28 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,12 +487,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!IsStatic) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/14/compiler-rt/X86-support-extension.patch b/llvm/14/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..66742e5 --- /dev/null +++ b/llvm/14/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -345,4 +345,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -608,6 +612,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/14/compiler-rt/armv7l.patch b/llvm/14/compiler-rt/armv7l.patch new file mode 100644 index 0000000..6818684 --- /dev/null +++ b/llvm/14/compiler-rt/armv7l.patch @@ -0,0 +1,31 @@ +diff -ur compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-10.0.0.src/cmake/builtin-config-ix.cmake 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:42:00.883450706 +0900 +@@ -37,6 +37,6 @@ + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv8m.main armv8.1m.main) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l armv8m.main armv8.1m.main) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-10.0.0.src/lib/builtins/CMakeLists.txt 2020-03-24 00:01:02.000000000 +0900 ++++ compiler-rt-10.0.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:44:49.468579650 +0900 +@@ -555,6 +555,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -705,7 +705,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em|armv8m.main|armv8.1m.main)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/14/compiler-rt/codesign.patch b/llvm/14/compiler-rt/codesign.patch new file mode 100644 index 0000000..065959d --- /dev/null +++ b/llvm/14/compiler-rt/codesign.patch @@ -0,0 +1,33 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc69ec95c419..9f100fdcec2f 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -366,14 +366,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} +- ) +- endif() + endif() + + set(parent_target_arg) +2.14.1 + diff --git a/llvm/14/compiler-rt/darwin-targetconditionals.patch b/llvm/14/compiler-rt/darwin-targetconditionals.patch new file mode 100644 index 0000000..425dc2a --- /dev/null +++ b/llvm/14/compiler-rt/darwin-targetconditionals.patch @@ -0,0 +1,71 @@ +diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp +--- a/lib/sanitizer_common/sanitizer_mac.cpp ++++ b/lib/sanitizer_common/sanitizer_mac.cpp +@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { + // Offset example: + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 + constexpr u16 GetOSMajorKernelOffset() { +- if (TARGET_OS_OSX) return 4; +- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; +- if (TARGET_OS_WATCH) return 13; ++#if TARGET_OS_OSX ++ return 4; ++#endif ++#if TARGET_OS_IOS || TARGET_OS_TV ++ return 6; ++#endif ++#if TARGET_OS_WATCH ++ return 13; ++#endif + } + + using VersStr = char[64]; +@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { + u16 os_major = kernel_major - offset; + + const char *format = "%d.0"; +- if (TARGET_OS_OSX) { +- if (os_major >= 16) { // macOS 11+ +- os_major -= 5; +- } else { // macOS 10.15 and below +- format = "10.%d"; +- } ++#if TARGET_OS_OSX ++ if (os_major >= 16) { // macOS 11+ ++ os_major -= 5; ++ } else { // macOS 10.15 and below ++ format = "10.%d"; + } ++#endif + return internal_snprintf(vers, sizeof(VersStr), format, os_major); + } + +@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { + // Aligned versions example: + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 + static void MapToMacos(u16 *major, u16 *minor) { +- if (TARGET_OS_OSX) +- return; +- +- if (TARGET_OS_IOS || TARGET_OS_TV) ++#if !TARGET_OS_OSX ++#if TARGET_OS_IOS || TARGET_OS_TV + *major += 2; +- else if (TARGET_OS_WATCH) ++#elif TARGET_OS_WATCH + *major += 9; +- else ++#else + UNREACHABLE("unsupported platform"); ++#endif + + if (*major >= 16) { // macOS 11+ + *major -= 5; +@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { + *minor = *major; + *major = 10; + } ++#endif + } + + static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/llvm/14/compiler-rt/default.nix b/llvm/14/compiler-rt/default.nix new file mode 100644 index 0000000..98ee813 --- /dev/null +++ b/llvm/14/compiler-rt/default.nix @@ -0,0 +1,141 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + + baseName = "compiler-rt"; + + src = runCommand "${baseName}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${baseName} "$out" + ''; +in + +stdenv.mkDerivation { + pname = baseName + lib.optionalString (haveLibc) "-libc"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${baseName}"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.isGnu) [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + # Prevent a compilation error on darwin + ./darwin-targetconditionals.patch + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + ./armv7l.patch + # Fix build on armv6l + ../../common/compiler-rt/armv6-mcr-dmb.patch + ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ../../common/compiler-rt/armv6-scudo-no-yield.patch + ../../common/compiler-rt/armv6-scudo-libatomic.patch + ]; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/14/compiler-rt/gnu-install-dirs.patch b/llvm/14/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..55837bd --- /dev/null +++ b/llvm/14/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,42 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3a41aa43e406..f000cee6eae0 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,6 +5,8 @@ + + cmake_minimum_required(VERSION 3.13.4) + ++include(GNUInstallDirs) ++ + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index d7b0124f3546..3e111146df4d 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -67,7 +67,7 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") + set(COMPILER_RT_INSTALL_PATH "" CACHE PATH +@@ -99,13 +99,13 @@ endif() + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + endif() diff --git a/llvm/14/compiler-rt/normalize-var.patch b/llvm/14/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..135cf62 --- /dev/null +++ b/llvm/14/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index f1f46fb9599c..6f19e69507ba 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -302,8 +302,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/llvm/14/default.nix b/llvm/14/default.nix new file mode 100644 index 0000000..b9a74e0 --- /dev/null +++ b/llvm/14/default.nix @@ -0,0 +1,320 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +}: + +let + release_version = "14.0.6"; + candidate = ""; # empty or "rcN" + dash-candidate = lib.optionalString (candidate != "") "-${candidate}"; + rev = ""; # When using a Git commit + rev-version = ""; # When using a Git commit + version = if rev != "" then rev-version else "${release_version}${dash-candidate}"; + targetConfig = stdenv.targetPlatform.config; + + monorepoSrc = fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + rev = if rev != "" then rev else "llvmorg-${version}"; + sha256 = "sha256-vffu4HilvYwtzwgq+NlS26m65DGbp6OSSne2aje1yJE="; + }; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.m68k ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # TODO: lldb/docs/index.rst:155:toctree contains reference to nonexisting document 'design/structureddataplugins' + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + patches = + let + resourceDirPatch = callPackage + ({ substituteAll, libclang }: substituteAll + { + src = ./lldb/resource-dir.patch; + clangLibDir = "${libclang.lib}/lib"; + }) + { }; + in + [ + ./lldb/procfs.patch + resourceDirPatch + ./lldb/gnu-install-dirs.patch + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./lldb/cpu_subtype_arm64e_replacement.patch; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ "-rtlib=compiler-rt" + "-Wno-unused-command-line-argument" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" + ++ lib.optional + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + "-lunwind" + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + "-nostdlib++" + ]; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ]; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + nixSupport.cc-cflags = [ "-nostartfiles" ]; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 release_version version monorepoSrc; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = let + stdenv_ = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + cxx-headers = callPackage ./libcxx { + inherit llvm_meta; + stdenv = stdenv_; + headersOnly = true; + }; + in callPackage ./libcxxabi { + stdenv = stdenv_; + inherit llvm_meta cxx-headers; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/14/libcxx/default.nix b/llvm/14/libcxx/default.nix new file mode 100644 index 0000000..3e42a8b --- /dev/null +++ b/llvm/14/libcxx/default.nix @@ -0,0 +1,98 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +let + basename = "libcxx"; +in + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation rec { + pname = basename + lib.optionalString headersOnly "-headers"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${basename} "$out" + mkdir -p "$out/libcxxabi" + cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + ''; + + sourceRoot = "${src.name}/${basename}"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = lib.optionals (!headersOnly) [ cxxabi ]; + + cmakeFlags = [ "-DLIBCXX_CXX_ABI=${cxxabi.pname}" ] + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + buildFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + preInstall = lib.optionalString (stdenv.isDarwin && !headersOnly) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/14/libcxx/gnu-install-dirs.patch b/llvm/14/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..bddf55d --- /dev/null +++ b/llvm/14/libcxx/gnu-install-dirs.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -436,7 +436,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}" CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH + "Path where target-specific libc++ headers should be installed.") +@@ -453,7 +453,7 @@ else() + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + endif() + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH + "Path where target-specific libc++ headers should be installed.") diff --git a/llvm/14/libcxxabi/default.nix b/llvm/14/libcxxabi/default.nix new file mode 100644 index 0000000..0f7cec3 --- /dev/null +++ b/llvm/14/libcxxabi/default.nix @@ -0,0 +1,103 @@ +{ lib, stdenv, llvm_meta, cmake, python3 +, monorepoSrc, runCommand +, cxx-headers, libunwind, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libcxxabi"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx/src" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/include "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/src/include "$out/libcxx/src" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "dev" ]; + + postUnpack = lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch} + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake python3 ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = [ + "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + installPhase = if stdenv.isDarwin + then '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + + make install + install -d 755 $out/include + install -m 644 ../include/*.h $out/include + '' + else '' + install -d -m 755 $out/include $out/lib + install -m 644 lib/libc++abi.a $out/lib + install -m 644 ../include/cxxabi.h $out/include + '' + lib.optionalString enableShared '' + install -m 644 lib/libc++abi.so.1.0 $out/lib + ln -s libc++abi.so.1.0 $out/lib/libc++abi.so + ln -s libc++abi.so.1.0 $out/lib/libc++abi.so.1 + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/14/libcxxabi/gnu-install-dirs.patch b/llvm/14/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..bd25c90 --- /dev/null +++ b/llvm/14/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ecbc7091864e..53ba2dbc3bd1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -216,7 +216,7 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++abi libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) +@@ -230,7 +230,7 @@ else() + set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) + endif() +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + endif() + diff --git a/llvm/14/libunwind/default.nix b/llvm/14/libunwind/default.nix new file mode 100644 index 0000000..c6d9eda --- /dev/null +++ b/llvm/14/libunwind/default.nix @@ -0,0 +1,47 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + # I am not so comfortable giving libc++ and friends the whole monorepo as + # requested, so I filter it to what is needed. + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/14/libunwind/gnu-install-dirs.patch b/llvm/14/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..3fce8bf --- /dev/null +++ b/llvm/14/libunwind/gnu-install-dirs.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -147,7 +147,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libunwind libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) +@@ -159,7 +159,7 @@ else() + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) + endif() +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + endif() + diff --git a/llvm/14/lld/default.nix b/llvm/14/lld/default.nix new file mode 100644 index 0000000..02ca4c8 --- /dev/null +++ b/llvm/14/lld/default.nix @@ -0,0 +1,58 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, monorepoSrc, runCommand +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + # Blank llvm dir just so relative path works + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libunwind" + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" + mkdir -p "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + # On Darwin the llvm-config is perhaps not working fine as the + # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as + # the include path is not correct. + ./fix-root-src-dir.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/14/lld/fix-root-src-dir.patch b/llvm/14/lld/fix-root-src-dir.patch new file mode 100644 index 0000000..38fb965 --- /dev/null +++ b/llvm/14/lld/fix-root-src-dir.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9bcc135665d0..d38679ed41e9 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -74,7 +74,7 @@ if(LLD_BUILT_STANDALONE) + + set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") +- set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") ++ set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree") + + find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} + NO_DEFAULT_PATH) diff --git a/llvm/14/lld/gnu-install-dirs.patch b/llvm/14/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..89a5822 --- /dev/null +++ b/llvm/14/lld/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index dd2898ce6236..ebbea040ff54 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -18,8 +18,8 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) +@@ -62,5 +62,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() diff --git a/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch b/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 0000000..20d35c9 --- /dev/null +++ b/llvm/14/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/llvm/14/lldb/gnu-install-dirs.patch b/llvm/14/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..f2a3b27 --- /dev/null +++ b/llvm/14/lldb/gnu-install-dirs.patch @@ -0,0 +1,67 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 79d451965ed4..78188978d6de 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -10,6 +10,8 @@ set(CMAKE_MODULE_PATH + # If we are not building as part of LLVM, build LLDB as a standalone project, + # using LLVM as an external library. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ++ include(GNUInstallDirs) ++ + project(lldb) + set(LLDB_BUILT_STANDALONE TRUE) + endif() +@@ -108,7 +110,7 @@ if (LLDB_ENABLE_PYTHON) + if(LLDB_BUILD_FRAMEWORK) + set(lldb_python_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Python/lldb") + else() +- set(lldb_python_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_PYTHON_RELATIVE_PATH}/lldb") ++ set(lldb_python_target_dir "${CMAKE_INSTALL_LIBDIR}/../${LLDB_PYTHON_RELATIVE_PATH}/lldb") + endif() + get_target_property(lldb_python_bindings_dir swig_wrapper_python BINARY_DIR) + finish_swig_python("lldb-python" "${lldb_python_bindings_dir}" "${lldb_python_target_dir}") +@@ -118,7 +120,7 @@ if (LLDB_ENABLE_LUA) + if(LLDB_BUILD_FRAMEWORK) + set(lldb_lua_target_dir "${LLDB_FRAMEWORK_ABSOLUTE_BUILD_DIR}/LLDB.framework/Resources/Lua") + else() +- set(lldb_lua_target_dir "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${LLDB_LUA_RELATIVE_PATH}") ++ set(lldb_lua_target_dir "${CMAKE_INSTALL_LIBDIR}/../${LLDB_LUA_RELATIVE_PATH}") + endif() + get_target_property(lldb_lua_bindings_dir swig_wrapper_lua BINARY_DIR) + finish_swig_lua("lldb-lua" "${lldb_lua_bindings_dir}" "${lldb_lua_target_dir}") +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 3291a7c808e1..b27d27ce6a87 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -109,7 +109,7 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 7d48491ec89a..c04543585588 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED + ) + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index 7d48491ec89a..c04543585588 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -70,7 +70,7 @@ endif() + + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) +-set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 OR CYGWIN) + # DLL platform -- put DLLs into bin. + set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR}) \ No newline at end of file diff --git a/llvm/14/lldb/procfs.patch b/llvm/14/lldb/procfs.patch new file mode 100644 index 0000000..b075dba --- /dev/null +++ b/llvm/14/lldb/procfs.patch @@ -0,0 +1,31 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -11,21 +11,12 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif diff --git a/llvm/14/lldb/resource-dir.patch b/llvm/14/lldb/resource-dir.patch new file mode 100644 index 0000000..e0db80a --- /dev/null +++ b/llvm/14/lldb/resource-dir.patch @@ -0,0 +1,13 @@ +diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake +index 37364341ff8b..7f74c1a3e257 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers) + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" +- "${LLVM_BUILD_LIBRARY_DIR}" ++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") diff --git a/llvm/14/llvm/default.nix b/llvm/14/llvm/default.nix new file mode 100644 index 0000000..081c84c --- /dev/null +++ b/llvm/14/llvm/default.nix @@ -0,0 +1,315 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, monorepoSrc +, runCommand +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, which +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? true +} @args: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} ('' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/third-party "$out" + '' + lib.optionalString enablePolly '' + chmod u+w "$out/${pname}/tools" + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" + ''); + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + nativeCheckInputs = [ which ]; + + patches = [ + ./gnu-install-dirs.patch + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s + rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + optionalString stdenv.hostPlatform.isRiscV '' + rm test/ExecutionEngine/frem.ll + rm test/ExecutionEngine/mov64zext32.ll + rm test/ExecutionEngine/test-interp-vec-arithm_float.ll + rm test/ExecutionEngine/test-interp-vec-arithm_int.ll + rm test/ExecutionEngine/test-interp-vec-logical.ll + rm test/ExecutionEngine/test-interp-vec-setcond-fp.ll + rm test/ExecutionEngine/test-interp-vec-setcond-int.ll + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "CrashRecoveryTest.cpp" "" + rm unittests/Support/CrashRecoveryTest.cpp + substituteInPlace unittests/ExecutionEngine/Orc/CMakeLists.txt \ + --replace "OrcCAPITest.cpp" "" + rm unittests/ExecutionEngine/Orc/OrcCAPITest.cpp + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=off" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + # For the update script: + passthru.monorepoSrc = monorepoSrc; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/14/llvm/gnu-install-dirs-polly.patch b/llvm/14/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..b01363e --- /dev/null +++ b/llvm/14/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,19 @@ +This is the one remaining Polly install dirs related change that hasn't made it +into upstream yet; previously this patch file also included: +https://reviews.llvm.org/D117541 + +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) diff --git a/llvm/14/llvm/gnu-install-dirs.patch b/llvm/14/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..55862ab --- /dev/null +++ b/llvm/14/llvm/gnu-install-dirs.patch @@ -0,0 +1,220 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index fec956091cd5..5a766f5c5d7c 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -303,6 +303,9 @@ set(LLVM_EXAMPLES_INSTALL_DIR "examples" CACHE STRING + "Path for examples subdirectory (enabled by LLVM_BUILD_EXAMPLES=ON) (defaults to 'examples')") + mark_as_advanced(LLVM_EXAMPLES_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index fed1fec7d72e..4baed19b9e98 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -838,8 +838,8 @@ macro(add_llvm_library name) + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) +@@ -1056,7 +1056,7 @@ function(process_llvm_pass_plugins) + "set(LLVM_STATIC_EXTENSIONS ${LLVM_STATIC_EXTENSIONS})") + install(FILES + ${llvm_cmake_builddir}/LLVMConfigExtensions.cmake +- DESTINATION ${LLVM_INSTALL_PACKAGE_DIR} ++ DESTINATION ${LLVM_INSTALL_CMAKE_DIR} + COMPONENT cmake-exports) + + set(ExtensionDef "${LLVM_BINARY_DIR}/include/llvm/Support/Extension.def") +@@ -1902,7 +1902,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1913,7 +1913,7 @@ function(llvm_install_library_symlink name dest type) + + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1936,7 +1936,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -2019,7 +2019,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -2148,9 +2149,9 @@ function(llvm_setup_rpath name) + # Since BUILD_SHARED_LIBS is only recommended for use by developers, + # hardcode the rpath to build/install lib dir first in this mode. + # FIXME: update this when there is better solution. +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 891c9e6d618c..8d963f3b0069 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -147,9 +147,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index cea0c1df0a14..eedcd9450312 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -2,7 +2,7 @@ include(ExtendPath) + include(LLVMDistributionSupport) + include(FindPrefixFromConfig) + +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -122,7 +122,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS + ) + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) + +-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") ++extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_LIBRARY_DIRS + "${LLVM_CONFIG_LIBRARY_DIR}" + # FIXME: Should there be other entries here? +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index b5c35f706cb7..9261ab797de6 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -6,7 +6,7 @@ include(GNUInstallDirs) + + function(install_symlink name target outdir) + set(DESTDIR $ENV{DESTDIR}) +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 044ec8a4d39d..504d0eac3ade 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -224,7 +224,7 @@ description is in `LLVM-related variables`_ below. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **LLVM_PARALLEL_{COMPILE,LINK}_JOBS**:STRING + Building the llvm toolchain can use a lot of resources, particularly +@@ -910,9 +910,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index b46319f24fc8..2feabd1954e4 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -5,5 +5,5 @@ add_subdirectory(Frontend) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index abbb8a450da6..70c497be12f5 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,7 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 8ed88f33ead4..5e7184bab90d 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -363,12 +363,20 @@ int main(int argc, char **argv) { + ActiveIncludeDir = std::string(Path.str()); + } + { +- SmallString<256> Path(LLVM_TOOLS_INSTALL_DIR); ++ SmallString<256> Path(LLVM_INSTALL_BINDIR); + sys::fs::make_absolute(ActivePrefix, Path); + ActiveBinDir = std::string(Path.str()); + } +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); ++ sys::fs::make_absolute(ActivePrefix, Path); ++ ActiveLibDir = std::string(Path.str()); ++ } ++ { ++ SmallString<256> Path(LLVM_INSTALL_CMAKEDIR); ++ sys::fs::make_absolute(ActivePrefix, Path); ++ ActiveCMakeDir = std::string(Path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + diff --git a/llvm/14/openmp/default.nix b/llvm/14/openmp/default.nix new file mode 100644 index 0000000..d1c6a46 --- /dev/null +++ b/llvm/14/openmp/default.nix @@ -0,0 +1,69 @@ +{ lib +, stdenv +, llvm_meta +, monorepoSrc +, runCommand +, cmake +, llvm +, targetLlvm +, lit +, clang-unwrapped +, perl +, pkg-config +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ./run-lit-directly.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake perl pkg-config lit ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + # Unsup:Pass:XFail:Fail + # 26:267:16:8 + doCheck = false; + checkTarget = "check-openmp"; + + preCheck = '' + patchShebangs ../tools/archer/tests/deflake.bash + ''; + + cmakeFlags = [ + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" + "-DOPT_TOOL=${llvm}/bin/opt" + "-DLINK_TOOL=${llvm}/bin/llvm-link" + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/14/openmp/gnu-install-dirs.patch b/llvm/14/openmp/gnu-install-dirs.patch new file mode 100644 index 0000000..e85fde4 --- /dev/null +++ b/llvm/14/openmp/gnu-install-dirs.patch @@ -0,0 +1,45 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -24,7 +24,7 @@ if (OPENMP_STANDALONE_BUILD) + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "Suffix of lib installation directory, e.g. 64 => lib64") + # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. +- set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}") + + # Group test settings. + set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING +@@ -35,7 +35,7 @@ if (OPENMP_STANDALONE_BUILD) + else() + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # If building in tree, we honor the same install suffix LLVM uses. +- set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + + if (NOT MSVC) + set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) +diff --git a/libomptarget/plugins/amdgpu/CMakeLists.txt b/libomptarget/plugins/amdgpu/CMakeLists.txt +--- a/libomptarget/plugins/amdgpu/CMakeLists.txt ++++ b/libomptarget/plugins/amdgpu/CMakeLists.txt +@@ -74,7 +74,7 @@ add_library(omptarget.rtl.amdgpu SHARED + + # Install plugin under the lib destination folder. + # When we build for debug, OPENMP_LIBDIR_SUFFIX get set to -debug +-install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "lib${OPENMP_LIBDIR_SUFFIX}") ++install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}") + set_property(TARGET omptarget.rtl.amdgpu PROPERTY INSTALL_RPATH_USE_LINK_PATH ON) + + if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") +diff --git a/libomptarget/plugins/ve/CMakeLists.txt b/libomptarget/plugins/ve/CMakeLists.txt +--- a/libomptarget/plugins/ve/CMakeLists.txt ++++ b/libomptarget/plugins/ve/CMakeLists.txt +@@ -32,7 +32,7 @@ if(${LIBOMPTARGET_DEP_VEO_FOUND}) + + # Install plugin under the lib destination folder. + install(TARGETS "omptarget.rtl.${tmachine_libname}" +- LIBRARY DESTINATION lib${OPENMP_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}) + + target_link_libraries( + "omptarget.rtl.${tmachine_libname}" diff --git a/llvm/14/openmp/run-lit-directly.patch b/llvm/14/openmp/run-lit-directly.patch new file mode 100644 index 0000000..1e952fd --- /dev/null +++ b/llvm/14/openmp/run-lit-directly.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/OpenMPTesting.cmake b/cmake/OpenMPTesting.cmake +--- a/cmake/OpenMPTesting.cmake ++++ b/cmake/OpenMPTesting.cmake +@@ -185,7 +185,7 @@ function(add_openmp_testsuite target comment) + if (${OPENMP_STANDALONE_BUILD}) + set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS}) + add_custom_target(${target} +- COMMAND ${PYTHON_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} ++ COMMAND ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} + COMMENT ${comment} + DEPENDS ${ARG_DEPENDS} + USES_TERMINAL diff --git a/llvm/15/clang/default.nix b/llvm/15/clang/default.nix new file mode 100644 index 0000000..894db1a --- /dev/null +++ b/llvm/15/clang/default.nix @@ -0,0 +1,138 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, substituteAll, cmake, ninja, libxml2, libllvm, version, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation (rec { + pname = "clang"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/clang-tools-extra "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + # Added in LLVM15: + # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb + # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 + "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" + "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + ../../common/clang/add-nostdlibinc-flag.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + (cd tools && ln -s ../../clang-tools-extra extra) + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + # The following warning is triggered with (at least) gcc >= + # 12, but appears to occur only for cross compiles. + NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized"; + }; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/clang/ + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + ninjaFlags = [ "docs-clang-man" ]; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/15/clang/gnu-install-dirs.patch b/llvm/15/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..f767c56 --- /dev/null +++ b/llvm/15/clang/gnu-install-dirs.patch @@ -0,0 +1,105 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c27beec313d7..480f13e73c9f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -78,15 +78,17 @@ if(CLANG_BUILT_STANDALONE) + if (NOT LLVM_CONFIG_FOUND) + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config + # path is removed. +- set(MAIN_INCLUDE_DIR "${LLVM_INCLUDE_DIR}") ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") + # N.B. this is just a default value, the CACHE PATHs below can be overriden. + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") + set(TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") + set(LIBRARY_DIR "${LLVM_LIBRARY_DIR}") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") + endif() + +- set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + set(LLVM_TOOLS_BINARY_DIR "${TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin") +@@ -128,7 +130,7 @@ if(CLANG_BUILT_STANDALONE) + set(LLVM_INCLUDE_TESTS ON) + endif() + +- include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") ++ include_directories(${LLVM_INCLUDE_DIRS}) + link_directories("${LLVM_LIBRARY_DIR}") + + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 21ac332e4f5f..b16c314bd1e2 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -119,8 +119,8 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (NOT LLVM_ENABLE_IDE) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 6e2060991b92..b9bc930d26b8 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -420,7 +420,7 @@ add_header_target("openmp-resource-headers" ${openmp_wrapper_files}) + add_header_target("windows-resource-headers" ${windows_only_files}) + add_header_target("utility-resource-headers" ${utility_files}) + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + ############################################################# + # Install rules for the catch-all clang-resource-headers target +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 8d95d0900e8c..ebc70ff7526d 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -180,7 +180,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt +index 061dc7ef4dd9..adc54b2edc32 100644 +--- a/tools/scan-build-py/CMakeLists.txt ++++ b/tools/scan-build-py/CMakeLists.txt +@@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib}) + install(PROGRAMS lib/libscanbuild/${lib} +- DESTINATION lib/libscanbuild ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild" + COMPONENT scan-build-py) + endforeach() + +@@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource}) + install(PROGRAMS lib/libscanbuild/resources/${resource} +- DESTINATION lib/libscanbuild/resources ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources" + COMPONENT scan-build-py) + endforeach() + +@@ -122,7 +122,7 @@ foreach(lib ${LibEar}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib}) + install(PROGRAMS lib/libear/${lib} +- DESTINATION lib/libear ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear" + COMPONENT scan-build-py) + endforeach() + diff --git a/llvm/15/clang/purity.patch b/llvm/15/clang/purity.patch new file mode 100644 index 0000000..1c94f29 --- /dev/null +++ b/llvm/15/clang/purity.patch @@ -0,0 +1,29 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,13 +487,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + } else { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); + +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE && +- !Args.hasArg(options::OPT_r)) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/15/compiler-rt/X86-support-extension.patch b/llvm/15/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..07013e5 --- /dev/null +++ b/llvm/15/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -348,4 +348,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -723,6 +723,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/15/compiler-rt/darwin-targetconditionals.patch b/llvm/15/compiler-rt/darwin-targetconditionals.patch new file mode 100644 index 0000000..425dc2a --- /dev/null +++ b/llvm/15/compiler-rt/darwin-targetconditionals.patch @@ -0,0 +1,71 @@ +diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp +--- a/lib/sanitizer_common/sanitizer_mac.cpp ++++ b/lib/sanitizer_common/sanitizer_mac.cpp +@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { + // Offset example: + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 + constexpr u16 GetOSMajorKernelOffset() { +- if (TARGET_OS_OSX) return 4; +- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; +- if (TARGET_OS_WATCH) return 13; ++#if TARGET_OS_OSX ++ return 4; ++#endif ++#if TARGET_OS_IOS || TARGET_OS_TV ++ return 6; ++#endif ++#if TARGET_OS_WATCH ++ return 13; ++#endif + } + + using VersStr = char[64]; +@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { + u16 os_major = kernel_major - offset; + + const char *format = "%d.0"; +- if (TARGET_OS_OSX) { +- if (os_major >= 16) { // macOS 11+ +- os_major -= 5; +- } else { // macOS 10.15 and below +- format = "10.%d"; +- } ++#if TARGET_OS_OSX ++ if (os_major >= 16) { // macOS 11+ ++ os_major -= 5; ++ } else { // macOS 10.15 and below ++ format = "10.%d"; + } ++#endif + return internal_snprintf(vers, sizeof(VersStr), format, os_major); + } + +@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { + // Aligned versions example: + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 + static void MapToMacos(u16 *major, u16 *minor) { +- if (TARGET_OS_OSX) +- return; +- +- if (TARGET_OS_IOS || TARGET_OS_TV) ++#if !TARGET_OS_OSX ++#if TARGET_OS_IOS || TARGET_OS_TV + *major += 2; +- else if (TARGET_OS_WATCH) ++#elif TARGET_OS_WATCH + *major += 9; +- else ++#else + UNREACHABLE("unsupported platform"); ++#endif + + if (*major >= 16) { // macOS 11+ + *major -= 5; +@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { + *minor = *major; + *major = 10; + } ++#endif + } + + static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/llvm/15/compiler-rt/default.nix b/llvm/15/compiler-rt/default.nix new file mode 100644 index 0000000..4ac51c1 --- /dev/null +++ b/llvm/15/compiler-rt/default.nix @@ -0,0 +1,140 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake, ninja, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl isGnu; + + baseName = "compiler-rt"; + + src = runCommand "${baseName}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${baseName} "$out" + ''; +in + +stdenv.mkDerivation { + pname = baseName + lib.optionalString (haveLibc) "-libc"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${baseName}"; + + nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + + # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 + "-DCOMPILER_RT_ENABLE_IOS=OFF" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + # Prevent a compilation error on darwin + ./darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + ../../common/compiler-rt/armv7l-15.patch + ]; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/15/compiler-rt/gnu-install-dirs.patch b/llvm/15/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..f3b1f63 --- /dev/null +++ b/llvm/15/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,20 @@ +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 8a6219568b3f..30ee68a47ccf 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -100,13 +100,13 @@ endif() + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + endif() diff --git a/llvm/15/compiler-rt/normalize-var.patch b/llvm/15/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..135cf62 --- /dev/null +++ b/llvm/15/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index f1f46fb9599c..6f19e69507ba 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -302,8 +302,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/llvm/15/default.nix b/llvm/15/default.nix new file mode 100644 index 0000000..6a3b8cb --- /dev/null +++ b/llvm/15/default.nix @@ -0,0 +1,403 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, stdenvNoCC, cmake, ninja +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +# LLVM release information; specify one of these but not both: +, gitRelease ? null + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # rev = /* commit SHA */; + # rev-version = /* human readable version; i.e. "unstable-2022-26-07" */; + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +, officialRelease ? { version = "15.0.7"; sha256 = "sha256-wjuZQyXQ/jsmvy6y1aksCcEDXGBjuhpgngF3XQJ/T4s="; } + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # candidate = /* optional; if specified, should be: "rcN" */ + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +# By default, we'll try to fetch a release from `github:llvm/llvm-project` +# corresponding to the `gitRelease` or `officialRelease` specified. +# +# You can provide your own LLVM source by specifying this arg but then it's up +# to you to make sure that the LLVM repo given matches the release configuration +# specified. +, monorepoSrc ? null +}: + +assert let + int = a: if a then 1 else 0; + xor = a: b: ((builtins.bitXor (int a) (int b)) == 1); +in + lib.assertMsg + (xor + (gitRelease != null) + (officialRelease != null)) + ("must specify `gitRelease` or `officialRelease`" + + (lib.optionalString (gitRelease != null) " — not both")); +let + monorepoSrc' = monorepoSrc; +in let + releaseInfo = if gitRelease != null then rec { + original = gitRelease; + release_version = original.version; + version = gitRelease.rev-version; + } else rec { + original = officialRelease; + release_version = original.version; + version = if original ? candidate then + "${release_version}-${original.candidate}" + else + release_version; + }; + + monorepoSrc = if monorepoSrc' != null then + monorepoSrc' + else let + sha256 = releaseInfo.original.sha256; + rev = if gitRelease != null then + gitRelease.rev + else + "llvmorg-${releaseInfo.version}"; + in fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + inherit rev sha256; + }; + + inherit (releaseInfo) release_version version; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.m68k ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + lldb-manpages = lowPrio (tools.lldb.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + patches = + let + resourceDirPatch = callPackage + ({ substituteAll, libclang }: substituteAll + { + src = ./lldb/resource-dir.patch; + clangLibDir = "${libclang.lib}/lib"; + }) + { }; + in + [ + ./lldb/procfs.patch + resourceDirPatch + ./lldb/gnu-install-dirs.patch + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./lldb/cpu_subtype_arm64e_replacement.patch; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ "-rtlib=compiler-rt" + "-Wno-unused-command-line-argument" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" + ++ lib.optional + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + "-lunwind" + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + "-nostdlib++" + ] + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + nixSupport.cc-cflags = + [ + "-nostartfiles" + ] + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoCompilerRtWithLibc = wrapCCWith (rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + } // lib.optionalAttrs stdenv.targetPlatform.isWasm { + nixSupport.cc-cflags = [ "-fno-exceptions" ]; + }); + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxxabi = let + # CMake will "require" a compiler capable of compiling C++ programs + # cxx-header's build does not actually use one so it doesn't really matter + # what stdenv we use here, as long as CMake is happy. + cxx-headers = callPackage ./libcxx { + inherit llvm_meta; + # Note that if we use the regular stdenv here we'll get cycle errors + # when attempting to use this compiler in the stdenv. + # + # The final stdenv pulls `cxx-headers` from the package set where + # hostPlatform *is* the target platform which means that `stdenv` at + # that point attempts to use this toolchain. + # + # So, we use `stdenv_` (the stdenv containing `clang` from this package + # set, defined below) to sidestep this issue. + # + # Because we only use `cxx-headers` in `libcxxabi` (which depends on the + # clang stdenv _anyways_), this is okay. + stdenv = stdenv_; + headersOnly = true; + }; + + # `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it + # *does* need a relatively modern C++ compiler (see: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support). + # + # So, we use the clang from this LLVM package set, like libc++ + # "boostrapping builds" do: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build + # + # We cannot use `clangNoLibcxx` because that contains `compiler-rt` which, + # on macOS, depends on `libcxxabi`, thus forming a cycle. + stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc; + in callPackage ./libcxxabi { + stdenv = stdenv_; + inherit llvm_meta cxx-headers; + }; + + # Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler, + # so: we use the clang from this LLVM package set instead of the regular + # stdenv's compiler. + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/15/libcxx/default.nix b/llvm/15/libcxx/default.nix new file mode 100644 index 0000000..ed5f48e --- /dev/null +++ b/llvm/15/libcxx/default.nix @@ -0,0 +1,131 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand, fetchpatch +, cmake, ninja, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt, libunwind +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +let + basename = "libcxx"; +in + +assert stdenv.isDarwin -> cxxabi.libName == "c++abi"; + +stdenv.mkDerivation rec { + pname = basename + lib.optionalString headersOnly "-headers"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${basename} "$out" + mkdir -p "$out/libcxxabi" + cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/third-party "$out" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + prePatch = '' + cd ../${basename} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + # See: + # - https://reviews.llvm.org/D133566 + # - https://github.com/NixOS/nixpkgs/issues/214524#issuecomment-1429146432 + # !!! Drop in LLVM 16+ + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/57c7bb3ec89565c68f858d316504668f9d214d59.patch"; + hash = "sha256-AaM9A6tQ4YAw7uDqCIV4VaiUyLZv+unwcOqbakwW9/k="; + relative = "libcxx"; + }) + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = + lib.optionals (!headersOnly) [ cxxabi ] + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ libunwind ]; + + cmakeFlags = let + # See: https://libcxx.llvm.org/BuildingLibcxx.html#cmdoption-arg-libcxx-cxx-abi-string + libcxx_cxx_abi_opt = { + "c++abi" = "system-libcxxabi"; + "cxxrt" = "libcxxrt"; + }.${cxxabi.libName} or (throw "unknown cxxabi: ${cxxabi.libName} (${cxxabi.pname})"); + in [ + "-DLLVM_ENABLE_RUNTIMES=libcxx" + "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}" + ] ++ lib.optional (!headersOnly && cxxabi.libName == "c++abi") "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi.dev}/include/c++/v1" + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLIBCXX_USE_COMPILER_RT=ON" + # (Backport fix from 16, which has LIBCXX_ADDITIONAL_LIBRARIES, but 15 + # does not appear to) + # There's precedent for this in llvm-project/libcxx/cmake/caches. + # In a monorepo build you might do the following in the libcxxabi build: + # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwind + # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On + # libcxx appears to require unwind and doesn't pull it in via other means. + # "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" + "-DCMAKE_SHARED_LINKER_FLAGS=-lunwind" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + # If we're only building the headers we don't actually *need* a functioning + # C/C++ compiler: + ++ lib.optionals (headersOnly) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ]; + + ninjaFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/15/libcxx/gnu-install-dirs.patch b/llvm/15/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..daee5bd --- /dev/null +++ b/llvm/15/libcxx/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 74eff2002fc9..c935d10878bb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -419,7 +419,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH + "Path where target-specific libc++ headers should be installed.") +@@ -436,7 +436,7 @@ else() + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + endif() + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH + "Path where target-specific libc++ headers should be installed.") diff --git a/llvm/15/libcxxabi/default.nix b/llvm/15/libcxxabi/default.nix new file mode 100644 index 0000000..04bfee1 --- /dev/null +++ b/llvm/15/libcxxabi/default.nix @@ -0,0 +1,113 @@ +{ lib, stdenv, llvm_meta, cmake, ninja, python3 +, monorepoSrc, runCommand, fetchpatch +, cxx-headers, libunwind, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libcxxabi"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx/src" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/include "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/src/include "$out/libcxx/src" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" "dev" ]; + + postUnpack = lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch} + ''; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + + # https://reviews.llvm.org/D132298, Allow building libcxxabi alone + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/e6a0800532bb409f6d1c62f3698bdd6994a877dc.patch"; + sha256 = "1xyjd56m4pfwq8p3xh6i8lhkk9kq15jaml7qbhxdf87z4jjkk63a"; + stripLen = 1; + }) + ]; + + postPatch = '' + cd ../runtimes + ''; + + nativeBuildInputs = [ cmake ninja python3 ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libcxxabi" + "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + + # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached + # (we specify the headers it should use explicitly above). + # + # CMake however checks for this anyways; this flag tells it not to. See: + # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, + # but that does not appear to be the case for example when building + # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). + "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" + "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + install_name_tool -id $out/$file $file + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/15/libcxxabi/gnu-install-dirs.patch b/llvm/15/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..fa58761 --- /dev/null +++ b/llvm/15/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b8326d08d23a..a1e36f713161 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -187,7 +187,7 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++abi libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) +@@ -201,7 +201,7 @@ else() + set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) + endif() +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + endif() + diff --git a/llvm/15/libunwind/default.nix b/llvm/15/libunwind/default.nix new file mode 100644 index 0000000..1b677a7 --- /dev/null +++ b/llvm/15/libunwind/default.nix @@ -0,0 +1,67 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake +, ninja +, python3 +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + # I am not so comfortable giving libc++ and friends the whole monorepo as + # requested, so I filter it to what is needed. + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' + # libcxxabi wants to link to libunwind_shared.so (?). + ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so + ''; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ninja python3 ]; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libunwind" + ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/15/libunwind/gnu-install-dirs.patch b/llvm/15/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..edfb2a8 --- /dev/null +++ b/llvm/15/libunwind/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5a06805f05f1..86a50329e6a8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -117,7 +117,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libunwind libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) +@@ -129,7 +129,7 @@ else() + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) + endif() +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + endif() + diff --git a/llvm/15/lld/default.nix b/llvm/15/lld/default.nix new file mode 100644 index 0000000..cc18aee --- /dev/null +++ b/llvm/15/lld/default.nix @@ -0,0 +1,57 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, monorepoSrc, runCommand +, cmake +, ninja +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + # Blank llvm dir just so relative path works + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libunwind" + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" + mkdir -p "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ninja ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/15/lld/gnu-install-dirs.patch b/llvm/15/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..ea62b2a --- /dev/null +++ b/llvm/15/lld/gnu-install-dirs.patch @@ -0,0 +1,46 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index dcc649629a4b..58dca54642e4 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -70,13 +70,15 @@ if(LLD_BUILT_STANDALONE) + if (NOT LLVM_CONFIG_FOUND) + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config + # path is removed. +- set(MAIN_INCLUDE_DIR "${LLVM_INCLUDE_DIR}") ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") + # N.B. this is just a default value, the CACHE PATHs below can be overridden. + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") + endif() + +- set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + +@@ -95,7 +97,7 @@ if(LLD_BUILT_STANDALONE) + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") + +- include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS}) ++ include_directories(${LLVM_INCLUDE_DIRS}) + link_directories(${LLVM_LIBRARY_DIRS}) + + if(LLVM_INCLUDE_TESTS) +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index d3924f7243d4..42a7cd62281c 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -18,8 +18,8 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) diff --git a/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch b/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 0000000..20d35c9 --- /dev/null +++ b/llvm/15/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/llvm/15/lldb/gnu-install-dirs.patch b/llvm/15/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..4388f5c --- /dev/null +++ b/llvm/15/lldb/gnu-install-dirs.patch @@ -0,0 +1,23 @@ +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 3291a7c808e1..b27d27ce6a87 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -109,7 +109,7 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 7d48491ec89a..c04543585588 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED + ) + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) diff --git a/llvm/15/lldb/procfs.patch b/llvm/15/lldb/procfs.patch new file mode 100644 index 0000000..7b200e8 --- /dev/null +++ b/llvm/15/lldb/procfs.patch @@ -0,0 +1,46 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -10,6 +10,13 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include ++ ++// on i686 preprocessor symbols with these register names are defined as ++// numeric constants; these symbols clash with identifier names used in ++// `llvm/Support/VirtualFileSystem.h` and `llvm/ADT/SmallVector.h` ++#undef FS ++#undef CS + + #include "lldb/lldb-types.h" + +@@ -17,23 +24,13 @@ + + #include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif + + namespace lldb_private { + namespace process_linux { diff --git a/llvm/15/lldb/resource-dir.patch b/llvm/15/lldb/resource-dir.patch new file mode 100644 index 0000000..e0db80a --- /dev/null +++ b/llvm/15/lldb/resource-dir.patch @@ -0,0 +1,13 @@ +diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake +index 37364341ff8b..7f74c1a3e257 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers) + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" +- "${LLVM_BUILD_LIBRARY_DIR}" ++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") diff --git a/llvm/15/llvm/default.nix b/llvm/15/llvm/default.nix new file mode 100644 index 0000000..8a1c054 --- /dev/null +++ b/llvm/15/llvm/default.nix @@ -0,0 +1,440 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, monorepoSrc +, runCommand +, fetchpatch +, cmake +, darwin +, ninja +, python3 +, python3Packages +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, which +, sysctl +, buildLlvmTools +, debugVersion ? false +, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +, enablePFM ? stdenv.isLinux /* PFM only supports Linux */ + # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + # broken for the armv7l builder + && !stdenv.hostPlatform.isAarch +, enablePolly ? true +} @args: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + # Note that we _explicitly_ ask for a python interpreter for our host + # platform here; the splicing that would ordinarily take care of this for + # us does not seem to work once we use `withPackages`. + let + checkDeps = ps: with ps; [ psutil ]; + in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} ('' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/third-party "$out" + '' + lib.optionalString enablePolly '' + chmod u+w "$out/${pname}/tools" + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" + ''); + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake ninja python ] + ++ optionals enableManpages [ + # Note: we intentionally use `python3Packages` instead of `python3.pkgs`; + # splicing does *not* work with the latter. (TODO: fix) + python3Packages.sphinx python3Packages.recommonmark + ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + nativeCheckInputs = [ + which + ] ++ lib.optional stdenv.isDarwin sysctl; + + patches = [ + ./gnu-install-dirs.patch + + # Running the tests involves invoking binaries (like `opt`) that depend on + # the LLVM dylibs and reference them by absolute install path (i.e. their + # nix store path). + # + # Because we have not yet run the install phase (we're running these tests + # as part of `checkPhase` instead of `installCheckPhase`) these absolute + # paths do not exist yet; to work around this we point the loader (`ld` on + # unix, `dyld` on macOS) at the `lib` directory which will later become this + # package's `lib` output. + # + # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib` + # dir but: + # - this doesn't generalize well to other platforms; `lit` doesn't forward + # `DYLD_LIBRARY_PATH` (macOS): + # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26 + # - even if `lit` forwarded this env var, we actually cannot set + # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because + # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for + # "protected processes" (i.e. the python interpreter that runs `lit`): + # https://stackoverflow.com/a/35570229 + # - other LLVM subprojects deal with this issue by having their `lit` + # configuration set these env vars for us; it makes sense to do the same + # for LLVM: + # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31 + # + # !!! TODO: look into upstreaming this patch + ./llvm-lit-cfg-add-libs-to-dylib-path.patch + + # `lit` has a mode where it executes run lines as a shell script which is + # constructs; this is problematic for macOS because it means that there's + # another process in between `lit` and the binaries being tested. As noted + # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our + # tests fail with dyld errors. + # + # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when + # present in the test configuration. + # + # It's not clear to me why this isn't an issue for LLVM developers running + # on macOS (nothing about this _seems_ nix specific).. + ./lit-shell-script-runner-set-dyld-library-path.patch + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + ] ++ lib.optionals enablePolly [ + ./gnu-install-dirs-polly.patch + + # Just like the `llvm-lit-cfg` patch, but for `polly`. + ./polly-lit-cfg-add-libs-to-dylib-path.patch + ]; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + + # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick + # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 + rm test/MC/ELF/cfi-version.ll + + # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) + # and thus fails under the sandbox: + substituteInPlace unittests/Support/Host.cpp \ + --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" + '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' + # This test tries to call the intrinsics `@llvm.roundeven.f32` and + # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` + # and `roundeven` on x86_64 macOS. + # + # However these functions are glibc specific so the test fails: + # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html + # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html + # + # TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it + # pass there? + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ + --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ + --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" + + # This test fails on darwin x86_64 because `sw_vers` reports a different + # macOS version than what LLVM finds by reading + # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into + # the sandbox on macOS). + # + # The `sw_vers` provided by nixpkgs reports the macOS version associated + # with the `CoreFoundation` framework with which it was built. Because + # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what + # `sw_vers` reports is not guaranteed to match the macOS version of the host + # that's building this derivation. + # + # Astute readers will note that we only _patch_ this test on aarch64-darwin + # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. + # So why does this test pass on aarch64? + # + # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ + # CoreFoundation framework instead of the nixpkgs provided one. + # + # Not entirely sure what the right fix is here. I'm assuming aarch64 + # `sw_vers` doesn't intentionally link against the host `CoreFoundation` + # (still digging into how this ends up happening, will follow up) but that + # aside I think the more pertinent question is: should we be patching LLVM's + # macOS version detection logic to use `sw_vers` instead of reading host + # paths? This *is* a way in which details about builder machines can creep + # into the artifacts that are produced, affecting reproducibility, but it's + # not clear to me when/where/for what this even gets used in LLVM. + # + # TODO(@rrbutani): fix/follow-up + substituteInPlace unittests/Support/Host.cpp \ + --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" + + # This test fails with a `dysmutil` crash; have not yet dug into what's + # going on here (TODO(@rrbutani)). + rm test/tools/dsymutil/ARM/obfuscated.test + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + # timing-based tests are trouble + rm utils/lit/tests/googletest-timeout.py + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s + rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s + + # !!! Note: these tests are removed in LLVM 16. + # + # See here for context: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999790443 + rm test/CodeGen/RISCV/rv32zbp.ll + rm test/CodeGen/RISCV/rv64zbp.ll + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" + ) + ''; + + # Defensive check: some paths (that we make symlinks to) depend on the release + # version, for example: + # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 + # + # So we want to sure that the version in the source matches the release + # version we were given. + # + # We do this check here, in the LLVM build, because it happens early. + postConfigure = let + v = lib.versions; + major = v.major release_version; + minor = v.minor release_version; + patch = v.patch release_version; + in '' + # $1: part, $2: expected + check_version() { + part="''${1^^}" + part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" + + if [[ "$part" != "$2" ]]; then + echo >&2 \ + "mismatch in the $1 version! we have version ${release_version}" \ + "and expected the $1 version to be '$2'; the source has '$part' instead" + exit 3 + fi + } + + check_version major ${major} + check_version minor ${minor} + check_version patch ${patch} + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=off" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + # For the update script: + passthru.monorepoSrc = monorepoSrc; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + propagatedBuildInputs = []; + + ninjaFlags = [ "docs-llvm-man" ]; + installTargets = [ "install-docs-llvm-man" ]; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/15/llvm/gnu-install-dirs-polly.patch b/llvm/15/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..b01363e --- /dev/null +++ b/llvm/15/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,19 @@ +This is the one remaining Polly install dirs related change that hasn't made it +into upstream yet; previously this patch file also included: +https://reviews.llvm.org/D117541 + +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) diff --git a/llvm/15/llvm/gnu-install-dirs.patch b/llvm/15/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..0ef317a --- /dev/null +++ b/llvm/15/llvm/gnu-install-dirs.patch @@ -0,0 +1,138 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 45399dc0537e..5d946e9e6583 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -942,7 +942,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") + add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) + install(TARGETS tf_xla_runtime EXPORT LLVMExports +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) + # Once we add more modules, we should handle this more automatically. + if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 057431208322..56f0dcb258da 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -844,8 +844,8 @@ macro(add_llvm_library name) + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) +@@ -2007,7 +2007,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir "${CMAKE_INSTALL_BINDIR}") + endif() +@@ -2271,15 +2271,15 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) + # $ORIGIN is not interpreted at link time by aix ld. + # Since BUILD_SHARED_LIBS is only recommended for use by developers, + # hardcode the rpath to build/install lib dir first in this mode. + # FIXME: update this when there is better solution. +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 891c9e6d618c..8d963f3b0069 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -147,9 +147,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index d4b0ab959148..26ed981fd09f 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -128,7 +128,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS + ) + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) + +-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") ++extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_LIBRARY_DIRS + "${LLVM_CONFIG_LIBRARY_DIR}" + # FIXME: Should there be other entries here? +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 879b7b231d4c..9c31d14e8950 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -250,7 +250,7 @@ description is in `LLVM-related variables`_ below. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **LLVM_PARALLEL_{COMPILE,LINK}_JOBS**:STRING + Building the llvm toolchain can use a lot of resources, particularly +@@ -284,6 +284,10 @@ manual, or execute ``cmake --help-variable VARIABLE_NAME``. + The path to install executables, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "bin". + ++**CMAKE_INSTALL_LIBDIR**:PATH ++ The path to install libraries, relative to the *CMAKE_INSTALL_PREFIX*. ++ Defaults to "lib". ++ + **CMAKE_INSTALL_INCLUDEDIR**:PATH + The path to install header files, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "include". +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 370005cd8d7d..7e790bc52111 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,7 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" + #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 2c6c55f89d38..f6d2068a0827 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -369,7 +369,11 @@ int main(int argc, char **argv) { + sys::fs::make_absolute(ActivePrefix, Path); + ActiveBinDir = std::string(Path.str()); + } +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; ++ { ++ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); ++ sys::fs::make_absolute(ActivePrefix, Path); ++ ActiveLibDir = std::string(Path.str()); ++ } + { + SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); + sys::fs::make_absolute(ActivePrefix, Path); diff --git a/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch b/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch new file mode 100644 index 0000000..32f1d13 --- /dev/null +++ b/llvm/15/llvm/lit-shell-script-runner-set-dyld-library-path.patch @@ -0,0 +1,26 @@ +diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py +index 0242e0b75af3..d732011306f7 100644 +--- a/utils/lit/lit/TestRunner.py ++++ b/utils/lit/lit/TestRunner.py +@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd): + f.write('@echo off\n') + f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands)) + else: ++ # This env var is *purged* when invoking subprocesses so we have to ++ # manually set it from within the bash script in order for the commands ++ # in run lines to see this var: ++ if "DYLD_LIBRARY_PATH" in test.config.environment: ++ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') ++ + for i, ln in enumerate(commands): + match = re.match(kPdbgRegex, ln) + if match: +@@ -1363,7 +1369,7 @@ def applySubstitutions(script, substitutions, conditions={}, + return processed + + process = processLine if recursion_limit is None else processLineToFixedPoint +- ++ + return [unescapePercents(process(ln)) for ln in script] + + diff --git a/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch b/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000..d824516 --- /dev/null +++ b/llvm/15/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,79 @@ +diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py +index 81e8dc04acea..479ff95681e2 100644 +--- a/test/Unit/lit.cfg.py ++++ b/test/Unit/lit.cfg.py +@@ -3,6 +3,7 @@ + # Configuration file for the 'lit' test runner. + + import os ++import platform + import subprocess + + import lit.formats +@@ -55,3 +56,26 @@ if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir): + # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate. + if sys.platform == 'win32' and 'SYSTEMDRIVE' in os.environ: + config.environment['SYSTEMDRIVE'] = os.environ['SYSTEMDRIVE'] ++ ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = os.path.pathsep.join( ++ (config.shlibdir, ++ config.environment.get(shlibpath_var, ''))) ++ config.environment[shlibpath_var] = shlibpath ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) +diff --git a/test/lit.cfg.py b/test/lit.cfg.py +index 75a38b4c5dad..856fc75c9d74 100644 +--- a/test/lit.cfg.py ++++ b/test/lit.cfg.py +@@ -42,6 +42,26 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) + llvm_config.with_system_environment( + ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP']) + ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = config.llvm_shlib_dir ++ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True) ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) + + # Set up OCAMLPATH to include newly built OCaml libraries. + top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml') +@@ -318,7 +338,7 @@ def have_cxx_shared_library(): + + try: + readobj_cmd = subprocess.Popen( +- [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE) ++ [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE, env=config.environment) + except OSError: + print('could not exec llvm-readobj') + return False diff --git a/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch b/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000..1354ad2 --- /dev/null +++ b/llvm/15/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,24 @@ +diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg +index 41e3a589c61e..09f3b17498b0 100644 +--- a/tools/polly/test/lit.cfg ++++ b/tools/polly/test/lit.cfg +@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']] + path = os.path.pathsep.join(base_paths + config.extra_paths) + config.environment['PATH'] = path + ++# (Copied from polly/test/Unit/lit.cfg) ++if platform.system() == 'Darwin': ++ shlibpath_var = 'DYLD_LIBRARY_PATH' ++elif platform.system() == 'Windows': ++ shlibpath_var = 'PATH' ++else: ++ shlibpath_var = 'LD_LIBRARY_PATH' ++ + path = os.path.pathsep.join((config.llvm_libs_dir, +- config.environment.get('LD_LIBRARY_PATH',''))) +-config.environment['LD_LIBRARY_PATH'] = path ++ config.environment.get(shlibpath_var,''))) ++config.environment[shlibpath_var] = path + + llvm_config.use_default_substitutions() + diff --git a/llvm/15/openmp/default.nix b/llvm/15/openmp/default.nix new file mode 100644 index 0000000..d513354 --- /dev/null +++ b/llvm/15/openmp/default.nix @@ -0,0 +1,74 @@ +{ lib +, stdenv +, llvm_meta +, monorepoSrc +, runCommand +, cmake +, ninja +, llvm +, targetLlvm +, lit +, clang-unwrapped +, perl +, pkg-config +, xcbuild +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./fix-find-tool.patch + ./gnu-install-dirs.patch + ./run-lit-directly.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ninja perl pkg-config lit ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun; + + # Unsup:Pass:XFail:Fail + # 26:267:16:8 + doCheck = false; + checkTarget = "check-openmp"; + + preCheck = '' + patchShebangs ../tools/archer/tests/deflake.bash + ''; + + cmakeFlags = [ + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" + "-DOPT_TOOL=${llvm}/bin/opt" + "-DLINK_TOOL=${llvm}/bin/llvm-link" + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/15/openmp/fix-find-tool.patch b/llvm/15/openmp/fix-find-tool.patch new file mode 100644 index 0000000..103b054 --- /dev/null +++ b/llvm/15/openmp/fix-find-tool.patch @@ -0,0 +1,18 @@ +diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt +index ce66214822a2..6ab7b33c95da 100644 +--- a/libomptarget/DeviceRTL/CMakeLists.txt ++++ b/libomptarget/DeviceRTL/CMakeLists.txt +@@ -27,10 +27,10 @@ endif() + if (LLVM_DIR) + # Builds that use pre-installed LLVM have LLVM_DIR set. + # A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route +- find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR}) + find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} +- NO_DEFAULT_PATH) +- find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ ) ++ find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR}) + if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL)) + libomptarget_say("Not building DeviceRTL. Missing clang: ${CLANG_TOOL}, llvm-link: ${LINK_TOOL} or opt: ${OPT_TOOL}") + return() diff --git a/llvm/15/openmp/gnu-install-dirs.patch b/llvm/15/openmp/gnu-install-dirs.patch new file mode 100644 index 0000000..77a9320 --- /dev/null +++ b/llvm/15/openmp/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b6ddbe90516d..311ab1d50e7f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD) + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "Suffix of lib installation directory, e.g. 64 => lib64") + # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. +- set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}") + + # Group test settings. + set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING +@@ -40,7 +40,7 @@ if (OPENMP_STANDALONE_BUILD) + else() + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # If building in tree, we honor the same install suffix LLVM uses. +- set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + + if (NOT MSVC) + set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) diff --git a/llvm/15/openmp/run-lit-directly.patch b/llvm/15/openmp/run-lit-directly.patch new file mode 100644 index 0000000..1e952fd --- /dev/null +++ b/llvm/15/openmp/run-lit-directly.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/OpenMPTesting.cmake b/cmake/OpenMPTesting.cmake +--- a/cmake/OpenMPTesting.cmake ++++ b/cmake/OpenMPTesting.cmake +@@ -185,7 +185,7 @@ function(add_openmp_testsuite target comment) + if (${OPENMP_STANDALONE_BUILD}) + set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS}) + add_custom_target(${target} +- COMMAND ${PYTHON_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} ++ COMMAND ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} + COMMENT ${comment} + DEPENDS ${ARG_DEPENDS} + USES_TERMINAL diff --git a/llvm/16/clang/default.nix b/llvm/16/clang/default.nix new file mode 100644 index 0000000..2a2656d --- /dev/null +++ b/llvm/16/clang/default.nix @@ -0,0 +1,133 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, substituteAll, cmake, ninja, libxml2, libllvm, version, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation (rec { + pname = "clang"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/clang-tools-extra "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + # Added in LLVM15: + # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb + # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 + "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" + "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + ../../common/clang/add-nostdlibinc-flag.patch + # FIMXE: do we need this patch? + # (substituteAll { + # src = ../../clang-11-12-LLVMgold-path.patch; + # libllvmLibdir = "${libllvm.lib}/lib"; + # }) + ]; + + postPatch = '' + (cd tools && ln -s ../../clang-tools-extra extra) + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/clang/ + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + ninjaFlags = [ "docs-clang-man" ]; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/16/clang/gnu-install-dirs.patch b/llvm/16/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..e5465c9 --- /dev/null +++ b/llvm/16/clang/gnu-install-dirs.patch @@ -0,0 +1,109 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 090cfa352078..624b7c9f3400 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -38,12 +38,26 @@ if(CLANG_BUILT_STANDALONE) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}") + +- # Turn into CACHE PATHs for overwritting +- set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") +- set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree") +- set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree") +- set(LLVM_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin") +- set(LLVM_LIBRARY_DIR "${LLVM_LIBRARY_DIR}" CACHE PATH "Path to llvm/lib") ++ # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets ++ # LLVM_CONFIG. ++ if (NOT LLVM_CONFIG_FOUND) ++ # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config ++ # path is removed. ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) ++ set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") ++ # N.B. this is just a default value, the CACHE PATHs below can be overriden. ++ set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") ++ set(TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") ++ set(LIBRARY_DIR "${LLVM_LIBRARY_DIR}") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") ++ endif() ++ ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") ++ set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") ++ set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") ++ set(LLVM_TOOLS_BINARY_DIR "${TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin") ++ set(LLVM_LIBRARY_DIR "${LIBRARY_DIR}" CACHE PATH "Path to llvm/lib") + + find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} + NO_DEFAULT_PATH) +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 75b0080f6715..c895b884cd27 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -119,8 +119,8 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (NOT LLVM_ENABLE_IDE) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index bb9a11eabbef..e2de91c65fbb 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -437,7 +437,7 @@ add_header_target("openmp-resource-headers" ${openmp_wrapper_files}) + add_header_target("windows-resource-headers" ${windows_only_files}) + add_header_target("utility-resource-headers" ${utility_files}) + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION_MAJOR}/include) + + ############################################################# + # Install rules for the catch-all clang-resource-headers target +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 4f23065a2472..6a0f55991e24 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -234,7 +234,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt +index 3aca22c0b0a8..3115353e3fe3 100644 +--- a/tools/scan-build-py/CMakeLists.txt ++++ b/tools/scan-build-py/CMakeLists.txt +@@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib}) + install(FILES lib/libscanbuild/${lib} +- DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libscanbuild ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild" + COMPONENT scan-build-py) + endforeach() + +@@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource}) + install(FILES lib/libscanbuild/resources/${resource} +- DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libscanbuild/resources ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources" + COMPONENT scan-build-py) + endforeach() + +@@ -122,7 +122,7 @@ foreach(lib ${LibEar}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib}) + install(FILES lib/libear/${lib} +- DESTINATION lib${CLANG_LIBDIR_SUFFIX}/libear ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear" + COMPONENT scan-build-py) + endforeach() + diff --git a/llvm/16/clang/purity.patch b/llvm/16/clang/purity.patch new file mode 100644 index 0000000..1c94f29 --- /dev/null +++ b/llvm/16/clang/purity.patch @@ -0,0 +1,29 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,13 +487,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + } else { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); + +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE && +- !Args.hasArg(options::OPT_r)) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/16/compiler-rt/X86-support-extension.patch b/llvm/16/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..07013e5 --- /dev/null +++ b/llvm/16/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -348,4 +348,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -723,6 +723,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/16/compiler-rt/darwin-targetconditionals.patch b/llvm/16/compiler-rt/darwin-targetconditionals.patch new file mode 100644 index 0000000..425dc2a --- /dev/null +++ b/llvm/16/compiler-rt/darwin-targetconditionals.patch @@ -0,0 +1,71 @@ +diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp +--- a/lib/sanitizer_common/sanitizer_mac.cpp ++++ b/lib/sanitizer_common/sanitizer_mac.cpp +@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { + // Offset example: + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 + constexpr u16 GetOSMajorKernelOffset() { +- if (TARGET_OS_OSX) return 4; +- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; +- if (TARGET_OS_WATCH) return 13; ++#if TARGET_OS_OSX ++ return 4; ++#endif ++#if TARGET_OS_IOS || TARGET_OS_TV ++ return 6; ++#endif ++#if TARGET_OS_WATCH ++ return 13; ++#endif + } + + using VersStr = char[64]; +@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { + u16 os_major = kernel_major - offset; + + const char *format = "%d.0"; +- if (TARGET_OS_OSX) { +- if (os_major >= 16) { // macOS 11+ +- os_major -= 5; +- } else { // macOS 10.15 and below +- format = "10.%d"; +- } ++#if TARGET_OS_OSX ++ if (os_major >= 16) { // macOS 11+ ++ os_major -= 5; ++ } else { // macOS 10.15 and below ++ format = "10.%d"; + } ++#endif + return internal_snprintf(vers, sizeof(VersStr), format, os_major); + } + +@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { + // Aligned versions example: + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 + static void MapToMacos(u16 *major, u16 *minor) { +- if (TARGET_OS_OSX) +- return; +- +- if (TARGET_OS_IOS || TARGET_OS_TV) ++#if !TARGET_OS_OSX ++#if TARGET_OS_IOS || TARGET_OS_TV + *major += 2; +- else if (TARGET_OS_WATCH) ++#elif TARGET_OS_WATCH + *major += 9; +- else ++#else + UNREACHABLE("unsupported platform"); ++#endif + + if (*major >= 16) { // macOS 11+ + *major -= 5; +@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { + *minor = *major; + *major = 10; + } ++#endif + } + + static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/llvm/16/compiler-rt/default.nix b/llvm/16/compiler-rt/default.nix new file mode 100644 index 0000000..9b6ab0a --- /dev/null +++ b/llvm/16/compiler-rt/default.nix @@ -0,0 +1,154 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake, ninja, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + isDarwinStatic = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic; + inherit (stdenv.hostPlatform) isMusl isGnu; + + baseName = "compiler-rt"; + + src = runCommand "${baseName}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${baseName} "$out" + ''; +in + +stdenv.mkDerivation { + pname = baseName + lib.optionalString (haveLibc) "-libc"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${baseName}"; + + nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString ([ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ] ++ lib.optionals (!haveLibc) [ + # The compiler got stricter about this, and there is a usellvm patch below + # which patches out the assert include causing an implicit definition of + # assert. It would be nicer to understand why compiler-rt thinks it should + # be able to #include in the first place; perhaps it's in the + # wrong, or perhaps there is a way to provide an assert.h. + "-Wno-error=implicit-function-declaration" + ]); + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl || isDarwinStatic) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal || isDarwinStatic ) [ + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM && !haveLibc) [ + "-DCMAKE_C_FLAGS=-nodefaultlibs" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DCMAKE_LIPO=${lib.getBin stdenv.cc.bintools.bintools}/bin/${stdenv.cc.targetPrefix}lipo" + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + + # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 + "-DCOMPILER_RT_ENABLE_IOS=OFF" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + # Prevent a compilation error on darwin + ./darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + # ../../common/compiler-rt/armv7l-15.patch + ]; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM && !haveLibc) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM && stdenv.hostPlatform.isLinux) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + # Note the history of crt{begin,end}S in previous versions of llvm in nixpkg: + # The presence of crtbegin_shared has been added and removed; it's possible + # people have added/removed it to get it working on their platforms. + # Try each in turn for now. + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/16/compiler-rt/gnu-install-dirs.patch b/llvm/16/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..f3b1f63 --- /dev/null +++ b/llvm/16/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,20 @@ +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 8a6219568b3f..30ee68a47ccf 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -100,13 +100,13 @@ endif() + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + endif() diff --git a/llvm/16/compiler-rt/normalize-var.patch b/llvm/16/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..2b25fd4 --- /dev/null +++ b/llvm/16/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index 4c85551d7766..297d7a47c54b 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -328,8 +328,9 @@ macro(load_llvm_config) + endif() + endif() + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + + set(LLVM_MAIN_SRC_DIR "${LLVM_MAIN_SRC_DIR_DEFAULT}" CACHE PATH "Path to LLVM source tree") + message(STATUS "LLVM_MAIN_SRC_DIR: \"${LLVM_MAIN_SRC_DIR}\"") diff --git a/llvm/16/default.nix b/llvm/16/default.nix new file mode 100644 index 0000000..541db8c --- /dev/null +++ b/llvm/16/default.nix @@ -0,0 +1,414 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, stdenvNoCC, cmake, ninja +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM verion's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +# LLVM release information; specify one of these but not both: +, gitRelease ? null + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # rev = /* commit SHA */; + # rev-version = /* human readable version; i.e. "unstable-2022-26-07" */; + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +, officialRelease ? { version = "16.0.6"; sha256 = "sha256-fspqSReX+VD+Nl/Cfq+tDcdPtnQPV1IRopNDfd5VtUs="; } + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # candidate = /* optional; if specified, should be: "rcN" */ + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +# By default, we'll try to fetch a release from `github:llvm/llvm-project` +# corresponding to the `gitRelease` or `officialRelease` specified. +# +# You can provide your own LLVM source by specifying this arg but then it's up +# to you to make sure that the LLVM repo given matches the release configuration +# specified. +, monorepoSrc ? null +}: + +assert let + int = a: if a then 1 else 0; + xor = a: b: ((builtins.bitXor (int a) (int b)) == 1); +in + lib.assertMsg + (xor + (gitRelease != null) + (officialRelease != null)) + ("must specify `gitRelease` or `officialRelease`" + + (lib.optionalString (gitRelease != null) " — not both")); +let + monorepoSrc' = monorepoSrc; +in let + releaseInfo = if gitRelease != null then rec { + original = gitRelease; + release_version = original.version; + version = gitRelease.rev-version; + } else rec { + original = officialRelease; + release_version = original.version; + version = if original ? candidate then + "${release_version}-${original.candidate}" + else + release_version; + }; + + monorepoSrc = if monorepoSrc' != null then + monorepoSrc' + else let + sha256 = releaseInfo.original.sha256; + rev = if gitRelease != null then + gitRelease.rev + else + "llvmorg-${releaseInfo.version}"; + in fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + inherit rev sha256; + }; + + inherit (releaseInfo) release_version version; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.m68k ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); + major = lib.versions.major release_version; + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${major}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + lldb-manpages = lowPrio (tools.lldb.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + src = callPackage ({ runCommand }: runCommand "lldb-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/lldb "$out" + '') { }; + patches = + let + resourceDirPatch = callPackage + ({ substituteAll, libclang }: substituteAll + { + src = ./lldb/resource-dir.patch; + clangLibDir = "${libclang.lib}/lib"; + }) + { }; + in + [ + # FIXME: do we need this? ./procfs.patch + resourceDirPatch + ./lldb/gnu-install-dirs.patch + ] + # This is a stopgap solution if/until the macOS SDK used for x86_64 is + # updated. + # + # The older 10.12 SDK used on x86_64 as of this writing has a `mach/machine.h` + # header that does not define `CPU_SUBTYPE_ARM64E` so we replace the one use + # of this preprocessor symbol in `lldb` with its expansion. + # + # See here for some context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionOlder darwin.apple_sdk.sdk.version "11.0") + ) ./lldb/cpu_subtype_arm64e_replacement.patch; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ "-rtlib=compiler-rt" + "-Wno-unused-command-line-argument" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" + ++ lib.optional + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + "-lunwind" + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + "-nostdlib++" + ] + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + nixSupport.cc-cflags = + [ + "-nostartfiles" + ] + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoCompilerRtWithLibc = wrapCCWith (rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + } // lib.optionalAttrs stdenv.targetPlatform.isWasm { + nixSupport.cc-cflags = [ "-fno-exceptions" ]; + }); + + # Has to be in tools despite mostly being a library, + # because we use a native helper executable from a + # non-cross build in cross builds. + libclc = callPackage ./libclc { + inherit buildLlvmTools; + }; + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false || (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isStatic) + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid || stdenv.hostPlatform.isDarwin + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxxabi = let + # CMake will "require" a compiler capable of compiling C++ programs + # cxx-header's build does not actually use one so it doesn't really matter + # what stdenv we use here, as long as CMake is happy. + cxx-headers = callPackage ./libcxx { + inherit llvm_meta; + # Note that if we use the regular stdenv here we'll get cycle errors + # when attempting to use this compiler in the stdenv. + # + # The final stdenv pulls `cxx-headers` from the package set where + # hostPlatform *is* the target platform which means that `stdenv` at + # that point attempts to use this toolchain. + # + # So, we use `stdenv_` (the stdenv containing `clang` from this package + # set, defined below) to sidestep this issue. + # + # Because we only use `cxx-headers` in `libcxxabi` (which depends on the + # clang stdenv _anyways_), this is okay. + stdenv = stdenv_; + headersOnly = true; + }; + + # `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it + # *does* need a relatively modern C++ compiler (see: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support). + # + # So, we use the clang from this LLVM package set, like libc++ + # "boostrapping builds" do: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build + # + # We cannot use `clangNoLibcxx` because that contains `compiler-rt` which, + # on macOS, depends on `libcxxabi`, thus forming a cycle. + stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc; + in callPackage ./libcxxabi { + stdenv = stdenv_; + inherit llvm_meta cxx-headers; + }; + + # Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler, + # so: we use the clang from this LLVM package set instead of the regular + # stdenv's compiler. + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/16/libclc/default.nix b/llvm/16/libclc/default.nix new file mode 100644 index 0000000..6fa0751 --- /dev/null +++ b/llvm/16/libclc/default.nix @@ -0,0 +1,54 @@ +{ lib, stdenv, version, runCommand, monorepoSrc, llvm, buildPackages, buildLlvmTools, ninja, cmake, python3 }: + +stdenv.mkDerivation rec { + pname = "libclc"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "dev" ]; + + patches = [ + ./libclc-gnu-install-dirs.patch + ]; + + # cmake expects all required binaries to be in the same place, so it will not be able to find clang without the patch + postPatch = '' + substituteInPlace CMakeLists.txt \ + --replace 'find_program( LLVM_CLANG clang PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ + 'find_program( LLVM_CLANG clang PATHS "${buildLlvmTools.clang.cc}/bin" NO_DEFAULT_PATH )' \ + --replace 'find_program( LLVM_AS llvm-as PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ + 'find_program( LLVM_AS llvm-as PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \ + --replace 'find_program( LLVM_LINK llvm-link PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ + 'find_program( LLVM_LINK llvm-link PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \ + --replace 'find_program( LLVM_OPT opt PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ + 'find_program( LLVM_OPT opt PATHS "${buildLlvmTools.llvm}/bin" NO_DEFAULT_PATH )' \ + --replace 'find_program( LLVM_SPIRV llvm-spirv PATHS ''${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH )' \ + 'find_program( LLVM_SPIRV llvm-spirv PATHS "${buildPackages.spirv-llvm-translator}/bin" NO_DEFAULT_PATH )' + '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' + substituteInPlace CMakeLists.txt \ + --replace 'COMMAND prepare_builtins' 'COMMAND ${buildPackages.libclc.dev}/bin/prepare_builtins' + ''; + + nativeBuildInputs = [ cmake ninja python3 ]; + buildInputs = [ llvm ]; + strictDeps = true; + + postInstall = '' + install -Dt $dev/bin prepare_builtins + ''; + + meta = with lib; { + broken = stdenv.isDarwin; + homepage = "http://libclc.llvm.org/"; + description = "Implementation of the library requirements of the OpenCL C programming language"; + license = licenses.mit; + platforms = platforms.all; + }; +} diff --git a/llvm/16/libclc/libclc-gnu-install-dirs.patch b/llvm/16/libclc/libclc-gnu-install-dirs.patch new file mode 100644 index 0000000..1e5108a --- /dev/null +++ b/llvm/16/libclc/libclc-gnu-install-dirs.patch @@ -0,0 +1,10 @@ +--- a/libclc.pc.in ++++ b/libclc.pc.in +@@ -1,5 +1,5 @@ +-includedir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@ +-libexecdir=@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_DATADIR@/clc ++includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ ++libexecdir=@CMAKE_INSTALL_FULL_DATADIR@/clc + + Name: libclc + Description: Library requirements of the OpenCL C programming language diff --git a/llvm/16/libcxx/default.nix b/llvm/16/libcxx/default.nix new file mode 100644 index 0000000..78cd632 --- /dev/null +++ b/llvm/16/libcxx/default.nix @@ -0,0 +1,118 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, cmake, ninja, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt, libunwind +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +let + basename = "libcxx"; +in + +assert stdenv.isDarwin -> cxxabi.libName == "c++abi"; + +stdenv.mkDerivation rec { + pname = basename + lib.optionalString headersOnly "-headers"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${basename} "$out" + mkdir -p "$out/libcxxabi" + cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/third-party "$out" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + prePatch = '' + cd ../${basename} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = + lib.optionals (!headersOnly) [ cxxabi ] + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false && !stdenv.hostPlatform.isWasm) [ libunwind ]; + + cmakeFlags = let + # See: https://libcxx.llvm.org/BuildingLibcxx.html#cmdoption-arg-libcxx-cxx-abi-string + libcxx_cxx_abi_opt = { + "c++abi" = "system-libcxxabi"; + "cxxrt" = "libcxxrt"; + }.${cxxabi.libName} or (throw "unknown cxxabi: ${cxxabi.libName} (${cxxabi.pname})"); + in [ + "-DLLVM_ENABLE_RUNTIMES=libcxx" + "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}" + ] ++ lib.optional (!headersOnly && cxxabi.libName == "c++abi") "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi.dev}/include/c++/v1" + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLIBCXX_USE_COMPILER_RT=ON" + # There's precedent for this in llvm-project/libcxx/cmake/caches. + # In a monorepo build you might do the following in the libcxxabi build: + # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder + # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On + # libcxx appears to require unwind and doesn't pull it in via other means. + "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + # If we're only building the headers we don't actually *need* a functioning + # C/C++ compiler: + ++ lib.optionals (headersOnly) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ]; + + ninjaFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/16/libcxx/gnu-install-dirs.patch b/llvm/16/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..daee5bd --- /dev/null +++ b/llvm/16/libcxx/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 74eff2002fc9..c935d10878bb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -419,7 +419,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH + "Path where target-specific libc++ headers should be installed.") +@@ -436,7 +436,7 @@ else() + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + endif() + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH + "Path where target-specific libc++ headers should be installed.") diff --git a/llvm/16/libcxxabi/default.nix b/llvm/16/libcxxabi/default.nix new file mode 100644 index 0000000..90c57dc --- /dev/null +++ b/llvm/16/libcxxabi/default.nix @@ -0,0 +1,114 @@ +{ lib, stdenv, llvm_meta, cmake, ninja, python3 +, monorepoSrc, runCommand, fetchpatch +, cxx-headers, libunwind, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libcxxabi"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx/src" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/include "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/src/include "$out/libcxx/src" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" "dev" ]; + + postUnpack = lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + ''; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + + # https://reviews.llvm.org/D132298, Allow building libcxxabi alone + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/e6a0800532bb409f6d1c62f3698bdd6994a877dc.patch"; + sha256 = "1xyjd56m4pfwq8p3xh6i8lhkk9kq15jaml7qbhxdf87z4jjkk63a"; + stripLen = 1; + }) + ]; + + postPatch = '' + cd ../runtimes + ''; + + nativeBuildInputs = [ cmake ninja python3 ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libcxxabi" + "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + + # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached + # (we specify the headers it should use explicitly above). + # + # CMake however checks for this anyways; this flag tells it not to. See: + # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false && !stdenv.hostPlatform.isWasm) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, + # but that does not appear to be the case for example when building + # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). + "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" + "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + "-DUNIX=ON" # Required otherwise libc++ fails to detect the correct linker + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + install_name_tool -id $out/$file $file + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/16/libcxxabi/gnu-install-dirs.patch b/llvm/16/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..fa58761 --- /dev/null +++ b/llvm/16/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b8326d08d23a..a1e36f713161 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -187,7 +187,7 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++abi libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) +@@ -201,7 +201,7 @@ else() + set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) + endif() +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + endif() + diff --git a/llvm/16/libunwind/default.nix b/llvm/16/libunwind/default.nix new file mode 100644 index 0000000..1b677a7 --- /dev/null +++ b/llvm/16/libunwind/default.nix @@ -0,0 +1,67 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake +, ninja +, python3 +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + # I am not so comfortable giving libc++ and friends the whole monorepo as + # requested, so I filter it to what is needed. + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' + # libcxxabi wants to link to libunwind_shared.so (?). + ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so + ''; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ninja python3 ]; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libunwind" + ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/16/libunwind/gnu-install-dirs.patch b/llvm/16/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..edfb2a8 --- /dev/null +++ b/llvm/16/libunwind/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5a06805f05f1..86a50329e6a8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -117,7 +117,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libunwind libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) +@@ -129,7 +129,7 @@ else() + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) + endif() +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + endif() + diff --git a/llvm/16/lld/add-table-base.patch b/llvm/16/lld/add-table-base.patch new file mode 100644 index 0000000..15fc903 --- /dev/null +++ b/llvm/16/lld/add-table-base.patch @@ -0,0 +1,190 @@ +From 93adcb770b99351b18553089c164fe3ef2119699 Mon Sep 17 00:00:00 2001 +From: Sam Clegg +Date: Fri, 25 Aug 2023 13:56:16 -0700 +Subject: [PATCH] [lld][WebAssembly] Add `--table-base` setting + +This is similar to `--global-base` but determines where to place the +table segments rather than that data segments. + +See https://github.com/emscripten-core/emscripten/issues/20097 + +Differential Revision: https://reviews.llvm.org/D158892 +--- + test/wasm/table-base.s | 72 ++++++++++++++++++++++++++++++++++++++ + wasm/Driver.cpp | 19 ++++++++-- + wasm/Options.td | 5 ++- + wasm/Writer.cpp | 8 ----- + 4 files changed, 93 insertions(+), 11 deletions(-) + create mode 100644 test/wasm/table-base.s + +diff --git a/test/wasm/table-base.s b/test/wasm/table-base.s +new file mode 100644 +index 000000000000000..56fff414fd31d96 +--- /dev/null ++++ b/test/wasm/table-base.s +@@ -0,0 +1,72 @@ ++# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o ++ ++# RUN: wasm-ld --export=__table_base -o %t.wasm %t.o ++# RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=CHECK-DEFAULT ++ ++# RUN: wasm-ld --table-base=100 --export=__table_base -o %t.wasm %t.o ++# RUN: obj2yaml %t.wasm | FileCheck %s -check-prefix=CHECK-100 ++ ++.globl _start ++_start: ++ .functype _start () -> () ++ i32.const _start ++ drop ++ end_function ++ ++# CHECK-DEFAULT: - Type: TABLE ++# CHECK-DEFAULT-NEXT: Tables: ++# CHECK-DEFAULT-NEXT: - Index: 0 ++# CHECK-DEFAULT-NEXT: ElemType: FUNCREF ++# CHECK-DEFAULT-NEXT: Limits: ++# CHECK-DEFAULT-NEXT: Flags: [ HAS_MAX ] ++# CHECK-DEFAULT-NEXT: Minimum: 0x2 ++# CHECK-DEFAULT-NEXT: Maximum: 0x2 ++ ++# CHECK-DEFAULT: - Type: GLOBAL ++# CHECK-DEFAULT-NEXT: Globals: ++# CHECK-DEFAULT-NEXT: - Index: 0 ++# CHECK-DEFAULT-NEXT: Type: I32 ++# CHECK-DEFAULT-NEXT: Mutable: true ++# CHECK-DEFAULT-NEXT: InitExpr: ++# CHECK-DEFAULT-NEXT: Opcode: I32_CONST ++# CHECK-DEFAULT-NEXT: Value: 66560 ++# CHECK-DEFAULT-NEXT: - Index: 1 ++# CHECK-DEFAULT-NEXT: Type: I32 ++# CHECK-DEFAULT-NEXT: Mutable: false ++# CHECK-DEFAULT-NEXT: InitExpr: ++# CHECK-DEFAULT-NEXT: Opcode: I32_CONST ++# CHECK-DEFAULT-NEXT: Value: 1 ++ ++# CHECK-DEFAULT: - Type: EXPORT ++# CHECK-DEFAULT: - Name: __table_base ++# CHECK-DEFAULT-NEXT: Kind: GLOBAL ++# CHECK-DEFAULT-NEXT: Index: 1 ++ ++# CHECK-100: - Type: TABLE ++# CHECK-100-NEXT: Tables: ++# CHECK-100-NEXT: - Index: 0 ++# CHECK-100-NEXT: ElemType: FUNCREF ++# CHECK-100-NEXT: Limits: ++# CHECK-100-NEXT: Flags: [ HAS_MAX ] ++# CHECK-100-NEXT: Minimum: 0x65 ++# CHECK-100-NEXT: Maximum: 0x65 ++ ++# CHECK-100: - Type: GLOBAL ++# CHECK-100-NEXT: Globals: ++# CHECK-100-NEXT: - Index: 0 ++# CHECK-100-NEXT: Type: I32 ++# CHECK-100-NEXT: Mutable: true ++# CHECK-100-NEXT: InitExpr: ++# CHECK-100-NEXT: Opcode: I32_CONST ++# CHECK-100-NEXT: Value: 66560 ++# CHECK-100-NEXT: - Index: 1 ++# CHECK-100-NEXT: Type: I32 ++# CHECK-100-NEXT: Mutable: false ++# CHECK-100-NEXT: InitExpr: ++# CHECK-100-NEXT: Opcode: I32_CONST ++# CHECK-100-NEXT: Value: 100 ++ ++# CHECK-100: - Type: EXPORT ++# CHECK-100: - Name: __table_base ++# CHECK-100-NEXT: Kind: GLOBAL ++# CHECK-100-NEXT: Index: 1 +diff --git a/wasm/Driver.cpp b/wasm/Driver.cpp +index 84304881f5ca34e..c2f5f0185781f36 100644 +--- a/wasm/Driver.cpp ++++ b/wasm/Driver.cpp +@@ -502,6 +502,7 @@ static void readConfigs(opt::InputArgList &args) { + + config->initialMemory = args::getInteger(args, OPT_initial_memory, 0); + config->globalBase = args::getInteger(args, OPT_global_base, 0); ++ config->tableBase = args::getInteger(args, OPT_table_base, 0); + config->maxMemory = args::getInteger(args, OPT_max_memory, 0); + config->zStackSize = + args::getZOptionValue(args, OPT_z, "stack-size", WasmPageSize); +@@ -573,6 +574,17 @@ static void setConfigs() { + if (config->exportTable) + error("-shared/-pie is incompatible with --export-table"); + config->importTable = true; ++ } else { ++ // Default table base. Defaults to 1, reserving 0 for the NULL function ++ // pointer. ++ if (!config->tableBase) ++ config->tableBase = 1; ++ // The default offset for static/global data, for when --global-base is ++ // not specified on the command line. The precise value of 1024 is ++ // somewhat arbitrary, and pre-dates wasm-ld (Its the value that ++ // emscripten used prior to wasm-ld). ++ if (!config->globalBase && !config->relocatable && !config->stackFirst) ++ config->globalBase = 1024; + } + + if (config->relocatable) { +@@ -666,8 +678,11 @@ static void checkOptions(opt::InputArgList &args) { + warn("-Bsymbolic is only meaningful when combined with -shared"); + } + +- if (config->globalBase && config->isPic) { +- error("--global-base may not be used with -shared/-pie"); ++ if (config->isPic) { ++ if (config->globalBase) ++ error("--global-base may not be used with -shared/-pie"); ++ if (config->tableBase) ++ error("--table-base may not be used with -shared/-pie"); + } + } + +diff --git a/wasm/Options.td b/wasm/Options.td +index 50417d2928e0a34..bb764396bf4df14 100644 +--- a/wasm/Options.td ++++ b/wasm/Options.td +@@ -191,7 +191,7 @@ def growable_table: FF<"growable-table">, + HelpText<"Remove maximum size from function table, allowing table to grow">; + + def global_base: JJ<"global-base=">, +- HelpText<"Where to start to place global data">; ++ HelpText<"Memory offset at which to place global data (Defaults to 1024)">; + + def import_memory: FF<"import-memory">, + HelpText<"Import the module's memory from the default module of \"env\" with the name \"memory\".">; +@@ -224,6 +224,9 @@ def no_entry: FF<"no-entry">, + def stack_first: FF<"stack-first">, + HelpText<"Place stack at start of linear memory rather than after data">; + ++def table_base: JJ<"table-base=">, ++ HelpText<"Table offset at which to place address taken functions (Defaults to 1)">; ++ + defm whole_archive: B<"whole-archive", + "Force load of all members in a static library", + "Do not force load of all members in a static library (default)">; +diff --git a/wasm/Writer.cpp b/wasm/Writer.cpp +index f25d358dc5bae6f..0576bf2907e49c4 100644 +--- a/wasm/Writer.cpp ++++ b/wasm/Writer.cpp +@@ -358,13 +358,6 @@ void Writer::layoutMemory() { + memoryPtr = config->globalBase; + } + } else { +- if (!config->globalBase && !config->relocatable && !config->isPic) { +- // The default offset for static/global data, for when --global-base is +- // not specified on the command line. The precise value of 1024 is +- // somewhat arbitrary, and pre-dates wasm-ld (Its the value that +- // emscripten used prior to wasm-ld). +- config->globalBase = 1024; +- } + memoryPtr = config->globalBase; + } + +@@ -1685,7 +1678,6 @@ void Writer::run() { + // For PIC code the table base is assigned dynamically by the loader. + // For non-PIC, we start at 1 so that accessing table index 0 always traps. + if (!config->isPic) { +- config->tableBase = 1; + if (WasmSym::definedTableBase) + WasmSym::definedTableBase->setVA(config->tableBase); + if (WasmSym::definedTableBase32) diff --git a/llvm/16/lld/default.nix b/llvm/16/lld/default.nix new file mode 100644 index 0000000..84943e8 --- /dev/null +++ b/llvm/16/lld/default.nix @@ -0,0 +1,58 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, monorepoSrc, runCommand +, cmake +, ninja +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + # Blank llvm dir just so relative path works + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libunwind" + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" + mkdir -p "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ./add-table-base.patch + ]; + + nativeBuildInputs = [ cmake ninja ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/16/lld/gnu-install-dirs.patch b/llvm/16/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..86e76f4 --- /dev/null +++ b/llvm/16/lld/gnu-install-dirs.patch @@ -0,0 +1,46 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3d6225646fe6..9b5d0b15af13 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -33,10 +33,22 @@ if(LLD_BUILT_STANDALONE) + find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}") + +- # Turn into CACHE PATHs for overwriting +- set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") +- set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree") +- set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree") ++ # We can't check LLVM_CONFIG here, because find_package(LLVM ...) also sets ++ # LLVM_CONFIG. ++ if (NOT LLVM_CONFIG_FOUND) ++ # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config ++ # path is removed. ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) ++ set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") ++ # N.B. this is just a default value, the CACHE PATHs below can be overridden. ++ set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") ++ endif() ++ ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") ++ set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") ++ set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + + find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} + NO_DEFAULT_PATH) +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index d3924f7243d4..42a7cd62281c 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -18,8 +18,8 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) diff --git a/llvm/16/lldb/cpu_subtype_arm64e_replacement.patch b/llvm/16/lldb/cpu_subtype_arm64e_replacement.patch new file mode 100644 index 0000000..20d35c9 --- /dev/null +++ b/llvm/16/lldb/cpu_subtype_arm64e_replacement.patch @@ -0,0 +1,12 @@ +diff --git a/source/Host/macosx/objcxx/HostInfoMacOSX.mm b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +--- a/source/Host/macosx/objcxx/HostInfoMacOSX.mm ++++ b/source/Host/macosx/objcxx/HostInfoMacOSX.mm +@@ -233,7 +233,7 @@ void HostInfoMacOSX::ComputeHostArchitectureSupport(ArchSpec &arch_32, + len = sizeof(is_64_bit_capable); + ::sysctlbyname("hw.cpu64bit_capable", &is_64_bit_capable, &len, NULL, 0); + +- if (cputype == CPU_TYPE_ARM64 && cpusubtype == CPU_SUBTYPE_ARM64E) { ++ if (cputype == CPU_TYPE_ARM64 && cpusubtype == ((cpu_subtype_t) 2)) { // CPU_SUBTYPE_ARM64E is not available in the macOS 10.12 headers + // The arm64e architecture is a preview. Pretend the host architecture + // is arm64. + cpusubtype = CPU_SUBTYPE_ARM64_ALL; diff --git a/llvm/16/lldb/gnu-install-dirs.patch b/llvm/16/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..4388f5c --- /dev/null +++ b/llvm/16/lldb/gnu-install-dirs.patch @@ -0,0 +1,23 @@ +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 3291a7c808e1..b27d27ce6a87 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -109,7 +109,7 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 7d48491ec89a..c04543585588 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED + ) + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) diff --git a/llvm/16/lldb/procfs.patch b/llvm/16/lldb/procfs.patch new file mode 100644 index 0000000..7b200e8 --- /dev/null +++ b/llvm/16/lldb/procfs.patch @@ -0,0 +1,46 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -10,6 +10,13 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include ++ ++// on i686 preprocessor symbols with these register names are defined as ++// numeric constants; these symbols clash with identifier names used in ++// `llvm/Support/VirtualFileSystem.h` and `llvm/ADT/SmallVector.h` ++#undef FS ++#undef CS + + #include "lldb/lldb-types.h" + +@@ -17,23 +24,13 @@ + + #include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif + + namespace lldb_private { + namespace process_linux { diff --git a/llvm/16/lldb/resource-dir.patch b/llvm/16/lldb/resource-dir.patch new file mode 100644 index 0000000..3e1a8b7 --- /dev/null +++ b/llvm/16/lldb/resource-dir.patch @@ -0,0 +1,14 @@ +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index ec06ba285f27..286162f098fb 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -290,7 +290,8 @@ if (NOT TARGET clang-resource-headers) + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" + "${LLVM_BUILD_LIBRARY_DIR}" +- "${LLVM_LIBRARY_DIR}") ++ "${LLVM_LIBRARY_DIR}" ++ "@clangLibDir@") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") + if (IS_DIRECTORY "${CANDIDATE_RESOURCE_DIR}") diff --git a/llvm/16/llvm/default.nix b/llvm/16/llvm/default.nix new file mode 100644 index 0000000..9475b5c --- /dev/null +++ b/llvm/16/llvm/default.nix @@ -0,0 +1,428 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, monorepoSrc +, runCommand +, fetchpatch +, cmake +, darwin +, ninja +, python3 +, python3Packages +, libffi +# TODO: Gold plugin on LLVM16 has a severe memory corruption bug: https://github.com/llvm/llvm-project/issues/61350. +, enableGoldPlugin ? false +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, which +, sysctl +, buildLlvmTools +, debugVersion ? false +, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +, enablePFM ? stdenv.isLinux /* PFM only supports Linux */ + # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + # broken for the armv7l builder + && !stdenv.hostPlatform.isAarch +, enablePolly ? true +} @args: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + # Note that we _explicitly_ ask for a python interpreter for our host + # platform here; the splicing that would ordinarily take care of this for + # us does not seem to work once we use `withPackages`. + let + checkDeps = ps: with ps; [ psutil ]; + in pkgsBuildBuild.targetPackages.python3.withPackages checkDeps + else python3; + +in + assert (lib.assertMsg (!enableGoldPlugin) "Gold plugin cannot be enabled on LLVM16 due to a upstream issue: https://github.com/llvm/llvm-project/issues/61350"); + stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} ('' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/third-party "$out" + '' + lib.optionalString enablePolly '' + chmod u+w "$out/${pname}/tools" + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" + ''); + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake ninja python ] + ++ optionals enableManpages [ + # Note: we intentionally use `python3Packages` instead of `python3.pkgs`; + # splicing does *not* work with the latter. (TODO: fix) + python3Packages.sphinx python3Packages.recommonmark + ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + nativeCheckInputs = [ + which + ] ++ lib.optional stdenv.isDarwin sysctl; + + patches = [ + ./gnu-install-dirs.patch + + # Running the tests involves invoking binaries (like `opt`) that depend on + # the LLVM dylibs and reference them by absolute install path (i.e. their + # nix store path). + # + # Because we have not yet run the install phase (we're running these tests + # as part of `checkPhase` instead of `installCheckPhase`) these absolute + # paths do not exist yet; to work around this we point the loader (`ld` on + # unix, `dyld` on macOS) at the `lib` directory which will later become this + # package's `lib` output. + # + # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib` + # dir but: + # - this doesn't generalize well to other platforms; `lit` doesn't forward + # `DYLD_LIBRARY_PATH` (macOS): + # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26 + # - even if `lit` forwarded this env var, we actually cannot set + # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because + # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for + # "protected processes" (i.e. the python interpreter that runs `lit`): + # https://stackoverflow.com/a/35570229 + # - other LLVM subprojects deal with this issue by having their `lit` + # configuration set these env vars for us; it makes sense to do the same + # for LLVM: + # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31 + # + # !!! TODO: look into upstreaming this patch + ./llvm-lit-cfg-add-libs-to-dylib-path.patch + + # `lit` has a mode where it executes run lines as a shell script which is + # constructs; this is problematic for macOS because it means that there's + # another process in between `lit` and the binaries being tested. As noted + # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our + # tests fail with dyld errors. + # + # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when + # present in the test configuration. + # + # It's not clear to me why this isn't an issue for LLVM developers running + # on macOS (nothing about this _seems_ nix specific).. + ./lit-shell-script-runner-set-dyld-library-path.patch + ] ++ lib.optionals enablePolly [ + ./gnu-install-dirs-polly.patch + + # Just like the `llvm-lit-cfg` patch, but for `polly`. + ./polly-lit-cfg-add-libs-to-dylib-path.patch + ]; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + + # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick + # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 + rm test/MC/ELF/cfi-version.ll + + # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) + # and thus fails under the sandbox: + substituteInPlace unittests/TargetParser/Host.cpp \ + --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" + + # This test tries to call the intrinsics `@llvm.roundeven.f32` and + # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` + # and `roundeven` on macOS. + # + # However these functions are glibc specific so the test fails: + # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html + # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html + # + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ + --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ + --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" + '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' + # This test fails on darwin x86_64 because `sw_vers` reports a different + # macOS version than what LLVM finds by reading + # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into + # the sandbox on macOS). + # + # The `sw_vers` provided by nixpkgs reports the macOS version associated + # with the `CoreFoundation` framework with which it was built. Because + # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what + # `sw_vers` reports is not guaranteed to match the macOS version of the host + # that's building this derivation. + # + # Astute readers will note that we only _patch_ this test on aarch64-darwin + # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. + # So why does this test pass on aarch64? + # + # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ + # CoreFoundation framework instead of the nixpkgs provided one. + # + # Not entirely sure what the right fix is here. I'm assuming aarch64 + # `sw_vers` doesn't intentionally link against the host `CoreFoundation` + # (still digging into how this ends up happening, will follow up) but that + # aside I think the more pertinent question is: should we be patching LLVM's + # macOS version detection logic to use `sw_vers` instead of reading host + # paths? This *is* a way in which details about builder machines can creep + # into the artifacts that are produced, affecting reproducibility, but it's + # not clear to me when/where/for what this even gets used in LLVM. + # + # TODO(@rrbutani): fix/follow-up + substituteInPlace unittests/TargetParser/Host.cpp \ + --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" + + # This test fails with a `dysmutil` crash; have not yet dug into what's + # going on here (TODO(@rrbutani)). + rm test/tools/dsymutil/ARM/obfuscated.test + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + # timing-based tests are trouble + rm utils/lit/tests/googletest-timeout.py + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s + rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" + ) + ''; + + # Defensive check: some paths (that we make symlinks to) depend on the release + # version, for example: + # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 + # + # So we want to sure that the version in the source matches the release + # version we were given. + # + # We do this check here, in the LLVM build, because it happens early. + postConfigure = let + v = lib.versions; + major = v.major release_version; + minor = v.minor release_version; + patch = v.patch release_version; + in '' + # $1: part, $2: expected + check_version() { + part="''${1^^}" + part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" + + if [[ "$part" != "$2" ]]; then + echo >&2 \ + "mismatch in the $1 version! we have version ${release_version}" \ + "and expected the $1 version to be '$2'; the source has '$part' instead" + exit 3 + fi + } + + check_version major ${major} + check_version minor ${minor} + check_version patch ${patch} + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=off" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (false) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + # For the update script: + passthru.monorepoSrc = monorepoSrc; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + propagatedBuildInputs = []; + + ninjaFlags = [ "docs-llvm-man" ]; + installTargets = [ "install-docs-llvm-man" ]; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/16/llvm/gnu-install-dirs-polly.patch b/llvm/16/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..b01363e --- /dev/null +++ b/llvm/16/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,19 @@ +This is the one remaining Polly install dirs related change that hasn't made it +into upstream yet; previously this patch file also included: +https://reviews.llvm.org/D117541 + +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) diff --git a/llvm/16/llvm/gnu-install-dirs.patch b/llvm/16/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..1c2d52d --- /dev/null +++ b/llvm/16/llvm/gnu-install-dirs.patch @@ -0,0 +1,161 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 7e25e0407db2..72f031a82b75 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -995,7 +995,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") + add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) + install(TARGETS tf_xla_runtime EXPORT LLVMExports +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) + # Once we add more modules, we should handle this more automatically. + if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 93e6d67551de..8d367457af5a 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -874,8 +874,8 @@ macro(add_llvm_library name) + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) +@@ -2043,7 +2043,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir "${CMAKE_INSTALL_BINDIR}") + endif() +@@ -2312,16 +2312,37 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) + # $ORIGIN is not interpreted at link time by aix ld. + # Since BUILD_SHARED_LIBS is only recommended for use by developers, + # hardcode the rpath to build/install lib dir first in this mode. + # FIXME: update this when there is better solution. +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_build_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}") ++ # Note that we add `extra_libdir` (aka `LLVM_LIBRARY_DIR` in our case) back ++ # to `_install_rpath` here. ++ # ++ # In nixpkgs we do not build and install LLVM alongside rdeps of LLVM (i.e. ++ # clang); instead LLVM is its own package and thus lands at its own nix ++ # store path. This makes it so that the default relative rpath (`../lib/`) ++ # does not point at the LLVM shared objects. ++ # ++ # More discussion here: ++ # - https://github.com/NixOS/nixpkgs/pull/235624#discussion_r1220150329 ++ # - https://reviews.llvm.org/D146918 (16.0.5+) ++ # ++ # Note that we leave `extra_libdir` in `_build_rpath`: without FHS there is ++ # no potential that this will result in us pulling in the "wrong" LLVM. ++ # Adding this to the build rpath means we aren't forced to use ++ # `installCheckPhase` instead of `checkPhase` (i.e. binaries in the build ++ # dir, pre-install, will have the right rpath for LLVM). ++ # ++ # As noted in the differential above, an alternative solution is to have ++ # all rdeps of nixpkgs' LLVM (that use the AddLLVM.cmake machinery) set ++ # `CMAKE_INSTALL_RPATH`. ++ set(_build_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 891c9e6d618c..8d963f3b0069 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -147,9 +147,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index d99af79aa38e..21e794224b99 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -127,7 +127,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS + ) + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) + +-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") ++extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_LIBRARY_DIRS + "${LLVM_CONFIG_LIBRARY_DIR}" + # FIXME: Should there be other entries here? +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 7926de258ec8..5ae01adc3905 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -250,7 +250,7 @@ description is in `LLVM-related variables`_ below. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **LLVM_PARALLEL_{COMPILE,LINK}_JOBS**:STRING + Building the llvm toolchain can use a lot of resources, particularly +@@ -284,6 +284,10 @@ manual, or execute ``cmake --help-variable VARIABLE_NAME``. + The path to install executables, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "bin". + ++**CMAKE_INSTALL_LIBDIR**:PATH ++ The path to install libraries, relative to the *CMAKE_INSTALL_PREFIX*. ++ Defaults to "lib". ++ + **CMAKE_INSTALL_INCLUDEDIR**:PATH + The path to install header files, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "include". +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 370005cd8d7d..7e790bc52111 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,7 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" + #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index b1d795a0a349..de6cb1514f05 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -366,7 +366,11 @@ int main(int argc, char **argv) { + sys::fs::make_absolute(ActivePrefix, Path); + ActiveBinDir = std::string(Path.str()); + } +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; ++ { ++ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); ++ sys::fs::make_absolute(ActivePrefix, Path); ++ ActiveLibDir = std::string(Path.str()); ++ } + { + SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); + sys::fs::make_absolute(ActivePrefix, Path); diff --git a/llvm/16/llvm/lit-shell-script-runner-set-dyld-library-path.patch b/llvm/16/llvm/lit-shell-script-runner-set-dyld-library-path.patch new file mode 100644 index 0000000..82b7b21 --- /dev/null +++ b/llvm/16/llvm/lit-shell-script-runner-set-dyld-library-path.patch @@ -0,0 +1,17 @@ +diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py +index 0242e0b75af3..d732011306f7 100644 +--- a/utils/lit/lit/TestRunner.py ++++ b/utils/lit/lit/TestRunner.py +@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd): + f.write('@echo off\n') + f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands)) + else: ++ # This env var is *purged* when invoking subprocesses so we have to ++ # manually set it from within the bash script in order for the commands ++ # in run lines to see this var: ++ if "DYLD_LIBRARY_PATH" in test.config.environment: ++ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') ++ + for i, ln in enumerate(commands): + match = re.match(kPdbgRegex, ln) + if match: diff --git a/llvm/16/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch b/llvm/16/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000..d824516 --- /dev/null +++ b/llvm/16/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,79 @@ +diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py +index 81e8dc04acea..479ff95681e2 100644 +--- a/test/Unit/lit.cfg.py ++++ b/test/Unit/lit.cfg.py +@@ -3,6 +3,7 @@ + # Configuration file for the 'lit' test runner. + + import os ++import platform + import subprocess + + import lit.formats +@@ -55,3 +56,26 @@ if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir): + # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate. + if sys.platform == 'win32' and 'SYSTEMDRIVE' in os.environ: + config.environment['SYSTEMDRIVE'] = os.environ['SYSTEMDRIVE'] ++ ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = os.path.pathsep.join( ++ (config.shlibdir, ++ config.environment.get(shlibpath_var, ''))) ++ config.environment[shlibpath_var] = shlibpath ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) +diff --git a/test/lit.cfg.py b/test/lit.cfg.py +index 75a38b4c5dad..856fc75c9d74 100644 +--- a/test/lit.cfg.py ++++ b/test/lit.cfg.py +@@ -42,6 +42,26 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) + llvm_config.with_system_environment( + ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP']) + ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = config.llvm_shlib_dir ++ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True) ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) + + # Set up OCAMLPATH to include newly built OCaml libraries. + top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml') +@@ -318,7 +338,7 @@ def have_cxx_shared_library(): + + try: + readobj_cmd = subprocess.Popen( +- [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE) ++ [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE, env=config.environment) + except OSError: + print('could not exec llvm-readobj') + return False diff --git a/llvm/16/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch b/llvm/16/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000..1354ad2 --- /dev/null +++ b/llvm/16/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,24 @@ +diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg +index 41e3a589c61e..09f3b17498b0 100644 +--- a/tools/polly/test/lit.cfg ++++ b/tools/polly/test/lit.cfg +@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']] + path = os.path.pathsep.join(base_paths + config.extra_paths) + config.environment['PATH'] = path + ++# (Copied from polly/test/Unit/lit.cfg) ++if platform.system() == 'Darwin': ++ shlibpath_var = 'DYLD_LIBRARY_PATH' ++elif platform.system() == 'Windows': ++ shlibpath_var = 'PATH' ++else: ++ shlibpath_var = 'LD_LIBRARY_PATH' ++ + path = os.path.pathsep.join((config.llvm_libs_dir, +- config.environment.get('LD_LIBRARY_PATH',''))) +-config.environment['LD_LIBRARY_PATH'] = path ++ config.environment.get(shlibpath_var,''))) ++config.environment[shlibpath_var] = path + + llvm_config.use_default_substitutions() + diff --git a/llvm/16/openmp/default.nix b/llvm/16/openmp/default.nix new file mode 100644 index 0000000..d513354 --- /dev/null +++ b/llvm/16/openmp/default.nix @@ -0,0 +1,74 @@ +{ lib +, stdenv +, llvm_meta +, monorepoSrc +, runCommand +, cmake +, ninja +, llvm +, targetLlvm +, lit +, clang-unwrapped +, perl +, pkg-config +, xcbuild +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./fix-find-tool.patch + ./gnu-install-dirs.patch + ./run-lit-directly.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ninja perl pkg-config lit ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + nativeCheckInputs = lib.optional stdenv.hostPlatform.isDarwin xcbuild.xcrun; + + # Unsup:Pass:XFail:Fail + # 26:267:16:8 + doCheck = false; + checkTarget = "check-openmp"; + + preCheck = '' + patchShebangs ../tools/archer/tests/deflake.bash + ''; + + cmakeFlags = [ + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" + "-DOPT_TOOL=${llvm}/bin/opt" + "-DLINK_TOOL=${llvm}/bin/llvm-link" + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/16/openmp/fix-find-tool.patch b/llvm/16/openmp/fix-find-tool.patch new file mode 100644 index 0000000..dd0a79f --- /dev/null +++ b/llvm/16/openmp/fix-find-tool.patch @@ -0,0 +1,21 @@ +diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt +index 49b398c9f765..6f1dd1340010 100644 +--- a/libomptarget/DeviceRTL/CMakeLists.txt ++++ b/libomptarget/DeviceRTL/CMakeLists.txt +@@ -27,11 +27,11 @@ endif() + if (LLVM_DIR) + # Builds that use pre-installed LLVM have LLVM_DIR set. + # A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route +- find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) +- find_program(PACKAGER_TOOL clang-offload-packager PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) +- find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) +- find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) +- find_program(EXTRACT_TOOL llvm-extract PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR}) ++ find_program(PACKAGER_TOOL clang-offload-packager PATHS ${LLVM_TOOLS_BINARY_DIR}) ++ find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR}) ++ find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR}) ++ find_program(EXTRACT_TOOL llvm-extract PATHS ${LLVM_TOOLS_BINARY_DIR}) + if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL) OR (NOT EXTRACT_TOOL) OR (NOT PACKAGER_TOOL)) + libomptarget_say("Not building DeviceRTL. Missing clang: ${CLANG_TOOL}, llvm-link: ${LINK_TOOL}, opt: ${OPT_TOOL}, llvm-extract: ${EXTRACT_TOOL}, or clang-offload-packager: ${PACKAGER_TOOL}") + return() diff --git a/llvm/16/openmp/gnu-install-dirs.patch b/llvm/16/openmp/gnu-install-dirs.patch new file mode 100644 index 0000000..77a9320 --- /dev/null +++ b/llvm/16/openmp/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b6ddbe90516d..311ab1d50e7f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD) + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "Suffix of lib installation directory, e.g. 64 => lib64") + # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. +- set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}") + + # Group test settings. + set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING +@@ -40,7 +40,7 @@ if (OPENMP_STANDALONE_BUILD) + else() + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # If building in tree, we honor the same install suffix LLVM uses. +- set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + + if (NOT MSVC) + set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) diff --git a/llvm/16/openmp/run-lit-directly.patch b/llvm/16/openmp/run-lit-directly.patch new file mode 100644 index 0000000..e69de29 diff --git a/llvm/6/clang/default.nix b/llvm/6/clang/default.nix new file mode 100644 index 0000000..bc69f1c --- /dev/null +++ b/llvm/6/clang/default.nix @@ -0,0 +1,127 @@ +{ lib, stdenv, llvm_meta, fetch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "cfe" "0rxn4rh7rrnsqbdgp4gzc8ishbkryhpl1kd3mpnxzpxxhla3y93w"; + + unpackPhase = '' + unpackFile $src + mv cfe-${version}* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCMAKE_CXX_FLAGS=-std=c++11" + "-DLLVM_ENABLE_RTTI=ON" + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ]; + + patches = [ + ../../common/clang/5-8-purity.patch + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-6-10-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/6/clang/gnu-install-dirs.patch b/llvm/6/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..bdbbae9 --- /dev/null +++ b/llvm/6/clang/gnu-install-dirs.patch @@ -0,0 +1,258 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 2eee8e6148f7..63efc7d2fdd0 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.4.3) + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + find_program(LLVM_CONFIG "llvm-config") +@@ -365,7 +367,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.def" + PATTERN "*.h" +@@ -374,7 +376,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE + PATTERN "*.inc" +@@ -382,7 +384,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + ) + endif() + +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index c09a8423f9f6..39f37e0097eb 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -99,9 +99,9 @@ macro(add_clang_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -141,7 +141,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -156,5 +156,5 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 97ba3edea1c5..9d2bc5714af5 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -142,13 +142,13 @@ install( + FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${cuda_wrapper_files} + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's. + add_llvm_install_targets(install-clang-headers +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index d38c7bb28709..c9b5499cb756 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -50,7 +50,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-check/CMakeLists.txt b/tools/clang-check/CMakeLists.txt +index c5ace26c2914..97bdfca7d896 100644 +--- a/tools/clang-check/CMakeLists.txt ++++ b/tools/clang-check/CMakeLists.txt +@@ -20,4 +20,4 @@ target_link_libraries(clang-check + ) + + install(TARGETS clang-check +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index a295e8cd0b2a..1973ff82c7f6 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-func-mapping/CMakeLists.txt b/tools/clang-func-mapping/CMakeLists.txt +index ae28e28d532d..8ecb2e37a8f7 100644 +--- a/tools/clang-func-mapping/CMakeLists.txt ++++ b/tools/clang-func-mapping/CMakeLists.txt +@@ -20,4 +20,4 @@ target_link_libraries(clang-func-mapping + ) + + install(TARGETS clang-func-mapping +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-offload-bundler/CMakeLists.txt b/tools/clang-offload-bundler/CMakeLists.txt +index 8718015be76a..7a038f39622e 100644 +--- a/tools/clang-offload-bundler/CMakeLists.txt ++++ b/tools/clang-offload-bundler/CMakeLists.txt +@@ -22,4 +22,4 @@ target_link_libraries(clang-offload-bundler + ${CLANG_OFFLOAD_BUNDLER_LIB_DEPS} + ) + +-install(TARGETS clang-offload-bundler RUNTIME DESTINATION bin) ++install(TARGETS clang-offload-bundler RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-refactor/CMakeLists.txt b/tools/clang-refactor/CMakeLists.txt +index d2029066b9b7..9bc152a675af 100644 +--- a/tools/clang-refactor/CMakeLists.txt ++++ b/tools/clang-refactor/CMakeLists.txt +@@ -21,4 +21,4 @@ target_link_libraries(clang-refactor + clangToolingRefactor + ) + +-install(TARGETS clang-refactor RUNTIME DESTINATION bin) ++install(TARGETS clang-refactor RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index 9689e1c6804d..6087716510a9 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -16,8 +16,8 @@ target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 44406378207b..3b64b18ad4a5 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -130,7 +130,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index 380379300b09..adfd58ed5f7d 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -41,7 +41,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(LibexecFile ${LibexecFiles}) +@@ -53,7 +53,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/libexec/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) +- install(PROGRAMS libexec/${LibexecFile} DESTINATION libexec) ++ install(PROGRAMS libexec/${LibexecFile} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) + endforeach() + + foreach(ManPage ${ManPages}) +@@ -77,7 +77,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/share/scan-build/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) +- install(FILES share/scan-build/${ShareFile} DESTINATION share/scan-build) ++ install(FILES share/scan-build/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build) + endforeach() + + add_custom_target(scan-build ALL DEPENDS ${Depends}) +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index b305ca562a72..554bcb379061 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -21,7 +21,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(ShareFile ${ShareFiles}) +@@ -33,7 +33,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/share/scan-view/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) +- install(FILES share/${ShareFile} DESTINATION share/scan-view) ++ install(FILES share/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view) + endforeach() + + add_custom_target(scan-view ALL DEPENDS ${Depends}) diff --git a/llvm/6/compiler-rt/armv7l.patch b/llvm/6/compiler-rt/armv7l.patch new file mode 100644 index 0000000..ca2ed63 --- /dev/null +++ b/llvm/6/compiler-rt/armv7l.patch @@ -0,0 +1,32 @@ +diff -ur compiler-rt-6.0.1.src/cmake/builtin-config-ix.cmake compiler-rt-6.0.1.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-6.0.1.src/cmake/builtin-config-ix.cmake 2017-12-01 06:04:11.000000000 +0900 ++++ compiler-rt-6.0.1.src-patched/cmake/builtin-config-ix.cmake 2020-05-10 03:30:01.939694303 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(X86 i386) + set(X86_64 x86_64) + set(MIPS32 mips mipsel) +diff -ur compiler-rt-6.0.1.src/lib/builtins/CMakeLists.txt compiler-rt-6.0.1.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-6.0.1.src/lib/builtins/CMakeLists.txt 2017-12-25 06:11:32.000000000 +0900 ++++ compiler-rt-6.0.1.src-patched/lib/builtins/CMakeLists.txt 2020-05-10 03:30:44.814964156 +0900 +@@ -452,6 +452,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -521,7 +522,7 @@ + set(_arch ${arch}) + if("${arch}" STREQUAL "armv6m") + set(_arch "arm|armv6m") +- elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + set(_arch "arm") + endif() + diff --git a/llvm/6/compiler-rt/codesign.patch b/llvm/6/compiler-rt/codesign.patch new file mode 100644 index 0000000..8f4c76b --- /dev/null +++ b/llvm/6/compiler-rt/codesign.patch @@ -0,0 +1,155 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc5fb9ff7..b64eb4246 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} +- ) +- endif() + endif() + install(TARGETS ${libname} + ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} +diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt +index 8bfc15b5c..f23d0f71a 100644 +--- a/test/asan/CMakeLists.txt ++++ b/test/asan/CMakeLists.txt +@@ -83,58 +83,6 @@ foreach(arch ${ASAN_TEST_ARCH}) + endif() + endforeach() + +-# iOS and iOS simulator test suites +-# These are not added into "check-all", in order to run these tests, use +-# "check-asan-iossim-x86_64" and similar. They also require that an extra env +-# variable to select which iOS device or simulator to use, e.g.: +-# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6" +-if(APPLE) +- set(EXCLUDE_FROM_ALL ON) +- +- set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) +- set(ASAN_TEST_IOS "1") +- pythonize_bool(ASAN_TEST_IOS) +- set(ASAN_TEST_DYNAMIC True) +- +- foreach(arch ${DARWIN_iossim_ARCHS}) +- set(ASAN_TEST_IOSSIM "1") +- pythonize_bool(ASAN_TEST_IOSSIM) +- set(ASAN_TEST_TARGET_ARCH ${arch}) +- set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") +- set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-iossim") +- get_bits_for_arch(${arch} ASAN_TEST_BITS) +- string(TOUPPER ${arch} ARCH_UPPER_CASE) +- set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config") +- configure_lit_site_cfg( +- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg +- ) +- add_lit_testsuite(check-asan-iossim-${arch} "AddressSanitizer iOS Simulator ${arch} tests" +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ +- DEPENDS ${ASAN_TEST_DEPS}) +- endforeach() +- +- foreach (arch ${DARWIN_ios_ARCHS}) +- set(ASAN_TEST_IOSSIM "0") +- pythonize_bool(ASAN_TEST_IOSSIM) +- set(ASAN_TEST_TARGET_ARCH ${arch}) +- set(ASAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") +- set(ASAN_TEST_CONFIG_SUFFIX "-${arch}-ios") +- get_bits_for_arch(${arch} ASAN_TEST_BITS) +- string(TOUPPER ${arch} ARCH_UPPER_CASE) +- set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config") +- configure_lit_site_cfg( +- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg +- ) +- add_lit_testsuite(check-asan-ios-${arch} "AddressSanitizer iOS ${arch} tests" +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ +- DEPENDS ${ASAN_TEST_DEPS}) +- endforeach() +- +- set(EXCLUDE_FROM_ALL OFF) +-endif() +- + # Add unit tests. + if(COMPILER_RT_INCLUDE_TESTS) + set(ASAN_TEST_DYNAMIC False) +diff --git a/test/tsan/CMakeLists.txt b/test/tsan/CMakeLists.txt +index a68908612..cde0accb5 100644 +--- a/test/tsan/CMakeLists.txt ++++ b/test/tsan/CMakeLists.txt +@@ -42,53 +42,6 @@ foreach(arch ${TSAN_TEST_ARCH}) + list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) + endforeach() + +-# iOS and iOS simulator test suites +-# These are not added into "check-all", in order to run these tests, use +-# "check-tsan-iossim-x86_64" and similar. They also require an extra environment +-# variable to select which iOS device or simulator to use, e.g.: +-# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6" +-if(APPLE) +- set(EXCLUDE_FROM_ALL ON) +- +- set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) +- set(TSAN_TEST_IOS "1") +- pythonize_bool(TSAN_TEST_IOS) +- +- set(arch "x86_64") +- set(TSAN_TEST_IOSSIM "1") +- pythonize_bool(TSAN_TEST_IOSSIM) +- set(TSAN_TEST_TARGET_ARCH ${arch}) +- set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") +- set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-iossim") +- string(TOUPPER ${arch} ARCH_UPPER_CASE) +- set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config") +- configure_lit_site_cfg( +- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg +- ) +- add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests" +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ +- DEPENDS ${TSAN_TEST_DEPS}) +- +- set(arch "arm64") +- set(TSAN_TEST_IOSSIM "0") +- pythonize_bool(TSAN_TEST_IOSSIM) +- set(TSAN_TEST_TARGET_ARCH ${arch}) +- set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}") +- set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-ios") +- string(TOUPPER ${arch} ARCH_UPPER_CASE) +- set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config") +- configure_lit_site_cfg( +- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg +- ) +- add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS Simulator ${arch} tests" +- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/ +- DEPENDS ${TSAN_TEST_DEPS}) +- +- set(EXCLUDE_FROM_ALL OFF) +-endif() +- + if(COMPILER_RT_INCLUDE_TESTS) + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in +-- +2.14.1 + diff --git a/llvm/6/compiler-rt/default.nix b/llvm/6/compiler-rt/default.nix new file mode 100644 index 0000000..1288bd9 --- /dev/null +++ b/llvm/6/compiler-rt/default.nix @@ -0,0 +1,112 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt"; + inherit version; + src = fetch "compiler-rt" "1fcr3jn24yr8lh36nc0c4ikli4744i2q9m1ik67p1jymwwaixkgl"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ]; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + "-DCMAKE_C_FLAGS=-nodefaultlibs" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + ./codesign.patch # Revert compiler-rt commit that makes codesign mandatory + # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce + ../../common/compiler-rt/glibc.patch + ./gnu-install-dirs.patch + ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch + ] ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/linux/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/linux/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/linux/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/linux/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/freebsd/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; + }; +} diff --git a/llvm/6/compiler-rt/gnu-install-dirs.patch b/llvm/6/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..8daf039 --- /dev/null +++ b/llvm/6/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,107 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4b953b212829..a10b69aa67dc 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.4.3) + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + endif() + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index 139b6140011c..502354a37d67 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -439,7 +439,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH} ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_PREFIX} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -456,7 +456,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index a25540bf46d1..77ea739fea74 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -375,7 +375,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index b208f0852408..cacf4e8fb69d 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -46,11 +46,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -70,9 +70,9 @@ if(NOT DEFINED COMPILER_RT_OS_DIR) + string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR) + endif() + set(COMPILER_RT_LIBRARY_OUTPUT_DIR +- ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_OUTPUT_DIR}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + + if(APPLE) + # On Darwin if /usr/include doesn't exist, the user probably has Xcode but not +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index f7efb102ab63..ab8a94d9ff40 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -47,12 +47,12 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index 2c486bff821b..0ee715da95f8 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -44,4 +44,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_PREFIX}) diff --git a/llvm/6/default.nix b/llvm/6/default.nix new file mode 100644 index 0000000..3dcc750 --- /dev/null +++ b/llvm/6/default.nix @@ -0,0 +1,141 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake, gccForLibs +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +}: + +let + release_version = "6.0.1"; + version = release_version; # differentiating these is important for rc's + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://releases.llvm.org/${release_version}/${name}-${version}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "1w8ml7fyn4vyxmy59n2qm4r1k1kgwgwkaldp6m45fdv4g0kkfbhd"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ''; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libllvm-polly = callPackage ./llvm { + inherit llvm_meta; + enablePolly = true; + }; + + llvm-polly = tools.libllvm-polly.lib // { outputSpecified = false; }; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + enableSharedLibraries = false; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ./lldb { + inherit llvm_meta; + }; + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt = callPackage ./compiler-rt { + inherit llvm_meta; + }; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/6/libcxx/default.nix b/llvm/6/libcxx/default.nix new file mode 100644 index 0000000..0fc31d4 --- /dev/null +++ b/llvm/6/libcxx/default.nix @@ -0,0 +1,85 @@ +{ lib, stdenv, llvm_meta, fetch, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "0rzw4qvxp6qx4l4h9amrq02gp7hbg8lw4m0sy3k60f50234gnm3n"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include" + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz" + postPatch = '' + substituteInPlace include/__config \ + --replace "#define _LIBCPP_USE_AVAILABILITY_APPLE" "" + ''; + + prePatch = '' + substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++" + ''; + + preConfigure = '' + # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package + cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR") + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + nativeBuildInputs = [ cmake ] + ++ lib.optional stdenv.hostPlatform.isMusl python3 + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_LIBCPPABI_VERSION=2" + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (cxxabi.pname == "libcxxabi") "-DLIBCXX_LIBCXXABI_LIB_PATH=${cxxabi}/lib"; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/6/libcxx/gnu-install-dirs.patch b/llvm/6/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..33ff9ef --- /dev/null +++ b/llvm/6/libcxx/gnu-install-dirs.patch @@ -0,0 +1,72 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9e8e9d5e3d9b..e1d6d2392b92 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -22,6 +22,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 6.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 558e11ba2cc1..c6a99cec0191 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -55,7 +55,7 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) + ) + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index b98e09260ca1..c920f48697bc 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -20,7 +20,7 @@ endif() + + if (LIBCXX_INSTALL_HEADERS) + install(DIRECTORY . +- DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + COMPONENT cxx-headers + FILES_MATCHING + ${LIBCXX_HEADER_PATTERN} +@@ -44,7 +44,7 @@ if (LIBCXX_INSTALL_HEADERS) + set(generated_config_deps generate_config_header) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT cxx-headers) +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index aa5ebf1568ec..36d85b94c3ba 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -357,8 +357,8 @@ if (LIBCXX_INSTALL_LIBRARY) + set(experimental_lib cxx_experimental) + endif() + install(TARGETS ${LIBCXX_TARGETS} ${experimental_lib} +- LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx +- ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ++ LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ++ ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx + ) + # NOTE: This install command must go after the cxx install command otherwise + # it will not be executed after the library symlinks are installed. +@@ -366,7 +366,7 @@ if (LIBCXX_INSTALL_LIBRARY) + # Replace the libc++ filename with $ + # after we required CMake 3.0. + install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" +- DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} ++ DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} + COMPONENT libcxx) + endif() + endif() diff --git a/llvm/6/libcxxabi/default.nix b/llvm/6/libcxxabi/default.nix new file mode 100644 index 0000000..0821dbd --- /dev/null +++ b/llvm/6/libcxxabi/default.nix @@ -0,0 +1,70 @@ +{ lib, stdenv, llvm_meta, cmake, fetch, libcxx, libunwind, llvm, version }: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "0prqvdj317qrc8nddaq1hh2ag9algkd9wbkj3y4mr5588k12x7r0"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + unpackFile ${llvm.src} + export cmakeFlags="-DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)" + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch} + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = lib.optional (!stdenv.isDarwin) libunwind; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/6/libcxxabi/gnu-install-dirs.patch b/llvm/6/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..649d28d --- /dev/null +++ b/llvm/6/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 1adbdb338322..2978631e1c58 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -20,6 +20,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 6.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 240f6d0d103b..7ad5c31ec7b4 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -181,8 +181,8 @@ add_custom_target(cxxabi DEPENDS ${LIBCXXABI_TARGETS}) + + if (LIBCXXABI_INSTALL_LIBRARY) + install(TARGETS ${LIBCXXABI_TARGETS} +- LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi +- ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi ++ LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi ++ ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi + ) + endif() + diff --git a/llvm/6/lld/default.nix b/llvm/6/lld/default.nix new file mode 100644 index 0000000..a2a011c --- /dev/null +++ b/llvm/6/lld/default.nix @@ -0,0 +1,46 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "04afcfq2h7ysyqxxhyhb7ig4p0vdw7mi63kh8mffl74j0rc781p7"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), and Mach-O (macOS) + in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/6/lld/gnu-install-dirs.patch b/llvm/6/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..8c6886c --- /dev/null +++ b/llvm/6/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index e2fbdbfbbb47..d601b231ebb8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -203,7 +205,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index 0d951799cdfe..7d8546ba87f8 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index d8829493fc22..df748a0e749b 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -16,7 +16,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE lld-link ld.lld ld64.lld wasm-ld) diff --git a/llvm/6/lldb/default.nix b/llvm/6/lldb/default.nix new file mode 100644 index 0000000..e64584e --- /dev/null +++ b/llvm/6/lldb/default.nix @@ -0,0 +1,88 @@ +{ lib, stdenv, llvm_meta +, fetch +, fetchpatch +, cmake +, zlib +, ncurses +, swig +, which +, libedit +, libxml2 +, libllvm +, libclang +, python3 +, version +, darwin +}: + +stdenv.mkDerivation rec { + pname = "lldb"; + inherit version; + + src = fetch "lldb" "05178zkyh84x32n91md6wm22lkzzrrfwa5cpmgzn0yrg3y2771bb"; + + patches = [ + # Fix PythonString::GetString for >=python-3.7 + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5457b426f5e15a29c0acc8af1a476132f8be2a36.patch"; + sha256 = "1zbx4m0m8kbg0wq6740jcw151vb2pb1p25p401wiq8diqqagkjps"; + stripLen = 1; + }) + ./gnu-install-dirs.patch + ]; + + postPatch = '' + # Fix up various paths that assume llvm and clang are installed in the same place + sed -i 's,".*ClangConfig.cmake","${libclang.dev}/lib/cmake/clang/ClangConfig.cmake",' \ + cmake/modules/LLDBStandalone.cmake + sed -i 's,".*tools/clang/include","${libclang.dev}/include",' \ + cmake/modules/LLDBStandalone.cmake + sed -i 's,"$.LLVM_LIBRARY_DIR.",${libllvm.lib}/lib ${libclang.lib}/lib,' \ + cmake/modules/LLDBStandalone.cmake + ''; + + outputs = [ "out" "lib" "dev" ]; + + nativeBuildInputs = [ + cmake python3 which swig + ]; + + buildInputs = [ + ncurses zlib libedit libxml2 libllvm + ] ++ lib.optionals stdenv.isDarwin [ + darwin.libobjc + darwin.apple_sdk.libs.xpc + darwin.apple_sdk.frameworks.Foundation darwin.bootstrap_cmds darwin.apple_sdk.frameworks.Carbon darwin.apple_sdk.frameworks.Cocoa + ]; + + CXXFLAGS = "-fno-rtti"; + hardeningDisable = [ "format" ]; + + cmakeFlags = [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + ] ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ]; + + doCheck = false; + + postInstall = '' + mkdir -p $out/share/man/man1 + cp ../docs/lldb.1 $out/share/man/man1/ + ''; + + meta = llvm_meta // { + homepage = "https://lldb.llvm.org/"; + description = "A next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + # never built on aarch64-darwin since first introduction in nixpkgs + broken = stdenv.isDarwin && stdenv.isAarch64; + }; +} diff --git a/llvm/6/lldb/gnu-install-dirs.patch b/llvm/6/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..a240eca --- /dev/null +++ b/llvm/6/lldb/gnu-install-dirs.patch @@ -0,0 +1,76 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c6b082e104e5..568a99837e1f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -7,6 +7,8 @@ set(CMAKE_MODULE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" + ) + ++include(GNUInstallDirs) ++ + include(LLDBStandalone) + include(LLDBConfig) + include(AddLLDB) +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 2fd8b384d9e3..4db5e786c493 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -56,14 +56,14 @@ function(add_lldb_library name) + endif() + install(TARGETS ${name} + COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${out_dir} + ARCHIVE DESTINATION ${out_dir}) + else() + install(TARGETS ${name} + COMPONENT ${name} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -132,7 +132,7 @@ function(add_lldb_executable name) + if(ARG_GENERATE_INSTALL AND NOT (ARG_INCLUDE_IN_FRAMEWORK AND LLDB_BUILD_FRAMEWORK )) + install(TARGETS ${name} + COMPONENT ${name} +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} + DEPENDS ${name} +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index 24878b5913f3..b9d27788bb87 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -278,7 +278,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +@@ -288,7 +288,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index b5316540fdf3..3c3c882d503f 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -64,4 +64,4 @@ if (NOT LLDB_DISABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) diff --git a/llvm/6/llvm/default.nix b/llvm/6/llvm/default.nix new file mode 100644 index 0000000..72e43ba --- /dev/null +++ b/llvm/6/llvm/default.nix @@ -0,0 +1,301 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, fetchpatch +, doCheck ? stdenv.isLinux && (!stdenv.isi686) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, debugVersion ? false +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a versioned symlinks of libLLVM.dylib + versionSuffixes = with lib; + let parts = splitVersion release_version; in + imap (i: _: concatStringsSep "." (take i parts)) parts; + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; +in + +stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch "llvm" "1qpls3vk85lydi5b4axl0809fv932qgsqgdgrk098567z4jc7mmn"; + polly_src = fetch "polly" "1k2frwg5mkqh0raia8xf69h3jhdw7a5nxd6vjscjn44cdkgmyxp7"; + + unpackPhase = '' + unpackFile $src + mv llvm-${version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optional enableManpages python3.pkgs.sphinx; + + buildInputs = [ libxml2 libffi ]; + + propagatedBuildInputs = [ ncurses zlib ]; + + patches = [ + # Patches to fix tests, included in llvm_7 + (fetchpatch { + url = "https://github.com/llvm-mirror/llvm/commit/737553be0c9c25c497b45a241689994f177d5a5d.patch"; + sha256 = "0hnaxnkx7zy5yg98f1ggv8a9l0r6g19n6ygqsv26masrnlcbccli"; + }) + (fetchpatch { + url = "https://github.com/llvm-mirror/llvm/commit/1c0dd31a7837c3e2f1c4ac14e4d5ac640688bd1f.patch"; + includes = [ "test/tools/gold/X86/common.ll" ]; + sha256 = "0fxgrxmfnjx17w3lcq19rk68b2xksh1bynz3ina784kma7hp4wdb"; + }) + + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + ./gnu-install-dirs.patch + + # Fix invalid std::string(nullptr) for GCC 12 + (fetchpatch { + name = "nvptx-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/99e64623ec9b31def9375753491cc6093c831809.patch"; + sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; + stripLen = 1; + }) + + ../../llvm-7-musl.patch + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SROA/dead-inst.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals (isDarwin) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ${lib.concatMapStringsSep "\n" (v: '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${v}.dylib + '') versionSuffixes} + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/6/llvm/gnu-install-dirs-polly.patch b/llvm/6/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..b4fda24 --- /dev/null +++ b/llvm/6/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,106 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index 9ddc0f7ff81d..7ca45f286d47 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.4.3) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -157,14 +161,14 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 969292cd6b00..d7aea77bdd20 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 32bed50bb060..cca5bfff4970 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index b3c6e73a7a00..c67acf8576c7 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -268,7 +268,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/6/llvm/gnu-install-dirs.patch b/llvm/6/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..987f972 --- /dev/null +++ b/llvm/6/llvm/gnu-install-dirs.patch @@ -0,0 +1,386 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f8da6cf92119..881e4cda4971 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -271,15 +271,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "bin" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -510,9 +516,9 @@ option (LLVM_ENABLE_DOXYGEN "Use doxygen to generate llvm API documentation." OF + option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -944,7 +950,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -956,7 +962,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index fd5627eecbb2..29e09c6f3f8a 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -621,11 +621,11 @@ macro(add_llvm_library name) + else() + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR + (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM")) +- set(install_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(ARG_SHARED OR BUILD_SHARED_LIBS) + if(WIN32 OR CYGWIN OR MINGW) + set(install_type RUNTIME) +- set(install_dir bin) ++ set(install_dir ${CMAKE_INSTALL_BINDIR}) + else() + set(install_type LIBRARY) + endif() +@@ -667,9 +667,9 @@ macro(add_llvm_loadable_module name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + if(WIN32 OR CYGWIN) + # DLL platform +- set(dlldir "bin") ++ set(dlldir "${CMAKE_INSTALL_BINDIR}") + else() +- set(dlldir "lib${LLVM_LIBDIR_SUFFIX}") ++ set(dlldir "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + + if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR +@@ -681,7 +681,7 @@ macro(add_llvm_loadable_module name) + install(TARGETS ${name} + ${export_to_llvmexports} + LIBRARY DESTINATION ${dlldir} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endif() +@@ -892,7 +892,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1410,7 +1410,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1426,7 +1426,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1449,7 +1449,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE) +@@ -1531,7 +1531,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -1583,9 +1584,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 02bab6846376..eff26adb2efc 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -140,9 +140,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index 22e3dcb776aa..ba77b9c195e2 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -73,7 +73,7 @@ function (add_sphinx_target builder project) + + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 6074e8358594..9d0be6c2ced5 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -84,11 +84,11 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") + set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}") + configure_file( +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 482697b06baf..af2ac1e6c979 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message("Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 05edec64da33..6db014f04656 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -465,8 +465,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -497,13 +497,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + OS X Only: If enabled CMake will generate a target named +@@ -660,9 +680,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index 1d5ca3ba92b0..026f5453c1da 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -4,5 +4,5 @@ add_subdirectory(Support) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index f201e1f7bff0..4582ed556a02 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -24,6 +24,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 08b096afb052..2deae0dcfacc 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -332,12 +332,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = path.str(); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 6e913519a809..85641eef721f 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -19,7 +19,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lto.exports) + add_llvm_library(LTO SHARED ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index 19b606933082..27b9f71b3d79 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,6 +8,6 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) diff --git a/llvm/6/openmp/default.nix b/llvm/6/openmp/default.nix new file mode 100644 index 0000000..fa07c65 --- /dev/null +++ b/llvm/6/openmp/default.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation { + pname = "openmp"; + inherit version; + + src = fetch "openmp" "0nhwfba9c351r16zgyjyfwdayr98nairky3c2f0b2lc360mwmbv6"; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/7/clang/HIP-use-PATH-7.patch b/llvm/7/clang/HIP-use-PATH-7.patch new file mode 100644 index 0000000..764dddd --- /dev/null +++ b/llvm/7/clang/HIP-use-PATH-7.patch @@ -0,0 +1,68 @@ +From 8412cba68835f8f4cc527d02194b181faa5944d4 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Holger=20W=C3=BCnsche?= +Date: Tue, 21 Jan 2020 19:46:09 +0100 +Subject: [PATCH] [HIP] use GetProgramPath for executable discovery + +This change replaces the manual building of executable paths +using llvm::sys::path::append with GetProgramPath. +This enables adding other paths in case executables reside +in different directories and makes the code easier to read. + +Differential Revision: https://reviews.llvm.org/D72903 +--- + clang/lib/Driver/ToolChains/HIP.cpp | 18 ++++++------------ + 1 file changed, 6 insertions(+), 12 deletions(-) + +diff --git a/lib/Driver/ToolChains/HIP.cpp b/lib/Driver/ToolChains/HIP.cpp +index 03acf45a9b3..75fd3226c75 100644 +--- a/lib/Driver/ToolChains/HIP.cpp ++++ b/lib/Driver/ToolChains/HIP.cpp +@@ -98,9 +98,8 @@ const char *AMDGCN::Linker::constructLLVMLinkCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpName)); + CmdArgs.push_back(OutputFileName); +- SmallString<128> ExecPath(C.getDriver().Dir); +- llvm::sys::path::append(ExecPath, "llvm-link"); +- const char *Exec = Args.MakeArgString(ExecPath); ++ const char *Exec = ++ Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + return OutputFileName; + } +@@ -141,9 +140,8 @@ const char *AMDGCN::Linker::constructOptCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); + OptArgs.push_back(OutputFileName); +- SmallString<128> OptPath(C.getDriver().Dir); +- llvm::sys::path::append(OptPath, "opt"); +- const char *OptExec = Args.MakeArgString(OptPath); ++ const char *OptExec = ++ Args.MakeArgString(getToolChain().GetProgramPath("opt")); + C.addCommand(llvm::make_unique(JA, *this, OptExec, OptArgs, Inputs)); + return OutputFileName; + } +@@ -161,9 +159,7 @@ const char *AMDGCN::Linker::constructLlcCommand( + const char *LlcOutputFile = + C.addTempFile(C.getArgs().MakeArgString(LlcOutputFileName)); + LlcArgs.push_back(LlcOutputFile); +- SmallString<128> LlcPath(C.getDriver().Dir); +- llvm::sys::path::append(LlcPath, "llc"); +- const char *Llc = Args.MakeArgString(LlcPath); ++ const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); + C.addCommand(llvm::make_unique(JA, *this, Llc, LlcArgs, Inputs)); + return LlcOutputFile; + } +@@ -178,9 +174,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA, + ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", + "-shared", "-o", Output.getFilename(), + InputFileName}; +- SmallString<128> LldPath(C.getDriver().Dir); +- llvm::sys::path::append(LldPath, "lld"); +- const char *Lld = Args.MakeArgString(LldPath); ++ const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); + C.addCommand(llvm::make_unique(JA, *this, Lld, LldArgs, Inputs)); + } + +-- +2.23.1 + diff --git a/llvm/7/clang/default.nix b/llvm/7/clang/default.nix new file mode 100644 index 0000000..136a69e --- /dev/null +++ b/llvm/7/clang/default.nix @@ -0,0 +1,139 @@ +{ lib, stdenv, llvm_meta, fetch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +, enablePolly ? false # TODO: get this info from llvm (passthru?) +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "cfe" "0vc4i87qwxnw9lci4ayws9spakg0z6w5w670snj9f8g5m9rc8zg9"; + + unpackPhase = '' + unpackFile $src + mv cfe-${version}* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCMAKE_CXX_FLAGS=-std=c++11" + "-DLLVM_ENABLE_RTTI=ON" + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals enablePolly [ + "-DWITH_POLLY=ON" + "-DLINK_POLLY_INTO_TOOLS=ON" + ]; + + patches = [ + ../../common/clang/5-8-purity.patch + # make clang -xhip use $PATH to find executables + ./HIP-use-PATH-7.patch + # Backport for the `--unwindlib=[libgcc|compiler-rt]` flag, which is + # needed for our bootstrapping to not interfere with C. + ./unwindlib.patch + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-6-10-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace tools/extra/clangd/CMakeLists.txt \ + --replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/7/clang/gnu-install-dirs.patch b/llvm/7/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..540c043 --- /dev/null +++ b/llvm/7/clang/gnu-install-dirs.patch @@ -0,0 +1,281 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 52b881939499..85662a2113e7 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,6 +5,8 @@ cmake_minimum_required(VERSION 3.4.3) + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + find_program(LLVM_CONFIG "llvm-config") +@@ -374,7 +376,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.def" + PATTERN "*.h" +@@ -383,7 +385,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE + PATTERN "*.inc" +@@ -391,7 +393,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + ) + endif() + +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index c09a8423f9f6..39f37e0097eb 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -99,9 +99,9 @@ macro(add_clang_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -141,7 +141,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -156,5 +156,5 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 1930d8e225c7..bb9158093079 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -162,19 +162,19 @@ install( + FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${cuda_wrapper_files} + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's. + add_llvm_install_targets(install-clang-headers +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index 53e3421f1b35..79ae5bb4c399 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-check/CMakeLists.txt b/tools/clang-check/CMakeLists.txt +index c5ace26c2914..97bdfca7d896 100644 +--- a/tools/clang-check/CMakeLists.txt ++++ b/tools/clang-check/CMakeLists.txt +@@ -20,4 +20,4 @@ target_link_libraries(clang-check + ) + + install(TARGETS clang-check +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index a295e8cd0b2a..1973ff82c7f6 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-func-mapping/CMakeLists.txt b/tools/clang-func-mapping/CMakeLists.txt +index ae28e28d532d..8ecb2e37a8f7 100644 +--- a/tools/clang-func-mapping/CMakeLists.txt ++++ b/tools/clang-func-mapping/CMakeLists.txt +@@ -20,4 +20,4 @@ target_link_libraries(clang-func-mapping + ) + + install(TARGETS clang-func-mapping +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-offload-bundler/CMakeLists.txt b/tools/clang-offload-bundler/CMakeLists.txt +index 8718015be76a..7a038f39622e 100644 +--- a/tools/clang-offload-bundler/CMakeLists.txt ++++ b/tools/clang-offload-bundler/CMakeLists.txt +@@ -22,4 +22,4 @@ target_link_libraries(clang-offload-bundler + ${CLANG_OFFLOAD_BUNDLER_LIB_DEPS} + ) + +-install(TARGETS clang-offload-bundler RUNTIME DESTINATION bin) ++install(TARGETS clang-offload-bundler RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index 3b3ab1540a80..9aca9ba4a2cf 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -18,8 +18,8 @@ target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/diagtool/CMakeLists.txt b/tools/diagtool/CMakeLists.txt +index 96d1c390249c..41c762b37b76 100644 +--- a/tools/diagtool/CMakeLists.txt ++++ b/tools/diagtool/CMakeLists.txt +@@ -21,7 +21,7 @@ target_link_libraries(diagtool + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(TARGETS diagtool + COMPONENT diagtool +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-diagtool +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index e539c8308e75..4e1fbccea35d 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -130,7 +130,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index 380379300b09..adfd58ed5f7d 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -41,7 +41,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(LibexecFile ${LibexecFiles}) +@@ -53,7 +53,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/libexec/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) +- install(PROGRAMS libexec/${LibexecFile} DESTINATION libexec) ++ install(PROGRAMS libexec/${LibexecFile} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) + endforeach() + + foreach(ManPage ${ManPages}) +@@ -77,7 +77,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/share/scan-build/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) +- install(FILES share/scan-build/${ShareFile} DESTINATION share/scan-build) ++ install(FILES share/scan-build/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build) + endforeach() + + add_custom_target(scan-build ALL DEPENDS ${Depends}) +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index b305ca562a72..554bcb379061 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -21,7 +21,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(ShareFile ${ShareFiles}) +@@ -33,7 +33,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/share/scan-view/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) +- install(FILES share/${ShareFile} DESTINATION share/scan-view) ++ install(FILES share/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view) + endforeach() + + add_custom_target(scan-view ALL DEPENDS ${Depends}) +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 5573009d343a..24b3a90f233f 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -9,7 +9,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}) + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) +-install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION bin) ++install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) + set_target_properties(hmaptool PROPERTIES FOLDER "Utils") diff --git a/llvm/7/clang/unwindlib.patch b/llvm/7/clang/unwindlib.patch new file mode 100644 index 0000000..59a092d --- /dev/null +++ b/llvm/7/clang/unwindlib.patch @@ -0,0 +1,227 @@ +commit a5cacb5ba7f1f18e7bb6f6709e42683eeb7e6470 +Author: Sterling Augustine +Date: Tue Mar 19 20:01:59 2019 +0000 + + Add --unwindlib=[libgcc|compiler-rt] to parallel --rtlib= [take 2] + + "clang++ hello.cc --rtlib=compiler-rt" + + now can works without specifying additional unwind or exception + handling libraries. + + This reworked version of the feature no longer modifies today's default + unwind library for compiler-rt: which is nothing. Rather, a user + can specify -DCLANG_DEFAULT_UNWINDLIB=libunwind when configuring + the compiler. + + This should address the issues from the previous version. + + Update tests for new --unwindlib semantics. + + Differential Revision: https://reviews.llvm.org/D59109 + + llvm-svn: 356508 + +diff --git clang/CMakeLists.txt clang/CMakeLists.txt +index 52b881939499..2c3fb62f6e73 100644 +--- clang/CMakeLists.txt ++++ clang/CMakeLists.txt +@@ -244,6 +244,24 @@ if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR + "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE) + endif() + ++set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING ++ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)") ++if (CLANG_DEFAULT_UNWINDLIB STREQUAL "") ++ if (CLANG_DEFAULT_RTLIB STREQUAL "libgcc") ++ set (CLANG_DEFAULT_UNWINDLIB "libgcc" CACHE STRING "" FORCE) ++ elseif (CLANG_DEFAULT_RTLIBS STREQUAL "libunwind") ++ set (CLANG_DEFAULT_UNWINDLIB "none" CACHE STRING "" FORCE) ++ endif() ++endif() ++ ++if (NOT(CLANG_DEFAULT_UNWINDLIB STREQUAL "none" OR ++ CLANG_DEFAULT_UNWINDLIB STREQUAL "libgcc" OR ++ CLANG_DEFAULT_UNWINDLIB STREQUAL "libunwind")) ++ message(WARNING "Resetting default unwindlib to use platform default") ++ set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING ++ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty for none)" FORCE) ++endif() ++ + set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING + "Default objcopy executable to use.") + +diff --git clang/include/clang/Basic/DiagnosticDriverKinds.td clang/include/clang/Basic/DiagnosticDriverKinds.td +index 7f75f45c6578..7e1bb33b5cef 100644 +--- clang/include/clang/Basic/DiagnosticDriverKinds.td ++++ clang/include/clang/Basic/DiagnosticDriverKinds.td +@@ -52,6 +52,10 @@ def err_drv_invalid_rtlib_name : Error< + "invalid runtime library name in argument '%0'">; + def err_drv_unsupported_rtlib_for_platform : Error< + "unsupported runtime library '%0' for platform '%1'">; ++def err_drv_invalid_unwindlib_name : Error< ++ "invalid unwind library name in argument '%0'">; ++def err_drv_incompatible_unwindlib : Error< ++ "--rtlib=libgcc requires --unwindlib=libgcc">; + def err_drv_invalid_stdlib_name : Error< + "invalid library name in argument '%0'">; + def err_drv_invalid_output_with_multiple_archs : Error< +diff --git clang/include/clang/Config/config.h.cmake clang/include/clang/Config/config.h.cmake +index 1d624450b9d9..2d4cb747e87e 100644 +--- clang/include/clang/Config/config.h.cmake ++++ clang/include/clang/Config/config.h.cmake +@@ -23,6 +23,9 @@ + /* Default runtime library to use. */ + #define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}" + ++/* Default unwind library to use. */ ++#define CLANG_DEFAULT_UNWINDLIB "${CLANG_DEFAULT_UNWINDLIB}" ++ + /* Default objcopy to use */ + #define CLANG_DEFAULT_OBJCOPY "${CLANG_DEFAULT_OBJCOPY}" + +diff --git clang/include/clang/Driver/Options.td clang/include/clang/Driver/Options.td +index 601aa8744967..0e74a2d36dea 100644 +--- clang/include/clang/Driver/Options.td ++++ clang/include/clang/Driver/Options.td +@@ -2428,6 +2428,8 @@ def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>, + }]>; + def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>, + HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">; ++def unwindlib_EQ : Joined<["-", "--"], "unwindlib=">, Flags<[CC1Option]>, ++ HelpText<"Unwind library to use">, Values<"libgcc,unwindlib,platform">; + def sub__library : JoinedOrSeparate<["-"], "sub_library">; + def sub__umbrella : JoinedOrSeparate<["-"], "sub_umbrella">; + def system_header_prefix : Joined<["--"], "system-header-prefix=">, +diff --git clang/include/clang/Driver/ToolChain.h clang/include/clang/Driver/ToolChain.h +index 2f9c2c190e32..d5b131bcf112 100644 +--- clang/include/clang/Driver/ToolChain.h ++++ clang/include/clang/Driver/ToolChain.h +@@ -99,6 +99,12 @@ public: + RLT_Libgcc + }; + ++ enum UnwindLibType { ++ UNW_None, ++ UNW_CompilerRT, ++ UNW_Libgcc ++ }; ++ + enum RTTIMode { + RM_Enabled, + RM_Disabled, +@@ -352,6 +358,10 @@ public: + return ToolChain::CST_Libstdcxx; + } + ++ virtual UnwindLibType GetDefaultUnwindLibType() const { ++ return ToolChain::UNW_None; ++ } ++ + virtual std::string getCompilerRTPath() const; + + virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, +@@ -484,6 +494,10 @@ public: + // given compilation arguments. + virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const; + ++ // GetUnwindLibType - Determine the unwind library type to use with the ++ // given compilation arguments. ++ virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const; ++ + /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set + /// the include paths to use for the given C++ standard library type. + virtual void +diff --git clang/lib/Driver/ToolChain.cpp clang/lib/Driver/ToolChain.cpp +index cf3db34688df..d980dd5d23fb 100644 +--- clang/lib/Driver/ToolChain.cpp ++++ clang/lib/Driver/ToolChain.cpp +@@ -665,6 +665,33 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( + return GetDefaultRuntimeLibType(); + } + ++ToolChain::UnwindLibType ToolChain::GetUnwindLibType( ++ const ArgList &Args) const { ++ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); ++ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB; ++ ++ if (LibName == "none") ++ return ToolChain::UNW_None; ++ else if (LibName == "platform" || LibName == "") { ++ ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args); ++ if (RtLibType == ToolChain::RLT_CompilerRT) ++ return ToolChain::UNW_None; ++ else if (RtLibType == ToolChain::RLT_Libgcc) ++ return ToolChain::UNW_Libgcc; ++ } else if (LibName == "libunwind") { ++ if (GetRuntimeLibType(Args) == RLT_Libgcc) ++ getDriver().Diag(diag::err_drv_incompatible_unwindlib); ++ return ToolChain::UNW_CompilerRT; ++ } else if (LibName == "libgcc") ++ return ToolChain::UNW_Libgcc; ++ ++ if (A) ++ getDriver().Diag(diag::err_drv_invalid_unwindlib_name) ++ << A->getAsString(Args); ++ ++ return GetDefaultUnwindLibType(); ++} ++ + ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ + const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); + StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB; +diff --git clang/test/Driver/compiler-rt-unwind.c clang/test/Driver/compiler-rt-unwind.c +new file mode 100644 +index 000000000000..00024dfa7ed3 +--- /dev/null ++++ clang/test/Driver/compiler-rt-unwind.c +@@ -0,0 +1,49 @@ ++// General tests that the driver handles combinations of --rtlib=XXX and ++// --unwindlib=XXX properly. ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-EMPTY %s ++// RTLIB-EMPTY: "{{.*}}lgcc" ++// RTLIB-EMPTY: "{{.*}}-lgcc_s" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-GCC %s ++// RTLIB-GCC: "{{.*}}lgcc" ++// RTLIB-GCC: "{{.*}}lgcc_s" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s ++// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc" ++// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT %s ++// RTLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC %s ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}libclang_rt.builtins-x86_64.a" ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}lgcc_s" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \ ++// RUN: -static --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC %s ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}libclang_rt.builtins-x86_64.a" ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}lgcc_eh" ++// ++// RUN: not %clang -no-canonical-prefixes %s -o %t.o 2> %t.err \ ++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ ++// RUN: --gcc-toolchain="" \ ++// RUN: FileCheck --input-file=%t.err --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s ++// RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires --unwindlib=libgcc" diff --git a/llvm/7/compiler-rt/armv7l.patch b/llvm/7/compiler-rt/armv7l.patch new file mode 100644 index 0000000..89d7f1a --- /dev/null +++ b/llvm/7/compiler-rt/armv7l.patch @@ -0,0 +1,38 @@ +diff -ur compiler-rt-7.1.0.src/cmake/builtin-config-ix.cmake compiler-rt-7.1.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-7.1.0.src/cmake/builtin-config-ix.cmake 2018-05-25 06:36:27.000000000 +0900 ++++ compiler-rt-7.1.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-09 20:26:33.030608692 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-7.1.0.src/lib/builtins/CMakeLists.txt compiler-rt-7.1.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-7.1.0.src/lib/builtins/CMakeLists.txt 2018-07-31 03:18:59.000000000 +0900 ++++ compiler-rt-7.1.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-09 20:27:38.893409318 +0900 +@@ -453,6 +453,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -563,12 +564,12 @@ + set(_arch ${arch}) + if("${arch}" STREQUAL "armv6m") + set(_arch "arm|armv6m") +- elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + set(_arch "arm") + endif() + + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/7/compiler-rt/crtbegin-and-end.patch b/llvm/7/compiler-rt/crtbegin-and-end.patch new file mode 100644 index 0000000..e63be18 --- /dev/null +++ b/llvm/7/compiler-rt/crtbegin-and-end.patch @@ -0,0 +1,595 @@ +Get crtbegin and crtend without compiler GCC! PR is at https://reviews.llvm.org/D28791 + +Index: compiler-rt/CMakeLists.txt +=================================================================== +--- compiler-rt/CMakeLists.txt ++++ compiler-rt/CMakeLists.txt +@@ -29,6 +29,8 @@ + + option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) + mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) ++option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON) ++mark_as_advanced(COMPILER_RT_BUILD_CRT) + option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON) + mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS) + option(COMPILER_RT_BUILD_XRAY "Build xray" ON) +Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake +=================================================================== +--- compiler-rt/cmake/Modules/AddCompilerRT.cmake ++++ compiler-rt/cmake/Modules/AddCompilerRT.cmake +@@ -132,7 +132,7 @@ + # Adds static or shared runtime for a list of architectures and operating + # systems and puts it in the proper directory in the build and install trees. + # add_compiler_rt_runtime( +-# {STATIC|SHARED} ++# {OBJECT|STATIC|SHARED} + # ARCHS + # OS + # SOURCES +@@ -144,8 +144,8 @@ + # PARENT_TARGET + # ADDITIONAL_HEADERS
) + function(add_compiler_rt_runtime name type) +- if(NOT type MATCHES "^(STATIC|SHARED)$") +- message(FATAL_ERROR "type argument must be STATIC or SHARED") ++ if(NOT type MATCHES "^(OBJECT|STATIC|SHARED)$") ++ message(FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED") + return() + endif() + cmake_parse_arguments(LIB +@@ -204,7 +204,10 @@ + message(FATAL_ERROR "Architecture ${arch} can't be targeted") + return() + endif() +- if(type STREQUAL "STATIC") ++ if(type STREQUAL "OBJECT") ++ set(libname "${name}-${arch}") ++ set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) ++ elseif(type STREQUAL "STATIC") + set(libname "${name}-${arch}") + set_output_name(output_name_${libname} ${name} ${arch}) + else() +@@ -270,12 +273,34 @@ + set(COMPONENT_OPTION COMPONENT ${libname}) + endif() + +- add_library(${libname} ${type} ${sources_${libname}}) +- set_target_compile_flags(${libname} ${extra_cflags_${libname}}) +- set_target_link_flags(${libname} ${extra_link_flags_${libname}}) +- set_property(TARGET ${libname} APPEND PROPERTY +- COMPILE_DEFINITIONS ${LIB_DEFS}) +- set_target_output_directories(${libname} ${output_dir_${libname}}) ++ if(type STREQUAL "OBJECT") ++ string(TOUPPER ${CMAKE_BUILD_TYPE} config) ++ get_property(cflags SOURCE ${sources_${libname}} PROPERTY COMPILE_FLAGS) ++ separate_arguments(cflags) ++ add_custom_command( ++ OUTPUT ${output_dir_${libname}}/${libname}.o ++ COMMAND ${CMAKE_C_COMPILER} ${sources_${libname}} ${cflags} ${extra_cflags_${libname}} -c -o ${output_dir_${libname}}/${libname}.o ++ DEPENDS ${sources_${libname}} ++ COMMENT "Building C object ${libname}.o") ++ add_custom_target(${libname} DEPENDS ${output_dir_${libname}}/${libname}.o) ++ install(FILES ${output_dir_${libname}}/${libname}.o ++ DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION}) ++ else() ++ add_library(${libname} ${type} ${sources_${libname}}) ++ set_target_compile_flags(${libname} ${extra_cflags_${libname}}) ++ set_target_link_flags(${libname} ${extra_link_flags_${libname}}) ++ set_property(TARGET ${libname} APPEND PROPERTY ++ COMPILE_DEFINITIONS ${LIB_DEFS}) ++ set_target_output_directories(${libname} ${output_dir_${libname}}) ++ install(TARGETS ${libname} ++ ARCHIVE DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION} ++ LIBRARY DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION} ++ RUNTIME DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION}) ++ endif() + set_target_properties(${libname} PROPERTIES + OUTPUT_NAME ${output_name_${libname}}) + set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime") +@@ -299,13 +324,6 @@ + ) + endif() + endif() +- install(TARGETS ${libname} +- ARCHIVE DESTINATION ${install_dir_${libname}} +- ${COMPONENT_OPTION} +- LIBRARY DESTINATION ${install_dir_${libname}} +- ${COMPONENT_OPTION} +- RUNTIME DESTINATION ${install_dir_${libname}} +- ${COMPONENT_OPTION}) + + # We only want to generate per-library install targets if you aren't using + # an IDE because the extra targets get cluttered in IDEs. +Index: compiler-rt/cmake/config-ix.cmake +=================================================================== +--- compiler-rt/cmake/config-ix.cmake ++++ compiler-rt/cmake/config-ix.cmake +@@ -227,6 +227,7 @@ + ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X}) + set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} + ${MIPS32} ${MIPS64} ${PPC64} ${S390X}) ++set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}) + set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) + set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64}) + +@@ -474,6 +475,7 @@ + SANITIZER_COMMON_SUPPORTED_ARCH) + + else() ++ filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH}) + # Architectures supported by compiler-rt libraries. + filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH + ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH}) +@@ -563,6 +565,12 @@ + + # TODO: Add builtins support. + ++if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux") ++ set(COMPILER_RT_HAS_CRT TRUE) ++else() ++ set(COMPILER_RT_HAS_CRT FALSE) ++endif() ++ + if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND + OS_NAME MATCHES "Linux") + set(COMPILER_RT_HAS_DFSAN TRUE) +Index: compiler-rt/lib/CMakeLists.txt +=================================================================== +--- compiler-rt/lib/CMakeLists.txt ++++ compiler-rt/lib/CMakeLists.txt +@@ -17,6 +17,10 @@ + add_subdirectory(builtins) + endif() + ++if(COMPILER_RT_BUILD_CRT) ++ add_subdirectory(crt) ++endif() ++ + function(compiler_rt_build_runtime runtime) + string(TOUPPER ${runtime} runtime_uppercase) + if(COMPILER_RT_HAS_${runtime_uppercase}) +Index: compiler-rt/lib/crt/CMakeLists.txt +=================================================================== +--- /dev/null ++++ compiler-rt/lib/crt/CMakeLists.txt +@@ -0,0 +1,102 @@ ++add_compiler_rt_component(crt) ++ ++function(check_cxx_section_exists section output) ++ cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN}) ++ if(NOT ARG_SOURCE) ++ set(ARG_SOURCE "int main() { return 0; }\n") ++ endif() ++ ++ string(RANDOM TARGET_NAME) ++ set(TARGET_NAME "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cmTC_${TARGET_NAME}.dir") ++ file(MAKE_DIRECTORY ${TARGET_NAME}) ++ ++ file(WRITE "${TARGET_NAME}/CheckSectionExists.c" "${ARG_SOURCE}\n") ++ ++ string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions ++ ${CMAKE_C_COMPILE_OBJECT}) ++ ++ set(try_compile_flags "${ARG_FLAGS}") ++ if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET) ++ list(APPEND try_compile_flags "-target ${CMAKE_C_COMPILER_TARGET}") ++ endif() ++ ++ string(REPLACE ";" " " extra_flags "${try_compile_flags}") ++ ++ set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") ++ foreach(substitution ${substitutions}) ++ if(substitution STREQUAL "") ++ string(REPLACE "" ++ "${CMAKE_C_COMPILER}" test_compile_command ${test_compile_command}) ++ elseif(substitution STREQUAL "") ++ string(REPLACE "" "${TARGET_NAME}/CheckSectionExists.o" ++ test_compile_command ${test_compile_command}) ++ elseif(substitution STREQUAL "") ++ string(REPLACE "" "${TARGET_NAME}/CheckSectionExists.c" ++ test_compile_command ${test_compile_command}) ++ elseif(substitution STREQUAL "") ++ string(REPLACE "" "${CMAKE_C_FLAGS} ${extra_flags}" ++ test_compile_command ${test_compile_command}) ++ else() ++ string(REPLACE "${substitution}" "" test_compile_command ++ ${test_compile_command}) ++ endif() ++ endforeach() ++ ++ string(REPLACE " " ";" test_compile_command "${test_compile_command}") ++ ++ execute_process( ++ COMMAND ${test_compile_command} ++ RESULT_VARIABLE TEST_RESULT ++ OUTPUT_VARIABLE TEST_OUTPUT ++ ERROR_VARIABLE TEST_ERROR ++ ) ++ ++ execute_process( ++ COMMAND ${CMAKE_OBJDUMP} -h "${TARGET_NAME}/CheckSectionExists.o" ++ RESULT_VARIABLE CHECK_RESULT ++ OUTPUT_VARIABLE CHECK_OUTPUT ++ ERROR_VARIABLE CHECK_ERROR ++ ) ++ string(FIND "${CHECK_OUTPUT}" "${section}" SECTION_FOUND) ++ ++ if(NOT SECTION_FOUND EQUAL -1) ++ set(${output} TRUE PARENT_SCOPE) ++ else() ++ set(${output} FALSE PARENT_SCOPE) ++ endif() ++ ++ file(REMOVE_RECURSE ${TARGET_NAME}) ++endfunction() ++ ++check_cxx_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY ++ SOURCE "__attribute__((constructor)) void f() {}\nint main() { return 0; }\n") ++ ++append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS) ++append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC CRT_CFLAGS) ++ ++foreach(arch ${CRT_SUPPORTED_ARCH}) ++ add_compiler_rt_runtime(clang_rt.crtbegin ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c ++ CFLAGS ${CRT_CFLAGS} ++ PARENT_TARGET crt) ++ add_compiler_rt_runtime(clang_rt.crtbegin_shared ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c ++ CFLAGS ${CRT_CFLAGS} -DCRT_SHARED ++ PARENT_TARGET crt) ++ add_compiler_rt_runtime(clang_rt.crtend ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c ++ CFLAGS ${CRT_CFLAGS} ++ PARENT_TARGET crt) ++ add_compiler_rt_runtime(clang_rt.crtend_shared ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c ++ CFLAGS ${CRT_CFLAGS} -DCRT_SHARED ++ PARENT_TARGET crt) ++endforeach() +Index: compiler-rt/lib/crt/crtbegin.c +=================================================================== +--- /dev/null ++++ compiler-rt/lib/crt/crtbegin.c +@@ -0,0 +1,108 @@ ++/* ===-- crtbegin.c - Start of constructors and destructors ----------------=== ++ * ++ * The LLVM Compiler Infrastructure ++ * ++ * This file is dual licensed under the MIT and the University of Illinois Open ++ * Source Licenses. See LICENSE.TXT for details. ++ * ++ * ===----------------------------------------------------------------------=== ++ */ ++ ++#include ++ ++__attribute__((visibility("hidden"))) ++#ifdef CRT_SHARED ++void *__dso_handle = &__dso_handle; ++#else ++void *__dso_handle = (void *)0; ++#endif ++ ++static long __EH_FRAME_LIST__[] ++ __attribute__((section(".eh_frame"), aligned(sizeof(void *)))) = {}; ++ ++extern void __register_frame_info(const void *, void *) __attribute__((weak)); ++extern void *__deregister_frame_info(const void *) __attribute__((weak)); ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++typedef void (*fp)(void); ++ ++static fp __CTOR_LIST__[] ++ __attribute__((section(".ctors"), aligned(sizeof(fp)), used)) = {(fp)-1}; ++extern fp __CTOR_LIST_END__[]; ++#endif ++ ++#ifdef CRT_SHARED ++extern void __cxa_finalize(void *) __attribute__((weak)); ++#endif ++ ++static void __attribute__((used)) __do_init() { ++ static _Bool __initialized; ++ if (__builtin_expect(__initialized, 0)) ++ return; ++ __initialized = 1; ++ ++ static struct { void *p[8]; } __object; ++ if (__register_frame_info) ++ __register_frame_info(__EH_FRAME_LIST__, &__object); ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++ const size_t n = __CTOR_LIST_END__ - __CTOR_LIST__ - 1; ++ for (size_t i = n; i >= 1; i--) __CTOR_LIST__[i](); ++#endif ++} ++ ++#ifdef CRT_HAS_INITFINI_ARRAY ++__attribute__((section(".init_array"), ++ used)) static void (*__init)(void) = __do_init; ++#else // CRT_HAS_INITFINI_ARRAY ++#if defined(__i386__) || defined(__x86_64__) ++asm(".pushsection .init,\"ax\",@progbits\n\t" ++ "call " __USER_LABEL_PREFIX__ "__do_init\n\t" ++ ".popsection"); ++#elif defined(__arm__) ++asm(".pushsection .init,\"ax\",%progbits\n\t" ++ "bl " __USER_LABEL_PREFIX__ "__do_init\n\t" ++ ".popsection"); ++#endif // CRT_HAS_INITFINI_ARRAY ++#endif ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++static fp __DTOR_LIST__[] ++ __attribute__((section(".dtors"), aligned(sizeof(fp)), used)) = {(fp)-1}; ++extern fp __DTOR_LIST_END__[]; ++#endif ++ ++static void __attribute__((used)) __do_fini() { ++ static _Bool __finalized; ++ if (__builtin_expect(__finalized, 0)) ++ return; ++ __finalized = 1; ++ ++#ifdef CRT_SHARED ++ if (__cxa_finalize) ++ __cxa_finalize(__dso_handle); ++#endif ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++ if (__deregister_frame_info) ++ __deregister_frame_info(__EH_FRAME_LIST__); ++ ++ const size_t n = __DTOR_LIST_END__ - __DTOR_LIST__ - 1; ++ for (size_t i = 1; i < n; i++) __DTOR_LIST__[i](); ++#endif ++} ++ ++#ifdef CRT_HAS_INITFINI_ARRAY ++__attribute__((section(".fini_array"), ++ used)) static void (*__fini)(void) = __do_fini; ++#else // CRT_HAS_INITFINI_ARRAY ++#if defined(__i386__) || defined(__x86_64__) ++asm(".pushsection .fini,\"ax\",@progbits\n\t" ++ "call " __USER_LABEL_PREFIX__ "__do_fini\n\t" ++ ".popsection"); ++#elif defined(__arm__) ++asm(".pushsection .fini,\"ax\",%progbits\n\t" ++ "bl " __USER_LABEL_PREFIX__ "__do_fini\n\t" ++ ".popsection"); ++#endif ++#endif // CRT_HAS_INIT_FINI_ARRAY +Index: compiler-rt/lib/crt/crtend.c +=================================================================== +--- /dev/null ++++ compiler-rt/lib/crt/crtend.c +@@ -0,0 +1,24 @@ ++/* ===-- crtend.c - End of constructors and destructors --------------------=== ++ * ++ * The LLVM Compiler Infrastructure ++ * ++ * This file is dual licensed under the MIT and the University of Illinois Open ++ * Source Licenses. See LICENSE.TXT for details. ++ * ++ * ===----------------------------------------------------------------------=== ++ */ ++ ++#include ++ ++// Put 4-byte zero which is the length field in FDE at the end as a terminator. ++const int32_t __EH_FRAME_LIST_END__[] ++ __attribute__((section(".eh_frame"), aligned(sizeof(int32_t)), ++ visibility("hidden"), used)) = {0}; ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++typedef void (*fp)(void); ++fp __CTOR_LIST_END__[] ++ __attribute__((section(".ctors"), visibility("hidden"), used)) = {0}; ++fp __DTOR_LIST_END__[] ++ __attribute__((section(".dtors"), visibility("hidden"), used)) = {0}; ++#endif +Index: compiler-rt/test/CMakeLists.txt +=================================================================== +--- compiler-rt/test/CMakeLists.txt ++++ compiler-rt/test/CMakeLists.txt +@@ -73,6 +73,9 @@ + if(COMPILER_RT_BUILD_XRAY) + compiler_rt_test_runtime(xray) + endif() ++ if(COMPILER_RT_HAS_CRT) ++ add_subdirectory(crt) ++ endif() + # ShadowCallStack does not yet provide a runtime with compiler-rt, the tests + # include their own minimal runtime + add_subdirectory(shadowcallstack) +Index: compiler-rt/test/crt/CMakeLists.txt +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/CMakeLists.txt +@@ -0,0 +1,31 @@ ++set(CRT_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) ++ ++set(CRT_TESTSUITES) ++ ++set(CRT_TEST_DEPS "") ++ ++if(NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_BUILD_CRT AND ++ COMPILER_RT_HAS_CRT) ++ list(APPEND CRT_TEST_DEPS crt) ++endif() ++ ++set(CRT_TEST_ARCH ${CRT_SUPPORTED_ARCH}) ++if (COMPILER_RT_BUILD_CRT AND COMPILER_RT_HAS_CRT) ++ foreach(arch ${CRT_TEST_ARCH}) ++ set(CRT_TEST_TARGET_ARCH ${arch}) ++ string(TOLOWER "-${arch}-${OS_NAME}" CRT_TEST_CONFIG_SUFFIX) ++ get_test_cc_for_arch(${arch} CRT_TEST_TARGET_CC CRT_TEST_TARGET_CFLAGS) ++ string(TOUPPER ${arch} ARCH_UPPER_CASE) ++ set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) ++ ++ configure_lit_site_cfg( ++ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ++ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) ++ list(APPEND CRT_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) ++ endforeach() ++endif() ++ ++add_lit_testsuite(check-crt "Running the CRT tests" ++ ${CRT_TESTSUITES} ++ DEPENDS ${CRT_TEST_DEPS}) ++set_target_properties(check-crt PROPERTIES FOLDER "Compiler-RT Misc") +Index: compiler-rt/test/crt/dso_handle.cpp +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/dso_handle.cpp +@@ -0,0 +1,33 @@ ++// RUN: %clangxx -g -DCRT_SHARED -c %s -fPIC -o %tshared.o ++// RUN: %clangxx -g -c %s -fPIC -o %t.o ++// RUN: %clangxx -g -shared -o %t.so -nostdlib %crti %shared_crtbegin %tshared.o %libstdcxx -lc -lm -lgcc_s %shared_crtend %crtn ++// RUN: %clangxx -g -o %t -nostdlib %crt1 %crti %crtbegin %t.o %libstdcxx -lc -lm %libgcc %t.so %crtend %crtn ++// RUN: %run %t 2>&1 | FileCheck %s ++ ++#include ++ ++// CHECK: 1 ++// CHECK-NEXT: ~A() ++ ++#ifdef CRT_SHARED ++bool G; ++void C() { ++ printf("%d\n", G); ++} ++ ++struct A { ++ A() { G = true; } ++ ~A() { ++ printf("~A()\n"); ++ } ++}; ++ ++A a; ++#else ++void C(); ++ ++int main() { ++ C(); ++ return 0; ++} ++#endif +Index: compiler-rt/test/crt/lit.cfg +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/lit.cfg +@@ -0,0 +1,80 @@ ++# -*- Python -*- ++ ++import os ++import subprocess ++ ++# Setup config name. ++config.name = 'CRT' + config.name_suffix ++ ++# Setup source root. ++config.test_source_root = os.path.dirname(__file__) ++ ++ ++def get_library_path(file): ++ cmd = subprocess.Popen([config.clang.strip(), ++ config.target_cflags.strip(), ++ '-print-file-name=%s' % file], ++ stdout=subprocess.PIPE, ++ env=config.environment) ++ if not cmd.stdout: ++ lit_config.fatal("Couldn't find the library path for '%s'" % file) ++ dir = cmd.stdout.read().strip() ++ if sys.platform in ['win32'] and execute_external: ++ # Don't pass dosish path separator to msys bash.exe. ++ dir = dir.replace('\\', '/') ++ # Ensure the result is an ascii string, across Python2.5+ - Python3. ++ return str(dir.decode('ascii')) ++ ++ ++def get_libgcc_file_name(): ++ cmd = subprocess.Popen([config.clang.strip(), ++ config.target_cflags.strip(), ++ '-print-libgcc-file-name'], ++ stdout=subprocess.PIPE, ++ env=config.environment) ++ if not cmd.stdout: ++ lit_config.fatal("Couldn't find the library path for '%s'" % file) ++ dir = cmd.stdout.read().strip() ++ if sys.platform in ['win32'] and execute_external: ++ # Don't pass dosish path separator to msys bash.exe. ++ dir = dir.replace('\\', '/') ++ # Ensure the result is an ascii string, across Python2.5+ - Python3. ++ return str(dir.decode('ascii')) ++ ++ ++def build_invocation(compile_flags): ++ return ' ' + ' '.join([config.clang] + compile_flags) + ' ' ++ ++ ++# Setup substitutions. ++config.substitutions.append( ++ ('%clang ', build_invocation([config.target_cflags]))) ++config.substitutions.append( ++ ('%clangxx ', ++ build_invocation(config.cxx_mode_flags + [config.target_cflags]))) ++ ++base_lib = os.path.join( ++ config.compiler_rt_libdir, "clang_rt.%%s-%s.o" % config.target_arch) ++config.substitutions.append(('%crtbegin', base_lib % "crtbegin")) ++config.substitutions.append(('%shared_crtbegin', base_lib % "crtbegin_shared")) ++config.substitutions.append(('%crtend', base_lib % "crtend")) ++config.substitutions.append(('%shared_crtend', base_lib % "crtend_shared")) ++ ++config.substitutions.append( ++ ('%crt1', get_library_path('crt1.o'))) ++config.substitutions.append( ++ ('%crti', get_library_path('crti.o'))) ++config.substitutions.append( ++ ('%crtn', get_library_path('crtn.o'))) ++ ++config.substitutions.append( ++ ('%libgcc', get_libgcc_file_name())) ++ ++config.substitutions.append( ++ ('%libstdcxx', '-l' + config.sanitizer_cxx_lib.lstrip('lib'))) ++ ++# Default test suffixes. ++config.suffixes = ['.c', '.cc', '.cpp'] ++ ++if config.host_os not in ['Linux']: ++ config.unsupported = True +Index: compiler-rt/test/crt/lit.site.cfg.in +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/lit.site.cfg.in +@@ -0,0 +1,14 @@ ++@LIT_SITE_CFG_IN_HEADER@ ++ ++# Tool-specific config options. ++config.name_suffix = "@CRT_TEST_CONFIG_SUFFIX@" ++config.crt_lit_source_dir = "@CRT_LIT_SOURCE_DIR@" ++config.target_cflags = "@CRT_TEST_TARGET_CFLAGS@" ++config.target_arch = "@CRT_TEST_TARGET_ARCH@" ++config.sanitizer_cxx_lib = "@SANITIZER_TEST_CXX_LIBNAME@" ++ ++# Load common config for all compiler-rt lit tests ++lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") ++ ++# Load tool-specific config that would do the real work. ++lit_config.load_config(config, "@CRT_LIT_SOURCE_DIR@/lit.cfg") diff --git a/llvm/7/compiler-rt/default.nix b/llvm/7/compiler-rt/default.nix new file mode 100644 index 0000000..7354397 --- /dev/null +++ b/llvm/7/compiler-rt/default.nix @@ -0,0 +1,117 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + src = fetch "compiler-rt" "1n48p8gjarihkws0i2bay5w9bdwyxyxxbpwyng7ba58jb30dlyq5"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ]; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce + ../../common/compiler-rt/glibc.patch + ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./gnu-install-dirs.patch + ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch + ] ++ lib.optional (useLLVM) ./crtbegin-and-end.patch + ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; + }; +} diff --git a/llvm/7/compiler-rt/gnu-install-dirs.patch b/llvm/7/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..41b501e --- /dev/null +++ b/llvm/7/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,117 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 86ca2b3ef74b..555103bd97fe 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.4.3) + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + endif() +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index cd4c704fc824..5abcd1260381 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -478,7 +478,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -495,7 +495,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index 04cc955980fa..a99f6dfb2f82 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -377,7 +377,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index e5651718fa34..d95cfc984a85 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -330,7 +330,7 @@ endfunction() + function(get_compiler_rt_install_dir arch install_dir) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + get_compiler_rt_target(${arch} target) +- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/lib PARENT_SCOPE) ++ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/${CMAKE_INSTALL_FULL_LIBDIR} PARENT_SCOPE) + else() + set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + endif() +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 91fe2494b476..b59a0ffc69f4 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -53,11 +53,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -85,7 +85,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + set(COMPILER_RT_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + endif() + + if(APPLE) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index c4b93b89a30c..3913dc3a1ee6 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -48,12 +48,12 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index b3ae713cf02c..52b364b900f5 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -54,4 +54,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}) diff --git a/llvm/7/default.nix b/llvm/7/default.nix new file mode 100644 index 0000000..0607b5e --- /dev/null +++ b/llvm/7/default.nix @@ -0,0 +1,288 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +}: + +let + release_version = "7.1.0"; + version = release_version; # differentiating these is important for rc's + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://releases.llvm.org/${release_version}/${name}-${version}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "0lb4kdh7j2fhfz8kd6iv5df7m3pikiryk1vvwsf87spc90n09q0w"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libllvm-polly = callPackage ./llvm { + inherit llvm_meta; + enablePolly = true; + }; + + llvm-polly = tools.libllvm-polly.lib // { outputSpecified = false; }; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + clang-polly-unwrapped = callPackage ./clang { + inherit llvm_meta; + inherit clang-tools-extra_src; + libllvm = tools.libllvm-polly; + enablePolly = true; + }; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ./lldb { + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = + if stdenv.hostPlatform.isAndroid || (stdenv.hostPlatform != stdenv.buildPlatform && stdenv.hostPlatform.isDarwin) + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + inherit (buildLlvmTools) llvm; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/7/libcxx/default.nix b/llvm/7/libcxx/default.nix new file mode 100644 index 0000000..3834e17 --- /dev/null +++ b/llvm/7/libcxx/default.nix @@ -0,0 +1,89 @@ +{ lib, stdenv, llvm_meta, fetch, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "0kmhcapm2cjwalyiqasj9dmqbw59mcwdl8fgl951wg7ax84b8hj4"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include" + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz" + postPatch = '' + substituteInPlace include/__config \ + --replace "# define _LIBCPP_USE_AVAILABILITY_APPLE" "" + ''; + + prePatch = '' + substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++" + ''; + + preConfigure = '' + # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package + cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR") + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake ] + ++ lib.optional stdenv.hostPlatform.isMusl python3 + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_LIBCPPABI_VERSION=2" + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional stdenv.hostPlatform.isMusl "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (cxxabi.pname == "libcxxabi") "-DLIBCXX_LIBCXXABI_LIB_PATH=${cxxabi}/lib" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" ; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/7/libcxx/gnu-install-dirs.patch b/llvm/7/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..910e528 --- /dev/null +++ b/llvm/7/libcxx/gnu-install-dirs.patch @@ -0,0 +1,72 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index acb49565ce97..6a863926cbca 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,6 +26,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 7.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 1c19d7e01af7..9c8aee8e8bb7 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -59,7 +59,7 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index d9def18d725c..16494dacaf6f 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -243,7 +243,7 @@ if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +@@ -252,7 +252,7 @@ if (LIBCXX_INSTALL_HEADERS) + if (LIBCXX_NEEDS_SITE_CONFIG) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT cxx-headers) +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index e068edc8a7af..b63ad92d1d78 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -399,8 +399,8 @@ if (LIBCXX_INSTALL_LIBRARY) + set(experimental_lib cxx_experimental) + endif() + install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${filesystem_lib} ${experimental_lib} +- LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx +- ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ++ LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ++ ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx + ) + # NOTE: This install command must go after the cxx install command otherwise + # it will not be executed after the library symlinks are installed. +@@ -408,7 +408,7 @@ if (LIBCXX_INSTALL_LIBRARY) + # Replace the libc++ filename with $ + # after we required CMake 3.0. + install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" +- DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} ++ DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} + COMPONENT libcxx) + endif() + endif() diff --git a/llvm/7/libcxxabi/default.nix b/llvm/7/libcxxabi/default.nix new file mode 100644 index 0000000..c33c613 --- /dev/null +++ b/llvm/7/libcxxabi/default.nix @@ -0,0 +1,89 @@ +{ lib, stdenv, llvm_meta, cmake, fetch, libcxx, libunwind, llvm, version +, fetchpatch +, standalone ? stdenv.hostPlatform.useLLVM or false +, withLibunwind ? !stdenv.isDarwin && !stdenv.hostPlatform.isWasm + # on musl the shared objects don't build +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "1zcqxsdjhawgz1cvpk07y3jl6fg9p3ay4nl69zsirqb2ghgyhhb2"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + unpackFile ${llvm.src} + cmakeFlagsArray=($cmakeFlagsArray -DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*) ) + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch} + '' + lib.optionalString (!stdenv.cc.isClang) '' + pushd libcxx-* + patch -p2 < ${fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/76ccec07b4fa0cc68dfd07d557e7fb661804a468.patch"; + sha256 = "1lgzkfkp7qinfc6gd8x5di1iq1gqdv81249c6f02chn9q122sbq1"; + }} + popd + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = lib.optional withLibunwind libunwind; + + cmakeFlags = lib.optionals standalone [ + "-DLLVM_ENABLE_LIBCXX=ON" + ] ++ lib.optionals (standalone && withLibunwind) [ + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optional (!enableShared) "-DLIBCXXABI_ENABLE_SHARED=OFF"; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/7/libcxxabi/gnu-install-dirs.patch b/llvm/7/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..92d9e94 --- /dev/null +++ b/llvm/7/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index d6648ede1f59..55a8f17ca5e6 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -20,6 +20,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 7.0.0svn) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 776c51294330..314b45feac69 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -195,8 +195,8 @@ add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS}) + + if (LIBCXXABI_INSTALL_LIBRARY) + install(TARGETS ${LIBCXXABI_INSTALL_TARGETS} +- LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi +- ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi ++ LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi ++ ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi + ) + endif() + diff --git a/llvm/7/libunwind/default.nix b/llvm/7/libunwind/default.nix new file mode 100644 index 0000000..4268950 --- /dev/null +++ b/llvm/7/libunwind/default.nix @@ -0,0 +1,53 @@ +{ lib, stdenv, llvm_meta, version, fetch, fetchpatch, cmake, llvm +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + src = fetch pname "035dsxs10nyiqd00q07yycvmkjl01yz4jdlrjvmch8klxg4pyjhp"; + + postUnpack = '' + unpackFile ${llvm.src} + cmakeFlagsArray=($cmakeFlagsArray -DLLVM_PATH=$PWD/$(ls -d llvm-*)) + ''; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + # removes use of `new` that require libc++ + (fetchpatch { + url = "https://github.com/llvm-mirror/libunwind/commit/34a45c630d4c79af403661d267db42fbe7de1178.patch"; + sha256 = "0n0pv6jvcky8pn3srhrf9x5kbnd0d2kia9xlx2g590f5q0bgwfhv"; + }) + # cleans up remaining libc++ dependencies (mostly header inclusions) + (fetchpatch { + url = "https://github.com/llvm-mirror/libunwind/commit/e050272d2eb57eb4e56a37b429a61df2ebb8aa3e.patch"; + sha256 = "170mwmj0wf40iyk1kzdpaiy36rz9n8dpl881h4h7s5da0rh51xya"; + includes = [ "src/libunwind.cpp" "src/UnwindCursor.hpp" ]; + }) + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optionals (!enableShared) [ + "-DLIBUNWIND_ENABLE_SHARED=OFF" + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + ]; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/7/libunwind/gnu-install-dirs.patch b/llvm/7/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..21d4fa8 --- /dev/null +++ b/llvm/7/libunwind/gnu-install-dirs.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0e48d713837a..05483c367bd1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -18,6 +18,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libunwind) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(NOT LLVM_CONFIG_PATH) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 937159e2cb86..07f8b936e7e5 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -141,8 +141,8 @@ add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS}) + + if (LIBUNWIND_INSTALL_LIBRARY) + install(TARGETS ${LIBUNWIND_INSTALL_TARGETS} +- LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind +- ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind) ++ LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind ++ ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind) + endif() + + if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY) diff --git a/llvm/7/lld/default.nix b/llvm/7/lld/default.nix new file mode 100644 index 0000000..2016e63 --- /dev/null +++ b/llvm/7/lld/default.nix @@ -0,0 +1,46 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "0rsqb7zcnij5r5ipfhr129j7skr5n9pyr388kjpqwh091952f3x1"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), and Mach-O (macOS) + in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/7/lld/gnu-install-dirs.patch b/llvm/7/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..acc2d3d --- /dev/null +++ b/llvm/7/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index e2fbdbfbbb47..d601b231ebb8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -203,7 +205,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index fa48b428d26b..e7967aad3ceb 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index d8829493fc22..df748a0e749b 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -16,7 +16,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE lld-link ld.lld ld64.lld wasm-ld) diff --git a/llvm/7/lldb/default.nix b/llvm/7/lldb/default.nix new file mode 100644 index 0000000..02e3cdc --- /dev/null +++ b/llvm/7/lldb/default.nix @@ -0,0 +1,95 @@ +{ lib, stdenv, llvm_meta +, fetch +, cmake +, zlib +, ncurses +, swig +, which +, libedit +, libxml2 +, libllvm +, libclang +, perl +, python3 +, version +, darwin +}: + +stdenv.mkDerivation rec { + pname = "lldb"; + inherit version; + + src = fetch "lldb" "0klsscg1sczc4nw2l53xggi969k361cng2sjjrfp3bv4g5x14s4v"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + # Fix up various paths that assume llvm and clang are installed in the same place + sed -i 's,".*ClangConfig.cmake","${libclang.dev}/lib/cmake/clang/ClangConfig.cmake",' \ + cmake/modules/LLDBStandalone.cmake + sed -i 's,".*tools/clang/include","${libclang.dev}/include",' \ + cmake/modules/LLDBStandalone.cmake + sed -i 's,"$.LLVM_LIBRARY_DIR.",${libllvm.lib}/lib ${libclang.lib}/lib,' \ + cmake/modules/LLDBStandalone.cmake + sed -i -e 's,message(SEND_ERROR "Cannot find debugserver on system."),,' \ + -e 's,string(STRIP ''${XCODE_DEV_DIR} XCODE_DEV_DIR),,' \ + tools/debugserver/source/CMakeLists.txt + + # Fix /usr/bin references for sandboxed builds. + patchShebangs scripts + ''; + + outputs = [ "out" "lib" "dev" ]; + + nativeBuildInputs = [ + cmake perl python3 which swig + ]; + + buildInputs = [ + ncurses zlib libedit libxml2 libllvm + ] ++ lib.optionals stdenv.isDarwin [ + darwin.libobjc + darwin.apple_sdk.libs.xpc + darwin.apple_sdk.frameworks.Foundation + darwin.bootstrap_cmds + darwin.apple_sdk.frameworks.Carbon + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.DebugSymbols + ]; + + CXXFLAGS = "-fno-rtti"; + hardeningDisable = [ "format" ]; + + env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang "-I${libxml2.dev}/include/libxml2"; + + cmakeFlags = [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + "-DSKIP_DEBUGSERVER=ON" + ] ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ]; + + doCheck = false; + + postInstall = '' + mkdir -p $out/share/man/man1 + cp ../docs/lldb.1 $out/share/man/man1/ + ''; + + meta = llvm_meta // { + homepage = "https://lldb.llvm.org/"; + description = "A next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + # never built on aarch64-darwin since first introduction in nixpkgs + broken = stdenv.isDarwin && stdenv.isAarch64; + }; +} diff --git a/llvm/7/lldb/gnu-install-dirs.patch b/llvm/7/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..4064574 --- /dev/null +++ b/llvm/7/lldb/gnu-install-dirs.patch @@ -0,0 +1,76 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 00ddcdc1488f..af2aa238939a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -7,6 +7,8 @@ set(CMAKE_MODULE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" + ) + ++include(GNUInstallDirs) ++ + include(LLDBStandalone) + include(LLDBConfig) + include(AddLLDB) +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 129a5ef7500d..fb3fb3ce655c 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -56,14 +56,14 @@ function(add_lldb_library name) + endif() + install(TARGETS ${name} + COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${out_dir} + ARCHIVE DESTINATION ${out_dir}) + else() + install(TARGETS ${name} + COMPONENT ${name} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -121,7 +121,7 @@ function(add_lldb_executable name) + endif() + + if(ARG_GENERATE_INSTALL) +- set(out_dir "bin") ++ set(out_dir "${CMAKE_INSTALL_BINDIR}") + if (LLDB_BUILD_FRAMEWORK AND ARG_INCLUDE_IN_SUITE) + set(out_dir ${LLDB_FRAMEWORK_INSTALL_DIR}/${LLDB_FRAMEWORK_RESOURCE_DIR}) + endif() +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index dae6e365da38..ef272d5de5c0 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -278,7 +278,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +@@ -288,7 +288,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index b5316540fdf3..3c3c882d503f 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -64,4 +64,4 @@ if (NOT LLDB_DISABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) diff --git a/llvm/7/llvm/default.nix b/llvm/7/llvm/default.nix new file mode 100644 index 0000000..97ac428 --- /dev/null +++ b/llvm/7/llvm/default.nix @@ -0,0 +1,322 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a versioned symlinks of libLLVM.dylib + versionSuffixes = with lib; + let parts = splitVersion release_version; in + imap (i: _: concatStringsSep "." (take i parts)) parts; + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch "llvm" "0r1p5didv4rkgxyvbkyz671xddg6i3dxvbpsi1xxipkla0l9pk0v"; + polly_src = fetch "polly" "16qkns4ab4x0azrvhy4j7cncbyb2rrbdrqj87zphvqxm5pvm8m1h"; + + unpackPhase = '' + unpackFile $src + mv llvm-${version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optional enableManpages python3.pkgs.sphinx; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + patches = [ + # backport, fix building rust crates with lto + (fetchpatch { + url = "https://github.com/llvm-mirror/llvm/commit/da1fb72bb305d6bc1f3899d541414146934bf80f.patch"; + sha256 = "0p81gkhc1xhcx0hmnkwyhrn8x8l8fd24xgaj1whni29yga466dwc"; + }) + (fetchpatch { + url = "https://github.com/llvm-mirror/llvm/commit/cc1f2a595ead516812a6c50398f0f3480ebe031f.patch"; + sha256 = "0k6k1p5yisgwx417a67s7sr9930rqh1n0zv5jvply8vjjy4b3kf8"; + }) + + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + ./gnu-install-dirs.patch + + # Fix invalid std::string(nullptr) for GCC 12 + (fetchpatch { + name = "nvptx-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/99e64623ec9b31def9375753491cc6093c831809.patch"; + sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; + stripLen = 1; + }) + + ../../llvm-7-musl.patch + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on armv7l + rm test/DebugInfo/X86/debug_addr.ll + rm test/tools/llvm-dwarfdump/X86/debug_addr.s + rm test/tools/llvm-dwarfdump/X86/debug_addr_address_size_mismatch.s + rm test/tools/llvm-dwarfdump/X86/debug_addr_dwarf4.s + rm test/tools/llvm-dwarfdump/X86/debug_addr_unsupported_version.s + rm test/tools/llvm-dwarfdump/X86/debug_addr_version_mismatch.s + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals (isDarwin) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ${lib.concatMapStringsSep "\n" (v: '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${v}.dylib + '') versionSuffixes} + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/7/llvm/gnu-install-dirs-polly.patch b/llvm/7/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..0b2d3b7 --- /dev/null +++ b/llvm/7/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,106 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index 9939097f743e..8cc538da912a 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.4.3) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -145,14 +149,14 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 969292cd6b00..d7aea77bdd20 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index e48203871884..5bc8a2a52541 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8ffd984e542b..261cc19f3238 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -274,7 +274,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/7/llvm/gnu-install-dirs.patch b/llvm/7/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..7e7921e --- /dev/null +++ b/llvm/7/llvm/gnu-install-dirs.patch @@ -0,0 +1,386 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index a3d3013cedcd..b298d6ef04af 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -275,15 +275,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -531,9 +537,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -966,7 +972,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -978,7 +984,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index c0f90ba7068d..d656156ff9c8 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -638,11 +638,11 @@ macro(add_llvm_library name) + else() + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR + (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM")) +- set(install_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(ARG_SHARED OR BUILD_SHARED_LIBS) + if(WIN32 OR CYGWIN OR MINGW) + set(install_type RUNTIME) +- set(install_dir bin) ++ set(install_dir ${CMAKE_INSTALL_BINDIR}) + else() + set(install_type LIBRARY) + endif() +@@ -684,9 +684,9 @@ macro(add_llvm_loadable_module name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + if(WIN32 OR CYGWIN) + # DLL platform +- set(dlldir "bin") ++ set(dlldir "${CMAKE_INSTALL_BINDIR}") + else() +- set(dlldir "lib${LLVM_LIBDIR_SUFFIX}") ++ set(dlldir "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + + if(${name} IN_LIST LLVM_DISTRIBUTION_COMPONENTS OR +@@ -698,7 +698,7 @@ macro(add_llvm_loadable_module name) + install(TARGETS ${name} + ${export_to_llvmexports} + LIBRARY DESTINATION ${dlldir} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endif() +@@ -912,7 +912,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1430,7 +1430,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1446,7 +1446,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1469,7 +1469,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT CMAKE_CONFIGURATION_TYPES AND NOT ARG_ALWAYS_GENERATE) +@@ -1551,7 +1551,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -1635,9 +1636,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 02bab6846376..eff26adb2efc 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -140,9 +140,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index 22e3dcb776aa..ba77b9c195e2 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -73,7 +73,7 @@ function (add_sphinx_target builder project) + + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 6c316a2f04fb..129c0995059c 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -90,11 +90,11 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") + set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}") + configure_file( +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 1a04de931ff7..1c5ea4200635 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message("Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index cbcadc212498..a3da96546f43 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -473,8 +473,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -505,13 +505,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + OS X Only: If enabled CMake will generate a target named +@@ -676,9 +696,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index 1d5ca3ba92b0..026f5453c1da 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -4,5 +4,5 @@ add_subdirectory(Support) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index f201e1f7bff0..4582ed556a02 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -24,6 +24,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 892adc3b9dd8..cabe7fcc630f 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -333,12 +333,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = path.str(); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 6e913519a809..85641eef721f 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -19,7 +19,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lto.exports) + add_llvm_library(LTO SHARED ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index 19b606933082..27b9f71b3d79 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,6 +8,6 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) diff --git a/llvm/7/openmp/default.nix b/llvm/7/openmp/default.nix new file mode 100644 index 0000000..a87dd31 --- /dev/null +++ b/llvm/7/openmp/default.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation { + pname = "openmp"; + inherit version; + + src = fetch "openmp" "1dg53wzsci2kra8lh1y0chh60h2l8h1by93br5spzvzlxshkmrqy"; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/8/clang/HIP-use-PATH-8.patch b/llvm/8/clang/HIP-use-PATH-8.patch new file mode 100644 index 0000000..f4be100 --- /dev/null +++ b/llvm/8/clang/HIP-use-PATH-8.patch @@ -0,0 +1,80 @@ +From d9f1b7d7571b252e0ba2359ae6cfa93a9903c0e7 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Holger=20W=C3=BCnsche?= +Date: Tue, 21 Jan 2020 19:49:44 +0100 +Subject: [PATCH] [HIP] use GetProgramPath for executable discovery + +This change replaces the manual building of executable paths +using llvm::sys::path::append with GetProgramPath. +This enables adding other paths in case executables reside +in different directories and makes the code easier to read. + +Differential Revision: https://reviews.llvm.org/D72903 +--- + clang/lib/Driver/ToolChains/HIP.cpp | 23 ++++++++--------------- + 1 file changed, 8 insertions(+), 15 deletions(-) + +diff --git a/lib/Driver/ToolChains/HIP.cpp b/lang/lib/Driver/ToolChains/HIP.cpp +index 868765cf88e..31f2d68ec6c 100644 +--- a/lib/Driver/ToolChains/HIP.cpp ++++ b/lib/Driver/ToolChains/HIP.cpp +@@ -104,9 +104,8 @@ const char *AMDGCN::Linker::constructLLVMLinkCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpName)); + CmdArgs.push_back(OutputFileName); +- SmallString<128> ExecPath(C.getDriver().Dir); +- llvm::sys::path::append(ExecPath, "llvm-link"); +- const char *Exec = Args.MakeArgString(ExecPath); ++ const char *Exec = ++ Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + return OutputFileName; + } +@@ -147,9 +146,8 @@ const char *AMDGCN::Linker::constructOptCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); + OptArgs.push_back(OutputFileName); +- SmallString<128> OptPath(C.getDriver().Dir); +- llvm::sys::path::append(OptPath, "opt"); +- const char *OptExec = Args.MakeArgString(OptPath); ++ const char *OptExec = ++ Args.MakeArgString(getToolChain().GetProgramPath("opt")); + C.addCommand(llvm::make_unique(JA, *this, OptExec, OptArgs, Inputs)); + return OutputFileName; + } +@@ -167,9 +165,7 @@ const char *AMDGCN::Linker::constructLlcCommand( + const char *LlcOutputFile = + C.addTempFile(C.getArgs().MakeArgString(LlcOutputFileName)); + LlcArgs.push_back(LlcOutputFile); +- SmallString<128> LlcPath(C.getDriver().Dir); +- llvm::sys::path::append(LlcPath, "llc"); +- const char *Llc = Args.MakeArgString(LlcPath); ++ const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); + C.addCommand(llvm::make_unique(JA, *this, Llc, LlcArgs, Inputs)); + return LlcOutputFile; + } +@@ -184,9 +180,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA, + ArgStringList LldArgs{"-flavor", "gnu", "--no-undefined", + "-shared", "-o", Output.getFilename(), + InputFileName}; +- SmallString<128> LldPath(C.getDriver().Dir); +- llvm::sys::path::append(LldPath, "lld"); +- const char *Lld = Args.MakeArgString(LldPath); ++ const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); + C.addCommand(llvm::make_unique(JA, *this, Lld, LldArgs, Inputs)); + } + +@@ -218,9 +212,8 @@ void AMDGCN::constructHIPFatbinCommand(Compilation &C, const JobAction &JA, + Args.MakeArgString(std::string("-outputs=").append(OutputFileName)); + BundlerArgs.push_back(BundlerOutputArg); + +- SmallString<128> BundlerPath(C.getDriver().Dir); +- llvm::sys::path::append(BundlerPath, "clang-offload-bundler"); +- const char *Bundler = Args.MakeArgString(BundlerPath); ++ const char *Bundler = Args.MakeArgString( ++ T.getToolChain().GetProgramPath("clang-offload-bundler")); + C.addCommand(llvm::make_unique(JA, T, Bundler, BundlerArgs, Inputs)); + } + +-- +2.23.1 + diff --git a/llvm/8/clang/compiler-rt-baremetal.patch b/llvm/8/clang/compiler-rt-baremetal.patch new file mode 100644 index 0000000..a4a0f21 --- /dev/null +++ b/llvm/8/clang/compiler-rt-baremetal.patch @@ -0,0 +1,53 @@ +Index: lib/Driver/ToolChains/BareMetal.cpp +=================================================================== +--- a/lib/Driver/ToolChains/BareMetal.cpp ++++ b/lib/Driver/ToolChains/BareMetal.cpp +@@ -157,7 +157,7 @@ + void BareMetal::AddLinkRuntimeLib(const ArgList &Args, + ArgStringList &CmdArgs) const { + CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" + +- getTriple().getArchName() + ".a")); ++ getTriple().getArchName())); + } + + void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, +Index: test/Driver/baremetal.cpp +=================================================================== +--- a/test/Driver/baremetal.cpp ++++ b/test/Driver/baremetal.cpp +@@ -13,7 +13,7 @@ + // CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for" +-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-C-SAME: "-o" "{{.*}}.o" + + // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -35,7 +35,7 @@ + // CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind" +-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-DEFAULTCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -48,7 +48,7 @@ + // CHECK-V6M-LIBCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind" +-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -61,7 +61,7 @@ + // CHECK-V6M-LIBSTDCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind" +-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-LIBSTDCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ diff --git a/llvm/8/clang/default.nix b/llvm/8/clang/default.nix new file mode 100644 index 0000000..994f9bd --- /dev/null +++ b/llvm/8/clang/default.nix @@ -0,0 +1,145 @@ +{ lib, stdenv, llvm_meta, fetch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +, enablePolly ? false # TODO: get this info from llvm (passthru?) +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "cfe" "0ihnbdl058gvl2wdy45p5am55bq8ifx8m9mhcsgj9ax8yxlzvvvh"; + + unpackPhase = '' + unpackFile $src + mv cfe-${version}* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCMAKE_CXX_FLAGS=-std=c++11" + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals enablePolly [ + "-DWITH_POLLY=ON" + "-DLINK_POLLY_INTO_TOOLS=ON" + ]; + + patches = [ + ../../common/clang/5-8-purity.patch + ./xpc.patch + # Backport for -static-pie, which the latter touches, and which is nice in + # its own right. + ./static-pie.patch + # Backport for the `--unwindlib=[libgcc|compiler-rt]` flag, which is + # needed for our bootstrapping to not interfere with C. + ./unwindlib.patch + # https://reviews.llvm.org/D51899 + ./compiler-rt-baremetal.patch + # make clang -xhip use $PATH to find executables + ./HIP-use-PATH-8.patch + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-6-10-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace tools/extra/clangd/CMakeLists.txt \ + --replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/8/clang/gnu-install-dirs.patch b/llvm/8/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..e4b9c3f --- /dev/null +++ b/llvm/8/clang/gnu-install-dirs.patch @@ -0,0 +1,290 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c2016a45ca6b..9224797da0b5 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,6 +9,8 @@ endif() + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(LLVM_CONFIG) +@@ -382,7 +384,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.def" + PATTERN "*.h" +@@ -391,7 +393,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE + PATTERN "*.inc" +@@ -399,7 +401,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + ) + endif() + +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 7e22f16f365b..3c0c1d245969 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -99,9 +99,9 @@ macro(add_clang_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -142,7 +142,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -157,5 +157,5 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index e444c9c8706f..f8e4d06366a4 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -164,19 +164,19 @@ install( + FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_neon.h + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${CMAKE_CURRENT_BINARY_DIR}/arm_fp16.h + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${cuda_wrapper_files} + COMPONENT clang-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) ++ DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include/cuda_wrappers) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's. + add_llvm_install_targets(install-clang-headers +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index 53e3421f1b35..79ae5bb4c399 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-check/CMakeLists.txt b/tools/clang-check/CMakeLists.txt +index b837b0a0a5d9..9e30bd5780a5 100644 +--- a/tools/clang-check/CMakeLists.txt ++++ b/tools/clang-check/CMakeLists.txt +@@ -21,4 +21,4 @@ target_link_libraries(clang-check + ) + + install(TARGETS clang-check +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-extdef-mapping/CMakeLists.txt b/tools/clang-extdef-mapping/CMakeLists.txt +index 6c81689a831a..dacc14737719 100644 +--- a/tools/clang-extdef-mapping/CMakeLists.txt ++++ b/tools/clang-extdef-mapping/CMakeLists.txt +@@ -18,4 +18,4 @@ target_link_libraries(clang-extdef-mapping + ) + + install(TARGETS clang-extdef-mapping +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index a295e8cd0b2a..1973ff82c7f6 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-offload-bundler/CMakeLists.txt b/tools/clang-offload-bundler/CMakeLists.txt +index 8718015be76a..7a038f39622e 100644 +--- a/tools/clang-offload-bundler/CMakeLists.txt ++++ b/tools/clang-offload-bundler/CMakeLists.txt +@@ -22,4 +22,4 @@ target_link_libraries(clang-offload-bundler + ${CLANG_OFFLOAD_BUNDLER_LIB_DEPS} + ) + +-install(TARGETS clang-offload-bundler RUNTIME DESTINATION bin) ++install(TARGETS clang-offload-bundler RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index 45cbd763425c..f534e022024a 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -19,8 +19,8 @@ target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/diagtool/CMakeLists.txt b/tools/diagtool/CMakeLists.txt +index 96d1c390249c..41c762b37b76 100644 +--- a/tools/diagtool/CMakeLists.txt ++++ b/tools/diagtool/CMakeLists.txt +@@ -21,7 +21,7 @@ target_link_libraries(diagtool + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(TARGETS diagtool + COMPONENT diagtool +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-diagtool +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 32333b011ad1..258dfb2d520c 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -131,7 +131,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +@@ -162,7 +162,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT CMAKE_CONFIGURATION_TYPES) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index 380379300b09..adfd58ed5f7d 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -41,7 +41,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(LibexecFile ${LibexecFiles}) +@@ -53,7 +53,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/libexec/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) +- install(PROGRAMS libexec/${LibexecFile} DESTINATION libexec) ++ install(PROGRAMS libexec/${LibexecFile} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) + endforeach() + + foreach(ManPage ${ManPages}) +@@ -77,7 +77,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/share/scan-build/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) +- install(FILES share/scan-build/${ShareFile} DESTINATION share/scan-build) ++ install(FILES share/scan-build/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build) + endforeach() + + add_custom_target(scan-build ALL DEPENDS ${Depends}) +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index b305ca562a72..554bcb379061 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -21,7 +21,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(ShareFile ${ShareFiles}) +@@ -33,7 +33,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/share/scan-view/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) +- install(FILES share/${ShareFile} DESTINATION share/scan-view) ++ install(FILES share/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view) + endforeach() + + add_custom_target(scan-view ALL DEPENDS ${Depends}) +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 5573009d343a..24b3a90f233f 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -9,7 +9,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}) + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) +-install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION bin) ++install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) + set_target_properties(hmaptool PROPERTIES FOLDER "Utils") diff --git a/llvm/8/clang/static-pie.patch b/llvm/8/clang/static-pie.patch new file mode 100644 index 0000000..d1f86a1 --- /dev/null +++ b/llvm/8/clang/static-pie.patch @@ -0,0 +1,157 @@ +commit 7a9842bc92921e79b84630045276861be90b2d47 +Author: Siva Chandra +Date: Wed Feb 20 19:07:04 2019 +0000 + + [Clang Driver] Add support for "-static-pie" argument to the Clang driver. + + Summary: This change mimics GCC's support for the "-static-pie" argument. + + Subscribers: cfe-commits + + Tags: #clang + + Differential Revision: https://reviews.llvm.org/D58307 + + git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354502 91177308-0d34-0410-b5e6-96231b3b80d8 + (cherry picked from commit 7d6cd7825e6883f8650e32b07f3750824c2cef62) + +diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td +index d02d9744d7..75a21e66c7 100644 +--- a/include/clang/Driver/Options.td ++++ b/include/clang/Driver/Options.td +@@ -2502,6 +2502,7 @@ def pthread : Flag<["-"], "pthread">, Flags<[CC1Option]>, + def no_pthread : Flag<["-"], "no-pthread">, Flags<[CC1Option]>; + def p : Flag<["-"], "p">; + def pie : Flag<["-"], "pie">; ++def static_pie : Flag<["-"], "static-pie">; + def read__only__relocs : Separate<["-"], "read_only_relocs">; + def remap : Flag<["-"], "remap">; + def rewrite_objc : Flag<["-"], "rewrite-objc">, Flags<[DriverOption,CC1Option]>, +diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp +index d7e316befa..85ffc1618d 100644 +--- a/lib/Driver/ToolChains/CommonArgs.cpp ++++ b/lib/Driver/ToolChains/CommonArgs.cpp +@@ -1138,19 +1138,22 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, + bool isCygMing = Triple.isOSCygMing(); + bool IsIAMCU = Triple.isOSIAMCU(); + bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) || +- Args.hasArg(options::OPT_static); ++ Args.hasArg(options::OPT_static) || ++ Args.hasArg(options::OPT_static_pie); + + bool SharedLibgcc = Args.hasArg(options::OPT_shared_libgcc); + bool UnspecifiedLibgcc = !StaticLibgcc && !SharedLibgcc; + + // Gcc adds libgcc arguments in various ways: + // +- // gcc : -lgcc --as-needed -lgcc_s --no-as-needed +- // g++ : -lgcc_s -lgcc +- // gcc shared: -lgcc_s -lgcc +- // g++ shared: -lgcc_s -lgcc +- // gcc static: -lgcc -lgcc_eh +- // g++ static: -lgcc -lgcc_eh ++ // gcc : -lgcc --as-needed -lgcc_s --no-as-needed ++ // g++ : -lgcc_s -lgcc ++ // gcc shared: -lgcc_s -lgcc ++ // g++ shared: -lgcc_s -lgcc ++ // gcc static: -lgcc -lgcc_eh ++ // g++ static: -lgcc -lgcc_eh ++ // gcc static-pie: -lgcc -lgcc_eh ++ // g++ static-pie: -lgcc -lgcc_eh + // + // Also, certain targets need additional adjustments. + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index 69dba8fec8..0faa0bb473 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -334,6 +334,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const bool isAndroid = ToolChain.getTriple().isAndroid(); + const bool IsIAMCU = ToolChain.getTriple().isOSIAMCU(); + const bool IsPIE = getPIE(Args, ToolChain); ++ const bool IsStaticPIE = Args.hasArg(options::OPT_static_pie); + const bool HasCRTBeginEndFiles = + ToolChain.getTriple().hasEnvironment() || + (ToolChain.getTriple().getVendor() != llvm::Triple::MipsTechnologies); +@@ -354,6 +355,12 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (IsPIE) + CmdArgs.push_back("-pie"); + ++ if (IsStaticPIE) { ++ CmdArgs.push_back("-static"); ++ CmdArgs.push_back("-pie"); ++ CmdArgs.push_back("--no-dynamic-linker"); ++ } ++ + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); + +@@ -415,6 +422,8 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + crt1 = "gcrt1.o"; + else if (IsPIE) + crt1 = "Scrt1.o"; ++ else if (IsStaticPIE) ++ crt1 = "rcrt1.o"; + else + crt1 = "crt1.o"; + } +@@ -432,7 +441,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + crtbegin = isAndroid ? "crtbegin_static.o" : "crtbeginT.o"; + else if (Args.hasArg(options::OPT_shared)) + crtbegin = isAndroid ? "crtbegin_so.o" : "crtbeginS.o"; +- else if (IsPIE) ++ else if (IsPIE || IsStaticPIE) + crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbeginS.o"; + else + crtbegin = isAndroid ? "crtbegin_dynamic.o" : "crtbegin.o"; +@@ -483,7 +492,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + + if (!Args.hasArg(options::OPT_nostdlib)) { + if (!Args.hasArg(options::OPT_nodefaultlibs)) { +- if (Args.hasArg(options::OPT_static)) ++ if (Args.hasArg(options::OPT_static) || IsStaticPIE) + CmdArgs.push_back("--start-group"); + + if (NeedsSanitizerDeps) +@@ -518,7 +527,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (IsIAMCU) + CmdArgs.push_back("-lgloss"); + +- if (Args.hasArg(options::OPT_static)) ++ if (Args.hasArg(options::OPT_static) || IsStaticPIE) + CmdArgs.push_back("--end-group"); + else + AddRunTimeLibs(ToolChain, D, CmdArgs, Args); +@@ -535,7 +544,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + const char *crtend; + if (Args.hasArg(options::OPT_shared)) + crtend = isAndroid ? "crtend_so.o" : "crtendS.o"; +- else if (IsPIE) ++ else if (IsPIE || IsStaticPIE) + crtend = isAndroid ? "crtend_android.o" : "crtendS.o"; + else + crtend = isAndroid ? "crtend_android.o" : "crtend.o"; +diff --git a/test/Driver/linux-ld.c b/test/Driver/linux-ld.c +index 3ab81be490..800f782523 100644 +--- a/test/Driver/linux-ld.c ++++ b/test/Driver/linux-ld.c +@@ -176,6 +176,19 @@ + // CHECK-CLANG-NO-LIBGCC-STATIC: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" + // CHECK-CLANG-NO-LIBGCC-STATIC: "--start-group" "-lgcc" "-lgcc_eh" "-lc" "--end-group" + // ++// RUN: %clang -static-pie -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=platform \ ++// RUN: --gcc-toolchain="" \ ++// RUN: --sysroot=%S/Inputs/basic_linux_tree \ ++// RUN: | FileCheck --check-prefix=CHECK-CLANG-LD-STATIC-PIE %s ++// CHECK-CLANG-LD-STATIC-PIE: "{{.*}}ld{{(.exe)?}}" "--sysroot=[[SYSROOT:[^"]+]]" ++// CHECK-CLANG-LD-STATIC-PIE: "-static" ++// CHECK-CLANG-LD-STATIC-PIE: "-pie" ++// CHECK-CLANG-LD-STATIC-PIE: "--no-dynamic-linker" ++// CHECK-CLANG-LD-STATIC-PIE: "-m" "elf_x86_64" ++// CHECK-CLANG-LD-STATIC-PIE: "{{.*}}rcrt1.o" ++// CHECK-CLANG-LD-STATIC-PIE: "--start-group" "-lgcc" "-lgcc_eh" "-lc" "--end-group" ++// + // RUN: %clang -dynamic -no-canonical-prefixes %s -### -o %t.o 2>&1 \ + // RUN: --target=x86_64-unknown-linux -rtlib=platform \ + // RUN: --gcc-toolchain="" \ diff --git a/llvm/8/clang/unwindlib.patch b/llvm/8/clang/unwindlib.patch new file mode 100644 index 0000000..6958fce --- /dev/null +++ b/llvm/8/clang/unwindlib.patch @@ -0,0 +1,372 @@ +commit cd5603a4767277a29d3e67a9c3f2a5d2129cd973 +Author: Sterling Augustine +Date: Tue Mar 19 20:01:59 2019 +0000 + + Add --unwindlib=[libgcc|compiler-rt] to parallel --rtlib= [take 2] + + "clang++ hello.cc --rtlib=compiler-rt" + + now can works without specifying additional unwind or exception + handling libraries. + + This reworked version of the feature no longer modifies today's default + unwind library for compiler-rt: which is nothing. Rather, a user + can specify -DCLANG_DEFAULT_UNWINDLIB=libunwind when configuring + the compiler. + + This should address the issues from the previous version. + + Update tests for new --unwindlib semantics. + + Differential Revision: https://reviews.llvm.org/D59109 + + git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@356508 91177308-0d34-0410-b5e6-96231b3b80d8 + (cherry picked from commit 344aa82a52f2fae527f58284567ae305a314f7a8) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c2016a45ca..edeb2b66a1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -261,6 +261,24 @@ if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR + "Default runtime library to use (\"libgcc\" or \"compiler-rt\", empty for platform default)" FORCE) + endif() + ++set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING ++ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty to match runtime library.)") ++if (CLANG_DEFAULT_UNWINDLIB STREQUAL "") ++ if (CLANG_DEFAULT_RTLIB STREQUAL "libgcc") ++ set (CLANG_DEFAULT_UNWINDLIB "libgcc" CACHE STRING "" FORCE) ++ elseif (CLANG_DEFAULT_RTLIBS STREQUAL "libunwind") ++ set (CLANG_DEFAULT_UNWINDLIB "none" CACHE STRING "" FORCE) ++ endif() ++endif() ++ ++if (NOT(CLANG_DEFAULT_UNWINDLIB STREQUAL "none" OR ++ CLANG_DEFAULT_UNWINDLIB STREQUAL "libgcc" OR ++ CLANG_DEFAULT_UNWINDLIB STREQUAL "libunwind")) ++ message(WARNING "Resetting default unwindlib to use platform default") ++ set(CLANG_DEFAULT_UNWINDLIB "" CACHE STRING ++ "Default unwind library to use (\"none\" \"libgcc\" or \"libunwind\", empty for none)" FORCE) ++endif() ++ + set(CLANG_DEFAULT_OBJCOPY "objcopy" CACHE STRING + "Default objcopy executable to use.") + +diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td +index 5475e28ed7..15971210e4 100644 +--- a/include/clang/Basic/DiagnosticDriverKinds.td ++++ b/include/clang/Basic/DiagnosticDriverKinds.td +@@ -52,6 +52,10 @@ def err_drv_invalid_rtlib_name : Error< + "invalid runtime library name in argument '%0'">; + def err_drv_unsupported_rtlib_for_platform : Error< + "unsupported runtime library '%0' for platform '%1'">; ++def err_drv_invalid_unwindlib_name : Error< ++ "invalid unwind library name in argument '%0'">; ++def err_drv_incompatible_unwindlib : Error< ++ "--rtlib=libgcc requires --unwindlib=libgcc">; + def err_drv_invalid_stdlib_name : Error< + "invalid library name in argument '%0'">; + def err_drv_invalid_output_with_multiple_archs : Error< +diff --git a/include/clang/Config/config.h.cmake b/include/clang/Config/config.h.cmake +index 1d624450b9..2d4cb747e8 100644 +--- a/include/clang/Config/config.h.cmake ++++ b/include/clang/Config/config.h.cmake +@@ -23,6 +23,9 @@ + /* Default runtime library to use. */ + #define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}" + ++/* Default unwind library to use. */ ++#define CLANG_DEFAULT_UNWINDLIB "${CLANG_DEFAULT_UNWINDLIB}" ++ + /* Default objcopy to use */ + #define CLANG_DEFAULT_OBJCOPY "${CLANG_DEFAULT_OBJCOPY}" + +diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td +index 75a21e66c7..4da0e54965 100644 +--- a/include/clang/Driver/Options.td ++++ b/include/clang/Driver/Options.td +@@ -2570,6 +2570,8 @@ def std_EQ : Joined<["-", "--"], "std=">, Flags<[CC1Option]>, + }]>; + def stdlib_EQ : Joined<["-", "--"], "stdlib=">, Flags<[CC1Option]>, + HelpText<"C++ standard library to use">, Values<"libc++,libstdc++,platform">; ++def unwindlib_EQ : Joined<["-", "--"], "unwindlib=">, Flags<[CC1Option]>, ++ HelpText<"Unwind library to use">, Values<"libgcc,unwindlib,platform">; + def sub__library : JoinedOrSeparate<["-"], "sub_library">; + def sub__umbrella : JoinedOrSeparate<["-"], "sub_umbrella">; + def system_header_prefix : Joined<["--"], "system-header-prefix=">, +diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h +index d5f75b8271..4bedf760eb 100644 +--- a/include/clang/Driver/ToolChain.h ++++ b/include/clang/Driver/ToolChain.h +@@ -100,6 +100,12 @@ public: + RLT_Libgcc + }; + ++ enum UnwindLibType { ++ UNW_None, ++ UNW_CompilerRT, ++ UNW_Libgcc ++ }; ++ + enum RTTIMode { + RM_Enabled, + RM_Disabled, +@@ -368,6 +374,10 @@ public: + return ToolChain::CST_Libstdcxx; + } + ++ virtual UnwindLibType GetDefaultUnwindLibType() const { ++ return ToolChain::UNW_None; ++ } ++ + virtual std::string getCompilerRTPath() const; + + virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, +@@ -512,6 +522,10 @@ public: + // given compilation arguments. + virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const; + ++ // GetUnwindLibType - Determine the unwind library type to use with the ++ // given compilation arguments. ++ virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const; ++ + /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set + /// the include paths to use for the given C++ standard library type. + virtual void +diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp +index 88a627eab6..d82423f4a8 100644 +--- a/lib/Driver/ToolChain.cpp ++++ b/lib/Driver/ToolChain.cpp +@@ -680,6 +680,33 @@ ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( + return GetDefaultRuntimeLibType(); + } + ++ToolChain::UnwindLibType ToolChain::GetUnwindLibType( ++ const ArgList &Args) const { ++ const Arg *A = Args.getLastArg(options::OPT_unwindlib_EQ); ++ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_UNWINDLIB; ++ ++ if (LibName == "none") ++ return ToolChain::UNW_None; ++ else if (LibName == "platform" || LibName == "") { ++ ToolChain::RuntimeLibType RtLibType = GetRuntimeLibType(Args); ++ if (RtLibType == ToolChain::RLT_CompilerRT) ++ return ToolChain::UNW_None; ++ else if (RtLibType == ToolChain::RLT_Libgcc) ++ return ToolChain::UNW_Libgcc; ++ } else if (LibName == "libunwind") { ++ if (GetRuntimeLibType(Args) == RLT_Libgcc) ++ getDriver().Diag(diag::err_drv_incompatible_unwindlib); ++ return ToolChain::UNW_CompilerRT; ++ } else if (LibName == "libgcc") ++ return ToolChain::UNW_Libgcc; ++ ++ if (A) ++ getDriver().Diag(diag::err_drv_invalid_unwindlib_name) ++ << A->getAsString(Args); ++ ++ return GetDefaultUnwindLibType(); ++} ++ + ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ + const Arg *A = Args.getLastArg(options::OPT_stdlib_EQ); + StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_CXX_STDLIB; +diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp +index 85ffc1618d..9fd29726a4 100644 +--- a/lib/Driver/ToolChains/CommonArgs.cpp ++++ b/lib/Driver/ToolChains/CommonArgs.cpp +@@ -1132,47 +1132,80 @@ bool tools::isObjCAutoRefCount(const ArgList &Args) { + return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc, false); + } + +-static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, +- ArgStringList &CmdArgs, const ArgList &Args) { +- bool isAndroid = Triple.isAndroid(); +- bool isCygMing = Triple.isOSCygMing(); +- bool IsIAMCU = Triple.isOSIAMCU(); +- bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) || +- Args.hasArg(options::OPT_static) || +- Args.hasArg(options::OPT_static_pie); +- +- bool SharedLibgcc = Args.hasArg(options::OPT_shared_libgcc); +- bool UnspecifiedLibgcc = !StaticLibgcc && !SharedLibgcc; +- +- // Gcc adds libgcc arguments in various ways: +- // +- // gcc : -lgcc --as-needed -lgcc_s --no-as-needed +- // g++ : -lgcc_s -lgcc +- // gcc shared: -lgcc_s -lgcc +- // g++ shared: -lgcc_s -lgcc +- // gcc static: -lgcc -lgcc_eh +- // g++ static: -lgcc -lgcc_eh +- // gcc static-pie: -lgcc -lgcc_eh +- // g++ static-pie: -lgcc -lgcc_eh +- // +- // Also, certain targets need additional adjustments. ++enum class LibGccType { UnspecifiedLibGcc, StaticLibGcc, SharedLibGcc }; ++ ++static LibGccType getLibGccType(const ArgList &Args) { ++ bool Static = Args.hasArg(options::OPT_static_libgcc) || ++ Args.hasArg(options::OPT_static) || ++ Args.hasArg(options::OPT_static_pie); ++ ++ bool Shared = Args.hasArg(options::OPT_shared_libgcc); ++ if (Shared) ++ return LibGccType::SharedLibGcc; ++ if (Static) ++ return LibGccType::StaticLibGcc; ++ return LibGccType::UnspecifiedLibGcc; ++} + +- bool LibGccFirst = (D.CCCIsCC() && UnspecifiedLibgcc) || StaticLibgcc; +- if (LibGccFirst) +- CmdArgs.push_back("-lgcc"); ++// Gcc adds libgcc arguments in various ways: ++// ++// gcc : -lgcc --as-needed -lgcc_s --no-as-needed ++// g++ : -lgcc_s -lgcc ++// gcc shared: -lgcc_s -lgcc ++// g++ shared: -lgcc_s -lgcc ++// gcc static: -lgcc -lgcc_eh ++// g++ static: -lgcc -lgcc_eh ++// gcc static-pie: -lgcc -lgcc_eh ++// g++ static-pie: -lgcc -lgcc_eh ++// ++// Also, certain targets need additional adjustments. ++ ++static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, ++ ArgStringList &CmdArgs, const ArgList &Args) { ++ ToolChain::UnwindLibType UNW = TC.GetUnwindLibType(Args); ++ // Targets that don't use unwind libraries. ++ if (TC.getTriple().isAndroid() || TC.getTriple().isOSIAMCU() || ++ TC.getTriple().isOSBinFormatWasm() || ++ UNW == ToolChain::UNW_None) ++ return; + +- bool AsNeeded = D.CCCIsCC() && UnspecifiedLibgcc && !isAndroid && !isCygMing; ++ LibGccType LGT = getLibGccType(Args); ++ bool AsNeeded = D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc && ++ !TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing(); + if (AsNeeded) + CmdArgs.push_back("--as-needed"); + +- if ((UnspecifiedLibgcc || SharedLibgcc) && !isAndroid) +- CmdArgs.push_back("-lgcc_s"); +- +- else if (StaticLibgcc && !isAndroid && !IsIAMCU) +- CmdArgs.push_back("-lgcc_eh"); ++ switch (UNW) { ++ case ToolChain::UNW_None: ++ return; ++ case ToolChain::UNW_Libgcc: { ++ LibGccType LGT = getLibGccType(Args); ++ if (LGT == LibGccType::UnspecifiedLibGcc || LGT == LibGccType::SharedLibGcc) ++ CmdArgs.push_back("-lgcc_s"); ++ else if (LGT == LibGccType::StaticLibGcc) ++ CmdArgs.push_back("-lgcc_eh"); ++ break; ++ } ++ case ToolChain::UNW_CompilerRT: ++ CmdArgs.push_back("-lunwind"); ++ break; ++ } + + if (AsNeeded) + CmdArgs.push_back("--no-as-needed"); ++} ++ ++static void AddLibgcc(const ToolChain &TC, const Driver &D, ++ ArgStringList &CmdArgs, const ArgList &Args) { ++ bool isAndroid = TC.getTriple().isAndroid(); ++ ++ LibGccType LGT = getLibGccType(Args); ++ bool LibGccFirst = (D.CCCIsCC() && LGT == LibGccType::UnspecifiedLibGcc) || ++ LGT == LibGccType::StaticLibGcc; ++ if (LibGccFirst) ++ CmdArgs.push_back("-lgcc"); ++ ++ AddUnwindLibrary(TC, D, CmdArgs, Args); + + if (!LibGccFirst) + CmdArgs.push_back("-lgcc"); +@@ -1182,7 +1215,7 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, + // + // NOTE: This fixes a link error on Android MIPS as well. The non-static + // libgcc for MIPS relies on _Unwind_Find_FDE and dl_iterate_phdr from libdl. +- if (isAndroid && !StaticLibgcc) ++ if (isAndroid && getLibGccType(Args) != LibGccType::StaticLibGcc) + CmdArgs.push_back("-ldl"); + } + +@@ -1194,6 +1227,7 @@ void tools::AddRunTimeLibs(const ToolChain &TC, const Driver &D, + switch (RLT) { + case ToolChain::RLT_CompilerRT: + CmdArgs.push_back(TC.getCompilerRTArgString(Args, "builtins")); ++ AddUnwindLibrary(TC, D, CmdArgs, Args); + break; + case ToolChain::RLT_Libgcc: + // Make sure libgcc is not used under MSVC environment by default +@@ -1205,7 +1239,7 @@ void tools::AddRunTimeLibs(const ToolChain &TC, const Driver &D, + << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "MSVC"; + } + } else +- AddLibgcc(TC.getTriple(), D, CmdArgs, Args); ++ AddLibgcc(TC, D, CmdArgs, Args); + break; + } + } +diff --git a/test/Driver/compiler-rt-unwind.c b/test/Driver/compiler-rt-unwind.c +new file mode 100644 +index 0000000000..00024dfa7e +--- /dev/null ++++ b/test/Driver/compiler-rt-unwind.c +@@ -0,0 +1,49 @@ ++// General tests that the driver handles combinations of --rtlib=XXX and ++// --unwindlib=XXX properly. ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-EMPTY %s ++// RTLIB-EMPTY: "{{.*}}lgcc" ++// RTLIB-EMPTY: "{{.*}}-lgcc_s" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-GCC %s ++// RTLIB-GCC: "{{.*}}lgcc" ++// RTLIB-GCC: "{{.*}}lgcc_s" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER-RT %s ++// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lgcc" ++// RTLIB-GCC-UNWINDLIB-COMPILER-RT: "{{.*}}lunwind" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT %s ++// RTLIB-COMPILER-RT: "{{.*}}libclang_rt.builtins-x86_64.a" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \ ++// RUN: --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC %s ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}libclang_rt.builtins-x86_64.a" ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC: "{{.*}}lgcc_s" ++// ++// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ ++// RUN: --target=x86_64-unknown-linux -rtlib=compiler-rt --unwindlib=libgcc \ ++// RUN: -static --gcc-toolchain="" \ ++// RUN: | FileCheck --check-prefix=RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC %s ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}libclang_rt.builtins-x86_64.a" ++// RTLIB-COMPILER-RT-UNWINDLIB-GCC-STATIC: "{{.*}}lgcc_eh" ++// ++// RUN: not %clang -no-canonical-prefixes %s -o %t.o 2> %t.err \ ++// RUN: --target=x86_64-unknown-linux -rtlib=libgcc --unwindlib=libunwind \ ++// RUN: --gcc-toolchain="" \ ++// RUN: FileCheck --input-file=%t.err --check-prefix=RTLIB-GCC-UNWINDLIB-COMPILER_RT %s ++// RTLIB-GCC-UNWINDLIB-COMPILER_RT: "{{[.|\\\n]*}}--rtlib=libgcc requires --unwindlib=libgcc" diff --git a/llvm/8/clang/xpc.patch b/llvm/8/clang/xpc.patch new file mode 100644 index 0000000..eb57d34 --- /dev/null +++ b/llvm/8/clang/xpc.patch @@ -0,0 +1,41 @@ +From 61c9b97d7b81cc2c013b423bf1763a92b14fcae3 Mon Sep 17 00:00:00 2001 +From: Jan Korous +Date: Tue, 26 Mar 2019 03:48:25 +0000 +Subject: [PATCH] [clangd][xpc][cmake] Respect explicit value of + CLANGD_BUILD_XPC + +We shouldn't prevent user from disabling XPC framework build on Darwin. +However, by keeping it on by default our CI systems also test +it by default on macOS. + +Based on user request: +http://lists.llvm.org/pipermail/cfe-dev/2019-March/061778.html + +Differential Revision: https://reviews.llvm.org/D59808 + +git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@356974 91177308-0d34-0410-b5e6-96231b3b80d8 +--- + CMakeLists.txt | 13 ++++++++++--- + 1 file changed, 10 insertions(+), 3 deletions(-) + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 66ebeaeeaa..514b17fb3c 100644 +--- a/tools/extra/CMakeLists.txt ++++ b/tools/extra/CMakeLists.txt +@@ -1,6 +1,13 @@ +-option(CLANGD_BUILD_XPC "Build XPC Support For Clangd." OFF) +-if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") +- set(CLANGD_BUILD_XPC ON CACHE BOOL "" FORCE) ++if (NOT DEFINED CLANGD_BUILD_XPC) ++ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") ++ set(CLANGD_BUILD_XPC_DEFAULT ON) ++ else () ++ set(CLANGD_BUILD_XPC_DEFAULT OFF) ++ endif () ++ ++ set(CLANGD_BUILD_XPC ${CLANGD_BUILD_XPC_DEFAULT} CACHE BOOL "Build XPC Support For Clangd." FORCE) ++ ++ unset(CLANGD_BUILD_XPC_DEFAULT) + endif () + + add_subdirectory(clang-apply-replacements) \ No newline at end of file diff --git a/llvm/8/compiler-rt/armv7l.patch b/llvm/8/compiler-rt/armv7l.patch new file mode 100644 index 0000000..89d7f1a --- /dev/null +++ b/llvm/8/compiler-rt/armv7l.patch @@ -0,0 +1,38 @@ +diff -ur compiler-rt-7.1.0.src/cmake/builtin-config-ix.cmake compiler-rt-7.1.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-7.1.0.src/cmake/builtin-config-ix.cmake 2018-05-25 06:36:27.000000000 +0900 ++++ compiler-rt-7.1.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-09 20:26:33.030608692 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-7.1.0.src/lib/builtins/CMakeLists.txt compiler-rt-7.1.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-7.1.0.src/lib/builtins/CMakeLists.txt 2018-07-31 03:18:59.000000000 +0900 ++++ compiler-rt-7.1.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-09 20:27:38.893409318 +0900 +@@ -453,6 +453,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -563,12 +564,12 @@ + set(_arch ${arch}) + if("${arch}" STREQUAL "armv6m") + set(_arch "arm|armv6m") +- elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + set(_arch "arm") + endif() + + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/8/compiler-rt/crtbegin-and-end.patch b/llvm/8/compiler-rt/crtbegin-and-end.patch new file mode 100644 index 0000000..e63be18 --- /dev/null +++ b/llvm/8/compiler-rt/crtbegin-and-end.patch @@ -0,0 +1,595 @@ +Get crtbegin and crtend without compiler GCC! PR is at https://reviews.llvm.org/D28791 + +Index: compiler-rt/CMakeLists.txt +=================================================================== +--- compiler-rt/CMakeLists.txt ++++ compiler-rt/CMakeLists.txt +@@ -29,6 +29,8 @@ + + option(COMPILER_RT_BUILD_BUILTINS "Build builtins" ON) + mark_as_advanced(COMPILER_RT_BUILD_BUILTINS) ++option(COMPILER_RT_BUILD_CRT "Build crtbegin.o/crtend.o" ON) ++mark_as_advanced(COMPILER_RT_BUILD_CRT) + option(COMPILER_RT_BUILD_SANITIZERS "Build sanitizers" ON) + mark_as_advanced(COMPILER_RT_BUILD_SANITIZERS) + option(COMPILER_RT_BUILD_XRAY "Build xray" ON) +Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake +=================================================================== +--- compiler-rt/cmake/Modules/AddCompilerRT.cmake ++++ compiler-rt/cmake/Modules/AddCompilerRT.cmake +@@ -132,7 +132,7 @@ + # Adds static or shared runtime for a list of architectures and operating + # systems and puts it in the proper directory in the build and install trees. + # add_compiler_rt_runtime( +-# {STATIC|SHARED} ++# {OBJECT|STATIC|SHARED} + # ARCHS + # OS + # SOURCES +@@ -144,8 +144,8 @@ + # PARENT_TARGET + # ADDITIONAL_HEADERS
) + function(add_compiler_rt_runtime name type) +- if(NOT type MATCHES "^(STATIC|SHARED)$") +- message(FATAL_ERROR "type argument must be STATIC or SHARED") ++ if(NOT type MATCHES "^(OBJECT|STATIC|SHARED)$") ++ message(FATAL_ERROR "type argument must be OBJECT, STATIC or SHARED") + return() + endif() + cmake_parse_arguments(LIB +@@ -204,7 +204,10 @@ + message(FATAL_ERROR "Architecture ${arch} can't be targeted") + return() + endif() +- if(type STREQUAL "STATIC") ++ if(type STREQUAL "OBJECT") ++ set(libname "${name}-${arch}") ++ set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX}) ++ elseif(type STREQUAL "STATIC") + set(libname "${name}-${arch}") + set_output_name(output_name_${libname} ${name} ${arch}) + else() +@@ -270,12 +273,34 @@ + set(COMPONENT_OPTION COMPONENT ${libname}) + endif() + +- add_library(${libname} ${type} ${sources_${libname}}) +- set_target_compile_flags(${libname} ${extra_cflags_${libname}}) +- set_target_link_flags(${libname} ${extra_link_flags_${libname}}) +- set_property(TARGET ${libname} APPEND PROPERTY +- COMPILE_DEFINITIONS ${LIB_DEFS}) +- set_target_output_directories(${libname} ${output_dir_${libname}}) ++ if(type STREQUAL "OBJECT") ++ string(TOUPPER ${CMAKE_BUILD_TYPE} config) ++ get_property(cflags SOURCE ${sources_${libname}} PROPERTY COMPILE_FLAGS) ++ separate_arguments(cflags) ++ add_custom_command( ++ OUTPUT ${output_dir_${libname}}/${libname}.o ++ COMMAND ${CMAKE_C_COMPILER} ${sources_${libname}} ${cflags} ${extra_cflags_${libname}} -c -o ${output_dir_${libname}}/${libname}.o ++ DEPENDS ${sources_${libname}} ++ COMMENT "Building C object ${libname}.o") ++ add_custom_target(${libname} DEPENDS ${output_dir_${libname}}/${libname}.o) ++ install(FILES ${output_dir_${libname}}/${libname}.o ++ DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION}) ++ else() ++ add_library(${libname} ${type} ${sources_${libname}}) ++ set_target_compile_flags(${libname} ${extra_cflags_${libname}}) ++ set_target_link_flags(${libname} ${extra_link_flags_${libname}}) ++ set_property(TARGET ${libname} APPEND PROPERTY ++ COMPILE_DEFINITIONS ${LIB_DEFS}) ++ set_target_output_directories(${libname} ${output_dir_${libname}}) ++ install(TARGETS ${libname} ++ ARCHIVE DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION} ++ LIBRARY DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION} ++ RUNTIME DESTINATION ${install_dir_${libname}} ++ ${COMPONENT_OPTION}) ++ endif() + set_target_properties(${libname} PROPERTIES + OUTPUT_NAME ${output_name_${libname}}) + set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime") +@@ -299,13 +324,6 @@ + ) + endif() + endif() +- install(TARGETS ${libname} +- ARCHIVE DESTINATION ${install_dir_${libname}} +- ${COMPONENT_OPTION} +- LIBRARY DESTINATION ${install_dir_${libname}} +- ${COMPONENT_OPTION} +- RUNTIME DESTINATION ${install_dir_${libname}} +- ${COMPONENT_OPTION}) + + # We only want to generate per-library install targets if you aren't using + # an IDE because the extra targets get cluttered in IDEs. +Index: compiler-rt/cmake/config-ix.cmake +=================================================================== +--- compiler-rt/cmake/config-ix.cmake ++++ compiler-rt/cmake/config-ix.cmake +@@ -227,6 +227,7 @@ + ${ARM32} ${ARM64} ${MIPS32} ${MIPS64} ${S390X}) + set(ALL_ASAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} + ${MIPS32} ${MIPS64} ${PPC64} ${S390X}) ++set(ALL_CRT_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64}) + set(ALL_DFSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64}) + set(ALL_FUZZER_SUPPORTED_ARCH ${X86_64} ${ARM64}) + +@@ -474,6 +475,7 @@ + SANITIZER_COMMON_SUPPORTED_ARCH) + + else() ++ filter_available_targets(CRT_SUPPORTED_ARCH ${ALL_CRT_SUPPORTED_ARCH}) + # Architectures supported by compiler-rt libraries. + filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH + ${ALL_SANITIZER_COMMON_SUPPORTED_ARCH}) +@@ -563,6 +565,12 @@ + + # TODO: Add builtins support. + ++if (CRT_SUPPORTED_ARCH AND OS_NAME MATCHES "Linux") ++ set(COMPILER_RT_HAS_CRT TRUE) ++else() ++ set(COMPILER_RT_HAS_CRT FALSE) ++endif() ++ + if (COMPILER_RT_HAS_SANITIZER_COMMON AND DFSAN_SUPPORTED_ARCH AND + OS_NAME MATCHES "Linux") + set(COMPILER_RT_HAS_DFSAN TRUE) +Index: compiler-rt/lib/CMakeLists.txt +=================================================================== +--- compiler-rt/lib/CMakeLists.txt ++++ compiler-rt/lib/CMakeLists.txt +@@ -17,6 +17,10 @@ + add_subdirectory(builtins) + endif() + ++if(COMPILER_RT_BUILD_CRT) ++ add_subdirectory(crt) ++endif() ++ + function(compiler_rt_build_runtime runtime) + string(TOUPPER ${runtime} runtime_uppercase) + if(COMPILER_RT_HAS_${runtime_uppercase}) +Index: compiler-rt/lib/crt/CMakeLists.txt +=================================================================== +--- /dev/null ++++ compiler-rt/lib/crt/CMakeLists.txt +@@ -0,0 +1,102 @@ ++add_compiler_rt_component(crt) ++ ++function(check_cxx_section_exists section output) ++ cmake_parse_arguments(ARG "" "" "SOURCE;FLAGS" ${ARGN}) ++ if(NOT ARG_SOURCE) ++ set(ARG_SOURCE "int main() { return 0; }\n") ++ endif() ++ ++ string(RANDOM TARGET_NAME) ++ set(TARGET_NAME "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/cmTC_${TARGET_NAME}.dir") ++ file(MAKE_DIRECTORY ${TARGET_NAME}) ++ ++ file(WRITE "${TARGET_NAME}/CheckSectionExists.c" "${ARG_SOURCE}\n") ++ ++ string(REGEX MATCHALL "<[A-Za-z0-9_]*>" substitutions ++ ${CMAKE_C_COMPILE_OBJECT}) ++ ++ set(try_compile_flags "${ARG_FLAGS}") ++ if(CMAKE_C_COMPILER_ID MATCHES Clang AND CMAKE_C_COMPILER_TARGET) ++ list(APPEND try_compile_flags "-target ${CMAKE_C_COMPILER_TARGET}") ++ endif() ++ ++ string(REPLACE ";" " " extra_flags "${try_compile_flags}") ++ ++ set(test_compile_command "${CMAKE_C_COMPILE_OBJECT}") ++ foreach(substitution ${substitutions}) ++ if(substitution STREQUAL "") ++ string(REPLACE "" ++ "${CMAKE_C_COMPILER}" test_compile_command ${test_compile_command}) ++ elseif(substitution STREQUAL "") ++ string(REPLACE "" "${TARGET_NAME}/CheckSectionExists.o" ++ test_compile_command ${test_compile_command}) ++ elseif(substitution STREQUAL "") ++ string(REPLACE "" "${TARGET_NAME}/CheckSectionExists.c" ++ test_compile_command ${test_compile_command}) ++ elseif(substitution STREQUAL "") ++ string(REPLACE "" "${CMAKE_C_FLAGS} ${extra_flags}" ++ test_compile_command ${test_compile_command}) ++ else() ++ string(REPLACE "${substitution}" "" test_compile_command ++ ${test_compile_command}) ++ endif() ++ endforeach() ++ ++ string(REPLACE " " ";" test_compile_command "${test_compile_command}") ++ ++ execute_process( ++ COMMAND ${test_compile_command} ++ RESULT_VARIABLE TEST_RESULT ++ OUTPUT_VARIABLE TEST_OUTPUT ++ ERROR_VARIABLE TEST_ERROR ++ ) ++ ++ execute_process( ++ COMMAND ${CMAKE_OBJDUMP} -h "${TARGET_NAME}/CheckSectionExists.o" ++ RESULT_VARIABLE CHECK_RESULT ++ OUTPUT_VARIABLE CHECK_OUTPUT ++ ERROR_VARIABLE CHECK_ERROR ++ ) ++ string(FIND "${CHECK_OUTPUT}" "${section}" SECTION_FOUND) ++ ++ if(NOT SECTION_FOUND EQUAL -1) ++ set(${output} TRUE PARENT_SCOPE) ++ else() ++ set(${output} FALSE PARENT_SCOPE) ++ endif() ++ ++ file(REMOVE_RECURSE ${TARGET_NAME}) ++endfunction() ++ ++check_cxx_section_exists(".init_array" COMPILER_RT_HAS_INITFINI_ARRAY ++ SOURCE "__attribute__((constructor)) void f() {}\nint main() { return 0; }\n") ++ ++append_list_if(COMPILER_RT_HAS_INITFINI_ARRAY -DCRT_HAS_INITFINI_ARRAY CRT_CFLAGS) ++append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC CRT_CFLAGS) ++ ++foreach(arch ${CRT_SUPPORTED_ARCH}) ++ add_compiler_rt_runtime(clang_rt.crtbegin ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c ++ CFLAGS ${CRT_CFLAGS} ++ PARENT_TARGET crt) ++ add_compiler_rt_runtime(clang_rt.crtbegin_shared ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtbegin.c ++ CFLAGS ${CRT_CFLAGS} -DCRT_SHARED ++ PARENT_TARGET crt) ++ add_compiler_rt_runtime(clang_rt.crtend ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c ++ CFLAGS ${CRT_CFLAGS} ++ PARENT_TARGET crt) ++ add_compiler_rt_runtime(clang_rt.crtend_shared ++ OBJECT ++ ARCHS ${arch} ++ SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/crtend.c ++ CFLAGS ${CRT_CFLAGS} -DCRT_SHARED ++ PARENT_TARGET crt) ++endforeach() +Index: compiler-rt/lib/crt/crtbegin.c +=================================================================== +--- /dev/null ++++ compiler-rt/lib/crt/crtbegin.c +@@ -0,0 +1,108 @@ ++/* ===-- crtbegin.c - Start of constructors and destructors ----------------=== ++ * ++ * The LLVM Compiler Infrastructure ++ * ++ * This file is dual licensed under the MIT and the University of Illinois Open ++ * Source Licenses. See LICENSE.TXT for details. ++ * ++ * ===----------------------------------------------------------------------=== ++ */ ++ ++#include ++ ++__attribute__((visibility("hidden"))) ++#ifdef CRT_SHARED ++void *__dso_handle = &__dso_handle; ++#else ++void *__dso_handle = (void *)0; ++#endif ++ ++static long __EH_FRAME_LIST__[] ++ __attribute__((section(".eh_frame"), aligned(sizeof(void *)))) = {}; ++ ++extern void __register_frame_info(const void *, void *) __attribute__((weak)); ++extern void *__deregister_frame_info(const void *) __attribute__((weak)); ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++typedef void (*fp)(void); ++ ++static fp __CTOR_LIST__[] ++ __attribute__((section(".ctors"), aligned(sizeof(fp)), used)) = {(fp)-1}; ++extern fp __CTOR_LIST_END__[]; ++#endif ++ ++#ifdef CRT_SHARED ++extern void __cxa_finalize(void *) __attribute__((weak)); ++#endif ++ ++static void __attribute__((used)) __do_init() { ++ static _Bool __initialized; ++ if (__builtin_expect(__initialized, 0)) ++ return; ++ __initialized = 1; ++ ++ static struct { void *p[8]; } __object; ++ if (__register_frame_info) ++ __register_frame_info(__EH_FRAME_LIST__, &__object); ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++ const size_t n = __CTOR_LIST_END__ - __CTOR_LIST__ - 1; ++ for (size_t i = n; i >= 1; i--) __CTOR_LIST__[i](); ++#endif ++} ++ ++#ifdef CRT_HAS_INITFINI_ARRAY ++__attribute__((section(".init_array"), ++ used)) static void (*__init)(void) = __do_init; ++#else // CRT_HAS_INITFINI_ARRAY ++#if defined(__i386__) || defined(__x86_64__) ++asm(".pushsection .init,\"ax\",@progbits\n\t" ++ "call " __USER_LABEL_PREFIX__ "__do_init\n\t" ++ ".popsection"); ++#elif defined(__arm__) ++asm(".pushsection .init,\"ax\",%progbits\n\t" ++ "bl " __USER_LABEL_PREFIX__ "__do_init\n\t" ++ ".popsection"); ++#endif // CRT_HAS_INITFINI_ARRAY ++#endif ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++static fp __DTOR_LIST__[] ++ __attribute__((section(".dtors"), aligned(sizeof(fp)), used)) = {(fp)-1}; ++extern fp __DTOR_LIST_END__[]; ++#endif ++ ++static void __attribute__((used)) __do_fini() { ++ static _Bool __finalized; ++ if (__builtin_expect(__finalized, 0)) ++ return; ++ __finalized = 1; ++ ++#ifdef CRT_SHARED ++ if (__cxa_finalize) ++ __cxa_finalize(__dso_handle); ++#endif ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++ if (__deregister_frame_info) ++ __deregister_frame_info(__EH_FRAME_LIST__); ++ ++ const size_t n = __DTOR_LIST_END__ - __DTOR_LIST__ - 1; ++ for (size_t i = 1; i < n; i++) __DTOR_LIST__[i](); ++#endif ++} ++ ++#ifdef CRT_HAS_INITFINI_ARRAY ++__attribute__((section(".fini_array"), ++ used)) static void (*__fini)(void) = __do_fini; ++#else // CRT_HAS_INITFINI_ARRAY ++#if defined(__i386__) || defined(__x86_64__) ++asm(".pushsection .fini,\"ax\",@progbits\n\t" ++ "call " __USER_LABEL_PREFIX__ "__do_fini\n\t" ++ ".popsection"); ++#elif defined(__arm__) ++asm(".pushsection .fini,\"ax\",%progbits\n\t" ++ "bl " __USER_LABEL_PREFIX__ "__do_fini\n\t" ++ ".popsection"); ++#endif ++#endif // CRT_HAS_INIT_FINI_ARRAY +Index: compiler-rt/lib/crt/crtend.c +=================================================================== +--- /dev/null ++++ compiler-rt/lib/crt/crtend.c +@@ -0,0 +1,24 @@ ++/* ===-- crtend.c - End of constructors and destructors --------------------=== ++ * ++ * The LLVM Compiler Infrastructure ++ * ++ * This file is dual licensed under the MIT and the University of Illinois Open ++ * Source Licenses. See LICENSE.TXT for details. ++ * ++ * ===----------------------------------------------------------------------=== ++ */ ++ ++#include ++ ++// Put 4-byte zero which is the length field in FDE at the end as a terminator. ++const int32_t __EH_FRAME_LIST_END__[] ++ __attribute__((section(".eh_frame"), aligned(sizeof(int32_t)), ++ visibility("hidden"), used)) = {0}; ++ ++#ifndef CRT_HAS_INITFINI_ARRAY ++typedef void (*fp)(void); ++fp __CTOR_LIST_END__[] ++ __attribute__((section(".ctors"), visibility("hidden"), used)) = {0}; ++fp __DTOR_LIST_END__[] ++ __attribute__((section(".dtors"), visibility("hidden"), used)) = {0}; ++#endif +Index: compiler-rt/test/CMakeLists.txt +=================================================================== +--- compiler-rt/test/CMakeLists.txt ++++ compiler-rt/test/CMakeLists.txt +@@ -73,6 +73,9 @@ + if(COMPILER_RT_BUILD_XRAY) + compiler_rt_test_runtime(xray) + endif() ++ if(COMPILER_RT_HAS_CRT) ++ add_subdirectory(crt) ++ endif() + # ShadowCallStack does not yet provide a runtime with compiler-rt, the tests + # include their own minimal runtime + add_subdirectory(shadowcallstack) +Index: compiler-rt/test/crt/CMakeLists.txt +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/CMakeLists.txt +@@ -0,0 +1,31 @@ ++set(CRT_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) ++ ++set(CRT_TESTSUITES) ++ ++set(CRT_TEST_DEPS "") ++ ++if(NOT COMPILER_RT_STANDALONE_BUILD AND COMPILER_RT_BUILD_CRT AND ++ COMPILER_RT_HAS_CRT) ++ list(APPEND CRT_TEST_DEPS crt) ++endif() ++ ++set(CRT_TEST_ARCH ${CRT_SUPPORTED_ARCH}) ++if (COMPILER_RT_BUILD_CRT AND COMPILER_RT_HAS_CRT) ++ foreach(arch ${CRT_TEST_ARCH}) ++ set(CRT_TEST_TARGET_ARCH ${arch}) ++ string(TOLOWER "-${arch}-${OS_NAME}" CRT_TEST_CONFIG_SUFFIX) ++ get_test_cc_for_arch(${arch} CRT_TEST_TARGET_CC CRT_TEST_TARGET_CFLAGS) ++ string(TOUPPER ${arch} ARCH_UPPER_CASE) ++ set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}Config) ++ ++ configure_lit_site_cfg( ++ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in ++ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) ++ list(APPEND CRT_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) ++ endforeach() ++endif() ++ ++add_lit_testsuite(check-crt "Running the CRT tests" ++ ${CRT_TESTSUITES} ++ DEPENDS ${CRT_TEST_DEPS}) ++set_target_properties(check-crt PROPERTIES FOLDER "Compiler-RT Misc") +Index: compiler-rt/test/crt/dso_handle.cpp +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/dso_handle.cpp +@@ -0,0 +1,33 @@ ++// RUN: %clangxx -g -DCRT_SHARED -c %s -fPIC -o %tshared.o ++// RUN: %clangxx -g -c %s -fPIC -o %t.o ++// RUN: %clangxx -g -shared -o %t.so -nostdlib %crti %shared_crtbegin %tshared.o %libstdcxx -lc -lm -lgcc_s %shared_crtend %crtn ++// RUN: %clangxx -g -o %t -nostdlib %crt1 %crti %crtbegin %t.o %libstdcxx -lc -lm %libgcc %t.so %crtend %crtn ++// RUN: %run %t 2>&1 | FileCheck %s ++ ++#include ++ ++// CHECK: 1 ++// CHECK-NEXT: ~A() ++ ++#ifdef CRT_SHARED ++bool G; ++void C() { ++ printf("%d\n", G); ++} ++ ++struct A { ++ A() { G = true; } ++ ~A() { ++ printf("~A()\n"); ++ } ++}; ++ ++A a; ++#else ++void C(); ++ ++int main() { ++ C(); ++ return 0; ++} ++#endif +Index: compiler-rt/test/crt/lit.cfg +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/lit.cfg +@@ -0,0 +1,80 @@ ++# -*- Python -*- ++ ++import os ++import subprocess ++ ++# Setup config name. ++config.name = 'CRT' + config.name_suffix ++ ++# Setup source root. ++config.test_source_root = os.path.dirname(__file__) ++ ++ ++def get_library_path(file): ++ cmd = subprocess.Popen([config.clang.strip(), ++ config.target_cflags.strip(), ++ '-print-file-name=%s' % file], ++ stdout=subprocess.PIPE, ++ env=config.environment) ++ if not cmd.stdout: ++ lit_config.fatal("Couldn't find the library path for '%s'" % file) ++ dir = cmd.stdout.read().strip() ++ if sys.platform in ['win32'] and execute_external: ++ # Don't pass dosish path separator to msys bash.exe. ++ dir = dir.replace('\\', '/') ++ # Ensure the result is an ascii string, across Python2.5+ - Python3. ++ return str(dir.decode('ascii')) ++ ++ ++def get_libgcc_file_name(): ++ cmd = subprocess.Popen([config.clang.strip(), ++ config.target_cflags.strip(), ++ '-print-libgcc-file-name'], ++ stdout=subprocess.PIPE, ++ env=config.environment) ++ if not cmd.stdout: ++ lit_config.fatal("Couldn't find the library path for '%s'" % file) ++ dir = cmd.stdout.read().strip() ++ if sys.platform in ['win32'] and execute_external: ++ # Don't pass dosish path separator to msys bash.exe. ++ dir = dir.replace('\\', '/') ++ # Ensure the result is an ascii string, across Python2.5+ - Python3. ++ return str(dir.decode('ascii')) ++ ++ ++def build_invocation(compile_flags): ++ return ' ' + ' '.join([config.clang] + compile_flags) + ' ' ++ ++ ++# Setup substitutions. ++config.substitutions.append( ++ ('%clang ', build_invocation([config.target_cflags]))) ++config.substitutions.append( ++ ('%clangxx ', ++ build_invocation(config.cxx_mode_flags + [config.target_cflags]))) ++ ++base_lib = os.path.join( ++ config.compiler_rt_libdir, "clang_rt.%%s-%s.o" % config.target_arch) ++config.substitutions.append(('%crtbegin', base_lib % "crtbegin")) ++config.substitutions.append(('%shared_crtbegin', base_lib % "crtbegin_shared")) ++config.substitutions.append(('%crtend', base_lib % "crtend")) ++config.substitutions.append(('%shared_crtend', base_lib % "crtend_shared")) ++ ++config.substitutions.append( ++ ('%crt1', get_library_path('crt1.o'))) ++config.substitutions.append( ++ ('%crti', get_library_path('crti.o'))) ++config.substitutions.append( ++ ('%crtn', get_library_path('crtn.o'))) ++ ++config.substitutions.append( ++ ('%libgcc', get_libgcc_file_name())) ++ ++config.substitutions.append( ++ ('%libstdcxx', '-l' + config.sanitizer_cxx_lib.lstrip('lib'))) ++ ++# Default test suffixes. ++config.suffixes = ['.c', '.cc', '.cpp'] ++ ++if config.host_os not in ['Linux']: ++ config.unsupported = True +Index: compiler-rt/test/crt/lit.site.cfg.in +=================================================================== +--- /dev/null ++++ compiler-rt/test/crt/lit.site.cfg.in +@@ -0,0 +1,14 @@ ++@LIT_SITE_CFG_IN_HEADER@ ++ ++# Tool-specific config options. ++config.name_suffix = "@CRT_TEST_CONFIG_SUFFIX@" ++config.crt_lit_source_dir = "@CRT_LIT_SOURCE_DIR@" ++config.target_cflags = "@CRT_TEST_TARGET_CFLAGS@" ++config.target_arch = "@CRT_TEST_TARGET_ARCH@" ++config.sanitizer_cxx_lib = "@SANITIZER_TEST_CXX_LIBNAME@" ++ ++# Load common config for all compiler-rt lit tests ++lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") ++ ++# Load tool-specific config that would do the real work. ++lit_config.load_config(config, "@CRT_LIT_SOURCE_DIR@/lit.cfg") diff --git a/llvm/8/compiler-rt/default.nix b/llvm/8/compiler-rt/default.nix new file mode 100644 index 0000000..26cb5aa --- /dev/null +++ b/llvm/8/compiler-rt/default.nix @@ -0,0 +1,117 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + src = fetch "compiler-rt" "0dqqf8f930l8gag4d9qjgn1n0pj0nbv2anviqqhdi1rkhas8z0hi"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ]; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce + ../../common/compiler-rt/glibc.patch + ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./gnu-install-dirs.patch + ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch + ] ++ lib.optional (useLLVM) ./crtbegin-and-end.patch + ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; + }; +} diff --git a/llvm/8/compiler-rt/gnu-install-dirs.patch b/llvm/8/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..a25fa90 --- /dev/null +++ b/llvm/8/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,117 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index aa360a3ef36e..a39676148181 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -8,6 +8,7 @@ cmake_minimum_required(VERSION 3.4.3) + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + endif() +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index 81b110203c27..df7598a11caf 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -479,7 +479,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -496,7 +496,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index 04cc955980fa..a99f6dfb2f82 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -377,7 +377,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index 5348f2064b67..d7b8fe190789 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -363,7 +363,7 @@ endfunction() + function(get_compiler_rt_install_dir arch install_dir) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + get_compiler_rt_target(${arch} target) +- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/lib PARENT_SCOPE) ++ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/${CMAKE_INSTALL_FULL_LIBDIR} PARENT_SCOPE) + else() + set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + endif() +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index aeabf17653f5..0a927fbfc750 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -59,11 +59,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -91,7 +91,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + set(COMPILER_RT_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + endif() + + if(APPLE) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index c4b93b89a30c..3913dc3a1ee6 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -48,12 +48,12 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index b3ae713cf02c..52b364b900f5 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -54,4 +54,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}) diff --git a/llvm/8/default.nix b/llvm/8/default.nix new file mode 100644 index 0000000..5beb8af --- /dev/null +++ b/llvm/8/default.nix @@ -0,0 +1,287 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +}: + +let + release_version = "8.0.1"; + version = release_version; # differentiating these is important for rc's + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${release_version}/${name}-${version}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "1qf3097bc5ia8p6cpmbx985rjr3yaah5s8fc0nv7pw742yv7jw8q"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libllvm-polly = callPackage ./llvm { + inherit llvm_meta; + enablePolly = true; + }; + + llvm-polly = tools.libllvm-polly.lib // { outputSpecified = false; }; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + clang-polly-unwrapped = callPackage ./clang { + inherit llvm_meta; + inherit clang-tools-extra_src; + libllvm = tools.libllvm-polly; + enablePolly = true; + }; + + # disabled until recommonmark supports sphinx 3 + #llvm-manpages = lowPrio (tools.libllvm.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + #}); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ./lldb { + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/8/libcxx/default.nix b/llvm/8/libcxx/default.nix new file mode 100644 index 0000000..967d4b7 --- /dev/null +++ b/llvm/8/libcxx/default.nix @@ -0,0 +1,92 @@ +{ lib, stdenv, llvm_meta, fetch, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "0y4vc9z36c1zlq15cnibdzxnc1xi5glbc6klnm8a41q3db4541kz"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include" + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz" + postPatch = '' + substituteInPlace include/__config \ + --replace "# define _LIBCPP_USE_AVAILABILITY_APPLE" "" + ''; + + prePatch = '' + substituteInPlace lib/CMakeLists.txt --replace "/usr/lib/libc++" "\''${LIBCXX_LIBCXXABI_LIB_PATH}/libc++" + ''; + + preConfigure = '' + # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package + cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR") + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + nativeBuildInputs = [ cmake ] + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) python3 + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_LIBCPPABI_VERSION=2" + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (cxxabi.pname == "libcxxabi") "-DLIBCXX_LIBCXXABI_LIB_PATH=${cxxabi}/lib" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/8/libcxx/gnu-install-dirs.patch b/llvm/8/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..6af403a --- /dev/null +++ b/llvm/8/libcxx/gnu-install-dirs.patch @@ -0,0 +1,72 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 6b83bce1ae72..63cda3e4e80c 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,6 +26,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 8.0.1) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 1c19d7e01af7..9c8aee8e8bb7 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -59,7 +59,7 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 73f7cfc4d8e3..92cf0864ac7e 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -243,7 +243,7 @@ if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +@@ -252,7 +252,7 @@ if (LIBCXX_INSTALL_HEADERS) + if (LIBCXX_NEEDS_SITE_CONFIG) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT cxx-headers) +diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt +index 24489e8fb5e8..7327e5ee4b85 100644 +--- a/lib/CMakeLists.txt ++++ b/lib/CMakeLists.txt +@@ -414,8 +414,8 @@ if (LIBCXX_INSTALL_LIBRARY) + set(experimental_lib cxx_experimental) + endif() + install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${filesystem_lib} ${experimental_lib} +- LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx +- ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ++ LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx ++ ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx + ) + # NOTE: This install command must go after the cxx install command otherwise + # it will not be executed after the library symlinks are installed. +@@ -423,7 +423,7 @@ if (LIBCXX_INSTALL_LIBRARY) + # Replace the libc++ filename with $ + # after we required CMake 3.0. + install(FILES "${LIBCXX_LIBRARY_DIR}/libc++${CMAKE_SHARED_LIBRARY_SUFFIX}" +- DESTINATION ${LIBCXX_INSTALL_PREFIX}lib${LIBCXX_LIBDIR_SUFFIX} ++ DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} + COMPONENT libcxx) + endif() + endif() diff --git a/llvm/8/libcxxabi/default.nix b/llvm/8/libcxxabi/default.nix new file mode 100644 index 0000000..885d85b --- /dev/null +++ b/llvm/8/libcxxabi/default.nix @@ -0,0 +1,85 @@ +{ lib, stdenv, llvm_meta, cmake, fetch, libcxx, libunwind, llvm, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "1vznz8n1z1h8af0ga451m98lc2hjnv4fyzl71napsvjhvk4g6nxp"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + unpackFile ${llvm.src} + cmakeFlags+=" -DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)" + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch} + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d $(ls -d llvm-*) -i ${./wasm.patch} + ''; + + patches = [ + ../../common/libcxxabi/no-threads.patch + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/8/libcxxabi/gnu-install-dirs.patch b/llvm/8/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..3f924b0 --- /dev/null +++ b/llvm/8/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 92c7dc5dc557..556b3e05a042 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -20,6 +20,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 8.0.0) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 7e21fb2d7926..30711099a19c 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -220,8 +220,8 @@ add_custom_target(cxxabi DEPENDS ${LIBCXXABI_BUILD_TARGETS}) + + if (LIBCXXABI_INSTALL_LIBRARY) + install(TARGETS ${LIBCXXABI_INSTALL_TARGETS} +- LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi +- ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}lib${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi ++ LIBRARY DESTINATION ${LIBCXXABI_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi ++ ARCHIVE DESTINATION ${LIBCXXABI_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} COMPONENT cxxabi + ) + endif() + diff --git a/llvm/8/libunwind/default.nix b/llvm/8/libunwind/default.nix new file mode 100644 index 0000000..244b577 --- /dev/null +++ b/llvm/8/libunwind/default.nix @@ -0,0 +1,40 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, fetchpatch +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + src = fetch pname "0vhgcgzsb33l83qaikrkj87ypqb48mi607rccczccwiiv8ficw0q"; + + patches = [ + (fetchpatch { + url = "https://github.com/llvm-mirror/libunwind/commit/34a45c630d4c79af403661d267db42fbe7de1178.patch"; + sha256 = "0n0pv6jvcky8pn3srhrf9x5kbnd0d2kia9xlx2g590f5q0bgwfhv"; + }) + (fetchpatch { + url = "https://github.com/llvm-mirror/libunwind/commit/e050272d2eb57eb4e56a37b429a61df2ebb8aa3e.patch"; + sha256 = "1sxyx5xnax8k713jjcxgq3jq3cpnxygs2rcdf5vfja0f2k9jzldl"; + }) + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/8/libunwind/gnu-install-dirs.patch b/llvm/8/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..ffabba8 --- /dev/null +++ b/llvm/8/libunwind/gnu-install-dirs.patch @@ -0,0 +1,28 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 3d06073cfe74..55c7d1635fcd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -18,6 +18,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + project(libunwind) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(NOT LLVM_CONFIG_PATH) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index f7523f88b6ac..4060dad214de 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -151,8 +151,8 @@ add_custom_target(unwind DEPENDS ${LIBUNWIND_BUILD_TARGETS}) + + if (LIBUNWIND_INSTALL_LIBRARY) + install(TARGETS ${LIBUNWIND_INSTALL_TARGETS} +- LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind +- ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}lib${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind) ++ LIBRARY DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind ++ ARCHIVE DESTINATION ${LIBUNWIND_INSTALL_PREFIX}${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} COMPONENT unwind) + endif() + + if (NOT CMAKE_CONFIGURATION_TYPES AND LIBUNWIND_INSTALL_LIBRARY) diff --git a/llvm/8/lld/default.nix b/llvm/8/lld/default.nix new file mode 100644 index 0000000..9a3a49d --- /dev/null +++ b/llvm/8/lld/default.nix @@ -0,0 +1,46 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "121xhxrlvwy3k5nf6p1wv31whxlb635ssfkci8z93mwv4ja1xflz"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/8/lld/gnu-install-dirs.patch b/llvm/8/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..acc2d3d --- /dev/null +++ b/llvm/8/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index e2fbdbfbbb47..d601b231ebb8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -203,7 +205,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index fa48b428d26b..e7967aad3ceb 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index d8829493fc22..df748a0e749b 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -16,7 +16,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE lld-link ld.lld ld64.lld wasm-ld) diff --git a/llvm/8/lldb/default.nix b/llvm/8/lldb/default.nix new file mode 100644 index 0000000..4e8cdcd --- /dev/null +++ b/llvm/8/lldb/default.nix @@ -0,0 +1,109 @@ +{ lib, stdenv, llvm_meta +, fetch +, cmake +, zlib +, ncurses +, swig +, which +, libedit +, libxml2 +, libllvm +, libclang +, python3 +, version +, darwin +, makeWrapper +}: + +stdenv.mkDerivation rec { + pname = "lldb"; + inherit version; + + src = fetch "lldb" "1mriw4adrwm6kzabrjr7yqmdiylxd6glf6samd80dp8idnm9p9z8"; + + patches = [ + ./gnu-install-dirs.patch + + # Fix darwin build + ./lldb-gdb-remote-no-libcompress.patch + ]; + + postPatch = '' + # Fix up various paths that assume llvm and clang are installed in the same place + sed -i 's,".*ClangConfig.cmake","${libclang.dev}/lib/cmake/clang/ClangConfig.cmake",' \ + cmake/modules/LLDBStandalone.cmake + sed -i 's,".*tools/clang/include","${libclang.dev}/include",' \ + cmake/modules/LLDBStandalone.cmake + sed -i 's,"$.LLVM_LIBRARY_DIR.",${libllvm.lib}/lib ${libclang.lib}/lib,' \ + cmake/modules/LLDBStandalone.cmake + + substituteInPlace tools/CMakeLists.txt \ + --replace "add_subdirectory(debugserver)" "" + ''; + + outputs = [ "out" "lib" "dev" ]; + + nativeBuildInputs = [ + cmake python3 which swig makeWrapper + ]; + + buildInputs = [ + ncurses zlib libedit libxml2 libllvm + ] ++ lib.optionals stdenv.isDarwin [ + darwin.libobjc + darwin.apple_sdk.libs.xpc + darwin.apple_sdk.frameworks.Foundation + darwin.bootstrap_cmds + darwin.apple_sdk.frameworks.Carbon + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.DebugSymbols + ]; + + CXXFLAGS = "-fno-rtti"; + hardeningDisable = [ "format" ]; + + cmakeFlags = [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + ] ++ lib.optionals stdenv.isDarwin [ + # Building debugserver requires the proprietary libcompression + "-DLLDB_NO_DEBUGSERVER=ON" + ] ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ]; + + doCheck = false; + + doInstallCheck = true; + + installCheckPhase = '' + if [ ! -e "$lib/${python3.sitePackages}/lldb/_lldb.so" ] ; then + echo "ERROR: python files not installed where expected!"; + return 1; + fi + ''; + + postInstall = '' + wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/ + + mkdir -p $out/share/man/man1 + cp ../docs/lldb.1 $out/share/man/man1/ + + install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json + mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ln -s $out/bin/llvm-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ''; + + meta = llvm_meta // { + broken = stdenv.isDarwin && stdenv.isAarch64; + homepage = "https://lldb.llvm.org/"; + description = "A next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + }; +} diff --git a/llvm/8/lldb/gnu-install-dirs.patch b/llvm/8/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..08b6fae --- /dev/null +++ b/llvm/8/lldb/gnu-install-dirs.patch @@ -0,0 +1,120 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cdf22c4b0fc8..8def776f2b4a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -7,6 +7,8 @@ set(CMAKE_MODULE_PATH + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules" + ) + ++include(GNUInstallDirs) ++ + include(LLDBStandalone) + include(LLDBConfig) + include(AddLLDB) +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index f82c11d3d317..776e6d6ef9de 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -63,18 +63,18 @@ function(add_lldb_library name) + set(install_dir ".") + endif() + else() +- set(install_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + install(TARGETS ${name} + COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${install_dir} + ARCHIVE DESTINATION ${install_dir}) + else() + install(TARGETS ${name} + COMPONENT ${name} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -122,7 +122,7 @@ function(add_lldb_executable name) + if(ARG_GENERATE_INSTALL) + install(TARGETS ${name} + COMPONENT ${name} +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + if (NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} + DEPENDS ${name} +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index 109c5132d3be..8b9092faa29d 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -319,7 +319,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +@@ -329,7 +329,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index b5316540fdf3..3c3c882d503f 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -64,4 +64,4 @@ if (NOT LLDB_DISABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cdf22c4..d56fc6a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -146,7 +146,7 @@ if (NOT LLDB_DISABLE_PYTHON) + --cfgBldDir=${lldb_scripts_dir} + --prefix=${CMAKE_BINARY_DIR} + --cmakeBuildConfiguration=${CMAKE_CFG_INTDIR} +- --lldbLibDir=lib${LLVM_LIBDIR_SUFFIX} ++ --lldbLibDir=${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} + ${use_python_wrapper_from_src_dir} + ${use_six_py_from_system} + VERBATIM +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index a9059dd..d76a47d 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -124,7 +124,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + link_directories("${LLVM_LIBRARY_DIR}") + + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +- set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/lib${LLVM_LIBDIR_SUFFIX}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) + + set(LLDB_BUILT_STANDALONE 1) +diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt +index 3598247..bd60451 100644 +--- a/scripts/CMakeLists.txt ++++ b/scripts/CMakeLists.txt +@@ -47,7 +47,7 @@ if(NOT LLDB_BUILD_FRAMEWORK) + endif() + + set(SWIG_PYTHON_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${swig_python_subdir}) +- set(SWIG_INSTALL_DIR lib${LLVM_LIBDIR_SUFFIX}) ++ set(SWIG_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + + # Install the LLDB python module + install(DIRECTORY ${SWIG_PYTHON_DIR} DESTINATION ${SWIG_INSTALL_DIR}) diff --git a/llvm/8/lldb/lldb-gdb-remote-no-libcompress.patch b/llvm/8/lldb/lldb-gdb-remote-no-libcompress.patch new file mode 100644 index 0000000..e04d4ff --- /dev/null +++ b/llvm/8/lldb/lldb-gdb-remote-no-libcompress.patch @@ -0,0 +1,30 @@ +diff -ru a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp +--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp 2019-01-09 19:46:09.000000000 -0500 ++++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunication.cpp 2021-11-27 00:23:08.000000000 -0500 +@@ -42,11 +42,6 @@ + #define DEBUGSERVER_BASENAME "lldb-server" + #endif + +-#if defined(__APPLE__) +-#define HAVE_LIBCOMPRESSION +-#include +-#endif +- + #if defined(HAVE_LIBZ) + #include + #endif +diff -ru a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 2018-12-18 18:02:50.000000000 -0500 ++++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 2021-11-27 00:09:07.000000000 -0500 +@@ -37,11 +37,6 @@ + + #include "llvm/ADT/StringSwitch.h" + +-#if defined(__APPLE__) +-#define HAVE_LIBCOMPRESSION +-#include +-#endif +- + using namespace lldb; + using namespace lldb_private; + using namespace lldb_private::process_gdb_remote; diff --git a/llvm/8/llvm/default.nix b/llvm/8/llvm/default.nix new file mode 100644 index 0000000..8a0fea8 --- /dev/null +++ b/llvm/8/llvm/default.nix @@ -0,0 +1,319 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitVersion release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch "llvm" "1rvm5gqp5v8hfn17kqws3zhk94w4kxndal12bqa0y57p09nply24"; + polly_src = fetch "polly" "1lfjdz3ilj5xmjxvicd8f5ykybks67ry2pdb777352r3mzlgg8g8"; + + unpackPhase = '' + unpackFile $src + mv llvm-${version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + patches = [ + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + # Fix missing includes for GCC 10 + (fetchpatch { + url = "https://bugs.gentoo.org/attachment.cgi?id=612792"; + sha256 = "0rwx6jpqq4xnf4mvfm8v2d4r34y1yi05am0mx5k2d5bha9j64lqg"; + }) + ./gnu-install-dirs.patch + + # Fix missing includes for GCC 11 + (fetchpatch { + name = "headers-gcc-11.patch"; + url = "https://github.com/llvm/llvm-project/commit/b498303066a63a203d24f739b2d2e0e56dca70d1.patch"; + sha256 = "0nh123kld0dgz2h941lng331dkj3wbm5lfxm375k1f569gv83hlk"; + stripLen = 1; + }) + + # Fix invalid std::string(nullptr) for GCC 12 + (fetchpatch { + name = "nvptx-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/99e64623ec9b31def9375753491cc6093c831809.patch"; + sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; + stripLen = 1; + }) + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals (isDarwin) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/8/llvm/gnu-install-dirs-polly.patch b/llvm/8/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..7c477c7 --- /dev/null +++ b/llvm/8/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,106 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index 9939097f743e..8cc538da912a 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.4.3) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -145,14 +149,14 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 211f95512717..f9e04a4844b6 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index e48203871884..5bc8a2a52541 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8ffd984e542b..261cc19f3238 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -274,7 +274,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/8/llvm/gnu-install-dirs.patch b/llvm/8/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..027e43f --- /dev/null +++ b/llvm/8/llvm/gnu-install-dirs.patch @@ -0,0 +1,394 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 81c2bab39ec9..075e68be6125 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -251,15 +251,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -517,9 +523,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -956,7 +962,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -968,7 +974,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -983,13 +989,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 1a417447278b..0c2aef338078 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -646,11 +646,11 @@ macro(add_llvm_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO" OR + ${name} STREQUAL "OptRemarks" OR + (LLVM_LINK_LLVM_DYLIB AND ${name} STREQUAL "LLVM")) +- set(install_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(ARG_MODULE OR ARG_SHARED OR BUILD_SHARED_LIBS) + if(WIN32 OR CYGWIN OR MINGW) + set(install_type RUNTIME) +- set(install_dir bin) ++ set(install_dir ${CMAKE_INSTALL_BINDIR}) + else() + set(install_type LIBRARY) + endif() +@@ -898,7 +898,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1442,7 +1442,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1458,7 +1458,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1481,7 +1481,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1563,7 +1563,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -1670,9 +1671,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 02bab6846376..eff26adb2efc 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -140,9 +140,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index 22e3dcb776aa..ba77b9c195e2 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -73,7 +73,7 @@ function (add_sphinx_target builder project) + + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index f5cc0006fa06..77698aeaf000 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -90,11 +90,11 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") + set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}") + configure_file( +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 1a04de931ff7..1c5ea4200635 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message("Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index eb219c58560b..6f32532f8ebf 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -479,8 +479,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -511,13 +511,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + OS X Only: If enabled CMake will generate a target named +@@ -691,9 +711,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index 1d5ca3ba92b0..026f5453c1da 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -4,5 +4,5 @@ add_subdirectory(Support) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index f201e1f7bff0..4582ed556a02 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -24,6 +24,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index bec89fef98ca..31d78f925d45 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -333,12 +333,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = path.str(); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index 6e913519a809..85641eef721f 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -19,7 +19,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lto.exports) + add_llvm_library(LTO SHARED ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-remarks/CMakeLists.txt b/tools/opt-remarks/CMakeLists.txt +index a87beae1e893..149ea3d10168 100644 +--- a/tools/opt-remarks/CMakeLists.txt ++++ b/tools/opt-remarks/CMakeLists.txt +@@ -11,7 +11,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/OptRemarks.exports) + add_llvm_library(OptRemarks SHARED ${SOURCES}) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/OptRemarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT OptRemarks) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index 19b606933082..27b9f71b3d79 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,6 +8,6 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) diff --git a/llvm/8/openmp/default.nix b/llvm/8/openmp/default.nix new file mode 100644 index 0000000..32b564f --- /dev/null +++ b/llvm/8/openmp/default.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation { + pname = "openmp"; + inherit version; + + src = fetch "openmp" "0b3jlxhqbpyd1nqkpxjfggm5d9va5qpyf7d4i5y7n4a1mlydv19y"; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/9/clang/HIP-use-PATH-9.patch b/llvm/9/clang/HIP-use-PATH-9.patch new file mode 100644 index 0000000..102d810 --- /dev/null +++ b/llvm/9/clang/HIP-use-PATH-9.patch @@ -0,0 +1,80 @@ +From 7147e9774c74abcd1d6db24e24d0fd989c2b97dd Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Holger=20W=C3=BCnsche?= +Date: Tue, 21 Jan 2020 19:52:04 +0100 +Subject: [PATCH] [HIP] use GetProgramPath for executable discovery + +This change replaces the manual building of executable paths +using llvm::sys::path::append with GetProgramPath. +This enables adding other paths in case executables reside +in different directories and makes the code easier to read. + +Differential Revision: https://reviews.llvm.org/D72903 +--- + clang/lib/Driver/ToolChains/HIP.cpp | 23 ++++++++--------------- + 1 file changed, 8 insertions(+), 15 deletions(-) + +diff --git a/lib/Driver/ToolChains/HIP.cpp b/lib/Driver/ToolChains/HIP.cpp +index 2ec97e798fd..735c302debb 100644 +--- a/lib/Driver/ToolChains/HIP.cpp ++++ b/lib/Driver/ToolChains/HIP.cpp +@@ -66,9 +66,8 @@ const char *AMDGCN::Linker::constructLLVMLinkCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpName)); + CmdArgs.push_back(OutputFileName); +- SmallString<128> ExecPath(C.getDriver().Dir); +- llvm::sys::path::append(ExecPath, "llvm-link"); +- const char *Exec = Args.MakeArgString(ExecPath); ++ const char *Exec = ++ Args.MakeArgString(getToolChain().GetProgramPath("llvm-link")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); + return OutputFileName; + } +@@ -114,9 +113,8 @@ const char *AMDGCN::Linker::constructOptCommand( + const char *OutputFileName = + C.addTempFile(C.getArgs().MakeArgString(TmpFileName)); + OptArgs.push_back(OutputFileName); +- SmallString<128> OptPath(C.getDriver().Dir); +- llvm::sys::path::append(OptPath, "opt"); +- const char *OptExec = Args.MakeArgString(OptPath); ++ const char *OptExec = ++ Args.MakeArgString(getToolChain().GetProgramPath("opt")); + C.addCommand(llvm::make_unique(JA, *this, OptExec, OptArgs, Inputs)); + return OutputFileName; + } +@@ -156,9 +154,7 @@ const char *AMDGCN::Linker::constructLlcCommand( + const char *LlcOutputFile = + C.addTempFile(C.getArgs().MakeArgString(LlcOutputFileName)); + LlcArgs.push_back(LlcOutputFile); +- SmallString<128> LlcPath(C.getDriver().Dir); +- llvm::sys::path::append(LlcPath, "llc"); +- const char *Llc = Args.MakeArgString(LlcPath); ++ const char *Llc = Args.MakeArgString(getToolChain().GetProgramPath("llc")); + C.addCommand(llvm::make_unique(JA, *this, Llc, LlcArgs, Inputs)); + return LlcOutputFile; + } +@@ -172,9 +168,7 @@ void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA, + // The output from ld.lld is an HSA code object file. + ArgStringList LldArgs{ + "-flavor", "gnu", "-shared", "-o", Output.getFilename(), InputFileName}; +- SmallString<128> LldPath(C.getDriver().Dir); +- llvm::sys::path::append(LldPath, "lld"); +- const char *Lld = Args.MakeArgString(LldPath); ++ const char *Lld = Args.MakeArgString(getToolChain().GetProgramPath("lld")); + C.addCommand(llvm::make_unique(JA, *this, Lld, LldArgs, Inputs)); + } + +@@ -206,9 +200,8 @@ void AMDGCN::constructHIPFatbinCommand(Compilation &C, const JobAction &JA, + Args.MakeArgString(std::string("-outputs=").append(OutputFileName)); + BundlerArgs.push_back(BundlerOutputArg); + +- SmallString<128> BundlerPath(C.getDriver().Dir); +- llvm::sys::path::append(BundlerPath, "clang-offload-bundler"); +- const char *Bundler = Args.MakeArgString(BundlerPath); ++ const char *Bundler = Args.MakeArgString( ++ T.getToolChain().GetProgramPath("clang-offload-bundler")); + C.addCommand(llvm::make_unique(JA, T, Bundler, BundlerArgs, Inputs)); + } + +-- +2.23.1 + diff --git a/llvm/9/clang/compiler-rt-baremetal.patch b/llvm/9/clang/compiler-rt-baremetal.patch new file mode 100644 index 0000000..a4a0f21 --- /dev/null +++ b/llvm/9/clang/compiler-rt-baremetal.patch @@ -0,0 +1,53 @@ +Index: lib/Driver/ToolChains/BareMetal.cpp +=================================================================== +--- a/lib/Driver/ToolChains/BareMetal.cpp ++++ b/lib/Driver/ToolChains/BareMetal.cpp +@@ -157,7 +157,7 @@ + void BareMetal::AddLinkRuntimeLib(const ArgList &Args, + ArgStringList &CmdArgs) const { + CmdArgs.push_back(Args.MakeArgString("-lclang_rt.builtins-" + +- getTriple().getArchName() + ".a")); ++ getTriple().getArchName())); + } + + void baremetal::Linker::ConstructJob(Compilation &C, const JobAction &JA, +Index: test/Driver/baremetal.cpp +=================================================================== +--- a/test/Driver/baremetal.cpp ++++ b/test/Driver/baremetal.cpp +@@ -13,7 +13,7 @@ + // CHECK-V6M-C-NEXT: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-C-SAME: "-L[[RESOURCE_DIR:[^"]+]]{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-C-SAME: "-T" "semihosted.lds" "-Lsome{{[/\\]+}}directory{{[/\\]+}}user{{[/\\]+}}asked{{[/\\]+}}for" +-// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-C-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-C-SAME: "-o" "{{.*}}.o" + + // RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -35,7 +35,7 @@ + // CHECK-V6M-DEFAULTCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-DEFAULTCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-DEFAULTCXX-SAME: "-lc++" "-lc++abi" "-lunwind" +-// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-DEFAULTCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-DEFAULTCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -48,7 +48,7 @@ + // CHECK-V6M-LIBCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-LIBCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-LIBCXX-SAME: "-lc++" "-lc++abi" "-lunwind" +-// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-LIBCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-LIBCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ +@@ -61,7 +61,7 @@ + // CHECK-V6M-LIBSTDCXX: "{{[^"]*}}ld{{(\.(lld|bfd|gold))?}}{{(\.exe)?}}" "{{.*}}.o" "-Bstatic" + // CHECK-V6M-LIBSTDCXX-SAME: "-L{{[^"]*}}{{[/\\]+}}lib{{(64)?}}{{[/\\]+}}clang{{[/\\]+}}{{.*}}{{[/\\]+}}lib{{[/\\]+}}baremetal" + // CHECK-V6M-LIBSTDCXX-SAME: "-lstdc++" "-lsupc++" "-lunwind" +-// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m.a" ++// CHECK-V6M-LIBSTDCXX-SAME: "-lc" "-lm" "-lclang_rt.builtins-armv6m" + // CHECK-V6M-LIBSTDCXX-SAME: "-o" "{{.*}}.o" + + // RUN: %clangxx -no-canonical-prefixes %s -### -o %t.o 2>&1 \ diff --git a/llvm/9/clang/default.nix b/llvm/9/clang/default.nix new file mode 100644 index 0000000..75814fc --- /dev/null +++ b/llvm/9/clang/default.nix @@ -0,0 +1,140 @@ +{ lib, stdenv, llvm_meta, fetch, substituteAll, cmake, libxml2, libllvm, version, clang-tools-extra_src, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +, enablePolly ? false # TODO: get this info from llvm (passthru?) +}: + +let + self = stdenv.mkDerivation ({ + pname = "clang"; + inherit version; + + src = fetch "clang" "0ls2h3iv4finqyflyhry21qhc9cm9ga7g1zq21020p065qmm2y2p"; + + unpackPhase = '' + unpackFile $src + mv clang-${version}* clang + sourceRoot=$PWD/clang + unpackFile ${clang-tools-extra_src} + mv clang-tools-extra-* $sourceRoot/tools/extra + ''; + + nativeBuildInputs = [ cmake python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCMAKE_CXX_FLAGS=-std=c++11" + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + ] ++ lib.optionals enablePolly [ + "-DWITH_POLLY=ON" + "-DLINK_POLLY_INTO_TOOLS=ON" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./compiler-rt-baremetal.patch + # make clang -xhip use $PATH to find executables + ./HIP-use-PATH-9.patch + ./gnu-install-dirs.patch + (substituteAll { + src = ../../clang-6-10-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + sed -i -e 's/DriverArgs.hasArg(options::OPT_nostdlibinc)/true/' \ + -e 's/Args.hasArg(options::OPT_nostdlibinc)/true/' \ + lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + '' + lib.optionalString stdenv.hostPlatform.isDarwin '' + substituteInPlace tools/extra/clangd/CMakeLists.txt \ + --replace "NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB" FALSE + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $out/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/clang-tblgen $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + buildPhase = '' + make docs-clang-man + ''; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/9/clang/gnu-install-dirs.patch b/llvm/9/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..625cbcc --- /dev/null +++ b/llvm/9/clang/gnu-install-dirs.patch @@ -0,0 +1,278 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 60937aa9db38..45522ff32998 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -9,6 +9,8 @@ endif() + if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR ) + project(Clang) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(LLVM_CONFIG) +@@ -413,7 +415,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/clang include/clang-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "*.def" +@@ -423,7 +425,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/clang +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT clang-headers + FILES_MATCHING + PATTERN "CMakeFiles" EXCLUDE +@@ -442,7 +444,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + endif() + + install(PROGRAMS utils/bash-autocomplete.sh +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + ) + endif() + +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index cbd618e18afb..63ba43f18e64 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -109,9 +109,9 @@ macro(add_clang_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -155,7 +155,7 @@ macro(add_clang_tool name) + + install(TARGETS ${name} + ${export_to_clangtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT LLVM_ENABLE_IDE) +@@ -170,7 +170,7 @@ endmacro() + macro(add_clang_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() + + function(clang_target_link_libraries target type) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index a3c0b08fa364..aa4215c0999c 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -185,7 +185,7 @@ set_target_properties(clang-resource-headers PROPERTIES + FOLDER "Misc" + RUNTIME_OUTPUT_DIRECTORY "${output_dir}") + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + install( + FILES ${files} ${generated_files} +diff --git a/tools/c-index-test/CMakeLists.txt b/tools/c-index-test/CMakeLists.txt +index ceef4b08637c..8efad5520ca4 100644 +--- a/tools/c-index-test/CMakeLists.txt ++++ b/tools/c-index-test/CMakeLists.txt +@@ -54,7 +54,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + set_property(TARGET c-index-test APPEND PROPERTY INSTALL_RPATH + "@executable_path/../../lib") + else() +- set(INSTALL_DESTINATION bin) ++ set(INSTALL_DESTINATION ${CMAKE_INSTALL_BINDIR}) + endif() + + install(TARGETS c-index-test +diff --git a/tools/clang-check/CMakeLists.txt b/tools/clang-check/CMakeLists.txt +index 4576d78bcfb4..7c3b302d8d59 100644 +--- a/tools/clang-check/CMakeLists.txt ++++ b/tools/clang-check/CMakeLists.txt +@@ -21,4 +21,4 @@ clang_target_link_libraries(clang-check + ) + + install(TARGETS clang-check +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-extdef-mapping/CMakeLists.txt b/tools/clang-extdef-mapping/CMakeLists.txt +index 4798bdb71ad0..02d07b9982ac 100644 +--- a/tools/clang-extdef-mapping/CMakeLists.txt ++++ b/tools/clang-extdef-mapping/CMakeLists.txt +@@ -18,4 +18,4 @@ clang_target_link_libraries(clang-extdef-mapping + ) + + install(TARGETS clang-extdef-mapping +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-format/CMakeLists.txt b/tools/clang-format/CMakeLists.txt +index 35ecdb11253c..d77d75de0094 100644 +--- a/tools/clang-format/CMakeLists.txt ++++ b/tools/clang-format/CMakeLists.txt +@@ -21,20 +21,20 @@ if( LLVM_LIB_FUZZING_ENGINE OR LLVM_USE_SANITIZE_COVERAGE ) + endif() + + install(PROGRAMS clang-format-bbedit.applescript +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-diff.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format-sublime.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS clang-format.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-format) + install(PROGRAMS git-clang-format +- DESTINATION bin ++ DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT clang-format) +diff --git a/tools/clang-offload-bundler/CMakeLists.txt b/tools/clang-offload-bundler/CMakeLists.txt +index 465bef040a6c..729369ed9429 100644 +--- a/tools/clang-offload-bundler/CMakeLists.txt ++++ b/tools/clang-offload-bundler/CMakeLists.txt +@@ -22,4 +22,4 @@ clang_target_link_libraries(clang-offload-bundler + ${CLANG_OFFLOAD_BUNDLER_LIB_DEPS} + ) + +-install(TARGETS clang-offload-bundler RUNTIME DESTINATION bin) ++install(TARGETS clang-offload-bundler RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +diff --git a/tools/clang-rename/CMakeLists.txt b/tools/clang-rename/CMakeLists.txt +index cda8e29ec5b1..0134d8ccd70b 100644 +--- a/tools/clang-rename/CMakeLists.txt ++++ b/tools/clang-rename/CMakeLists.txt +@@ -19,8 +19,8 @@ clang_target_link_libraries(clang-rename + ) + + install(PROGRAMS clang-rename.py +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) + install(PROGRAMS clang-rename.el +- DESTINATION share/clang ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/clang + COMPONENT clang-rename) +diff --git a/tools/diagtool/CMakeLists.txt b/tools/diagtool/CMakeLists.txt +index a95444be40ee..136d96d9bf5b 100644 +--- a/tools/diagtool/CMakeLists.txt ++++ b/tools/diagtool/CMakeLists.txt +@@ -21,7 +21,7 @@ clang_target_link_libraries(diagtool + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(TARGETS diagtool + COMPONENT diagtool +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-diagtool +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 613ead1a36b6..e5c7bf27f739 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -137,7 +137,7 @@ endif() + if(INTERNAL_INSTALL_PREFIX) + set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include") + else() +- set(LIBCLANG_HEADERS_INSTALL_DESTINATION include) ++ set(LIBCLANG_HEADERS_INSTALL_DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + endif() + + install(DIRECTORY ../../include/clang-c +@@ -168,7 +168,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build/CMakeLists.txt b/tools/scan-build/CMakeLists.txt +index 380379300b09..adfd58ed5f7d 100644 +--- a/tools/scan-build/CMakeLists.txt ++++ b/tools/scan-build/CMakeLists.txt +@@ -41,7 +41,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(LibexecFile ${LibexecFiles}) +@@ -53,7 +53,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/libexec/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/libexec/${LibexecFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/libexec/${LibexecFile}) +- install(PROGRAMS libexec/${LibexecFile} DESTINATION libexec) ++ install(PROGRAMS libexec/${LibexecFile} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) + endforeach() + + foreach(ManPage ${ManPages}) +@@ -77,7 +77,7 @@ if(CLANG_INSTALL_SCANBUILD) + ${CMAKE_BINARY_DIR}/share/scan-build/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/scan-build/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-build/${ShareFile}) +- install(FILES share/scan-build/${ShareFile} DESTINATION share/scan-build) ++ install(FILES share/scan-build/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-build) + endforeach() + + add_custom_target(scan-build ALL DEPENDS ${Depends}) +diff --git a/tools/scan-view/CMakeLists.txt b/tools/scan-view/CMakeLists.txt +index b305ca562a72..554bcb379061 100644 +--- a/tools/scan-view/CMakeLists.txt ++++ b/tools/scan-view/CMakeLists.txt +@@ -21,7 +21,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/bin/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/bin/${BinFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/bin/${BinFile}) +- install(PROGRAMS bin/${BinFile} DESTINATION bin) ++ install(PROGRAMS bin/${BinFile} DESTINATION ${CMAKE_INSTALL_BINDIR}) + endforeach() + + foreach(ShareFile ${ShareFiles}) +@@ -33,7 +33,7 @@ if(CLANG_INSTALL_SCANVIEW) + ${CMAKE_BINARY_DIR}/share/scan-view/ + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/share/${ShareFile}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/share/scan-view/${ShareFile}) +- install(FILES share/${ShareFile} DESTINATION share/scan-view) ++ install(FILES share/${ShareFile} DESTINATION ${CMAKE_INSTALL_DATADIR}/scan-view) + endforeach() + + add_custom_target(scan-view ALL DEPENDS ${Depends}) +diff --git a/utils/hmaptool/CMakeLists.txt b/utils/hmaptool/CMakeLists.txt +index 5573009d343a..24b3a90f233f 100644 +--- a/utils/hmaptool/CMakeLists.txt ++++ b/utils/hmaptool/CMakeLists.txt +@@ -9,7 +9,7 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HM + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}) + + list(APPEND Depends ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}) +-install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION bin) ++install(PROGRAMS ${CLANG_HMAPTOOL} DESTINATION ${CMAKE_INSTALL_BINDIR}) + + add_custom_target(hmaptool ALL DEPENDS ${Depends}) + set_target_properties(hmaptool PROPERTIES FOLDER "Utils") diff --git a/llvm/9/clang/purity.patch b/llvm/9/clang/purity.patch new file mode 100644 index 0000000..a6729a9 --- /dev/null +++ b/llvm/9/clang/purity.patch @@ -0,0 +1,30 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!IsStatic) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE) { +- const std::string Loader = +- D.DyldPrefix + ToolChain.getDynamicLinker(Args); +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Loader)); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 + diff --git a/llvm/9/compiler-rt/armv7l.patch b/llvm/9/compiler-rt/armv7l.patch new file mode 100644 index 0000000..89d7f1a --- /dev/null +++ b/llvm/9/compiler-rt/armv7l.patch @@ -0,0 +1,38 @@ +diff -ur compiler-rt-7.1.0.src/cmake/builtin-config-ix.cmake compiler-rt-7.1.0.src-patched/cmake/builtin-config-ix.cmake +--- compiler-rt-7.1.0.src/cmake/builtin-config-ix.cmake 2018-05-25 06:36:27.000000000 +0900 ++++ compiler-rt-7.1.0.src-patched/cmake/builtin-config-ix.cmake 2020-05-09 20:26:33.030608692 +0900 +@@ -24,7 +24,7 @@ + + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur compiler-rt-7.1.0.src/lib/builtins/CMakeLists.txt compiler-rt-7.1.0.src-patched/lib/builtins/CMakeLists.txt +--- compiler-rt-7.1.0.src/lib/builtins/CMakeLists.txt 2018-07-31 03:18:59.000000000 +0900 ++++ compiler-rt-7.1.0.src-patched/lib/builtins/CMakeLists.txt 2020-05-09 20:27:38.893409318 +0900 +@@ -453,6 +453,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -563,12 +564,12 @@ + set(_arch ${arch}) + if("${arch}" STREQUAL "armv6m") + set(_arch "arm|armv6m") +- elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ elseif("${arch}" MATCHES "^(armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + set(_arch "arm") + endif() + + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/9/compiler-rt/default.nix b/llvm/9/compiler-rt/default.nix new file mode 100644 index 0000000..d03fcbc --- /dev/null +++ b/llvm/9/compiler-rt/default.nix @@ -0,0 +1,120 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, python3, libllvm, libcxxabi +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + +in + +stdenv.mkDerivation { + pname = "compiler-rt" + lib.optionalString (haveLibc) "-libc"; + inherit version; + src = fetch "compiler-rt" "0xwh79g3zggdabxgnd0bphry75asm1qz7mv3hcqihqwqr6aspgy2"; + + nativeBuildInputs = [ cmake python3 libllvm.dev ]; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM || bareMetal) && !haveLibc) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + # The compiler-rt build infrastructure sniffs supported platforms on Darwin + # and finds i386;x86_64;x86_64h. We only build for x86_64, so linking fails + # when it tries to use libc++ and libc++api for i386. + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + ]; + + outputs = [ "out" "dev" ]; + + patches = [ + # https://github.com/llvm/llvm-project/commit/947f9692440836dcb8d88b74b69dd379d85974ce + ../../common/compiler-rt/glibc.patch + ../../common/compiler-rt/7-12-codesign.patch # Revert compiler-rt commit that makes codesign mandatory + ./gnu-install-dirs.patch + ../../common/compiler-rt/libsanitizer-no-cyclades-9.patch + # Fix build on armv6l + ../../common/compiler-rt/armv6-mcr-dmb.patch + ../../common/compiler-rt/armv6-sync-ops-no-thumb.patch + ../../common/compiler-rt/armv6-no-ldrexd-strexd.patch + ] ++ lib.optional stdenv.hostPlatform.isAarch32 ./armv7l.patch; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + broken = stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64; + }; +} diff --git a/llvm/9/compiler-rt/gnu-install-dirs.patch b/llvm/9/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..9f63bef --- /dev/null +++ b/llvm/9/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,117 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f26ae25ada30..8ba536afdccc 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -12,6 +12,7 @@ endif() + # Check if compiler-rt is built as a standalone project. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD) + project(CompilerRT C CXX ASM) ++ include(GNUInstallDirs) + set(COMPILER_RT_STANDALONE_BUILD TRUE) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) + endif() +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index f7ee932f214f..ef94a97c4be9 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -488,7 +488,7 @@ macro(add_compiler_rt_resource_file target_name file_name component) + add_custom_target(${target_name} DEPENDS ${dst_file}) + # Install in Clang resource directory. + install(FILES ${file_name} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR} + COMPONENT ${component}) + add_dependencies(${component} ${target_name}) + +@@ -505,7 +505,7 @@ macro(add_compiler_rt_script name) + add_custom_target(${name} DEPENDS ${dst}) + install(FILES ${dst} + PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_BINDIR}) + endmacro(add_compiler_rt_script src name) + + # Builds custom version of libc++ and installs it in . +diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake +index b50d55b56940..7e5729ad9c8e 100644 +--- a/cmake/Modules/CompilerRTDarwinUtils.cmake ++++ b/cmake/Modules/CompilerRTDarwinUtils.cmake +@@ -386,7 +386,7 @@ macro(darwin_add_embedded_builtin_libraries) + set(DARWIN_macho_embedded_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/macho_embedded) + set(DARWIN_macho_embedded_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/macho_embedded) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/macho_embedded) + + set(CFLAGS_armv7 "-target thumbv7-apple-darwin-eabi") + set(CFLAGS_i386 "-march=pentium") +diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake +index 6e672b1e1818..64999709958e 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -371,7 +371,7 @@ endfunction() + function(get_compiler_rt_install_dir arch install_dir) + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + get_compiler_rt_target(${arch} target) +- set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/lib/${target} PARENT_SCOPE) ++ set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${target} PARENT_SCOPE) + else() + set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE) + endif() +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index cef0e0d73d87..db33fb028287 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -55,11 +55,11 @@ if (LLVM_TREE_AVAILABLE) + else() + # Take output dir and install path from the user. + set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH +- "Path where built compiler-rt libraries should be stored.") ++ "Path where built compiler-rt build artifacts should be stored.") + set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH + "Path where built compiler-rt executables should be stored.") +- set(COMPILER_RT_INSTALL_PATH ${CMAKE_INSTALL_PREFIX} CACHE PATH +- "Path where built compiler-rt libraries should be installed.") ++ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH ++ "Prefix where built compiler-rt artifacts should be installed, comes before CMAKE_INSTALL_PREFIX.") + option(COMPILER_RT_INCLUDE_TESTS "Generate and build compiler-rt unit tests." OFF) + option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) + # Use a host compiler to compile/link tests. +@@ -87,7 +87,7 @@ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR) + set(COMPILER_RT_LIBRARY_OUTPUT_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) + set(COMPILER_RT_LIBRARY_INSTALL_DIR +- ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR}) ++ ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_LIBDIR}/${COMPILER_RT_OS_DIR}) + endif() + + if(APPLE) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 38bd6e41a912..2092d0d08247 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -50,12 +50,12 @@ set_target_properties(compiler-rt-headers PROPERTIES FOLDER "Compiler-RT Misc") + install(FILES ${SANITIZER_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/sanitizer) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/sanitizer) + # Install xray headers. + install(FILES ${XRAY_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_INCLUDEDIR}/xray) + + if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. + add_custom_target(install-compiler-rt-headers +diff --git a/lib/dfsan/CMakeLists.txt b/lib/dfsan/CMakeLists.txt +index b3ae713cf02c..52b364b900f5 100644 +--- a/lib/dfsan/CMakeLists.txt ++++ b/lib/dfsan/CMakeLists.txt +@@ -54,4 +54,4 @@ add_custom_command(OUTPUT ${dfsan_abilist_filename} + DEPENDS done_abilist.txt libc_ubuntu1404_abilist.txt) + add_dependencies(dfsan dfsan_abilist) + install(FILES ${dfsan_abilist_filename} +- DESTINATION ${COMPILER_RT_INSTALL_PATH}/share) ++ DESTINATION ${COMPILER_RT_INSTALL_PATH}/${CMAKE_INSTALL_FULL_DATADIR}) diff --git a/llvm/9/default.nix b/llvm/9/default.nix new file mode 100644 index 0000000..9f79dc5 --- /dev/null +++ b/llvm/9/default.nix @@ -0,0 +1,287 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, isl, fetchurl, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +}: + +let + release_version = "9.0.1"; + version = release_version; # differentiating these is important for rc's + targetConfig = stdenv.targetPlatform.config; + + fetch = name: sha256: fetchurl { + url = "https://github.com/llvm/llvm-project/releases/download/llvmorg-${release_version}/${name}-${version}.src.tar.xz"; + inherit sha256; + }; + + clang-tools-extra_src = fetch "clang-tools-extra" "01vgzd4k1q93nfs8gyl83mjlc4x0qsgfqw32lacbjzdxg0mdfvxj"; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libllvm-polly = callPackage ./llvm { + inherit llvm_meta; + enablePolly = true; + }; + + llvm-polly = tools.libllvm-polly.lib // { outputSpecified = false; }; + + libclang = callPackage ./clang { + inherit clang-tools-extra_src llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + clang-polly-unwrapped = callPackage ./clang { + inherit llvm_meta; + inherit clang-tools-extra_src; + libllvm = tools.libllvm-polly; + enablePolly = true; + }; + + # disabled until recommonmark supports sphinx 3 + #llvm-manpages = lowPrio (tools.libllvm.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + #}); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ./lldb { + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + lib.optionalString (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) '' + echo "-lunwind" >> $out/nix-support/cc-ldflags + '' + lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + echo "-nostdlib++" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = '' + echo "-nostartfiles" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands0 cc; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake libxml2 python3 isl release_version version fetch; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libcxxabi = callPackage ./libcxxabi { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoLibcxx + else stdenv; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/9/libcxx/default.nix b/llvm/9/libcxx/default.nix new file mode 100644 index 0000000..ec09998 --- /dev/null +++ b/llvm/9/libcxx/default.nix @@ -0,0 +1,88 @@ +{ lib, stdenv, llvm_meta, fetch, cmake, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +assert stdenv.isDarwin -> cxxabi.pname == "libcxxabi"; + +stdenv.mkDerivation { + pname = "libcxx"; + inherit version; + + src = fetch "libcxx" "0d2bj5i6mk4caq7skd5nsdmz8c2m5w5anximl5wz3x32p08zz089"; + + postUnpack = '' + unpackFile ${libcxxabi.src} + export LIBCXXABI_INCLUDE_DIR="$PWD/$(ls -d libcxxabi-${version}*)/include" + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + # Prevent errors like "error: 'foo' is unavailable: introduced in macOS yy.zz" + postPatch = '' + substituteInPlace include/__config \ + --replace "# define _LIBCPP_USE_AVAILABILITY_APPLE" "" + ''; + + preConfigure = '' + # Get headers from the cxxabi source so we can see private headers not installed by the cxxabi package + cmakeFlagsArray=($cmakeFlagsArray -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$LIBCXXABI_INCLUDE_DIR") + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + nativeBuildInputs = [ cmake ] + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) python3 + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ cxxabi ]; + + cmakeFlags = [ + "-DLIBCXX_LIBCPPABI_VERSION=2" + "-DLIBCXX_CXX_ABI=${cxxabi.pname}" + ] ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optional (cxxabi.pname == "libcxxabi") "-DLIBCXX_LIBCXXABI_LIB_PATH=${cxxabi}/lib" + ++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON" + ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF"; + + preInstall = lib.optionalString (stdenv.isDarwin) '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + baseName=$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1)) + installName="$out/lib/$baseName" + abiName=$(echo "$baseName" | sed -e 's/libc++/libc++abi/') + + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other ${cxxabi}/lib/$abiName $file + done + done + ''; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/9/libcxx/gnu-install-dirs.patch b/llvm/9/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..424488b --- /dev/null +++ b/llvm/9/libcxx/gnu-install-dirs.patch @@ -0,0 +1,99 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index ec1869ddc7ae..a1c040235c8d 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -26,6 +26,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXX_STANDALONE_BUILD) + project(libcxx CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxx) + set(PACKAGE_VERSION 9.0.1) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -416,7 +418,7 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXX_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) + string(APPEND LIBCXX_INSTALL_LIBRARY_DIR /${LIBCXX_LIBDIR_SUBDIR}) +@@ -424,10 +426,10 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) + set(LIBCXX_HEADER_DIR ${LLVM_BINARY_DIR}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + else() + set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX}) ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX}) + endif() + + file(MAKE_DIRECTORY "${LIBCXX_BINARY_INCLUDE_DIR}") +diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake +index 10f100f7f0fb..95ed3978ab73 100644 +--- a/cmake/Modules/HandleLibCXXABI.cmake ++++ b/cmake/Modules/HandleLibCXXABI.cmake +@@ -61,7 +61,7 @@ macro(setup_abi_lib abidefines abishared abistatic abifiles abidirs) + + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${LIBCXX_BINARY_INCLUDE_DIR}/${fpath}" +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dstdir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dstdir} + COMPONENT cxx-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt +index 7cbf82caa81f..7cbde7accd78 100644 +--- a/include/CMakeLists.txt ++++ b/include/CMakeLists.txt +@@ -243,7 +243,7 @@ if (LIBCXX_INSTALL_HEADERS) + foreach(file ${files}) + get_filename_component(dir ${file} DIRECTORY) + install(FILES ${file} +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1/${dir} ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1/${dir} + COMPONENT ${CXX_HEADER_TARGET} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) +@@ -252,7 +252,7 @@ if (LIBCXX_INSTALL_HEADERS) + if (LIBCXX_NEEDS_SITE_CONFIG) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config +- DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}include/c++/v1 ++ DESTINATION ${LIBCXX_INSTALL_HEADER_PREFIX}${CMAKE_INSTALL_INCLUDEDIR}/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT ${CXX_HEADER_TARGET}) +diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt +index 31cd24333a5e..a419cef662b0 100644 +--- a/src/CMakeLists.txt ++++ b/src/CMakeLists.txt +@@ -437,21 +437,21 @@ if (LIBCXX_INSTALL_LIBRARY) + install(TARGETS cxx_shared + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if (LIBCXX_INSTALL_STATIC_LIBRARY) + install(TARGETS cxx_static + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + if(LIBCXX_INSTALL_EXPERIMENTAL_LIBRARY) + install(TARGETS ${LIBCXX_INSTALL_TARGETS} ${experimental_lib} + LIBRARY DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx + ARCHIVE DESTINATION ${LIBCXX_INSTALL_PREFIX}${LIBCXX_INSTALL_LIBRARY_DIR} COMPONENT cxx +- RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}bin COMPONENT cxx) ++ RUNTIME DESTINATION ${LIBCXX_INSTALL_PREFIX}${CMAKE_INSTALL_BINDIR} COMPONENT cxx) + endif() + + # NOTE: This install command must go after the cxx install command otherwise diff --git a/llvm/9/libcxxabi/default.nix b/llvm/9/libcxxabi/default.nix new file mode 100644 index 0000000..24d89b1 --- /dev/null +++ b/llvm/9/libcxxabi/default.nix @@ -0,0 +1,85 @@ +{ lib, stdenv, llvm_meta, cmake, fetch, libcxx, libunwind, llvm, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation { + pname = "libcxxabi"; + inherit version; + + src = fetch "libcxxabi" "1b4aiaa8cirx52vk2p5kfk57qmbqf1ipb4nqnjhdgqps9jm7iyg8"; + + outputs = [ "out" "dev" ]; + + postUnpack = '' + unpackFile ${libcxx.src} + unpackFile ${llvm.src} + cmakeFlags+=" -DLLVM_PATH=$PWD/$(ls -d llvm-*) -DLIBCXXABI_LIBCXX_PATH=$PWD/$(ls -d libcxx-*)" + '' + lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -d $(ls -d libcxx-*) -i ${../../libcxx-0001-musl-hacks.patch} + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d $(ls -d llvm-*) -i ${../../common/libcxxabi/wasm.patch} + ''; + + patches = [ + ../../common/libcxxabi/no-threads.patch + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/9/libcxxabi/gnu-install-dirs.patch b/llvm/9/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..70b41a6 --- /dev/null +++ b/llvm/9/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index aa0b124fc3c4..d74373f465c5 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -20,6 +20,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBCXXABI_STANDALONE_BUILD) + project(libcxxabi CXX C) + ++ include(GNUInstallDirs) ++ + set(PACKAGE_NAME libcxxabi) + set(PACKAGE_VERSION 9.0.1) + set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +@@ -181,17 +183,17 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + string(APPEND LIBCXXABI_INSTALL_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + else() + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX}) ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX}) + endif() + + set(LIBCXXABI_INSTALL_PREFIX "" CACHE STRING "Define libc++abi destination prefix.") diff --git a/llvm/9/libunwind/default.nix b/llvm/9/libunwind/default.nix new file mode 100644 index 0000000..65b89c6 --- /dev/null +++ b/llvm/9/libunwind/default.nix @@ -0,0 +1,32 @@ +{ lib, stdenv, llvm_meta, version, fetch, cmake, fetchpatch +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + src = fetch pname "1wb02ha3gl6p0a321hwpll74pz5qvjr11xmjqx62g288f1m10njk"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ]; + + cmakeFlags = lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/9/libunwind/gnu-install-dirs.patch b/llvm/9/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..12171bb --- /dev/null +++ b/llvm/9/libunwind/gnu-install-dirs.patch @@ -0,0 +1,34 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index df68491d686e..3b53267ae464 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -18,6 +18,8 @@ set(CMAKE_MODULE_PATH + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR LIBUNWIND_STANDALONE_BUILD) + project(libunwind) + ++ include(GNUInstallDirs) ++ + # Rely on llvm-config. + set(CONFIG_OUTPUT) + if(NOT LLVM_CONFIG_PATH) +@@ -189,17 +191,17 @@ string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" CLANG_VERSION + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++) + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + string(APPEND LIBUNWIND_INSTALL_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) + endif() + elseif(LLVM_LIBRARY_OUTPUT_INTDIR) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX}) ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX}) + endif() + + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBUNWIND_LIBRARY_DIR}) diff --git a/llvm/9/lld/default.nix b/llvm/9/lld/default.nix new file mode 100644 index 0000000..bf79c75 --- /dev/null +++ b/llvm/9/lld/default.nix @@ -0,0 +1,46 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, fetch +, cmake +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + src = fetch pname "10hckfxpapfnh6y9apjiya2jpw9nmbbmh8ayijx89mrg7snjn9l6"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLVM_CONFIG_PATH=${libllvm.dev}/bin/llvm-config${lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) "-native"}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/9/lld/gnu-install-dirs.patch b/llvm/9/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..232f5cb --- /dev/null +++ b/llvm/9/lld/gnu-install-dirs.patch @@ -0,0 +1,68 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 641f71c114ae..9d44c1463aff 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -6,6 +6,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(LLD_BUILT_STANDALONE TRUE) + ++ include(GNUInstallDirs) ++ + find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary") + if(NOT LLVM_CONFIG_PATH) + message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH") +@@ -202,7 +204,7 @@ include_directories(BEFORE + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index fa48b428d26b..e7967aad3ceb 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -20,9 +20,9 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- RUNTIME DESTINATION bin) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) + add_llvm_install_targets(install-${name} +@@ -54,7 +54,7 @@ macro(add_lld_tool name) + + install(TARGETS ${name} + ${export_to_lldtargets} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + COMPONENT ${name}) + + if(NOT CMAKE_CONFIGURATION_TYPES) +@@ -69,5 +69,5 @@ endmacro() + macro(add_lld_symlink name dest) + add_llvm_tool_symlink(${name} ${dest} ALWAYS_GENERATE) + # Always generate install targets +- llvm_install_symlink(${name} ${dest} ALWAYS_GENERATE) ++ llvm_install_symlink(${name} ${dest} ${CMAKE_INSTALL_FULL_BINDIR} ALWAYS_GENERATE) + endmacro() +diff --git a/tools/lld/CMakeLists.txt b/tools/lld/CMakeLists.txt +index a15e296e31df..654c2cfdb9c0 100644 +--- a/tools/lld/CMakeLists.txt ++++ b/tools/lld/CMakeLists.txt +@@ -17,7 +17,7 @@ target_link_libraries(lld + ) + + install(TARGETS lld +- RUNTIME DESTINATION bin) ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + + if(NOT LLD_SYMLINKS_TO_CREATE) + set(LLD_SYMLINKS_TO_CREATE lld-link ld.lld ld64.lld wasm-ld) diff --git a/llvm/9/lldb/default.nix b/llvm/9/lldb/default.nix new file mode 100644 index 0000000..49cc0a0 --- /dev/null +++ b/llvm/9/lldb/default.nix @@ -0,0 +1,117 @@ +{ lib, stdenv, llvm_meta +, fetch +, fetchpatch +, cmake +, zlib +, ncurses +, swig +, which +, libedit +, libxml2 +, libllvm +, libclang +, python3 +, version +, darwin +, makeWrapper +, perl +, lit +}: + +stdenv.mkDerivation rec { + pname = "lldb"; + inherit version; + + src = fetch pname "02gb3fbz09kyw8n71218v5v77ip559x3gqbcp8y3w6n3jpbryywa"; + + patches = [ + ./procfs.patch + ./gnu-install-dirs.patch + + # Fix darwin build + (fetchpatch { + name = "lldb-use-system-debugserver-fix.patch"; + url = "https://github.com/llvm-mirror/lldb/commit/be770754cc43da22eacdb70c6203f4582eeb011f.diff"; + sha256 = "sha256-tKkk6sn//0Hu0nlzoKWs5fXMWc+O2JAWOEJ1ZnaLuVU="; + excludes = [ "packages/*" ]; + postFetch = '' + substituteInPlace "$out" --replace add_lldb_tool_subdirectory add_subdirectory + ''; + }) + ./lldb-gdb-remote-no-libcompress.patch + ]; + + outputs = [ "out" "lib" "dev" ]; + + nativeBuildInputs = [ + cmake python3 which swig lit makeWrapper + ] ++ lib.optionals stdenv.isDarwin [ + # for scripts/generate-vers.pl + perl + ]; + + buildInputs = [ + ncurses zlib libedit libxml2 libllvm + ] ++ lib.optionals stdenv.isDarwin [ + darwin.libobjc + darwin.apple_sdk.libs.xpc + darwin.apple_sdk.frameworks.Foundation + darwin.bootstrap_cmds + darwin.apple_sdk.frameworks.Carbon + darwin.apple_sdk.frameworks.Cocoa + darwin.apple_sdk.frameworks.DebugSymbols + ]; + + CXXFLAGS = "-fno-rtti"; + hardeningDisable = [ "format" ]; + + cmakeFlags = [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DClang_DIR=${libclang.dev}/lib/cmake" + "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit" + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + ] ++ lib.optionals stdenv.isDarwin [ + # Building debugserver requires the proprietary libcompression + "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" + ] ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ]; + + doCheck = false; + + doInstallCheck = true; + + installCheckPhase = '' + if [ ! -e "$lib/${python3.sitePackages}/lldb/_lldb.so" ] ; then + echo "ERROR: python files not installed where expected!"; + return 1; + fi + ''; + + postInstall = '' + wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/ + + # man page + mkdir -p $out/share/man/man1 + install ../docs/lldb.1 -t $out/share/man/man1/ + + # Editor support + # vscode: + install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json + mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ln -s $out/bin/llvm-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ''; + + meta = llvm_meta // { + broken = stdenv.isDarwin && stdenv.isAarch64; + homepage = "https://lldb.llvm.org/"; + description = "A next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + }; +} diff --git a/llvm/9/lldb/gnu-install-dirs.patch b/llvm/9/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..6ceb29c --- /dev/null +++ b/llvm/9/lldb/gnu-install-dirs.patch @@ -0,0 +1,105 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5d52f6450657..a05130cf80b9 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -14,6 +14,8 @@ set(CMAKE_MODULE_PATH + # If we are not building as part of LLVM, build LLDB as a standalone project, + # using LLVM as an external library. + if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ++ include(GNUInstallDirs) ++ + include(LLDBStandalone) + endif() + +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 4c99278c583b..36d3640a6afc 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -94,13 +94,13 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() + # RUNTIME is relevant for DLL platforms, FRAMEWORK for macOS + install(TARGETS ${name} COMPONENT ${name} +- RUNTIME DESTINATION bin ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${install_dest} + ARCHIVE DESTINATION ${install_dest} + FRAMEWORK DESTINATION ${install_dest}) +diff --git a/cmake/modules/LLDBConfig.cmake b/cmake/modules/LLDBConfig.cmake +index e1a133709ff2..357b4bb4492a 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -335,7 +335,7 @@ include_directories(BEFORE + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +@@ -345,7 +345,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ + COMPONENT lldb-headers +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index b5316540fdf3..3c3c882d503f 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -64,4 +64,4 @@ if (NOT LLDB_DISABLE_PYTHON AND LLDB_BUILD_INTEL_PT) + endif() + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) +diff --git a/CMakeLists.txt b/CMakeLists.txt +index cdf22c4..d56fc6a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -146,7 +146,7 @@ if (NOT LLDB_DISABLE_PYTHON) + --cfgBldDir=${lldb_scripts_dir} + --prefix=${CMAKE_BINARY_DIR} + --cmakeBuildConfiguration=${CMAKE_CFG_INTDIR} +- --lldbLibDir=lib${LLVM_LIBDIR_SUFFIX} ++ --lldbLibDir=${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} + ${use_python_wrapper_from_src_dir} + ${use_six_py_from_system} + VERBATIM +diff --git a/cmake/modules/LLDBStandalone.cmake b/cmake/modules/LLDBStandalone.cmake +index b726797..1f057ac 100644 +--- a/cmake/modules/LLDBStandalone.cmake ++++ b/cmake/modules/LLDBStandalone.cmake +@@ -95,7 +95,7 @@ include_directories( + "${CLANG_INCLUDE_DIRS}") + + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) ++set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_INSTALL_LIBDIR}/lib${LLVM_LIBDIR_SUFFIX}) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}) + + set(LLDB_BUILT_STANDALONE 1) +diff --git a/scripts/CMakeLists.txt b/scripts/CMakeLists.txt +index 7de7973..b70aecc 100644 +--- a/scripts/CMakeLists.txt ++++ b/scripts/CMakeLists.txt +@@ -50,7 +50,8 @@ if(NOT LLDB_BUILD_FRAMEWORK) + OUTPUT_STRIP_TRAILING_WHITESPACE) + execute_process( + COMMAND ${PYTHON_EXECUTABLE} +- -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(True, False, ''))" ++ -c "import distutils.sysconfig, sys; print(distutils.sysconfig.get_python_lib(True, False, sys.argv[1]))" ++ ${CMAKE_INSTALL_LIBDIR}/../ + OUTPUT_VARIABLE SWIG_INSTALL_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE) + diff --git a/llvm/9/lldb/lldb-gdb-remote-no-libcompress.patch b/llvm/9/lldb/lldb-gdb-remote-no-libcompress.patch new file mode 100644 index 0000000..ff2dcd3 --- /dev/null +++ b/llvm/9/lldb/lldb-gdb-remote-no-libcompress.patch @@ -0,0 +1,17 @@ +diff -ru a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +--- a/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 2019-12-11 14:15:30.000000000 -0500 ++++ b/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp 2021-11-26 23:44:28.000000000 -0500 +@@ -36,13 +36,6 @@ + + #include "llvm/ADT/StringSwitch.h" + +-#if defined(__APPLE__) +-#ifndef HAVE_LIBCOMPRESSION +-#define HAVE_LIBCOMPRESSION +-#endif +-#include +-#endif +- + using namespace lldb; + using namespace lldb_private; + using namespace lldb_private::process_gdb_remote; diff --git a/llvm/9/lldb/procfs.patch b/llvm/9/lldb/procfs.patch new file mode 100644 index 0000000..b075dba --- /dev/null +++ b/llvm/9/lldb/procfs.patch @@ -0,0 +1,31 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -11,21 +11,12 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif diff --git a/llvm/9/llvm/default.nix b/llvm/9/llvm/default.nix new file mode 100644 index 0000000..526030d --- /dev/null +++ b/llvm/9/llvm/default.nix @@ -0,0 +1,334 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, fetch +, fetchpatch +, cmake +, python3 +, libffi +, enableGoldPlugin ? libbfd.hasPluginAPI +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, buildLlvmTools +, debugVersion ? false +, doCheck ? stdenv.isLinux && (!stdenv.isx86_32) && (!stdenv.hostPlatform.isRiscV) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +# broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 +# broken for the armv7l builder +, enablePFM ? stdenv.isLinux && !stdenv.hostPlatform.isAarch +, enablePolly ? false +}: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = fetch pname "16hwp3qa54c3a3v7h8nlw0fh5criqh0hlr1skybyk0cz70gyx880"; + polly_src = fetch "polly" "1kqg0isv0kicnylrdp5iajlgd6alc0zx1l3cxc9hs8r3z6fwcjls"; + + unpackPhase = '' + unpackFile $src + mv llvm-${version}* llvm + sourceRoot=$PWD/llvm + '' + optionalString enablePolly '' + unpackFile $polly_src + mv polly-* $sourceRoot/tools/polly + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + patches = [ + # When cross-compiling we configure llvm-config-native with an approximation + # of the flags used for the normal LLVM build. To avoid the need for building + # a native libLLVM.so (which would fail) we force llvm-config to be linked + # statically against the necessary LLVM components always. + ../../llvm-config-link-static.patch + + ./gnu-install-dirs.patch + # Force a test to evaluate the saved benchmark for a CPU for which LLVM has + # an execution model. See NixOS/nixpkgs#119673. + ../../exegesis-force-bdver2.patch + + # Fix missing includes for GCC 11 + (fetchpatch { + name = "headers-gcc-11.patch"; + url = "https://github.com/llvm/llvm-project/commit/b498303066a63a203d24f739b2d2e0e56dca70d1.patch"; + sha256 = "0nh123kld0dgz2h941lng331dkj3wbm5lfxm375k1f569gv83hlk"; + stripLen = 1; + }) + + # Fix invalid std::string(nullptr) for GCC 12 + (fetchpatch { + name = "nvptx-gcc-12.patch"; + url = "https://github.com/llvm/llvm-project/commit/99e64623ec9b31def9375753491cc6093c831809.patch"; + sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; + stripLen = 1; + }) + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}" ''${extra_libdir})' "" + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + + # Fix test so that no extra locale files are needed + substituteInPlace test/tools/llvm-ar/mri-utf8.test \ + --replace en_US.UTF-8 C.UTF-8 + + # Fix x86 gold test on non-x86 platforms + # (similar fix made to others in this directory previously, FWIW) + patch -p1 -i ${./fix-test-on-non-x86-like-others.patch} + '' + '' + # Tweak tests to ignore namespace part of type to support + # gcc-12: https://gcc.gnu.org/PR103598. + # The change below mangles strings like: + # CHECK-NEXT: Starting llvm::Function pass manager run. + # to: + # CHECK-NEXT: Starting {{.*}}Function pass manager run. + for f in \ + test/Other/new-pass-manager.ll \ + test/Other/new-pm-defaults.ll \ + test/Other/new-pm-lto-defaults.ll \ + test/Other/new-pm-thinlto-defaults.ll \ + test/Other/pass-pipeline-parsing.ll \ + test/Transforms/Inline/cgscc-incremental-invalidate.ll \ + test/Transforms/Inline/clear-analyses.ll \ + test/Transforms/LoopUnroll/unroll-loop-invalidation.ll \ + test/Transforms/SCCP/ipsccp-preserve-analysis.ll \ + test/Transforms/SCCP/preserve-analysis.ll \ + test/Transforms/SROA/dead-inst.ll \ + test/tools/gold/X86/new-pm.ll \ + ; do + echo "PATCH: $f" + substituteInPlace $f \ + --replace 'Starting llvm::' 'Starting {{.*}}' \ + --replace 'Finished llvm::' 'Finished {{.*}}' + done + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar' + ) + ''; + + # hacky fix: created binaries need to be run before installation + preBuild = '' + mkdir -p $out/ + ln -sv $PWD/lib $out + ''; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_CMAKE_DIR=${placeholder "dev"}/lib/cmake/llvm/" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals (isDarwin) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postBuild = '' + rm -fR $out + ''; + + preCheck = '' + export LD_LIBRARY_PATH=$LD_LIBRARY_PATH''${LD_LIBRARY_PATH:+:}$PWD/lib + ''; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + buildPhase = '' + make docs-llvm-man + ''; + + propagatedBuildInputs = []; + + installPhase = '' + make -C docs install + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/9/llvm/fix-test-on-non-x86-like-others.patch b/llvm/9/llvm/fix-test-on-non-x86-like-others.patch new file mode 100644 index 0000000..e6c2f04 --- /dev/null +++ b/llvm/9/llvm/fix-test-on-non-x86-like-others.patch @@ -0,0 +1,23 @@ +Index: test/tools/gold/X86/linkonce_odr_unnamed_addr.ll +=================================================================== +diff --git a/test/tools/gold/X86/linkonce_odr_unnamed_addr.ll b/llvm/trunk/test/tools/gold/X86/linkonce_odr_unnamed_addr.ll +--- a/test/tools/gold/X86/linkonce_odr_unnamed_addr.ll (revision 372333) ++++ b/test/tools/gold/X86/linkonce_odr_unnamed_addr.ll (working copy) +@@ -3,7 +3,7 @@ + + ; RUN: opt -module-summary %s -o %t.o + ; RUN: opt -module-summary %p/Inputs/linkonce_odr_unnamed_addr.ll -o %t2.o +-; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \ ++; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ + ; RUN: --plugin-opt=save-temps \ + ; RUN: %t.o %t2.o -o %t3.o + ; RUN: llvm-dis %t.o.1.promote.bc -o - | FileCheck %s +@@ -11,7 +11,7 @@ + ; Now test when one module is a native object. In that case we must be + ; conservative and not auto hide. + ; RUN: llc %p/Inputs/linkonce_odr_unnamed_addr.ll -o %t2native.o -filetype=obj +-; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext \ ++; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ + ; RUN: --plugin-opt=save-temps \ + ; RUN: %t.o %t2native.o -o %t3.o + ; RUN: llvm-dis %t.o.1.promote.bc -o - | FileCheck %s --check-prefix=NOSUMMARY diff --git a/llvm/9/llvm/gnu-install-dirs-polly.patch b/llvm/9/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..7c477c7 --- /dev/null +++ b/llvm/9/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,106 @@ +diff --git a/tools/polly/CMakeLists.txt b/tools/polly/CMakeLists.txt +index 9939097f743e..8cc538da912a 100644 +--- a/tools/polly/CMakeLists.txt ++++ b/tools/polly/CMakeLists.txt +@@ -2,7 +2,11 @@ + if (NOT DEFINED LLVM_MAIN_SRC_DIR) + project(Polly) + cmake_minimum_required(VERSION 3.4.3) ++endif() ++ ++include(GNUInstallDirs) + ++if (NOT DEFINED LLVM_MAIN_SRC_DIR) + # Where is LLVM installed? + find_package(LLVM CONFIG REQUIRED) + set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR}) +@@ -145,14 +149,14 @@ include_directories( + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN ".svn" EXCLUDE + ) + + install(DIRECTORY ${POLLY_BINARY_DIR}/include/ +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE +diff --git a/tools/polly/cmake/CMakeLists.txt b/tools/polly/cmake/CMakeLists.txt +index 211f95512717..f9e04a4844b6 100644 +--- a/tools/polly/cmake/CMakeLists.txt ++++ b/tools/polly/cmake/CMakeLists.txt +@@ -79,18 +79,18 @@ file(GENERATE + + # Generate PollyConfig.cmake for the install tree. + unset(POLLY_EXPORTS) +-set(POLLY_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") ++set(POLLY_INSTALL_PREFIX "") + set(POLLY_CONFIG_LLVM_CMAKE_DIR "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") +-set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}") ++set(POLLY_CONFIG_CMAKE_DIR "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_PREFIX}/${POLLY_INSTALL_PACKAGE_DIR}") ++set(POLLY_CONFIG_LIBRARY_DIRS "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + if (POLLY_BUNDLED_ISL) + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" +- "${POLLY_INSTALL_PREFIX}/include/polly" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_LIBDIR}/polly" + ) + else() + set(POLLY_CONFIG_INCLUDE_DIRS +- "${POLLY_INSTALL_PREFIX}/include" ++ "${POLLY_INSTALL_PREFIX}${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ${ISL_INCLUDE_DIRS} + ) + endif() +@@ -100,12 +100,12 @@ endif() + foreach(tgt IN LISTS POLLY_CONFIG_EXPORTED_TARGETS) + get_target_property(tgt_type ${tgt} TYPE) + if (tgt_type STREQUAL "EXECUTABLE") +- set(tgt_prefix "bin/") ++ set(tgt_prefix "${CMAKE_INSTALL_BINDIR}/") + else() +- set(tgt_prefix "lib/") ++ set(tgt_prefix "${CMAKE_INSTALL_LIBDIR}/") + endif() + +- set(tgt_path "${CMAKE_INSTALL_PREFIX}/${tgt_prefix}$") ++ set(tgt_path "${tgt_prefix}$") + file(RELATIVE_PATH tgt_path ${POLLY_CONFIG_CMAKE_DIR} ${tgt_path}) + + if (NOT tgt_type STREQUAL "INTERFACE_LIBRARY") +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index e48203871884..5bc8a2a52541 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) +diff --git a/tools/polly/lib/External/CMakeLists.txt b/tools/polly/lib/External/CMakeLists.txt +index 8ffd984e542b..261cc19f3238 100644 +--- a/tools/polly/lib/External/CMakeLists.txt ++++ b/tools/polly/lib/External/CMakeLists.txt +@@ -274,7 +274,7 @@ if (POLLY_BUNDLED_ISL) + install(DIRECTORY + ${ISL_SOURCE_DIR}/include/ + ${ISL_BINARY_DIR}/include/ +- DESTINATION include/polly ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/polly + FILES_MATCHING + PATTERN "*.h" + PATTERN "CMakeFiles" EXCLUDE diff --git a/llvm/9/llvm/gnu-install-dirs.patch b/llvm/9/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..380cc3f --- /dev/null +++ b/llvm/9/llvm/gnu-install-dirs.patch @@ -0,0 +1,395 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b9a10685b99f..c2750500df99 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -242,15 +242,21 @@ if (CMAKE_BUILD_TYPE AND + message(FATAL_ERROR "Invalid value for CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") + endif() + ++include(GNUInstallDirs) ++ + set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) + +-set(LLVM_TOOLS_INSTALL_DIR "bin" CACHE STRING "Path for binary subdirectory (defaults to 'bin')") ++set(LLVM_TOOLS_INSTALL_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING ++ "Path for binary subdirectory (defaults to 'bin')") + mark_as_advanced(LLVM_TOOLS_INSTALL_DIR) + + set(LLVM_UTILS_INSTALL_DIR "${LLVM_TOOLS_INSTALL_DIR}" CACHE STRING + "Path to install LLVM utilities (enabled by LLVM_INSTALL_UTILS=ON) (defaults to LLVM_TOOLS_INSTALL_DIR)") + mark_as_advanced(LLVM_UTILS_INSTALL_DIR) + ++set(LLVM_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/cmake/llvm" CACHE STRING ++ "Path for CMake subdirectory (defaults to lib/cmake/llvm)" ) ++ + # They are used as destination of target generators. + set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) + set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) +@@ -534,9 +540,9 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF) + option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON) + option (LLVM_ENABLE_BINDINGS "Build bindings." ON) + +-set(LLVM_INSTALL_DOXYGEN_HTML_DIR "share/doc/llvm/doxygen-html" ++set(LLVM_INSTALL_DOXYGEN_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html" + CACHE STRING "Doxygen-generated HTML documentation install directory") +-set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "share/doc/llvm/ocaml-html" ++set(LLVM_INSTALL_OCAMLDOC_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html" + CACHE STRING "OCamldoc-generated HTML documentation install directory") + + option (LLVM_BUILD_EXTERNAL_COMPILER_RT +@@ -1002,7 +1008,7 @@ endif() + + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1014,7 +1020,7 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + ) + + install(DIRECTORY ${LLVM_INCLUDE_DIR}/llvm ${LLVM_INCLUDE_DIR}/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "*.def" +@@ -1029,13 +1035,13 @@ if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) + + if (LLVM_INSTALL_MODULEMAPS) + install(DIRECTORY include/llvm include/llvm-c +- DESTINATION include ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + COMPONENT llvm-headers + FILES_MATCHING + PATTERN "module.modulemap" + ) + install(FILES include/llvm/module.install.modulemap +- DESTINATION include/llvm ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm + COMPONENT llvm-headers + RENAME "module.extern.modulemap" + ) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 619e986b8aa0..842b4f71d07e 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -697,9 +697,9 @@ macro(add_llvm_library name) + + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- RUNTIME DESTINATION bin COMPONENT ${name}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) + add_llvm_install_targets(install-${name} +@@ -930,7 +930,7 @@ macro(add_llvm_example name) + endif() + add_llvm_executable(${name} ${ARGN}) + if( LLVM_BUILD_EXAMPLES ) +- install(TARGETS ${name} RUNTIME DESTINATION examples) ++ install(TARGETS ${name} RUNTIME DESTINATION ${CMAKE_INSTALL_DOCDIR}/examples) + endif() + set_target_properties(${name} PROPERTIES FOLDER "Examples") + endmacro(add_llvm_example name) +@@ -1485,7 +1485,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir bin) + endif() +@@ -1501,7 +1501,7 @@ function(llvm_install_library_symlink name dest type) + endif() + endfunction() + +-function(llvm_install_symlink name dest) ++function(llvm_install_symlink name dest output_dir) + cmake_parse_arguments(ARG "ALWAYS_GENERATE" "COMPONENT" "" ${ARGN}) + foreach(path ${CMAKE_MODULE_PATH}) + if(EXISTS ${path}/LLVMInstallSymlink.cmake) +@@ -1524,7 +1524,7 @@ function(llvm_install_symlink name dest) + set(full_dest ${dest}${CMAKE_EXECUTABLE_SUFFIX}) + + install(SCRIPT ${INSTALL_SYMLINK} +- CODE "install_symlink(${full_name} ${full_dest} ${LLVM_TOOLS_INSTALL_DIR})" ++ CODE "install_symlink(${full_name} ${full_dest} ${output_dir})" + COMPONENT ${component}) + + if (NOT LLVM_ENABLE_IDE AND NOT ARG_ALWAYS_GENERATE) +@@ -1606,7 +1606,8 @@ function(add_llvm_tool_symlink link_name target) + endif() + + if ((TOOL_IS_TOOLCHAIN OR NOT LLVM_INSTALL_TOOLCHAIN_ONLY) AND LLVM_BUILD_TOOLS) +- llvm_install_symlink(${link_name} ${target}) ++ GNUInstallDirs_get_absolute_install_dir(output_dir LLVM_TOOLS_INSTALL_DIR) ++ llvm_install_symlink(${link_name} ${target} ${output_dir}) + endif() + endif() + endfunction() +@@ -1728,9 +1729,9 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 02bab6846376..eff26adb2efc 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -140,9 +140,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/AddSphinxTarget.cmake b/cmake/modules/AddSphinxTarget.cmake +index 22e3dcb776aa..ba77b9c195e2 100644 +--- a/cmake/modules/AddSphinxTarget.cmake ++++ b/cmake/modules/AddSphinxTarget.cmake +@@ -73,7 +73,7 @@ function (add_sphinx_target builder project) + + elseif (builder STREQUAL html) + string(TOUPPER "${project}" project_upper) +- set(${project_upper}_INSTALL_SPHINX_HTML_DIR "share/doc/${project}/html" ++ set(${project_upper}_INSTALL_SPHINX_HTML_DIR "${CMAKE_INSTALL_DOCDIR}/${project}/html" + CACHE STRING "HTML documentation install directory for ${project}") + + # '/.' indicates: copy the contents of the directory directly into +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index 9cf22b436fa7..486e40010cd8 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -1,4 +1,4 @@ +-set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) ++set(LLVM_INSTALL_PACKAGE_DIR ${LLVM_INSTALL_CMAKE_DIR} CACHE STRING "Path for CMake subdirectory (defaults to 'cmake/llvm')") + set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") + + # First for users who use an installed LLVM, create the LLVMExports.cmake file. +@@ -96,13 +96,13 @@ foreach(p ${_count}) + set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE} + get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)") + endforeach(p) +-set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include") ++set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}") + set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") + set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}") +-set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}") ++set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") + set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") +-set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") ++set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}") + set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") + set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}") + configure_file( +diff --git a/cmake/modules/LLVMInstallSymlink.cmake b/cmake/modules/LLVMInstallSymlink.cmake +index 09fed8085c23..aa79f192abf0 100644 +--- a/cmake/modules/LLVMInstallSymlink.cmake ++++ b/cmake/modules/LLVMInstallSymlink.cmake +@@ -10,7 +10,7 @@ function(install_symlink name target outdir) + set(LINK_OR_COPY copy) + endif() + +- set(bindir "${DESTDIR}${CMAKE_INSTALL_PREFIX}/${outdir}/") ++ set(bindir "${DESTDIR}${outdir}/") + + message(STATUS "Creating ${name}") + +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 91fb5282206f..d2c9fd94d131 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -196,7 +196,7 @@ CMake manual, or execute ``cmake --help-variable VARIABLE_NAME``. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **CMAKE_C_FLAGS**:STRING + Extra flags to use when compiling C source files. +@@ -492,8 +492,8 @@ LLVM-specific variables + + **LLVM_INSTALL_DOXYGEN_HTML_DIR**:STRING + The path to install Doxygen-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/doxygen-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/doxygen-html`. + + **LLVM_ENABLE_SPHINX**:BOOL + If specified, CMake will search for the ``sphinx-build`` executable and will make +@@ -524,13 +524,33 @@ LLVM-specific variables + + **LLVM_INSTALL_SPHINX_HTML_DIR**:STRING + The path to install Sphinx-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/html`. + + **LLVM_INSTALL_OCAMLDOC_HTML_DIR**:STRING + The path to install OCamldoc-generated HTML documentation to. This path can +- either be absolute or relative to the CMAKE_INSTALL_PREFIX. Defaults to +- `share/doc/llvm/ocaml-html`. ++ either be absolute or relative to the ``CMAKE_INSTALL_PREFIX``. Defaults to ++ `${CMAKE_INSTALL_DOCDIR}/${project}/ocaml-html`. ++ ++**CMAKE_INSTALL_BINDIR**:STRING ++ The path to install binary tools, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `bin`. ++ ++**CMAKE_INSTALL_LIBDIR**:STRING ++ The path to install libraries, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `lib`. ++ ++**CMAKE_INSTALL_INCLUDEDIR**:STRING ++ The path to install header files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `include`. ++ ++**CMAKE_INSTALL_DOCDIR**:STRING ++ The path to install documentation, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/doc`. ++ ++**CMAKE_INSTALL_MANDIR**:STRING ++ The path to install manpage files, relative to the ``CMAKE_INSTALL_PREFIX``. ++ Defaults to `share/man`. + + **LLVM_CREATE_XCODE_TOOLCHAIN**:BOOL + macOS Only: If enabled CMake will generate a target named +@@ -710,9 +730,11 @@ the ``cmake`` command or by setting it directly in ``ccmake`` or ``cmake-gui``). + + This file is available in two different locations. + +-* ``/lib/cmake/llvm/LLVMConfig.cmake`` where +- ```` is the install prefix of an installed version of LLVM. +- On Linux typically this is ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. ++* ``LLVMConfig.cmake`` where ++ ```` is the location where LLVM CMake modules are ++ installed as part of an installed version of LLVM. This is typically ++ ``cmake/llvm/`` within the lib directory. On Linux, this is typically ++ ``/usr/lib/cmake/llvm/LLVMConfig.cmake``. + + * ``/lib/cmake/llvm/LLVMConfig.cmake`` where + ```` is the root of the LLVM build tree. **Note: this is only +diff --git a/include/llvm/CMakeLists.txt b/include/llvm/CMakeLists.txt +index 1d5ca3ba92b0..026f5453c1da 100644 +--- a/include/llvm/CMakeLists.txt ++++ b/include/llvm/CMakeLists.txt +@@ -4,5 +4,5 @@ add_subdirectory(Support) + # If we're doing an out-of-tree build, copy a module map for generated + # header files into the build area. + if (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +- configure_file(module.modulemap.build module.modulemap COPYONLY) ++ configure_file(module.modulemap.build ${LLVM_INCLUDE_DIR}/module.modulemap COPYONLY) + endif (NOT "${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}") +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 3a24d3e974e1..987d82c1bb97 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,10 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_BINDIR "@CMAKE_INSTALL_BINDIR@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" ++#define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" ++#define LLVM_INSTALL_CMAKEDIR "@LLVM_INSTALL_CMAKE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" + #define LLVM_SYSTEM_LIBS "@LLVM_SYSTEM_LIBS@" + #define LLVM_BUILD_SYSTEM "@LLVM_BUILD_SYSTEM@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 7ef7c46a2627..1f71f8b0f820 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -332,12 +332,26 @@ int main(int argc, char **argv) { + ("-I" + ActiveIncludeDir + " " + "-I" + ActiveObjRoot + "/include"); + } else { + ActivePrefix = CurrentExecPrefix; +- ActiveIncludeDir = ActivePrefix + "/include"; +- SmallString<256> path(StringRef(LLVM_TOOLS_INSTALL_DIR)); +- sys::fs::make_absolute(ActivePrefix, path); +- ActiveBinDir = path.str(); +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; +- ActiveCMakeDir = ActiveLibDir + "/cmake/llvm"; ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_INCLUDEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveIncludeDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_BINDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveBinDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveLibDir = std::string(path.str()); ++ } ++ { ++ SmallString<256> path(StringRef(LLVM_INSTALL_CMAKEDIR)); ++ sys::fs::make_absolute(ActivePrefix, path); ++ ActiveCMakeDir = std::string(path.str()); ++ } + ActiveIncludeOption = "-I" + ActiveIncludeDir; + } + +diff --git a/tools/lto/CMakeLists.txt b/tools/lto/CMakeLists.txt +index b86e4abd01a7..02ce5773f17d 100644 +--- a/tools/lto/CMakeLists.txt ++++ b/tools/lto/CMakeLists.txt +@@ -23,7 +23,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/lto.exports) + add_llvm_library(LTO SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES} DEPENDS intrinsics_gen) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/lto.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT LTO) + + if (APPLE) +diff --git a/tools/opt-viewer/CMakeLists.txt b/tools/opt-viewer/CMakeLists.txt +index 19b606933082..27b9f71b3d79 100644 +--- a/tools/opt-viewer/CMakeLists.txt ++++ b/tools/opt-viewer/CMakeLists.txt +@@ -8,6 +8,6 @@ set (files + + foreach (file ${files}) + install(PROGRAMS ${file} +- DESTINATION share/opt-viewer ++ DESTINATION ${CMAKE_INSTALL_DATADIR}/opt-viewer + COMPONENT opt-viewer) + endforeach (file) +diff --git a/tools/remarks-shlib/CMakeLists.txt b/tools/remarks-shlib/CMakeLists.txt +index e948496c603a..1f4df8a98b10 100644 +--- a/tools/remarks-shlib/CMakeLists.txt ++++ b/tools/remarks-shlib/CMakeLists.txt +@@ -11,7 +11,7 @@ set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Remarks.exports) + add_llvm_library(Remarks SHARED INSTALL_WITH_TOOLCHAIN ${SOURCES}) + + install(FILES ${LLVM_MAIN_INCLUDE_DIR}/llvm-c/Remarks.h +- DESTINATION include/llvm-c ++ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/llvm-c + COMPONENT Remarks) + + if (APPLE) diff --git a/llvm/9/openmp/default.nix b/llvm/9/openmp/default.nix new file mode 100644 index 0000000..7cd9ad7 --- /dev/null +++ b/llvm/9/openmp/default.nix @@ -0,0 +1,37 @@ +{ lib +, stdenv +, llvm_meta +, fetch +, cmake +, llvm +, targetLlvm +, perl +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = fetch pname "1knafnpp0f7hylx8q20lkd6g1sf0flly572dayc5d5kghh7hd52w"; + + nativeBuildInputs = [ cmake perl ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/README.md b/llvm/README.md new file mode 100644 index 0000000..af5530f --- /dev/null +++ b/llvm/README.md @@ -0,0 +1,79 @@ +## How to upgrade llvm_git + +- Run `update-git.py`. + This will set the github revision and sha256 for `llvmPackages_git.llvm` to whatever the latest chromium build is using. + For a more recent, commit run `nix-prefetch-github` and change the rev and sha256 accordingly. + +- That was the easy part. + The hard part is updating the patch files. + + The general process is: + + 1. Try to build `llvmPackages_git.llvm` and associated packages such as + `clang` and `compiler-rt`. You can use the `-L` and `--keep-failed` flags to make + debugging patch errors easy, e.g., `nix build .#llvmPackages_git.clang -L --keep-failed` + + 2. The build will error out with something similar to this: + ```sh + ... + clang-unstable> patching sources + clang-unstable> applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch + clang-unstable> patching file lib/Driver/ToolChains/Gnu.cpp + clang-unstable> Hunk #1 FAILED at 487. + clang-unstable> 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej + note: keeping build directory '/tmp/nix-build-clang-unstable-2022-25-07.drv-17' + error: builder for '/nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv' failed with exit code 1; + last 8 log lines: + > unpacking sources + > unpacking source archive /nix/store/mrxadx11wv1ckjr2208qgxp472pmmg6g-clang-src-unstable-2022-25-07 + > source root is clang-src-unstable-2022-25-07/clang + > patching sources + > applying patch /nix/store/nndv6gq6w608n197fndvv5my4a5zg2qi-purity.patch + > patching file lib/Driver/ToolChains/Gnu.cpp + > Hunk #1 FAILED at 487. + > 1 out of 1 hunk FAILED -- saving rejects to file lib/Driver/ToolChains/Gnu.cpp.rej + For full logs, run 'nix log /nix/store/zwi123kpkyz52fy7p6v23azixd807r8c-clang-unstable-2022-25-07.drv'. + note: keeping build directory '/tmp/nix-build-compiler-rt-libc-unstable-2022-25-07.drv-20' + error: 1 dependencies of derivation '/nix/store/ndbbh3wrl0l39b22azf46f1n7zlqwmag-clang-wrapper-unstable-2022-25-07.drv' failed to build + ``` + + Notice the `Hunk #1 Failed at 487` line. + The lines above show us that the `purity.patch` failed on `lib/Driver/ToolChains/Gnu.cpp` when compiling `clang`. + + 3. The task now is to cross reference the hunks in the purity patch with + `lib/Driver/ToolCahins/Gnu.cpp.orig` to see why the patch failed. + The `.orig` file will be in the build directory referenced in the line `note: keeping build directory ...`; + this message results from the `--keep-failed` flag. + + 4. Now you should be able to open whichever patch failed, and the `foo.orig` file that it failed on. + Correct the patch by adapting it to the new code and be mindful of whitespace; + which can be an easily missed reason for failures. + For cases where the hunk is no longer needed you can simply remove it from the patch. + + This is fine for small corrections, but when more serious changes are needed its better to use git. + + 1. Clone the LLVM monorepo at https://github.com/llvm/llvm-project/ + + 2. Check out the revision we were using before. + + 3. Use `patch -p1 < path/to-path` in the project subdirectories to apply the patches and commit. + + 4. Use `git rebase HEAD^ --onto ` to rebase the patches onto the new revision we are trying to build, and fix all conflicts. + + 5. Use `git diff HEAD^: HEAD:` to get subdir diff to write back to Nixpkgs. + +## Information on our current patch sets + +### "GNU Install Dirs" patches + +Use CMake's [`GNUInstallDirs`](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html) to support multiple outputs. + +Previously, LLVM Just hard-coded `bin`, `include`, and `lib${LLVM_TARGET_PREFIX}`. +We are making it use these variables. + +For the older LLVM versions, these patches live in https://github.com/Ericson2314/llvm-project branches `split-prefix`. +Instead of applying the patches to the worktree per the above instructions, one can checkout those directly and rebase those instead. + +For newer LLVM versions, enough has has been upstreamed, +(see https://reviews.llvm.org/differential/query/5UAfpj_9zHwY/ for my progress upstreaming), +that I have just assembled new gnu-install-dirs patches from the remaining unmerged patches instead of rebasing from the prior LLVM's gnu install dirs patch. diff --git a/llvm/TLI-musl.patch b/llvm/TLI-musl.patch new file mode 100644 index 0000000..1a69080 --- /dev/null +++ b/llvm/TLI-musl.patch @@ -0,0 +1,35 @@ +From 5c571082fdaf61f6df19d9b7137dc26d71334058 Mon Sep 17 00:00:00 2001 +From: Natanael Copa +Date: Thu, 18 Feb 2016 10:33:04 +0100 +Subject: [PATCH 2/3] Fix build with musl libc + +On musl libc the fopen64 and fopen are the same thing, but for +compatibility they have a `#define fopen64 fopen`. Same applies for +fseek64, fstat64, fstatvfs64, ftello64, lstat64, stat64 and tmpfile64. +--- + include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h +index 7becdf0..7f14427 100644 +--- a/include/llvm/Analysis/TargetLibraryInfo.h ++++ b/include/llvm/Analysis/TargetLibraryInfo.h +@@ -18,6 +18,15 @@ + #include "llvm/IR/Module.h" + #include "llvm/Pass.h" + ++#undef fopen64 ++#undef fseeko64 ++#undef fstat64 ++#undef fstatvfs64 ++#undef ftello64 ++#undef lstat64 ++#undef stat64 ++#undef tmpfile64 ++ + namespace llvm { + /// VecDesc - Describes a possible vectorization of a function. + /// Function 'VectorFnName' is equivalent to 'ScalarFnName' vectorized +-- +2.7.3 + diff --git a/llvm/aarch64.patch b/llvm/aarch64.patch new file mode 100644 index 0000000..205074e --- /dev/null +++ b/llvm/aarch64.patch @@ -0,0 +1,51 @@ +--- lib/Support/Unix/Memory.inc ++++ lib/Support/Unix/Memory.inc +@@ -126,8 +126,12 @@ + Result.Address = Addr; + Result.Size = NumPages*PageSize; + +- if (PFlags & MF_EXEC) +- Memory::InvalidateInstructionCache(Result.Address, Result.Size); ++ // Rely on protectMappedMemory to invalidate instruction cache. ++ if (PFlags & MF_EXEC) { ++ EC = Memory::protectMappedMemory (Result, PFlags); ++ if (EC != std::error_code()) ++ return MemoryBlock(); ++ } + + return Result; + } +@@ -156,15 +160,31 @@ + return std::error_code(EINVAL, std::generic_category()); + + int Protect = getPosixProtectionFlags(Flags); +- + uintptr_t Start = alignAddr((uint8_t *)M.Address - PageSize + 1, PageSize); + uintptr_t End = alignAddr((uint8_t *)M.Address + M.Size, PageSize); ++ ++ bool InvalidateCache = (Flags & MF_EXEC); ++ ++#if defined(__arm__) || defined(__aarch64__) ++ // Certain ARM implementations treat icache clear instruction as a memory read, ++ // and CPU segfaults on trying to clear cache on !PROT_READ page. Therefore we need ++ // to temporarily add PROT_READ for the sake of flushing the instruction caches. ++ if (InvalidateCache && !(Protect & PROT_READ)) { ++ int Result = ::mprotect((void *)Start, End - Start, Protect | PROT_READ); ++ if (Result != 0) ++ return std::error_code(errno, std::generic_category()); ++ ++ Memory::InvalidateInstructionCache(M.Address, M.Size); ++ InvalidateCache = false; ++ } ++#endif ++ + int Result = ::mprotect((void *)Start, End - Start, Protect); + + if (Result != 0) + return std::error_code(errno, std::generic_category()); + +- if (Flags & MF_EXEC) ++ if (InvalidateCache) + Memory::InvalidateInstructionCache(M.Address, M.Size); + + return std::error_code(); diff --git a/llvm/clang-11-12-LLVMgold-path.patch b/llvm/clang-11-12-LLVMgold-path.patch new file mode 100644 index 0000000..8f89919 --- /dev/null +++ b/llvm/clang-11-12-LLVMgold-path.patch @@ -0,0 +1,13 @@ +diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp +index 6b6e276b8ce7..7896542a1202 100644 +--- a/lib/Driver/ToolChains/CommonArgs.cpp ++++ b/lib/Driver/ToolChains/CommonArgs.cpp +@@ -409,7 +409,7 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args, + + SmallString<1024> Plugin; + llvm::sys::path::native( +- Twine(D.Dir) + "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold" + Suffix, ++ Twine("@libllvmLibdir@" "/LLVMgold") + Suffix, + Plugin); + CmdArgs.push_back(Args.MakeArgString(Plugin)); + } diff --git a/llvm/clang-6-10-LLVMgold-path.patch b/llvm/clang-6-10-LLVMgold-path.patch new file mode 100644 index 0000000..9350431 --- /dev/null +++ b/llvm/clang-6-10-LLVMgold-path.patch @@ -0,0 +1,15 @@ +diff --git a/lib/Driver/ToolChains/CommonArgs.cpp b/lib/Driver/ToolChains/CommonArgs.cpp +index 37ec73468570..b73e75aa6e59 100644 +--- a/lib/Driver/ToolChains/CommonArgs.cpp ++++ b/lib/Driver/ToolChains/CommonArgs.cpp +@@ -370,8 +370,8 @@ void tools::AddGoldPlugin(const ToolChain &ToolChain, const ArgList &Args, + #endif + + SmallString<1024> Plugin; +- llvm::sys::path::native(Twine(ToolChain.getDriver().Dir) + +- "/../lib" CLANG_LIBDIR_SUFFIX "/LLVMgold" + ++ llvm::sys::path::native(Twine("@libllvmLibdir@" ++ "/LLVMgold") + + Suffix, + Plugin); + CmdArgs.push_back(Args.MakeArgString(Plugin)); diff --git a/llvm/common/bintools.nix b/llvm/common/bintools.nix new file mode 100644 index 0000000..a60060e --- /dev/null +++ b/llvm/common/bintools.nix @@ -0,0 +1,48 @@ +{ lib, runCommand, stdenv, llvm, lld, version, release_version }: + +let + targetPrefix = lib.optionalString (stdenv.hostPlatform != stdenv.targetPlatform) "${stdenv.targetPlatform.config}-"; +in +runCommand "llvm-binutils-${version}" +{ + preferLocalBuild = true; + passthru = { + isLLVM = true; + }; +} + ('' + mkdir -p $out/bin + for prog in ${lld}/bin/*; do + ln -s $prog $out/bin/${targetPrefix}$(basename $prog) + done + for prog in ${llvm}/bin/*; do + ln -sf $prog $out/bin/${targetPrefix}$(basename $prog) + done + + llvmBin="${llvm}/bin" + + ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ar + ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}dlltool + ln -s $llvmBin/llvm-ar $out/bin/${targetPrefix}ranlib + ln -s $llvmBin/llvm-cxxfilt $out/bin/${targetPrefix}c++filt + ln -s $llvmBin/llvm-dwp $out/bin/${targetPrefix}dwp + ln -s $llvmBin/llvm-nm $out/bin/${targetPrefix}nm + ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}objcopy + ln -s $llvmBin/llvm-objcopy $out/bin/${targetPrefix}strip + ln -s $llvmBin/llvm-objdump $out/bin/${targetPrefix}objdump + ln -s $llvmBin/llvm-readobj $out/bin/${targetPrefix}readelf + ln -s $llvmBin/llvm-size $out/bin/${targetPrefix}size + ln -s $llvmBin/llvm-strings $out/bin/${targetPrefix}strings + ln -s $llvmBin/llvm-symbolizer $out/bin/${targetPrefix}addr2line + + if [ -e "$llvmBin/llvm-debuginfod" ]; then + ln -s $llvmBin/llvm-debuginfod $out/bin/${targetPrefix}debuginfod + ln -s $llvmBin/llvm-debuginfod-find $out/bin/${targetPrefix}debuginfod-find + fi + + ln -s ${lld}/bin/lld $out/bin/${targetPrefix}ld + + # Only >=13 show GNU windres compatible in help + '' + lib.optionalString (lib.versionAtLeast release_version "13") '' + ln -s $llvmBin/llvm-rc $out/bin/${targetPrefix}windres + '') diff --git a/llvm/common/clang/5-8-purity.patch b/llvm/common/clang/5-8-purity.patch new file mode 100644 index 0000000..b30d0d0 --- /dev/null +++ b/llvm/common/clang/5-8-purity.patch @@ -0,0 +1,30 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -494,13 +494,6 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + if (!Args.hasArg(options::OPT_static)) { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); +- +- if (!Args.hasArg(options::OPT_shared)) { +- const std::string Loader = +- D.DyldPrefix + ToolChain.getDynamicLinker(Args); +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Loader)); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 + diff --git a/llvm/common/clang/add-nostdlibinc-flag.patch b/llvm/common/clang/add-nostdlibinc-flag.patch new file mode 100644 index 0000000..80c2eb3 --- /dev/null +++ b/llvm/common/clang/add-nostdlibinc-flag.patch @@ -0,0 +1,18 @@ +diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp +index 3f29afd35971..223d2769cdfc 100644 +--- a/lib/Driver/Driver.cpp ++++ b/lib/Driver/Driver.cpp +@@ -491,6 +491,13 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { + } + #endif + ++ { ++ Arg *A = DAL->MakeFlagArg(/*BaseArg=*/nullptr, ++ Opts.getOption(options::OPT_nostdlibinc)); ++ A->claim(); ++ DAL->append(A); ++ } ++ + return DAL; + } + diff --git a/llvm/common/compiler-rt/7-12-codesign.patch b/llvm/common/compiler-rt/7-12-codesign.patch new file mode 100644 index 0000000..3cc12b9 --- /dev/null +++ b/llvm/common/compiler-rt/7-12-codesign.patch @@ -0,0 +1,33 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc5fb9ff7..b64eb4246 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -210,14 +210,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR} +- ) +- endif() + endif() + install(TARGETS ${libname} + ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR} +2.14.1 + diff --git a/llvm/common/compiler-rt/armv6-mcr-dmb.patch b/llvm/common/compiler-rt/armv6-mcr-dmb.patch new file mode 100644 index 0000000..acdcc9e --- /dev/null +++ b/llvm/common/compiler-rt/armv6-mcr-dmb.patch @@ -0,0 +1,75 @@ +From a11d1cc41c725ec6dee58f75e4a852a658dd7543 Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Thu, 10 Mar 2022 19:30:00 -0800 +Subject: [PATCH] [builtins] Use mcr for dmb instruction on armv6 + +At present compiler-rt cross compiles for armv6 ( -march=armv6 ) but includes +dmb instructions which are only available in armv7+ this causes SIGILL on +clang+compiler-rt compiled components on rpi0w platforms. + +Reviewed By: MaskRay + +Differential Revision: https://reviews.llvm.org/D99282 +--- + compiler-rt/lib/builtins/arm/sync-ops.h | 8 ++++---- + compiler-rt/lib/builtins/assembly.h | 8 ++++++++ + 2 files changed, 12 insertions(+), 4 deletions(-) + +diff --git a/lib/builtins/arm/sync-ops.h b/lib/builtins/arm/sync-ops.h +index c9623249e5d20..7a26170741ad2 100644 +--- a/lib/builtins/arm/sync-ops.h ++++ b/lib/builtins/arm/sync-ops.h +@@ -19,14 +19,14 @@ + .thumb; \ + .syntax unified; \ + DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op) \ +- dmb; \ ++ DMB; \ + mov r12, r0; \ + LOCAL_LABEL(tryatomic_##op) : ldrex r0, [r12]; \ + op(r2, r0, r1); \ + strex r3, r2, [r12]; \ + cmp r3, #0; \ + bne LOCAL_LABEL(tryatomic_##op); \ +- dmb; \ ++ DMB; \ + bx lr + + #define SYNC_OP_8(op) \ +@@ -35,14 +35,14 @@ + .syntax unified; \ + DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op) \ + push {r4, r5, r6, lr}; \ +- dmb; \ ++ DMB; \ + mov r12, r0; \ + LOCAL_LABEL(tryatomic_##op) : ldrexd r0, r1, [r12]; \ + op(r4, r5, r0, r1, r2, r3); \ + strexd r6, r4, r5, [r12]; \ + cmp r6, #0; \ + bne LOCAL_LABEL(tryatomic_##op); \ +- dmb; \ ++ DMB; \ + pop { r4, r5, r6, pc } + + #define MINMAX_4(rD, rN, rM, cmp_kind) \ +diff --git a/lib/builtins/assembly.h b/lib/builtins/assembly.h +index 69a3d8620f924..06aa18162e3b4 100644 +--- a/lib/builtins/assembly.h ++++ b/lib/builtins/assembly.h +@@ -189,6 +189,14 @@ + JMP(ip) + #endif + ++#if __ARM_ARCH >= 7 ++#define DMB dmb ++#elif __ARM_ARCH >= 6 ++#define DMB mcr p15, #0, r0, c7, c10, #5 ++#else ++#error only supported on ARMv6+ ++#endif ++ + #if defined(USE_THUMB_2) + #define WIDE(op) op.w + #else + diff --git a/llvm/common/compiler-rt/armv6-no-ldrexd-strexd.patch b/llvm/common/compiler-rt/armv6-no-ldrexd-strexd.patch new file mode 100644 index 0000000..2537ae1 --- /dev/null +++ b/llvm/common/compiler-rt/armv6-no-ldrexd-strexd.patch @@ -0,0 +1,162 @@ +From 4fe3f21bf8b20c766877d2251d61118d0ff36688 Mon Sep 17 00:00:00 2001 +From: Ben Wolsieffer +Date: Wed, 7 Dec 2022 14:56:51 -0500 +Subject: [PATCH] [compiler-rt][builtins] Do not use ldrexd or strexd on ARMv6 + +The ldrexd and strexd instructions are not available on base ARMv6, and were +only added in ARMv6K (see [1]). This patch solves this problem once and for all +using the __ARM_FEATURE_LDREX macro (see [2]) defined in the ARM C Language +Extensions (ACLE). Although this macro is technically deprecated in the ACLE, +it allows compiler-rt to reliably detect whether ldrexd and strexd are supported +without complicated conditionals to detect different ARM architecture variants. + +[1] https://developer.arm.com/documentation/dht0008/a/ch01s02s01 +[2] https://arm-software.github.io/acle/main/acle.html#ldrexstrex + +Differential Revision: https://reviews.llvm.org/D139585 +--- + compiler-rt/lib/builtins/arm/sync_fetch_and_add_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_and_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_max_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_min_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_nand_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_or_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_sub_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_umax_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_umin_8.S | 2 +- + compiler-rt/lib/builtins/arm/sync_fetch_and_xor_8.S | 2 +- + 10 files changed, 10 insertions(+), 10 deletions(-) + +diff --git a/lib/builtins/arm/sync_fetch_and_add_8.S b/lib/builtins/arm/sync_fetch_and_add_8.S +index 18bdd875b8b7..bee6f7ba0f34 100644 +--- a/lib/builtins/arm/sync_fetch_and_add_8.S ++++ b/lib/builtins/arm/sync_fetch_and_add_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define add_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \ + adds rD_LO, rN_LO, rM_LO ; \ + adc rD_HI, rN_HI, rM_HI +diff --git a/lib/builtins/arm/sync_fetch_and_and_8.S b/lib/builtins/arm/sync_fetch_and_and_8.S +index 3716eff809d5..b4e77a54edf6 100644 +--- a/lib/builtins/arm/sync_fetch_and_and_8.S ++++ b/lib/builtins/arm/sync_fetch_and_and_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define and_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \ + and rD_LO, rN_LO, rM_LO ; \ + and rD_HI, rN_HI, rM_HI +diff --git a/lib/builtins/arm/sync_fetch_and_max_8.S b/lib/builtins/arm/sync_fetch_and_max_8.S +index 06115ab55246..1813274cc649 100644 +--- a/lib/builtins/arm/sync_fetch_and_max_8.S ++++ b/lib/builtins/arm/sync_fetch_and_max_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define max_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, gt) + + SYNC_OP_8(max_8) +diff --git a/lib/builtins/arm/sync_fetch_and_min_8.S b/lib/builtins/arm/sync_fetch_and_min_8.S +index 4f3e299d95cc..fa8f3477757b 100644 +--- a/lib/builtins/arm/sync_fetch_and_min_8.S ++++ b/lib/builtins/arm/sync_fetch_and_min_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define min_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, lt) + + SYNC_OP_8(min_8) +diff --git a/lib/builtins/arm/sync_fetch_and_nand_8.S b/lib/builtins/arm/sync_fetch_and_nand_8.S +index 425c94474af7..fb27219ee200 100644 +--- a/lib/builtins/arm/sync_fetch_and_nand_8.S ++++ b/lib/builtins/arm/sync_fetch_and_nand_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define nand_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \ + bic rD_LO, rN_LO, rM_LO ; \ + bic rD_HI, rN_HI, rM_HI +diff --git a/lib/builtins/arm/sync_fetch_and_or_8.S b/lib/builtins/arm/sync_fetch_and_or_8.S +index 4f18dcf84df9..3b077c8737b1 100644 +--- a/lib/builtins/arm/sync_fetch_and_or_8.S ++++ b/lib/builtins/arm/sync_fetch_and_or_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define or_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \ + orr rD_LO, rN_LO, rM_LO ; \ + orr rD_HI, rN_HI, rM_HI +diff --git a/lib/builtins/arm/sync_fetch_and_sub_8.S b/lib/builtins/arm/sync_fetch_and_sub_8.S +index 25a4a1076555..c171607eabd8 100644 +--- a/lib/builtins/arm/sync_fetch_and_sub_8.S ++++ b/lib/builtins/arm/sync_fetch_and_sub_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define sub_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \ + subs rD_LO, rN_LO, rM_LO ; \ + sbc rD_HI, rN_HI, rM_HI +diff --git a/lib/builtins/arm/sync_fetch_and_umax_8.S b/lib/builtins/arm/sync_fetch_and_umax_8.S +index aa5213ff1def..d1224f758049 100644 +--- a/lib/builtins/arm/sync_fetch_and_umax_8.S ++++ b/lib/builtins/arm/sync_fetch_and_umax_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define umax_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, hi) + + SYNC_OP_8(umax_8) +diff --git a/lib/builtins/arm/sync_fetch_and_umin_8.S b/lib/builtins/arm/sync_fetch_and_umin_8.S +index 8b40541ab47d..595444e6d053 100644 +--- a/lib/builtins/arm/sync_fetch_and_umin_8.S ++++ b/lib/builtins/arm/sync_fetch_and_umin_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define umin_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) MINMAX_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI, lo) + + SYNC_OP_8(umin_8) +diff --git a/lib/builtins/arm/sync_fetch_and_xor_8.S b/lib/builtins/arm/sync_fetch_and_xor_8.S +index 7436eb1d4cae..9fc3d85cef75 100644 +--- a/lib/builtins/arm/sync_fetch_and_xor_8.S ++++ b/lib/builtins/arm/sync_fetch_and_xor_8.S +@@ -13,7 +13,7 @@ + + #include "sync-ops.h" + +-#if __ARM_ARCH_PROFILE != 'M' ++#if __ARM_FEATURE_LDREX & 8 + #define xor_8(rD_LO, rD_HI, rN_LO, rN_HI, rM_LO, rM_HI) \ + eor rD_LO, rN_LO, rM_LO ; \ + eor rD_HI, rN_HI, rM_HI +-- +2.38.1 + diff --git a/llvm/common/compiler-rt/armv6-scudo-libatomic.patch b/llvm/common/compiler-rt/armv6-scudo-libatomic.patch new file mode 100644 index 0000000..13b67eb --- /dev/null +++ b/llvm/common/compiler-rt/armv6-scudo-libatomic.patch @@ -0,0 +1,65 @@ +From a56bb19a9dc303a50ef12d83cd24c2395bf81076 Mon Sep 17 00:00:00 2001 +From: Ben Wolsieffer +Date: Wed, 7 Dec 2022 21:25:46 -0500 +Subject: [PATCH] [scudo][standalone] Use CheckAtomic to decide to link to + libatomic + +Standalone scudo uses the atomic operation builtin functions, which require +linking to libatomic on some platforms. Currently, this is done in an ad-hoc +manner. MIPS platforms always link to libatomic, and the tests are always linked +to it as well. libatomic is required on base ARMv6 (but not ARMv6K), but it is +currently not linked, causing the build to fail. + +This patch replaces this ad-hoc logic with the CheckAtomic CMake module already +used in other parts of LLVM. The CheckAtomic module checks whether std::atomic +requires libatomic, which is not strictly the same as checking the atomic +builtins, but should have the same results as far as I know. If this is +problematic, a custom version of CheckAtomic could be used to specifically test +the builtins. +--- + compiler-rt/lib/scudo/standalone/CMakeLists.txt | 7 +++++++ + compiler-rt/lib/scudo/standalone/tests/CMakeLists.txt | 4 +--- + 2 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/lib/scudo/standalone/CMakeLists.txt b/lib/scudo/standalone/CMakeLists.txt +index ae5c354768c8..eb27374ca520 100644 +--- a/lib/scudo/standalone/CMakeLists.txt ++++ b/lib/scudo/standalone/CMakeLists.txt +@@ -1,5 +1,8 @@ + add_compiler_rt_component(scudo_standalone) + ++include(DetermineGCCCompatible) ++include(CheckAtomic) ++ + include_directories(../.. include) + + set(SCUDO_CFLAGS) +@@ -34,6 +37,10 @@ list(APPEND SCUDO_LINK_FLAGS -Wl,-z,defs,-z,now,-z,relro) + + list(APPEND SCUDO_LINK_FLAGS -ffunction-sections -fdata-sections -Wl,--gc-sections) + ++if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) ++ list(APPEND SCUDO_LINK_FLAGS -latomic) ++endif() ++ + # We don't use the C++ standard library, so avoid including it by mistake. + append_list_if(COMPILER_RT_HAS_NOSTDLIBXX_FLAG -nostdlib++ SCUDO_LINK_FLAGS) + +diff --git a/lib/scudo/standalone/tests/CMakeLists.txt b/lib/scudo/standalone/tests/CMakeLists.txt +index 6d0936cbb5c1..70a5a7e959c1 100644 +--- a/lib/scudo/standalone/tests/CMakeLists.txt ++++ b/lib/scudo/standalone/tests/CMakeLists.txt +@@ -38,9 +38,7 @@ set(LINK_FLAGS + ${SANITIZER_TEST_CXX_LIBRARIES} + ) + list(APPEND LINK_FLAGS -pthread) +-# Linking against libatomic is required with some compilers +-check_library_exists(atomic __atomic_load_8 "" COMPILER_RT_HAS_LIBATOMIC) +-if (COMPILER_RT_HAS_LIBATOMIC) ++if(HAVE_CXX_ATOMICS_WITH_LIB OR HAVE_CXX_ATOMICS64_WITH_LIB) + list(APPEND LINK_FLAGS -latomic) + endif() + +-- +2.38.1 + diff --git a/llvm/common/compiler-rt/armv6-scudo-no-yield.patch b/llvm/common/compiler-rt/armv6-scudo-no-yield.patch new file mode 100644 index 0000000..2fd48ed --- /dev/null +++ b/llvm/common/compiler-rt/armv6-scudo-no-yield.patch @@ -0,0 +1,34 @@ +From ff0b373b959165477f45d9f5f9a8da471ae111ab Mon Sep 17 00:00:00 2001 +From: Ben Wolsieffer +Date: Wed, 7 Dec 2022 18:03:56 -0500 +Subject: [PATCH] [scudo][standalone] Only use yield on ARMv6K and newer + +The yield instruction is only available in ARMv6K and newer. It behaves as a +nop on single threaded platforms anyway, so use nop instead on unsupported +architectures. + +Differential Revision: https://reviews.llvm.org/D139600 +--- + compiler-rt/lib/scudo/standalone/common.h | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/lib/scudo/standalone/common.h b/lib/scudo/standalone/common.h +index bc3dfec6dbba..862cda1d4bc4 100644 +--- a/lib/scudo/standalone/common.h ++++ b/lib/scudo/standalone/common.h +@@ -109,7 +109,12 @@ inline void yieldProcessor(u8 Count) { + #elif defined(__aarch64__) || defined(__arm__) + __asm__ __volatile__("" ::: "memory"); + for (u8 I = 0; I < Count; I++) ++#if __ARM_ARCH >= 6 && !defined(__ARM_ARCH_6__) ++ // yield is supported on ARMv6K and newer + __asm__ __volatile__("yield"); ++#else ++ __asm__ __volatile__("nop"); ++#endif + #endif + __asm__ __volatile__("" ::: "memory"); + } +-- +2.38.1 + diff --git a/llvm/common/compiler-rt/armv6-sync-ops-no-thumb.patch b/llvm/common/compiler-rt/armv6-sync-ops-no-thumb.patch new file mode 100644 index 0000000..098a155 --- /dev/null +++ b/llvm/common/compiler-rt/armv6-sync-ops-no-thumb.patch @@ -0,0 +1,52 @@ +From 5017de8ba4b1fe985169cf54590e858a9019a91f Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Fri, 11 Mar 2022 16:25:49 -0800 +Subject: [PATCH] [builtins] Do not force thumb mode directive in + arm/sync-ops.h + +.thumb_func was not switching mode until [1] +so it did not show up but now that .thumb_func (without argument) is +switching mode, its causing build failures on armv6 ( rpi0 ) even when +build is explicitly asking for this file to be built with -marm (ARM +mode), therefore use DEFINE_COMPILERRT_FUNCTION macro to add function +header which considers arch and mode from compiler cmdline to decide if +the function is built using thumb mode or arm mode. + +[1] https://reviews.llvm.org/D101975 + +Note that it also needs https://reviews.llvm.org/D99282 + +Reviewed By: peter.smith, MaskRay + +Differential Revision: https://reviews.llvm.org/D104183 +--- + compiler-rt/lib/builtins/arm/sync-ops.h | 6 ++---- + 1 file changed, 2 insertions(+), 4 deletions(-) + +diff --git a/lib/builtins/arm/sync-ops.h b/lib/builtins/arm/sync-ops.h +index 7a26170741ad2..d914f9d3a1093 100644 +--- a/lib/builtins/arm/sync-ops.h ++++ b/lib/builtins/arm/sync-ops.h +@@ -16,9 +16,8 @@ + + #define SYNC_OP_4(op) \ + .p2align 2; \ +- .thumb; \ + .syntax unified; \ +- DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op) \ ++ DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op) \ + DMB; \ + mov r12, r0; \ + LOCAL_LABEL(tryatomic_##op) : ldrex r0, [r12]; \ +@@ -31,9 +30,8 @@ + + #define SYNC_OP_8(op) \ + .p2align 2; \ +- .thumb; \ + .syntax unified; \ +- DEFINE_COMPILERRT_THUMB_FUNCTION(__sync_fetch_and_##op) \ ++ DEFINE_COMPILERRT_FUNCTION(__sync_fetch_and_##op) \ + push {r4, r5, r6, lr}; \ + DMB; \ + mov r12, r0; \ + diff --git a/llvm/common/compiler-rt/armv7l-15.patch b/llvm/common/compiler-rt/armv7l-15.patch new file mode 100644 index 0000000..ca1c233 --- /dev/null +++ b/llvm/common/compiler-rt/armv7l-15.patch @@ -0,0 +1,32 @@ +diff -ur a/cmake/builtin-config-ix.cmake b/cmake/builtin-config-ix.cmake +--- a/cmake/builtin-config-ix.cmake @llvm 15.0.6 ++++ b/cmake/builtin-config-ix.cmake +@@ -46,7 +46,7 @@ + + set(ARM64 aarch64) +-set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv8m.main armv8.1m.main) ++set(ARM32 arm armhf armv6m armv7m armv7em armv7 armv7s armv7k armv7l armv8m.main armv8.1m.main) + set(AVR avr) + set(HEXAGON hexagon) + set(X86 i386) + set(X86_64 x86_64) +diff -ur a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +--- a/lib/builtins/CMakeLists.txt @llvm 15.0.6 ++++ b/lib/builtins/CMakeLists.txt +@@ -565,6 +565,7 @@ + set(armv7_SOURCES ${arm_SOURCES}) + set(armv7s_SOURCES ${arm_SOURCES}) + set(armv7k_SOURCES ${arm_SOURCES}) ++set(armv7l_SOURCES ${arm_SOURCES}) + set(arm64_SOURCES ${aarch64_SOURCES}) + + # macho_embedded archs +@@ -734,7 +735,7 @@ + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported +- if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em|armv8m.main|armv8.1m.main)$") ++ if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7l|armv7m|armv7em|armv8m.main|armv8.1m.main)$") + string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") + check_compile_definition(__VFP_FP__ "${CMAKE_C_FLAGS} ${_TARGET_${arch}_CFLAGS}" COMPILER_RT_HAS_${arch}_VFP) + if(NOT COMPILER_RT_HAS_${arch}_VFP) diff --git a/llvm/common/compiler-rt/darwin-plistbuddy-workaround.patch b/llvm/common/compiler-rt/darwin-plistbuddy-workaround.patch new file mode 100644 index 0000000..dae8b3a --- /dev/null +++ b/llvm/common/compiler-rt/darwin-plistbuddy-workaround.patch @@ -0,0 +1,25 @@ +CMake tries to read a list field from SDKSettings.plist, but the output of +xcbuild PlistBuddy is incompatible with Apple's. (Plus we don't want it in our +dependencies.) + +Simply assume ARM64 is supported by the SDK. We already limit the actual archs +we build for by setting DARWIN_osx_BUILTIN_ARCHS explicitely. + +--- a/cmake/builtin-config-ix.cmake ++++ b/cmake/builtin-config-ix.cmake +@@ -97,14 +97,7 @@ if(APPLE) + set(DARWIN_osx_BUILTIN_MIN_VER 10.5) + set(DARWIN_osx_BUILTIN_MIN_VER_FLAG + -mmacosx-version-min=${DARWIN_osx_BUILTIN_MIN_VER}) +- set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64}) +- # Add support for arm64 macOS if available in SDK. +- foreach(arch ${ARM64}) +- sdk_has_arch_support(${DARWIN_osx_SYSROOT} macosx ${arch} MACOS_ARM_SUPPORT) +- if (MACOS_ARM_SUPPORT) +- list(APPEND DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${arch}) +- endif() +- endforeach(arch) ++ set(DARWIN_osx_BUILTIN_ALL_POSSIBLE_ARCHS ${X86} ${X86_64} ${ARM64}) + + if(COMPILER_RT_ENABLE_IOS) + list(APPEND DARWIN_EMBEDDED_PLATFORMS ios) diff --git a/llvm/common/compiler-rt/glibc.patch b/llvm/common/compiler-rt/glibc.patch new file mode 100644 index 0000000..2d21179 --- /dev/null +++ b/llvm/common/compiler-rt/glibc.patch @@ -0,0 +1,48 @@ +diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc +index 54da635..c5dc1cd 100644 +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc +@@ -1158,8 +1158,9 @@ CHECK_SIZE_AND_OFFSET(ipc_perm, uid); + CHECK_SIZE_AND_OFFSET(ipc_perm, gid); + CHECK_SIZE_AND_OFFSET(ipc_perm, cuid); + CHECK_SIZE_AND_OFFSET(ipc_perm, cgid); +-#if !defined(__aarch64__) || !SANITIZER_LINUX || __GLIBC_PREREQ (2, 21) +-/* On aarch64 glibc 2.20 and earlier provided incorrect mode field. */ ++#if !SANITIZER_LINUX || __GLIBC_PREREQ (2, 31) ++/* glibc 2.30 and earlier provided 16-bit mode field instead of 32-bit ++ on many architectures. */ + CHECK_SIZE_AND_OFFSET(ipc_perm, mode); + #endif + +diff --git a/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/lib/sanitizer_common/sanitizer_platform_limits_posix.h +index f89a113..f6f986f 100644 +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h +@@ -213,26 +213,13 @@ namespace __sanitizer { + u64 __unused1; + u64 __unused2; + #elif defined(__sparc__) +-#if defined(__arch64__) + unsigned mode; +- unsigned short __pad1; +-#else +- unsigned short __pad1; +- unsigned short mode; + unsigned short __pad2; +-#endif + unsigned short __seq; + unsigned long long __unused1; + unsigned long long __unused2; +-#elif defined(__mips__) || defined(__aarch64__) || defined(__s390x__) +- unsigned int mode; +- unsigned short __seq; +- unsigned short __pad1; +- unsigned long __unused1; +- unsigned long __unused2; + #else +- unsigned short mode; +- unsigned short __pad1; ++ unsigned int mode; + unsigned short __seq; + unsigned short __pad2; + #if defined(__x86_64__) && !defined(_LP64) diff --git a/llvm/common/compiler-rt/libsanitizer-no-cyclades-11.patch b/llvm/common/compiler-rt/libsanitizer-no-cyclades-11.patch new file mode 100644 index 0000000..890230c --- /dev/null +++ b/llvm/common/compiler-rt/libsanitizer-no-cyclades-11.patch @@ -0,0 +1,80 @@ +https://github.com/llvm/llvm-project/commit/68d5235cb58f988c71b403334cd9482d663841ab.patch +https://reviews.llvm.org/D102059 +--- a/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc ++++ b/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc +@@ -370,15 +370,6 @@ static void ioctl_table_fill() { + + #if SANITIZER_GLIBC + // _(SIOCDEVPLIP, WRITE, struct_ifreq_sz); // the same as EQL_ENSLAVE +- _(CYGETDEFTHRESH, WRITE, sizeof(int)); +- _(CYGETDEFTIMEOUT, WRITE, sizeof(int)); +- _(CYGETMON, WRITE, struct_cyclades_monitor_sz); +- _(CYGETTHRESH, WRITE, sizeof(int)); +- _(CYGETTIMEOUT, WRITE, sizeof(int)); +- _(CYSETDEFTHRESH, NONE, 0); +- _(CYSETDEFTIMEOUT, NONE, 0); +- _(CYSETTHRESH, NONE, 0); +- _(CYSETTIMEOUT, NONE, 0); + _(EQL_EMANCIPATE, WRITE, struct_ifreq_sz); + _(EQL_ENSLAVE, WRITE, struct_ifreq_sz); + _(EQL_GETMASTRCFG, WRITE, struct_ifreq_sz); +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +@@ -143,7 +143,6 @@ typedef struct user_fpregs elf_fpregset_t; + # include + #endif + #include +-#include + #include + #include + #include +@@ -460,7 +459,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); + + #if SANITIZER_GLIBC + unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct); +- unsigned struct_cyclades_monitor_sz = sizeof(struct cyclades_monitor); + #if EV_VERSION > (0x010000) + unsigned struct_input_keymap_entry_sz = sizeof(struct input_keymap_entry); + #else +@@ -824,15 +822,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); + #endif // SANITIZER_LINUX + + #if SANITIZER_LINUX && !SANITIZER_ANDROID +- unsigned IOCTL_CYGETDEFTHRESH = CYGETDEFTHRESH; +- unsigned IOCTL_CYGETDEFTIMEOUT = CYGETDEFTIMEOUT; +- unsigned IOCTL_CYGETMON = CYGETMON; +- unsigned IOCTL_CYGETTHRESH = CYGETTHRESH; +- unsigned IOCTL_CYGETTIMEOUT = CYGETTIMEOUT; +- unsigned IOCTL_CYSETDEFTHRESH = CYSETDEFTHRESH; +- unsigned IOCTL_CYSETDEFTIMEOUT = CYSETDEFTIMEOUT; +- unsigned IOCTL_CYSETTHRESH = CYSETTHRESH; +- unsigned IOCTL_CYSETTIMEOUT = CYSETTIMEOUT; + unsigned IOCTL_EQL_EMANCIPATE = EQL_EMANCIPATE; + unsigned IOCTL_EQL_ENSLAVE = EQL_ENSLAVE; + unsigned IOCTL_EQL_GETMASTRCFG = EQL_GETMASTRCFG; +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h +@@ -983,7 +983,6 @@ extern unsigned struct_vt_mode_sz; + + #if SANITIZER_LINUX && !SANITIZER_ANDROID + extern unsigned struct_ax25_parms_struct_sz; +-extern unsigned struct_cyclades_monitor_sz; + extern unsigned struct_input_keymap_entry_sz; + extern unsigned struct_ipx_config_data_sz; + extern unsigned struct_kbdiacrs_sz; +@@ -1328,15 +1327,6 @@ extern unsigned IOCTL_VT_WAITACTIVE; + #endif // SANITIZER_LINUX + + #if SANITIZER_LINUX && !SANITIZER_ANDROID +-extern unsigned IOCTL_CYGETDEFTHRESH; +-extern unsigned IOCTL_CYGETDEFTIMEOUT; +-extern unsigned IOCTL_CYGETMON; +-extern unsigned IOCTL_CYGETTHRESH; +-extern unsigned IOCTL_CYGETTIMEOUT; +-extern unsigned IOCTL_CYSETDEFTHRESH; +-extern unsigned IOCTL_CYSETDEFTIMEOUT; +-extern unsigned IOCTL_CYSETTHRESH; +-extern unsigned IOCTL_CYSETTIMEOUT; + extern unsigned IOCTL_EQL_EMANCIPATE; + extern unsigned IOCTL_EQL_ENSLAVE; + extern unsigned IOCTL_EQL_GETMASTRCFG; diff --git a/llvm/common/compiler-rt/libsanitizer-no-cyclades-9.patch b/llvm/common/compiler-rt/libsanitizer-no-cyclades-9.patch new file mode 100644 index 0000000..7ef02a1 --- /dev/null +++ b/llvm/common/compiler-rt/libsanitizer-no-cyclades-9.patch @@ -0,0 +1,80 @@ +https://github.com/llvm/llvm-project/commit/68d5235cb58f988c71b403334cd9482d663841ab.patch +https://reviews.llvm.org/D102059 +--- a/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc ++++ b/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc +@@ -370,15 +370,6 @@ static void ioctl_table_fill() { + + #if SANITIZER_GLIBC + // _(SIOCDEVPLIP, WRITE, struct_ifreq_sz); // the same as EQL_ENSLAVE +- _(CYGETDEFTHRESH, WRITE, sizeof(int)); +- _(CYGETDEFTIMEOUT, WRITE, sizeof(int)); +- _(CYGETMON, WRITE, struct_cyclades_monitor_sz); +- _(CYGETTHRESH, WRITE, sizeof(int)); +- _(CYGETTIMEOUT, WRITE, sizeof(int)); +- _(CYSETDEFTHRESH, NONE, 0); +- _(CYSETDEFTIMEOUT, NONE, 0); +- _(CYSETTHRESH, NONE, 0); +- _(CYSETTIMEOUT, NONE, 0); + _(EQL_EMANCIPATE, WRITE, struct_ifreq_sz); + _(EQL_ENSLAVE, WRITE, struct_ifreq_sz); + _(EQL_GETMASTRCFG, WRITE, struct_ifreq_sz); +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cc ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cc +@@ -143,7 +143,6 @@ typedef struct user_fpregs elf_fpregset_t; + # include + #endif + #include +-#include + #include + #include + #include +@@ -460,7 +459,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); + + #if SANITIZER_GLIBC + unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct); +- unsigned struct_cyclades_monitor_sz = sizeof(struct cyclades_monitor); + #if EV_VERSION > (0x010000) + unsigned struct_input_keymap_entry_sz = sizeof(struct input_keymap_entry); + #else +@@ -824,15 +822,6 @@ unsigned struct_ElfW_Phdr_sz = sizeof(Elf_Phdr); + #endif // SANITIZER_LINUX + + #if SANITIZER_LINUX && !SANITIZER_ANDROID +- unsigned IOCTL_CYGETDEFTHRESH = CYGETDEFTHRESH; +- unsigned IOCTL_CYGETDEFTIMEOUT = CYGETDEFTIMEOUT; +- unsigned IOCTL_CYGETMON = CYGETMON; +- unsigned IOCTL_CYGETTHRESH = CYGETTHRESH; +- unsigned IOCTL_CYGETTIMEOUT = CYGETTIMEOUT; +- unsigned IOCTL_CYSETDEFTHRESH = CYSETDEFTHRESH; +- unsigned IOCTL_CYSETDEFTIMEOUT = CYSETDEFTIMEOUT; +- unsigned IOCTL_CYSETTHRESH = CYSETTHRESH; +- unsigned IOCTL_CYSETTIMEOUT = CYSETTIMEOUT; + unsigned IOCTL_EQL_EMANCIPATE = EQL_EMANCIPATE; + unsigned IOCTL_EQL_ENSLAVE = EQL_ENSLAVE; + unsigned IOCTL_EQL_GETMASTRCFG = EQL_GETMASTRCFG; +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.h ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.h +@@ -983,7 +983,6 @@ extern unsigned struct_vt_mode_sz; + + #if SANITIZER_LINUX && !SANITIZER_ANDROID + extern unsigned struct_ax25_parms_struct_sz; +- extern unsigned struct_cyclades_monitor_sz; + extern unsigned struct_input_keymap_entry_sz; + extern unsigned struct_ipx_config_data_sz; + extern unsigned struct_kbdiacrs_sz; +@@ -1328,15 +1327,6 @@ extern unsigned IOCTL_VT_WAITACTIVE; + #endif // SANITIZER_LINUX + + #if SANITIZER_LINUX && !SANITIZER_ANDROID +- extern unsigned IOCTL_CYGETDEFTHRESH; +- extern unsigned IOCTL_CYGETDEFTIMEOUT; +- extern unsigned IOCTL_CYGETMON; +- extern unsigned IOCTL_CYGETTHRESH; +- extern unsigned IOCTL_CYGETTIMEOUT; +- extern unsigned IOCTL_CYSETDEFTHRESH; +- extern unsigned IOCTL_CYSETDEFTIMEOUT; +- extern unsigned IOCTL_CYSETTHRESH; +- extern unsigned IOCTL_CYSETTIMEOUT; + extern unsigned IOCTL_EQL_EMANCIPATE; + extern unsigned IOCTL_EQL_ENSLAVE; + extern unsigned IOCTL_EQL_GETMASTRCFG; diff --git a/llvm/common/libcxxabi/no-threads.patch b/llvm/common/libcxxabi/no-threads.patch new file mode 100644 index 0000000..787f3e1 --- /dev/null +++ b/llvm/common/libcxxabi/no-threads.patch @@ -0,0 +1,12 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 4138acf..41b4763 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -362,6 +362,7 @@ if (NOT LIBCXXABI_ENABLE_THREADS) + " is also set to ON.") + endif() + add_definitions(-D_LIBCXXABI_HAS_NO_THREADS) ++ add_definitions(-D_LIBCPP_HAS_NO_THREADS) + endif() + + if (LIBCXXABI_HAS_EXTERNAL_THREAD_API) diff --git a/llvm/common/libcxxabi/wasm.patch b/llvm/common/libcxxabi/wasm.patch new file mode 100644 index 0000000..4ebfe46 --- /dev/null +++ b/llvm/common/libcxxabi/wasm.patch @@ -0,0 +1,16 @@ +diff --git a/cmake/modules/HandleLLVMOptions.cmake b/cmake/modules/HandleLLVMOptions.cmake +index 15497d405e0..33f7f18193a 100644 +--- a/cmake/modules/HandleLLVMOptions.cmake ++++ b/cmake/modules/HandleLLVMOptions.cmake +@@ -127,7 +127,10 @@ else(WIN32) + set(LLVM_HAVE_LINK_VERSION_SCRIPT 1) + endif() + else(FUCHSIA OR UNIX) +- MESSAGE(SEND_ERROR "Unable to determine platform") ++ if(${CMAKE_SYSTEM_NAME} MATCHES "Wasi") ++ else() ++ MESSAGE(SEND_ERROR "Unable to determine platform") ++ endif() + endif(FUCHSIA OR UNIX) + endif(WIN32) + diff --git a/llvm/common/lldb.nix b/llvm/common/lldb.nix new file mode 100644 index 0000000..1f5d4a1 --- /dev/null +++ b/llvm/common/lldb.nix @@ -0,0 +1,196 @@ +{ lib +, stdenv +, llvm_meta +, release_version +, cmake +, zlib +, ncurses +, swig +, which +, libedit +, libxml2 +, libllvm +, libclang +, python3 +, version +, darwin +, lit +, makeWrapper +, lua5_3 +, ninja +, runCommand +, src ? null +, monorepoSrc ? null +, patches ? [ ] +, enableManpages ? false +}: + +let + src' = + if monorepoSrc != null then + runCommand "lldb-src-${version}" { } '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/lldb "$out" + '' else src; +in + +stdenv.mkDerivation (rec { + passthru.monorepoSrc = monorepoSrc; + pname = "lldb"; + inherit version; + + src = src'; + inherit patches; + + outputs = [ "out" "lib" "dev" ]; + + sourceRoot = lib.optional (lib.versionAtLeast release_version "13") "${src.name}/${pname}"; + + nativeBuildInputs = [ + cmake + python3 + which + swig + lit + makeWrapper + lua5_3 + ] ++ lib.optionals enableManpages [ + python3.pkgs.sphinx + python3.pkgs.recommonmark + ] ++ lib.optionals (lib.versionAtLeast release_version "14") [ + ninja + ]; + + buildInputs = [ + ncurses + zlib + libedit + libxml2 + libllvm + ] ++ lib.optionals stdenv.isDarwin [ + darwin.libobjc + darwin.apple_sdk.libs.xpc + darwin.apple_sdk.frameworks.Foundation + darwin.bootstrap_cmds + darwin.apple_sdk.frameworks.Carbon + darwin.apple_sdk.frameworks.Cocoa + ] + # The older libSystem used on x86_64 macOS is missing the + # `` header which `lldb` uses. + # + # We copy this header over from macOS 10.12 SDK. + # + # See here for context: + # https://github.com/NixOS/nixpkgs/pull/194634#issuecomment-1272129132 + ++ lib.optional + ( + stdenv.targetPlatform.isDarwin + && !stdenv.targetPlatform.isAarch64 + && (lib.versionAtLeast release_version "15") + ) + ( + runCommand "bsm-audit-session-header" { } '' + install -Dm444 \ + "${lib.getDev darwin.apple_sdk.sdk}/include/bsm/audit_session.h" \ + "$out/include/bsm/audit_session.h" + '' + ); + + hardeningDisable = [ "format" ]; + + cmakeFlags = [ + "-DLLDB_INCLUDE_TESTS=${if doCheck then "YES" else "NO"}" + "-DLLVM_ENABLE_RTTI=OFF" + "-DClang_DIR=${lib.getDev libclang}/lib/cmake" + "-DLLVM_EXTERNAL_LIT=${lit}/bin/lit" + ] ++ lib.optionals stdenv.isDarwin [ + "-DLLDB_USE_SYSTEM_DEBUGSERVER=ON" + ] ++ lib.optionals (!stdenv.isDarwin) [ + "-DLLDB_CODESIGN_IDENTITY=" # codesigning makes nondeterministic + ] ++ lib.optionals enableManpages ([ + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + ] ++ lib.optionals (lib.versionAtLeast release_version "15") [ + # docs reference `automodapi` but it's not added to the extensions list when + # only building the manpages: + # https://github.com/llvm/llvm-project/blob/af6ec9200b09039573d85e349496c4f5b17c3d7f/lldb/docs/conf.py#L54 + # + # so, we just ignore the resulting errors + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ]) ++ lib.optionals doCheck [ + "-DLLDB_TEST_C_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc" + "-DLLDB_TEST_CXX_COMPILER=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++" + ]; + + doCheck = false; + doInstallCheck = lib.versionOlder release_version "15"; + + # TODO: cleanup with mass-rebuild + installCheckPhase = '' + if [ ! -e $lib/${python3.sitePackages}/lldb/_lldb*.so ] ; then + echo "ERROR: python files not installed where expected!"; + return 1; + fi + '' # Something lua is built on older versions but this file doesn't exist. + + lib.optionalString (lib.versionAtLeast release_version "14") '' + if [ ! -e "$lib/lib/lua/${lua5_3.luaversion}/lldb.so" ] ; then + echo "ERROR: lua files not installed where expected!"; + return 1; + fi + ''; + + postInstall = '' + wrapProgram $out/bin/lldb --prefix PYTHONPATH : $lib/${python3.sitePackages}/ + + # Editor support + # vscode: + install -D ../tools/lldb-vscode/package.json $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/package.json + mkdir -p $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ln -s $out/bin/*-vscode $out/share/vscode/extensions/llvm-org.lldb-vscode-0.1.0/bin + ''; + + meta = llvm_meta // { + homepage = "https://lldb.llvm.org/"; + description = "A next-generation high-performance debugger"; + longDescription = '' + LLDB is a next generation, high-performance debugger. It is built as a set + of reusable components which highly leverage existing libraries in the + larger LLVM Project, such as the Clang expression parser and LLVM + disassembler. + ''; + # llvm <10 never built on aarch64-darwin since first introduction in nixpkgs + broken = + (lib.versionOlder release_version "11" && stdenv.isDarwin && stdenv.isAarch64) + || (((lib.versions.major release_version) == "13") && stdenv.isDarwin); + }; +} // lib.optionalAttrs enableManpages { + pname = "lldb-manpages"; + + buildPhase = lib.optionalString (lib.versionOlder release_version "15") '' + make ${if (lib.versionOlder release_version "12") then "docs-man" else "docs-lldb-man"} + ''; + + + ninjaFlags = lib.optionals (lib.versionAtLeast release_version "15") [ "docs-lldb-man" ]; + + propagatedBuildInputs = [ ]; + + # manually install lldb man page + installPhase = '' + mkdir -p $out/share/man/man1 + install docs/man/lldb.1 -t $out/share/man/man1/ + ''; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLDB ${version}"; + }; +}) diff --git a/llvm/exegesis-force-bdver2.patch b/llvm/exegesis-force-bdver2.patch new file mode 100644 index 0000000..c265415 --- /dev/null +++ b/llvm/exegesis-force-bdver2.patch @@ -0,0 +1,11 @@ +diff --git a/test/tools/llvm-exegesis/X86/uops-CMOV16rm-noreg.s b/test/tools/llvm-exegesis/X86/uops-CMOV16rm-noreg.s +index 3fc1f31d54dc..a4c9bdd92131 100644 +--- a/test/tools/llvm-exegesis/X86/uops-CMOV16rm-noreg.s ++++ b/test/tools/llvm-exegesis/X86/uops-CMOV16rm-noreg.s +@@ -1,5 +1,6 @@ + # RUN: llvm-exegesis -mode=uops -opcode-name=CMOV16rm -benchmarks-file=%t.CMOV16rm-uops.yaml + # RUN: FileCheck -check-prefixes=CHECK-YAML -input-file=%t.CMOV16rm-uops.yaml %s ++# RUN: sed -i 's,cpu_name:.*,cpu_name: bdver2,g' %t.CMOV16rm-uops.yaml + # RUN: llvm-exegesis -mcpu=bdver2 -mode=analysis -benchmarks-file=%t.CMOV16rm-uops.yaml -analysis-clusters-output-file=- -analysis-clustering-epsilon=0.1 -analysis-inconsistency-epsilon=0.1 -analysis-numpoints=1 -analysis-clustering=naive | FileCheck -check-prefixes=CHECK-CLUSTERS %s + + # https://bugs.llvm.org/show_bug.cgi?id=41448 diff --git a/llvm/git/clang/default.nix b/llvm/git/clang/default.nix new file mode 100644 index 0000000..733f546 --- /dev/null +++ b/llvm/git/clang/default.nix @@ -0,0 +1,139 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, substituteAll, cmake, ninja, libxml2, libllvm, version, python3 +, buildLlvmTools +, fixDarwinDylibNames +, enableManpages ? false +}: + +let + self = stdenv.mkDerivation (rec { + pname = "clang"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/clang-tools-extra "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional enableManpages python3.pkgs.sphinx + ++ lib.optional stdenv.hostPlatform.isDarwin fixDarwinDylibNames; + + buildInputs = [ libxml2 libllvm ]; + + cmakeFlags = [ + "-DCLANG_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/clang" + "-DCLANGD_BUILD_XPC=OFF" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ lib.optionals enableManpages [ + "-DCLANG_INCLUDE_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ lib.optionals (!stdenv.buildPlatform.canExecute stdenv.hostPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + "-DCLANG_TABLEGEN=${buildLlvmTools.libclang.dev}/bin/clang-tblgen" + # Added in LLVM15: + # `clang-tidy-confusable-chars-gen`: https://github.com/llvm/llvm-project/commit/c3574ef739fbfcc59d405985a3a4fa6f4619ecdb + # `clang-pseudo-gen`: https://github.com/llvm/llvm-project/commit/cd2292ef824591cc34cc299910a3098545c840c7 + "-DCLANG_TIDY_CONFUSABLE_CHARS_GEN=${buildLlvmTools.libclang.dev}/bin/clang-tidy-confusable-chars-gen" + "-DCLANG_PSEUDO_GEN=${buildLlvmTools.libclang.dev}/bin/clang-pseudo-gen" + ]; + + patches = [ + ./purity.patch + # https://reviews.llvm.org/D51899 + ./gnu-install-dirs.patch + ../../common/clang/add-nostdlibinc-flag.patch + (substituteAll { + src = ../../clang-11-12-LLVMgold-path.patch; + libllvmLibdir = "${libllvm.lib}/lib"; + }) + ]; + + postPatch = '' + (cd tools && ln -s ../../clang-tools-extra extra) + '' + lib.optionalString stdenv.hostPlatform.isMusl '' + sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp + ''; + + outputs = [ "out" "lib" "dev" "python" ]; + + env = lib.optionalAttrs (stdenv.buildPlatform != stdenv.hostPlatform) { + # The following warning is triggered with (at least) gcc >= + # 12, but appears to occur only for cross compiles. + NIX_CFLAGS_COMPILE = "-Wno-maybe-uninitialized"; + }; + + postInstall = '' + ln -sv $out/bin/clang $out/bin/cpp + + # Move libclang to 'lib' output + moveToOutput "lib/libclang.*" "$lib" + moveToOutput "lib/libclang-cpp.*" "$lib" + substituteInPlace $dev/lib/cmake/clang/ClangTargets-release.cmake \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang." "$lib/lib/libclang." \ + --replace "\''${_IMPORT_PREFIX}/lib/libclang-cpp." "$lib/lib/libclang-cpp." + + mkdir -p $python/bin $python/share/{clang,scan-view} + mv $out/bin/{git-clang-format,scan-view} $python/bin + if [ -e $out/bin/set-xcode-analyzer ]; then + mv $out/bin/set-xcode-analyzer $python/bin + fi + mv $out/share/clang/*.py $python/share/clang + mv $out/share/scan-view/*.py $python/share/scan-view + rm $out/bin/c-index-test + patchShebangs $python/bin + + mkdir -p $dev/bin + cp bin/{clang-tblgen,clang-tidy-confusable-chars-gen,clang-pseudo-gen} $dev/bin + ''; + + passthru = { + inherit libllvm; + isClang = true; + hardeningUnsupportedFlags = [ "fortify3" ]; + }; + + meta = llvm_meta // { + homepage = "https://clang.llvm.org/"; + description = "A C language family frontend for LLVM"; + longDescription = '' + The Clang project provides a language front-end and tooling + infrastructure for languages in the C language family (C, C++, Objective + C/C++, OpenCL, CUDA, and RenderScript) for the LLVM project. + It aims to deliver amazingly fast compiles, extremely useful error and + warning messages and to provide a platform for building great source + level tools. The Clang Static Analyzer and clang-tidy are tools that + automatically find bugs in your code, and are great examples of the sort + of tools that can be built using the Clang frontend as a library to + parse C/C++ code. + ''; + mainProgram = "clang"; + }; + } // lib.optionalAttrs enableManpages { + pname = "clang-manpages"; + + ninjaFlags = [ "docs-clang-man" ]; + + installPhase = '' + mkdir -p $out/share/man/man1 + # Manually install clang manpage + cp docs/man/*.1 $out/share/man/man1/ + ''; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man page for Clang ${version}"; + }; + }); +in self diff --git a/llvm/git/clang/gnu-install-dirs.patch b/llvm/git/clang/gnu-install-dirs.patch new file mode 100644 index 0000000..f767c56 --- /dev/null +++ b/llvm/git/clang/gnu-install-dirs.patch @@ -0,0 +1,105 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index c27beec313d7..480f13e73c9f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -78,15 +78,17 @@ if(CLANG_BUILT_STANDALONE) + if (NOT LLVM_CONFIG_FOUND) + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config + # path is removed. +- set(MAIN_INCLUDE_DIR "${LLVM_INCLUDE_DIR}") ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") + # N.B. this is just a default value, the CACHE PATHs below can be overriden. + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") + set(TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") + set(LIBRARY_DIR "${LLVM_LIBRARY_DIR}") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") + endif() + +- set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + set(LLVM_TOOLS_BINARY_DIR "${TOOLS_BINARY_DIR}" CACHE PATH "Path to llvm/bin") +@@ -128,7 +130,7 @@ if(CLANG_BUILT_STANDALONE) + set(LLVM_INCLUDE_TESTS ON) + endif() + +- include_directories("${LLVM_BINARY_DIR}/include" "${LLVM_MAIN_INCLUDE_DIR}") ++ include_directories(${LLVM_INCLUDE_DIRS}) + link_directories("${LLVM_LIBRARY_DIR}") + + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin ) +diff --git a/cmake/modules/AddClang.cmake b/cmake/modules/AddClang.cmake +index 21ac332e4f5f..b16c314bd1e2 100644 +--- a/cmake/modules/AddClang.cmake ++++ b/cmake/modules/AddClang.cmake +@@ -119,8 +119,8 @@ macro(add_clang_library name) + install(TARGETS ${lib} + COMPONENT ${lib} + ${export_to_clangtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (NOT LLVM_ENABLE_IDE) +diff --git a/lib/Headers/CMakeLists.txt b/lib/Headers/CMakeLists.txt +index 6e2060991b92..b9bc930d26b8 100644 +--- a/lib/Headers/CMakeLists.txt ++++ b/lib/Headers/CMakeLists.txt +@@ -420,7 +420,7 @@ add_header_target("openmp-resource-headers" ${openmp_wrapper_files}) + add_header_target("windows-resource-headers" ${windows_only_files}) + add_header_target("utility-resource-headers" ${utility_files}) + +-set(header_install_dir lib${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) ++set(header_install_dir ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/clang/${CLANG_VERSION}/include) + + ############################################################# + # Install rules for the catch-all clang-resource-headers target +diff --git a/tools/libclang/CMakeLists.txt b/tools/libclang/CMakeLists.txt +index 8d95d0900e8c..ebc70ff7526d 100644 +--- a/tools/libclang/CMakeLists.txt ++++ b/tools/libclang/CMakeLists.txt +@@ -180,7 +180,7 @@ foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS}) + COMPONENT + libclang-python-bindings + DESTINATION +- "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") ++ "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages") + endforeach() + if(NOT LLVM_ENABLE_IDE) + add_custom_target(libclang-python-bindings) +diff --git a/tools/scan-build-py/CMakeLists.txt b/tools/scan-build-py/CMakeLists.txt +index 061dc7ef4dd9..adc54b2edc32 100644 +--- a/tools/scan-build-py/CMakeLists.txt ++++ b/tools/scan-build-py/CMakeLists.txt +@@ -88,7 +88,7 @@ foreach(lib ${LibScanbuild}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/${lib}) + install(PROGRAMS lib/libscanbuild/${lib} +- DESTINATION lib/libscanbuild ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild" + COMPONENT scan-build-py) + endforeach() + +@@ -106,7 +106,7 @@ foreach(resource ${LibScanbuildResources}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libscanbuild/resources/${resource}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libscanbuild/resources/${resource}) + install(PROGRAMS lib/libscanbuild/resources/${resource} +- DESTINATION lib/libscanbuild/resources ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libscanbuild/resources" + COMPONENT scan-build-py) + endforeach() + +@@ -122,7 +122,7 @@ foreach(lib ${LibEar}) + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lib/libear/${lib}) + list(APPEND Depends ${CMAKE_BINARY_DIR}/lib/libear/${lib}) + install(PROGRAMS lib/libear/${lib} +- DESTINATION lib/libear ++ DESTINATION "${CMAKE_INSTALL_LIBDIR}/libear" + COMPONENT scan-build-py) + endforeach() + diff --git a/llvm/git/clang/purity.patch b/llvm/git/clang/purity.patch new file mode 100644 index 0000000..1c94f29 --- /dev/null +++ b/llvm/git/clang/purity.patch @@ -0,0 +1,29 @@ +From 4add81bba40dcec62c4ea4481be8e35ac53e89d8 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Thu, 18 May 2017 11:56:12 -0500 +Subject: [PATCH] "purity" patch for 5.0 + +--- + lib/Driver/ToolChains/Gnu.cpp | 7 ------- + 1 file changed, 7 deletions(-) + +diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp +index fe3c0191bb..c6a482bece 100644 +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -487,13 +487,7 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA, + } else { + if (Args.hasArg(options::OPT_rdynamic)) + CmdArgs.push_back("-export-dynamic"); + +- if (!Args.hasArg(options::OPT_shared) && !IsStaticPIE && +- !Args.hasArg(options::OPT_r)) { +- CmdArgs.push_back("-dynamic-linker"); +- CmdArgs.push_back(Args.MakeArgString(Twine(D.DyldPrefix) + +- ToolChain.getDynamicLinker(Args))); +- } + } + + CmdArgs.push_back("-o"); +-- +2.11.0 diff --git a/llvm/git/compiler-rt/X86-support-extension.patch b/llvm/git/compiler-rt/X86-support-extension.patch new file mode 100644 index 0000000..07013e5 --- /dev/null +++ b/llvm/git/compiler-rt/X86-support-extension.patch @@ -0,0 +1,21 @@ +diff --git a/lib/builtins/CMakeLists.txt b/lib/builtins/CMakeLists.txt +index 3a66dd9c3fb..7efc85d9f9f 100644 +--- a/lib/builtins/CMakeLists.txt ++++ b/lib/builtins/CMakeLists.txt +@@ -348,4 +348,8 @@ if (NOT MSVC) + ++ set(i486_SOURCES ${i386_SOURCES}) ++ set(i586_SOURCES ${i386_SOURCES}) ++ set(i686_SOURCES ${i386_SOURCES}) ++ + if (WIN32) + set(i386_SOURCES + ${i386_SOURCES} +@@ -723,6 +723,7 @@ else () + endif() + + foreach (arch ${BUILTIN_SUPPORTED_ARCH}) ++ message("arch: ${arch}") + if (CAN_TARGET_${arch}) + # For ARM archs, exclude any VFP builtins if VFP is not supported + if (${arch} MATCHES "^(arm|armhf|armv7|armv7s|armv7k|armv7m|armv7em)$") diff --git a/llvm/git/compiler-rt/codesign.patch b/llvm/git/compiler-rt/codesign.patch new file mode 100644 index 0000000..065959d --- /dev/null +++ b/llvm/git/compiler-rt/codesign.patch @@ -0,0 +1,33 @@ +From 3dec5f3475a26aeb4678627795c4b67c6b7b4785 Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Tue, 19 Sep 2017 13:13:06 -0500 +Subject: [PATCH] remove codesign use on Apple, disable ios sim testing that + needs it + +--- + cmake/Modules/AddCompilerRT.cmake | 8 ------ + test/asan/CMakeLists.txt | 52 --------------------------------------- + test/tsan/CMakeLists.txt | 47 ----------------------------------- + 3 files changed, 107 deletions(-) + +diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake +index bc69ec95c419..9f100fdcec2f 100644 +--- a/cmake/Modules/AddCompilerRT.cmake ++++ b/cmake/Modules/AddCompilerRT.cmake +@@ -366,14 +366,6 @@ function(add_compiler_rt_runtime name type) + set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "") + set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib") + endif() +- if(APPLE) +- # Ad-hoc sign the dylibs +- add_custom_command(TARGET ${libname} +- POST_BUILD +- COMMAND codesign --sign - $ +- WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR} +- ) +- endif() + endif() + + set(parent_target_arg) +2.14.1 + diff --git a/llvm/git/compiler-rt/darwin-targetconditionals.patch b/llvm/git/compiler-rt/darwin-targetconditionals.patch new file mode 100644 index 0000000..425dc2a --- /dev/null +++ b/llvm/git/compiler-rt/darwin-targetconditionals.patch @@ -0,0 +1,71 @@ +diff --git a/lib/sanitizer_common/sanitizer_mac.cpp b/lib/sanitizer_common/sanitizer_mac.cpp +--- a/lib/sanitizer_common/sanitizer_mac.cpp ++++ b/lib/sanitizer_common/sanitizer_mac.cpp +@@ -613,9 +613,15 @@ HandleSignalMode GetHandleSignalMode(int signum) { + // Offset example: + // XNU 17 -- macOS 10.13 -- iOS 11 -- tvOS 11 -- watchOS 4 + constexpr u16 GetOSMajorKernelOffset() { +- if (TARGET_OS_OSX) return 4; +- if (TARGET_OS_IOS || TARGET_OS_TV) return 6; +- if (TARGET_OS_WATCH) return 13; ++#if TARGET_OS_OSX ++ return 4; ++#endif ++#if TARGET_OS_IOS || TARGET_OS_TV ++ return 6; ++#endif ++#if TARGET_OS_WATCH ++ return 13; ++#endif + } + + using VersStr = char[64]; +@@ -627,13 +633,13 @@ static uptr ApproximateOSVersionViaKernelVersion(VersStr vers) { + u16 os_major = kernel_major - offset; + + const char *format = "%d.0"; +- if (TARGET_OS_OSX) { +- if (os_major >= 16) { // macOS 11+ +- os_major -= 5; +- } else { // macOS 10.15 and below +- format = "10.%d"; +- } ++#if TARGET_OS_OSX ++ if (os_major >= 16) { // macOS 11+ ++ os_major -= 5; ++ } else { // macOS 10.15 and below ++ format = "10.%d"; + } ++#endif + return internal_snprintf(vers, sizeof(VersStr), format, os_major); + } + +@@ -681,15 +687,14 @@ void ParseVersion(const char *vers, u16 *major, u16 *minor) { + // Aligned versions example: + // macOS 10.15 -- iOS 13 -- tvOS 13 -- watchOS 6 + static void MapToMacos(u16 *major, u16 *minor) { +- if (TARGET_OS_OSX) +- return; +- +- if (TARGET_OS_IOS || TARGET_OS_TV) ++#if !TARGET_OS_OSX ++#if TARGET_OS_IOS || TARGET_OS_TV + *major += 2; +- else if (TARGET_OS_WATCH) ++#elif TARGET_OS_WATCH + *major += 9; +- else ++#else + UNREACHABLE("unsupported platform"); ++#endif + + if (*major >= 16) { // macOS 11+ + *major -= 5; +@@ -697,6 +702,7 @@ static void MapToMacos(u16 *major, u16 *minor) { + *minor = *major; + *major = 10; + } ++#endif + } + + static MacosVersion GetMacosAlignedVersionInternal() { diff --git a/llvm/git/compiler-rt/default.nix b/llvm/git/compiler-rt/default.nix new file mode 100644 index 0000000..b20796a --- /dev/null +++ b/llvm/git/compiler-rt/default.nix @@ -0,0 +1,139 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake, ninja, python3, xcbuild, libllvm, libcxxabi, libxcrypt +, doFakeLibgcc ? stdenv.hostPlatform.isFreeBSD +}: + +let + + useLLVM = stdenv.hostPlatform.useLLVM or false; + bareMetal = stdenv.hostPlatform.parsed.kernel.name == "none"; + haveLibc = stdenv.cc.libc != null; + inherit (stdenv.hostPlatform) isMusl; + + baseName = "compiler-rt"; + + src = runCommand "${baseName}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${baseName} "$out" + ''; +in + +stdenv.mkDerivation { + pname = baseName + lib.optionalString (haveLibc) "-libc"; + inherit version; + + inherit src; + sourceRoot = "${src.name}/${baseName}"; + + nativeBuildInputs = [ cmake ninja python3 libllvm.dev ] + ++ lib.optional stdenv.isDarwin xcbuild.xcrun; + buildInputs = lib.optional stdenv.hostPlatform.isDarwin libcxxabi; + + env.NIX_CFLAGS_COMPILE = toString [ + "-DSCUDO_DEFAULT_OPTIONS=DeleteSizeMismatch=0:DeallocationTypeMismatch=0" + ]; + + cmakeFlags = [ + "-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON" + "-DCMAKE_C_COMPILER_TARGET=${stdenv.hostPlatform.config}" + "-DCMAKE_ASM_COMPILER_TARGET=${stdenv.hostPlatform.config}" + ] ++ lib.optionals (haveLibc && stdenv.hostPlatform.libc == "glibc") [ + "-DSANITIZER_COMMON_CFLAGS=-I${libxcrypt}/include" + ] ++ lib.optionals (useLLVM || bareMetal || isMusl) [ + "-DCOMPILER_RT_BUILD_SANITIZERS=OFF" + "-DCOMPILER_RT_BUILD_XRAY=OFF" + "-DCOMPILER_RT_BUILD_LIBFUZZER=OFF" + "-DCOMPILER_RT_BUILD_MEMPROF=OFF" + "-DCOMPILER_RT_BUILD_ORC=OFF" # may be possible to build with musl if necessary + ] ++ lib.optionals (useLLVM || bareMetal) [ + "-DCOMPILER_RT_BUILD_PROFILE=OFF" + ] ++ lib.optionals ((useLLVM && !haveLibc) || bareMetal) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + "-DCOMPILER_RT_BAREMETAL_BUILD=ON" + "-DCMAKE_SIZEOF_VOID_P=${toString (stdenv.hostPlatform.parsed.cpu.bits / 8)}" + ] ++ lib.optionals (useLLVM) [ + "-DCOMPILER_RT_BUILD_BUILTINS=ON" + #https://stackoverflow.com/questions/53633705/cmake-the-c-compiler-is-not-able-to-compile-a-simple-test-program + "-DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY" + ] ++ lib.optionals (bareMetal) [ + "-DCOMPILER_RT_OS_DIR=baremetal" + ] ++ lib.optionals (stdenv.hostPlatform.isDarwin) [ + "-DDARWIN_macosx_OVERRIDE_SDK_VERSION=ON" + "-DDARWIN_osx_ARCHS=${stdenv.hostPlatform.darwinArch}" + "-DDARWIN_osx_BUILTIN_ARCHS=${stdenv.hostPlatform.darwinArch}" + # `COMPILER_RT_DEFAULT_TARGET_ONLY` does not apply to Darwin: + # https://github.com/llvm/llvm-project/blob/27ef42bec80b6c010b7b3729ed0528619521a690/compiler-rt/cmake/base-config-ix.cmake#L153 + "-DCOMPILER_RT_ENABLE_IOS=OFF" + ]; + + preConfigure = lib.optionalString (useLLVM && !haveLibc) '' + cmakeFlagsArray+=(-DCMAKE_C_FLAGS="-nodefaultlibs -ffreestanding") + ''; + + outputs = [ "out" "dev" ]; + + patches = [ + ./X86-support-extension.patch # Add support for i486 i586 i686 by reusing i386 config + ./gnu-install-dirs.patch + # ld-wrapper dislikes `-rpath-link //nix/store`, so we normalize away the + # extra `/`. + ./normalize-var.patch + # Prevent a compilation error on darwin + ./darwin-targetconditionals.patch + # See: https://github.com/NixOS/nixpkgs/pull/186575 + ../../common/compiler-rt/darwin-plistbuddy-workaround.patch + # See: https://github.com/NixOS/nixpkgs/pull/194634#discussion_r999829893 + ../../common/compiler-rt/armv7l-15.patch + ]; + + # TSAN requires XPC on Darwin, which we have no public/free source files for. We can depend on the Apple frameworks + # to get it, but they're unfree. Since LLVM is rather central to the stdenv, we patch out TSAN support so that Hydra + # can build this. If we didn't do it, basically the entire nixpkgs on Darwin would have an unfree dependency and we'd + # get no binary cache for the entire platform. If you really find yourself wanting the TSAN, make this controllable by + # a flag and turn the flag off during the stdenv build. + postPatch = lib.optionalString (!stdenv.isDarwin) '' + substituteInPlace cmake/builtin-config-ix.cmake \ + --replace 'set(X86 i386)' 'set(X86 i386 i486 i586 i686)' + '' + lib.optionalString stdenv.isDarwin '' + substituteInPlace cmake/config-ix.cmake \ + --replace 'set(COMPILER_RT_HAS_TSAN TRUE)' 'set(COMPILER_RT_HAS_TSAN FALSE)' + '' + lib.optionalString (useLLVM) '' + substituteInPlace lib/builtins/int_util.c \ + --replace "#include " "" + substituteInPlace lib/builtins/clear_cache.c \ + --replace "#include " "" + substituteInPlace lib/builtins/cpu_model.c \ + --replace "#include " "" + ''; + + # Hack around weird upsream RPATH bug + postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin || stdenv.hostPlatform.isWasm) '' + ln -s "$out/lib"/*/* "$out/lib" + '' + lib.optionalString (useLLVM) '' + ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o + ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o + ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o + ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o + '' + lib.optionalString doFakeLibgcc '' + ln -s $out/lib/freebsd/libclang_rt.builtins-*.a $out/lib/libgcc.a + ''; + + meta = llvm_meta // { + homepage = "https://compiler-rt.llvm.org/"; + description = "Compiler runtime libraries"; + longDescription = '' + The compiler-rt project provides highly tuned implementations of the + low-level code generator support routines like "__fixunsdfdi" and other + calls generated when a target doesn't have a short sequence of native + instructions to implement a core IR operation. It also provides + implementations of run-time libraries for dynamic testing tools such as + AddressSanitizer, ThreadSanitizer, MemorySanitizer, and DataFlowSanitizer. + ''; + # "All of the code in the compiler-rt project is dual licensed under the MIT + # license and the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/git/compiler-rt/gnu-install-dirs.patch b/llvm/git/compiler-rt/gnu-install-dirs.patch new file mode 100644 index 0000000..f3b1f63 --- /dev/null +++ b/llvm/git/compiler-rt/gnu-install-dirs.patch @@ -0,0 +1,20 @@ +diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake +index 8a6219568b3f..30ee68a47ccf 100644 +--- a/cmake/base-config-ix.cmake ++++ b/cmake/base-config-ix.cmake +@@ -100,13 +100,13 @@ endif() + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib) ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(COMPILER_RT_OUTPUT_LIBRARY_DIR + ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR}) +- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}") ++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}") + set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH + "Path where built compiler-rt libraries should be installed.") + endif() diff --git a/llvm/git/compiler-rt/normalize-var.patch b/llvm/git/compiler-rt/normalize-var.patch new file mode 100644 index 0000000..135cf62 --- /dev/null +++ b/llvm/git/compiler-rt/normalize-var.patch @@ -0,0 +1,16 @@ +diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake +index f1f46fb9599c..6f19e69507ba 100644 +--- a/cmake/Modules/CompilerRTUtils.cmake ++++ b/cmake/Modules/CompilerRTUtils.cmake +@@ -302,8 +302,9 @@ macro(load_llvm_config) + # Get some LLVM variables from LLVMConfig. + include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake") + +- set(LLVM_LIBRARY_OUTPUT_INTDIR +- ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX}) ++ get_filename_component(LLVM_LIBRARY_OUTPUT_INTDIR ++ ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX} ++ REALPATH) + endif() + endmacro() + diff --git a/llvm/git/default.nix b/llvm/git/default.nix new file mode 100644 index 0000000..930b716 --- /dev/null +++ b/llvm/git/default.nix @@ -0,0 +1,384 @@ +{ lowPrio, newScope, pkgs, lib, stdenv, cmake, ninja +, gccForLibs, preLibcCrossHeaders +, libxml2, python3, fetchFromGitHub, overrideCC, wrapCCWith, wrapBintoolsWith +, buildLlvmTools # tools, but from the previous stage, for cross +, targetLlvmLibraries # libraries, but from the next stage, for cross +, targetLlvm +# This is the default binutils, but with *this* version of LLD rather +# than the default LLVM version's, if LLD is the choice. We use these for +# the `useLLVM` bootstrapping below. +, bootBintoolsNoLibc ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintoolsNoLibc +, bootBintools ? + if stdenv.targetPlatform.linker == "lld" + then null + else pkgs.bintools +, darwin +# LLVM release information; specify one of these but not both: +, gitRelease ? null + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # rev = /* commit SHA */; + # rev-version = /* human readable version; i.e. "unstable-2022-26-07" */; + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +, officialRelease ? { version = "15.0.7"; sha256 = "sha256-wjuZQyXQ/jsmvy6y1aksCcEDXGBjuhpgngF3XQJ/T4s="; } + # i.e.: + # { + # version = /* i.e. "15.0.0" */; + # candidate = /* optional; if specified, should be: "rcN" */ + # sha256 = /* checksum for this release, can omit if specifying your own `monorepoSrc` */; + # } +# By default, we'll try to fetch a release from `github:llvm/llvm-project` +# corresponding to the `gitRelease` or `officialRelease` specified. +# +# You can provide your own LLVM source by specifying this arg but then it's up +# to you to make sure that the LLVM repo given matches the release configuration +# specified. +, monorepoSrc ? null +}: +assert let + int = a: if a then 1 else 0; + xor = a: b: ((builtins.bitXor (int a) (int b)) == 1); +in + lib.assertMsg + (xor + (gitRelease != null) + (officialRelease != null)) + ("must specify `gitRelease` or `officialRelease`" + + (lib.optionalString (gitRelease != null) " — not both")); +let + monorepoSrc' = monorepoSrc; +in let + releaseInfo = if gitRelease != null then rec { + original = gitRelease; + release_version = original.version; + version = gitRelease.rev-version; + } else rec { + original = officialRelease; + release_version = original.version; + version = if original ? candidate then + "${release_version}-${original.candidate}" + else + release_version; + }; + + monorepoSrc = if monorepoSrc' != null then + monorepoSrc' + else let + sha256 = releaseInfo.original.sha256; + rev = if gitRelease != null then + gitRelease.rev + else + "llvmorg-${releaseInfo.version}"; + in fetchFromGitHub { + owner = "llvm"; + repo = "llvm-project"; + inherit rev sha256; + }; + + inherit (releaseInfo) release_version version; + + llvm_meta = { + license = lib.licenses.ncsa; + maintainers = lib.teams.llvm.members; + + # See llvm/cmake/config-ix.cmake. + platforms = + lib.platforms.aarch64 ++ + lib.platforms.arm ++ + lib.platforms.m68k ++ + lib.platforms.mips ++ + lib.platforms.power ++ + lib.platforms.riscv ++ + lib.platforms.s390x ++ + lib.platforms.wasi ++ + lib.platforms.x86; + }; + + tools = lib.makeExtensible (tools: let + callPackage = newScope (tools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc buildLlvmTools; }); + mkExtraBuildCommands0 = cc: '' + rsrc="$out/resource-root" + mkdir "$rsrc" + ln -s "${cc.lib}/lib/clang/${release_version}/include" "$rsrc" + echo "-resource-dir=$rsrc" >> $out/nix-support/cc-cflags + ''; + mkExtraBuildCommands = cc: mkExtraBuildCommands0 cc + '' + ln -s "${targetLlvmLibraries.compiler-rt.out}/lib" "$rsrc/lib" + ln -s "${targetLlvmLibraries.compiler-rt.out}/share" "$rsrc/share" + ''; + + bintoolsNoLibc' = + if bootBintoolsNoLibc == null + then tools.bintoolsNoLibc + else bootBintoolsNoLibc; + bintools' = + if bootBintools == null + then tools.bintools + else bootBintools; + + in { + + libllvm = callPackage ./llvm { + inherit llvm_meta; + }; + + # `llvm` historically had the binaries. When choosing an output explicitly, + # we need to reintroduce `outputSpecified` to get the expected behavior e.g. of lib.get* + llvm = tools.libllvm; + + libclang = callPackage ./clang { + inherit llvm_meta; + }; + + clang-unwrapped = tools.libclang; + + llvm-manpages = lowPrio (tools.libllvm.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + clang-manpages = lowPrio (tools.libclang.override { + enableManpages = true; + python3 = pkgs.python3; # don't use python-boot + }); + + # TODO: lldb/docs/index.rst:155:toctree contains reference to nonexisting document 'design/structureddataplugins' + # lldb-manpages = lowPrio (tools.lldb.override { + # enableManpages = true; + # python3 = pkgs.python3; # don't use python-boot + # }); + + # pick clang appropriate for package set we are targeting + clang = + /**/ if stdenv.targetPlatform.libc == null then tools.clangNoLibc + else if stdenv.targetPlatform.useLLVM or false then tools.clangUseLLVM + else if (pkgs.targetPackages.stdenv or stdenv).cc.isGNU then tools.libstdcxxClang + else tools.libcxxClang; + + libstdcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + # libstdcxx is taken from gcc in an ad-hoc way in cc-wrapper. + libcxx = null; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + libcxxClang = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + }; + + lld = callPackage ./lld { + inherit llvm_meta; + }; + + lldb = callPackage ../common/lldb.nix { + src = callPackage ({ runCommand }: runCommand "lldb-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/lldb "$out" + '') { }; + patches = + let + resourceDirPatch = callPackage + ({ substituteAll, libclang }: substituteAll + { + src = ./lldb/resource-dir.patch; + clangLibDir = "${libclang.lib}/lib"; + }) + { }; + in + [ + ./lldb/procfs.patch # FIXME: do we need this? + resourceDirPatch + ./lldb/gnu-install-dirs.patch + ]; + inherit llvm_meta; + }; + + # Below, is the LLVM bootstrapping logic. It handles building a + # fully LLVM toolchain from scratch. No GCC toolchain should be + # pulled in. As a consequence, it is very quick to build different + # targets provided by LLVM and we can also build for what GCC + # doesn’t support like LLVM. Probably we should move to some other + # file. + + bintools-unwrapped = callPackage ../common/bintools.nix { }; + + bintoolsNoLibc = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + libc = preLibcCrossHeaders; + }; + + bintools = wrapBintoolsWith { + bintools = tools.bintools-unwrapped; + }; + + clangUseLLVM = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = bintools'; + extraPackages = [ + libcxx.cxxabi + targetLlvmLibraries.compiler-rt + ] ++ lib.optionals (!stdenv.targetPlatform.isWasm) [ + targetLlvmLibraries.libunwind + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = + [ "-rtlib=compiler-rt" + "-Wno-unused-command-line-argument" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ] + ++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind" + ++ lib.optional + (!stdenv.targetPlatform.isWasm && stdenv.targetPlatform.useLLVM or false) + "-lunwind" + ++ lib.optional stdenv.targetPlatform.isWasm "-fno-exceptions"; + }; + + clangNoLibcxx = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + "-nostdlib++" + ]; + }; + + clangNoLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ + targetLlvmLibraries.compiler-rt + ]; + extraBuildCommands = mkExtraBuildCommands cc; + nixSupport.cc-cflags = [ + "-rtlib=compiler-rt" + "-B${targetLlvmLibraries.compiler-rt}/lib" + ]; + }; + + clangNoCompilerRt = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintoolsNoLibc'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + nixSupport.cc-cflags = [ "-nostartfiles" ]; + }; + + clangNoCompilerRtWithLibc = wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = null; + bintools = bintools'; + extraPackages = [ ]; + extraBuildCommands = mkExtraBuildCommands0 cc; + }; + + }); + + libraries = lib.makeExtensible (libraries: let + callPackage = newScope (libraries // buildLlvmTools // { inherit stdenv cmake ninja libxml2 python3 release_version version monorepoSrc; }); + in { + + compiler-rt-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc + else stdenv; + }; + + compiler-rt-no-libc = callPackage ./compiler-rt { + inherit llvm_meta; + stdenv = if stdenv.hostPlatform.useLLVM or false + then overrideCC stdenv buildLlvmTools.clangNoCompilerRt + else stdenv; + }; + + # N.B. condition is safe because without useLLVM both are the same. + compiler-rt = if stdenv.hostPlatform.isAndroid + then libraries.compiler-rt-libc + else libraries.compiler-rt-no-libc; + + stdenv = overrideCC stdenv buildLlvmTools.clang; + + libcxxStdenv = overrideCC stdenv buildLlvmTools.libcxxClang; + + libcxxabi = let + # CMake will "require" a compiler capable of compiling C++ programs + # cxx-header's build does not actually use one so it doesn't really matter + # what stdenv we use here, as long as CMake is happy. + cxx-headers = callPackage ./libcxx { + inherit llvm_meta; + # Note that if we use the regular stdenv here we'll get cycle errors + # when attempting to use this compiler in the stdenv. + # + # The final stdenv pulls `cxx-headers` from the package set where + # hostPlatform *is* the target platform which means that `stdenv` at + # that point attempts to use this toolchain. + # + # So, we use `stdenv_` (the stdenv containing `clang` from this package + # set, defined below) to sidestep this issue. + # + # Because we only use `cxx-headers` in `libcxxabi` (which depends on the + # clang stdenv _anyways_), this is okay. + stdenv = stdenv_; + headersOnly = true; + }; + + # `libcxxabi` *doesn't* need a compiler with a working C++ stdlib but it + # *does* need a relatively modern C++ compiler (see: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/index.html#platform-and-compiler-support). + # + # So, we use the clang from this LLVM package set, like libc++ + # "boostrapping builds" do: + # https://releases.llvm.org/15.0.0/projects/libcxx/docs/BuildingLibcxx.html#bootstrapping-build + # + # We cannot use `clangNoLibcxx` because that contains `compiler-rt` which, + # on macOS, depends on `libcxxabi`, thus forming a cycle. + stdenv_ = overrideCC stdenv buildLlvmTools.clangNoCompilerRtWithLibc; + in callPackage ./libcxxabi { + stdenv = stdenv_; + inherit llvm_meta cxx-headers; + }; + + # Like `libcxxabi` above, `libcxx` requires a fairly modern C++ compiler, + # so: we use the clang from this LLVM package set instead of the regular + # stdenv's compiler. + libcxx = callPackage ./libcxx { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + libunwind = callPackage ./libunwind { + inherit llvm_meta; + stdenv = overrideCC stdenv buildLlvmTools.clangNoLibcxx; + }; + + openmp = callPackage ./openmp { + inherit llvm_meta targetLlvm; + }; + }); + noExtend = extensible: lib.attrsets.removeAttrs extensible [ "extend" ]; + +in { inherit tools libraries release_version; } // (noExtend libraries) // (noExtend tools) diff --git a/llvm/git/libcxx/default.nix b/llvm/git/libcxx/default.nix new file mode 100644 index 0000000..f267b75 --- /dev/null +++ b/llvm/git/libcxx/default.nix @@ -0,0 +1,123 @@ +{ lib, stdenv, llvm_meta +, monorepoSrc, runCommand +, cmake, ninja, python3, fixDarwinDylibNames, version +, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else libcxxabi +, libcxxabi, libcxxrt, libunwind +, enableShared ? !stdenv.hostPlatform.isStatic + +# If headersOnly is true, the resulting package would only include the headers. +# Use this to break the circular dependency between libcxx and libcxxabi. +# +# Some context: +# https://reviews.llvm.org/rG1687f2bbe2e2aaa092f942d4a97d41fad43eedfb +, headersOnly ? false +}: + +let + basename = "libcxx"; +in + +assert stdenv.isDarwin -> cxxabi.libName == "c++abi"; + +stdenv.mkDerivation rec { + pname = basename + lib.optionalString headersOnly "-headers"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${basename} "$out" + mkdir -p "$out/libcxxabi" + cp -r ${monorepoSrc}/libcxxabi/include "$out/libcxxabi" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/third-party "$out" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" ] ++ lib.optional (!headersOnly) "dev"; + + prePatch = '' + cd ../${basename} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ] ++ lib.optionals stdenv.hostPlatform.isMusl [ + ../../libcxx-0001-musl-hacks.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' + patchShebangs utils/cat_files.py + ''; + + nativeBuildInputs = [ cmake ninja python3 ] + ++ lib.optional stdenv.isDarwin fixDarwinDylibNames; + + buildInputs = + lib.optionals (!headersOnly) [ cxxabi ] + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ libunwind ]; + + + cmakeFlags = let + # See: https://libcxx.llvm.org/BuildingLibcxx.html#cmdoption-arg-libcxx-cxx-abi-string + libcxx_cxx_abi_opt = { + "c++abi" = "system-libcxxabi"; + "cxxrt" = "libcxxrt"; + }.${cxxabi.libName} or (throw "unknown cxxabi: ${cxxabi.libName} (${cxxabi.pname})"); + in [ + "-DLLVM_ENABLE_RUNTIMES=libcxx" + "-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}" + ] ++ lib.optional (!headersOnly && cxxabi.libName == "c++abi") "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi.dev}/include/c++/v1" + ++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1" + ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLIBCXX_USE_COMPILER_RT=ON" + # (Backport fix from 16, which has LIBCXX_ADDITIONAL_LIBRARIES, but 15 + # does not appear to) + # There's precedent for this in llvm-project/libcxx/cmake/caches. + # In a monorepo build you might do the following in the libcxxabi build: + # -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder + # -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On + # libcxx appears to require unwind and doesn't pull it in via other means. + # "-DLIBCXX_ADDITIONAL_LIBRARIES=unwind" + "-DCMAKE_SHARED_LINKER_FLAGS=-lunwind" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXX_ENABLE_THREADS=OFF" + "-DLIBCXX_ENABLE_FILESYSTEM=OFF" + "-DLIBCXX_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optional (!enableShared) "-DLIBCXX_ENABLE_SHARED=OFF" + # If we're only building the headers we don't actually *need* a functioning + # C/C++ compiler: + ++ lib.optionals (headersOnly) [ + "-DCMAKE_C_COMPILER_WORKS=ON" + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ]; + + ninjaFlags = lib.optional headersOnly "generate-cxx-headers"; + installTargets = lib.optional headersOnly "install-cxx-headers"; + + passthru = { + isLLVM = true; + inherit cxxabi; + }; + + meta = llvm_meta // { + homepage = "https://libcxx.llvm.org/"; + description = "C++ standard library"; + longDescription = '' + libc++ is an implementation of the C++ standard library, targeting C++11, + C++14 and above. + ''; + # "All of the code in libc++ is dual licensed under the MIT license and the + # UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/git/libcxx/gnu-install-dirs.patch b/llvm/git/libcxx/gnu-install-dirs.patch new file mode 100644 index 0000000..daee5bd --- /dev/null +++ b/llvm/git/libcxx/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 74eff2002fc9..c935d10878bb 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -419,7 +419,7 @@ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXX_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) + set(LIBCXX_GENERATED_INCLUDE_DIR "${LLVM_BINARY_DIR}/include/c++/v1") + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LLVM_BINARY_DIR}/include/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${CMAKE_INSTALL_INCLUDEDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}/c++/v1" CACHE PATH + "Path where target-specific libc++ headers should be installed.") +@@ -436,7 +436,7 @@ else() + set(LIBCXX_GENERATED_INCLUDE_DIR "${CMAKE_BINARY_DIR}/include/c++/v1") + endif() + set(LIBCXX_GENERATED_INCLUDE_TARGET_DIR "${LIBCXX_GENERATED_INCLUDE_DIR}") +- set(LIBCXX_INSTALL_LIBRARY_DIR lib${LIBCXX_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXX_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXX_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++ libraries should be installed.") + set(LIBCXX_INSTALL_INCLUDE_TARGET_DIR "${LIBCXX_INSTALL_INCLUDE_DIR}" CACHE PATH + "Path where target-specific libc++ headers should be installed.") diff --git a/llvm/git/libcxxabi/default.nix b/llvm/git/libcxxabi/default.nix new file mode 100644 index 0000000..6987e6b --- /dev/null +++ b/llvm/git/libcxxabi/default.nix @@ -0,0 +1,125 @@ +{ lib, stdenv, llvm_meta, cmake, ninja, python3 +, monorepoSrc, runCommand, fetchpatch +, cxx-headers, libunwind, version +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libcxxabi"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx/src" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/include "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/src/include "$out/libcxx/src" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + outputs = [ "out" "dev" ]; + + postUnpack = lib.optionalString stdenv.isDarwin '' + export TRIPLE=x86_64-apple-darwin + '' + lib.optionalString stdenv.hostPlatform.isWasm '' + patch -p1 -d llvm -i ${../../common/libcxxabi/wasm.patch} + ''; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + + # https://reviews.llvm.org/D132298, Allow building libcxxabi alone + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/e6a0800532bb409f6d1c62f3698bdd6994a877dc.patch"; + sha256 = "1xyjd56m4pfwq8p3xh6i8lhkk9kq15jaml7qbhxdf87z4jjkk63a"; + stripLen = 1; + }) + ]; + + postPatch = '' + cd ../runtimes + ''; + + nativeBuildInputs = [ cmake ninja python3 ]; + buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libcxxabi" + "-DLIBCXXABI_LIBCXX_INCLUDES=${cxx-headers}/include/c++/v1" + + # `libcxxabi`'s build does not need a toolchain with a c++ stdlib attached + # (we specify the headers it should use explicitly above). + # + # CMake however checks for this anyways; this flag tells it not to. See: + # https://github.com/llvm/llvm-project/blob/4bd3f3759259548e159aeba5c76efb9a0864e6fa/llvm/runtimes/CMakeLists.txt#L243 + "-DCMAKE_CXX_COMPILER_WORKS=ON" + ] ++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DLIBCXXABI_USE_LLVM_UNWINDER=ON" + # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, + # but that does not appear to be the case for example when building + # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). + "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" + "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" + ] ++ lib.optionals stdenv.hostPlatform.isWasm [ + "-DLIBCXXABI_ENABLE_THREADS=OFF" + "-DLIBCXXABI_ENABLE_EXCEPTIONS=OFF" + ] ++ lib.optionals (!enableShared) [ + "-DLIBCXXABI_ENABLE_SHARED=OFF" + ]; + + preInstall = lib.optionalString stdenv.isDarwin '' + for file in lib/*.dylib; do + if [ -L "$file" ]; then continue; fi + + # Fix up the install name. Preserve the basename, just replace the path. + installName="$out/lib/$(basename $(${stdenv.cc.targetPrefix}otool -D $file | tail -n 1))" + + # this should be done in CMake, but having trouble figuring out + # the magic combination of necessary CMake variables + # if you fancy a try, take a look at + # https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling + ${stdenv.cc.targetPrefix}install_name_tool -id $installName $file + + # cc-wrapper passes '-lc++abi' to all c++ link steps, but that causes + # libcxxabi to sometimes link against a different version of itself. + # Here we simply make that second reference point to ourselves. + for other in $(${stdenv.cc.targetPrefix}otool -L $file | awk '$1 ~ "/libc\\+\\+abi" { print $1 }'); do + ${stdenv.cc.targetPrefix}install_name_tool -change $other $installName $file + done + done + ''; + + postInstall = '' + mkdir -p "$dev/include" + install -m 644 ../../${pname}/include/${if stdenv.isDarwin then "*" else "cxxabi.h"} "$dev/include" + ''; + + passthru = { + libName = "c++abi"; + }; + + meta = llvm_meta // { + homepage = "https://libcxxabi.llvm.org/"; + description = "Provides C++ standard library support"; + longDescription = '' + libc++abi is a new implementation of low level support for a standard C++ library. + ''; + # "All of the code in libc++abi is dual licensed under the MIT license and + # the UIUC License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + maintainers = llvm_meta.maintainers ++ [ lib.maintainers.vlstill ]; + }; +} diff --git a/llvm/git/libcxxabi/gnu-install-dirs.patch b/llvm/git/libcxxabi/gnu-install-dirs.patch new file mode 100644 index 0000000..fa58761 --- /dev/null +++ b/llvm/git/libcxxabi/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b8326d08d23a..a1e36f713161 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -187,7 +187,7 @@ set(LIBCXXABI_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBCXXABI_HEADER_DIR ${LLVM_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libc++abi libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBCXXABI_LIBRARY_DIR /${LIBCXXABI_LIBDIR_SUBDIR}) +@@ -201,7 +201,7 @@ else() + set(LIBCXXABI_HEADER_DIR ${CMAKE_BINARY_DIR}) + set(LIBCXXABI_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXXABI_LIBDIR_SUFFIX}) + endif() +- set(LIBCXXABI_INSTALL_LIBRARY_DIR lib${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBCXXABI_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBCXXABI_LIBDIR_SUFFIX} CACHE PATH + "Path where built libc++abi libraries should be installed.") + endif() + diff --git a/llvm/git/libunwind/default.nix b/llvm/git/libunwind/default.nix new file mode 100644 index 0000000..1b677a7 --- /dev/null +++ b/llvm/git/libunwind/default.nix @@ -0,0 +1,67 @@ +{ lib, stdenv, llvm_meta, version +, monorepoSrc, runCommand +, cmake +, ninja +, python3 +, enableShared ? !stdenv.hostPlatform.isStatic +}: + +stdenv.mkDerivation rec { + pname = "libunwind"; + inherit version; + + # I am not so comfortable giving libc++ and friends the whole monorepo as + # requested, so I filter it to what is needed. + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/cmake "$out/libcxx" + cp -r ${monorepoSrc}/libcxx/utils "$out/libcxx" + mkdir -p "$out/llvm" + cp -r ${monorepoSrc}/llvm/cmake "$out/llvm" + cp -r ${monorepoSrc}/llvm/utils "$out/llvm" + cp -r ${monorepoSrc}/runtimes "$out" + ''; + + sourceRoot = "${src.name}/runtimes"; + + prePatch = '' + cd ../${pname} + chmod -R u+w . + ''; + + patches = [ + ./gnu-install-dirs.patch + ]; + + postPatch = '' + cd ../runtimes + ''; + + postInstall = lib.optionalString (enableShared && !stdenv.hostPlatform.isDarwin) '' + # libcxxabi wants to link to libunwind_shared.so (?). + ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so + ''; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ninja python3 ]; + + cmakeFlags = [ + "-DLLVM_ENABLE_RUNTIMES=libunwind" + ] ++ lib.optional (!enableShared) "-DLIBUNWIND_ENABLE_SHARED=OFF"; + + meta = llvm_meta // { + # Details: https://github.com/llvm/llvm-project/blob/main/libunwind/docs/index.rst + homepage = "https://clang.llvm.org/docs/Toolchain.html#unwind-library"; + description = "LLVM's unwinder library"; + longDescription = '' + The unwind library provides a family of _Unwind_* functions implementing + the language-neutral stack unwinding portion of the Itanium C++ ABI (Level + I). It is a dependency of the C++ ABI library, and sometimes is a + dependency of other runtimes. + ''; + }; +} diff --git a/llvm/git/libunwind/gnu-install-dirs.patch b/llvm/git/libunwind/gnu-install-dirs.patch new file mode 100644 index 0000000..edfb2a8 --- /dev/null +++ b/llvm/git/libunwind/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 5a06805f05f1..86a50329e6a8 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -117,7 +117,7 @@ set(LIBUNWIND_INSTALL_RUNTIME_DIR "${CMAKE_INSTALL_BINDIR}" CACHE PATH + + if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE) + set(LIBUNWIND_LIBRARY_DIR ${LLVM_LIBRARY_OUTPUT_INTDIR}/${LLVM_DEFAULT_TARGET_TRIPLE}) +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}/${LLVM_DEFAULT_TARGET_TRIPLE} CACHE PATH + "Path where built libunwind libraries should be installed.") + if(LIBCXX_LIBDIR_SUBDIR) + string(APPEND LIBUNWIND_LIBRARY_DIR /${LIBUNWIND_LIBDIR_SUBDIR}) +@@ -129,7 +129,7 @@ else() + else() + set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBUNWIND_LIBDIR_SUFFIX}) + endif() +- set(LIBUNWIND_INSTALL_LIBRARY_DIR lib${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH ++ set(LIBUNWIND_INSTALL_LIBRARY_DIR ${CMAKE_INSTALL_LIBDIR}${LIBUNWIND_LIBDIR_SUFFIX} CACHE PATH + "Path where built libunwind libraries should be installed.") + endif() + diff --git a/llvm/git/lld/default.nix b/llvm/git/lld/default.nix new file mode 100644 index 0000000..cc18aee --- /dev/null +++ b/llvm/git/lld/default.nix @@ -0,0 +1,57 @@ +{ lib, stdenv, llvm_meta +, buildLlvmTools +, monorepoSrc, runCommand +, cmake +, ninja +, libxml2 +, libllvm +, version +}: + +stdenv.mkDerivation rec { + pname = "lld"; + inherit version; + + # Blank llvm dir just so relative path works + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + mkdir -p "$out/libunwind" + cp -r ${monorepoSrc}/libunwind/include "$out/libunwind" + mkdir -p "$out/llvm" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./gnu-install-dirs.patch + ]; + + nativeBuildInputs = [ cmake ninja ]; + buildInputs = [ libllvm libxml2 ]; + + cmakeFlags = [ + "-DLLD_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/lld" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ]; + + # Musl's default stack size is too small for lld to be able to link Firefox. + LDFLAGS = lib.optionalString stdenv.hostPlatform.isMusl "-Wl,-z,stack-size=2097152"; + + outputs = [ "out" "lib" "dev" ]; + + meta = llvm_meta // { + homepage = "https://lld.llvm.org/"; + description = "The LLVM linker (unwrapped)"; + longDescription = '' + LLD is a linker from the LLVM project that is a drop-in replacement for + system linkers and runs much faster than them. It also provides features + that are useful for toolchain developers. + The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and + WebAssembly in descending order of completeness. Internally, LLD consists + of several different linkers. + ''; + }; +} diff --git a/llvm/git/lld/gnu-install-dirs.patch b/llvm/git/lld/gnu-install-dirs.patch new file mode 100644 index 0000000..ea62b2a --- /dev/null +++ b/llvm/git/lld/gnu-install-dirs.patch @@ -0,0 +1,46 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index dcc649629a4b..58dca54642e4 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -70,13 +70,15 @@ if(LLD_BUILT_STANDALONE) + if (NOT LLVM_CONFIG_FOUND) + # Pull values from LLVMConfig.cmake. We can drop this once the llvm-config + # path is removed. +- set(MAIN_INCLUDE_DIR "${LLVM_INCLUDE_DIR}") ++ set(INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) + set(LLVM_OBJ_DIR "${LLVM_BINARY_DIR}") + # N.B. this is just a default value, the CACHE PATHs below can be overridden. + set(MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm") ++ else() ++ set(INCLUDE_DIRS "${LLVM_BINARY_DIR}/include" "${MAIN_INCLUDE_DIR}") + endif() + +- set(LLVM_MAIN_INCLUDE_DIR "${MAIN_INCLUDE_DIR}" CACHE PATH "Path to llvm/include") ++ set(LLVM_INCLUDE_DIRS ${INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed") + set(LLVM_BINARY_DIR "${LLVM_OBJ_ROOT}" CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR "${MAIN_SRC_DIR}" CACHE PATH "Path to LLVM source tree") + +@@ -95,7 +97,7 @@ if(LLD_BUILT_STANDALONE) + + set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}") + +- include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS}) ++ include_directories(${LLVM_INCLUDE_DIRS}) + link_directories(${LLVM_LIBRARY_DIRS}) + + if(LLVM_INCLUDE_TESTS) +diff --git a/cmake/modules/AddLLD.cmake b/cmake/modules/AddLLD.cmake +index d3924f7243d4..42a7cd62281c 100644 +--- a/cmake/modules/AddLLD.cmake ++++ b/cmake/modules/AddLLD.cmake +@@ -18,8 +18,8 @@ macro(add_lld_library name) + install(TARGETS ${name} + COMPONENT ${name} + ${export_to_lldtargets} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + if (${ARG_SHARED} AND NOT CMAKE_CONFIGURATION_TYPES) diff --git a/llvm/git/lldb/gnu-install-dirs.patch b/llvm/git/lldb/gnu-install-dirs.patch new file mode 100644 index 0000000..4388f5c --- /dev/null +++ b/llvm/git/lldb/gnu-install-dirs.patch @@ -0,0 +1,23 @@ +diff --git a/cmake/modules/AddLLDB.cmake b/cmake/modules/AddLLDB.cmake +index 3291a7c808e1..b27d27ce6a87 100644 +--- a/cmake/modules/AddLLDB.cmake ++++ b/cmake/modules/AddLLDB.cmake +@@ -109,7 +109,7 @@ function(add_lldb_library name) + endif() + + if(PARAM_SHARED) +- set(install_dest lib${LLVM_LIBDIR_SUFFIX}) ++ set(install_dest ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(PARAM_INSTALL_PREFIX) + set(install_dest ${PARAM_INSTALL_PREFIX}) + endif() +diff --git a/tools/intel-features/CMakeLists.txt b/tools/intel-features/CMakeLists.txt +index 7d48491ec89a..c04543585588 100644 +--- a/tools/intel-features/CMakeLists.txt ++++ b/tools/intel-features/CMakeLists.txt +@@ -30,4 +30,4 @@ add_lldb_library(lldbIntelFeatures SHARED + ) + + install(TARGETS lldbIntelFeatures +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) diff --git a/llvm/git/lldb/procfs.patch b/llvm/git/lldb/procfs.patch new file mode 100644 index 0000000..a798216 --- /dev/null +++ b/llvm/git/lldb/procfs.patch @@ -0,0 +1,40 @@ +--- a/source/Plugins/Process/Linux/Procfs.h ++++ b/source/Plugins/Process/Linux/Procfs.h +@@ -10,6 +10,7 @@ + // sys/procfs.h on Android/Linux for all supported architectures. + + #include ++#include + + #include "lldb/lldb-types.h" + +@@ -17,23 +18,13 @@ + + #include + +-#ifdef __ANDROID__ +-#if defined(__arm64__) || defined(__aarch64__) +-typedef unsigned long elf_greg_t; +-typedef elf_greg_t +- elf_gregset_t[(sizeof(struct user_pt_regs) / sizeof(elf_greg_t))]; +-typedef struct user_fpsimd_state elf_fpregset_t; +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#elif defined(__mips__) +-#ifndef NT_FPREGSET +-#define NT_FPREGSET NT_PRFPREG +-#endif // NT_FPREGSET +-#endif +-#else // __ANDROID__ ++#if !defined(__GLIBC__) && defined(__powerpc__) ++#define pt_regs musl_pt_regs ++#include ++#undef pt_regs ++#else + #include +-#endif // __ANDROID__ ++#endif + + namespace lldb_private { + namespace process_linux { diff --git a/llvm/git/lldb/resource-dir.patch b/llvm/git/lldb/resource-dir.patch new file mode 100644 index 0000000..e0db80a --- /dev/null +++ b/llvm/git/lldb/resource-dir.patch @@ -0,0 +1,13 @@ +diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake +index 37364341ff8b..7f74c1a3e257 100644 +--- a/cmake/modules/LLDBConfig.cmake ++++ b/cmake/modules/LLDBConfig.cmake +@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers) + # Iterate over the possible places where the external resource directory + # could be and pick the first that exists. + foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}" +- "${LLVM_BUILD_LIBRARY_DIR}" ++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@" + "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}") + # Build the resource directory path by appending 'clang/'. + set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}") diff --git a/llvm/git/llvm/default.nix b/llvm/git/llvm/default.nix new file mode 100644 index 0000000..66b0a74 --- /dev/null +++ b/llvm/git/llvm/default.nix @@ -0,0 +1,423 @@ +{ lib, stdenv, llvm_meta +, pkgsBuildBuild +, monorepoSrc +, runCommand +, fetchpatch +, cmake +, darwin +, ninja +, python3 +, libffi +, enableGoldPlugin ? (!stdenv.isDarwin && !stdenv.targetPlatform.isWasi) +, libbfd +, libpfm +, libxml2 +, ncurses +, version +, release_version +, zlib +, which +, sysctl +, buildLlvmTools +, debugVersion ? false +, doCheck ? (!stdenv.isx86_32 /* TODO: why */) && (!stdenv.hostPlatform.isMusl) + && (stdenv.hostPlatform == stdenv.buildPlatform) +, enableManpages ? false +, enableSharedLibraries ? !stdenv.hostPlatform.isStatic +, enablePFM ? stdenv.isLinux /* PFM only supports Linux */ + # broken for Ampere eMAG 8180 (c2.large.arm on Packet) #56245 + # broken for the armv7l builder + && !stdenv.hostPlatform.isAarch +, enablePolly ? true +} @args: + +let + inherit (lib) optional optionals optionalString; + + # Used when creating a version-suffixed symlink of libLLVM.dylib + shortVersion = with lib; + concatStringsSep "." (take 1 (splitString "." release_version)); + + # Ordinarily we would just the `doCheck` and `checkDeps` functionality + # `mkDerivation` gives us to manage our test dependencies (instead of breaking + # out `doCheck` as a package level attribute). + # + # Unfortunately `lit` does not forward `$PYTHONPATH` to children processes, in + # particular the children it uses to do feature detection. + # + # This means that python deps we add to `checkDeps` (which the python + # interpreter is made aware of via `$PYTHONPATH` – populated by the python + # setup hook) are not picked up by `lit` which causes it to skip tests. + # + # Adding `python3.withPackages (ps: [ ... ])` to `checkDeps` also doesn't work + # because this package is shadowed in `$PATH` by the regular `python3` + # package. + # + # So, we "manually" assemble one python derivation for the package to depend + # on, taking into account whether checks are enabled or not: + python = if doCheck then + let + checkDeps = ps: with ps; [ psutil ]; + in python3.withPackages checkDeps + else python3; + +in stdenv.mkDerivation (rec { + pname = "llvm"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} ('' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + cp -r ${monorepoSrc}/third-party "$out" + '' + lib.optionalString enablePolly '' + chmod u+w "$out/${pname}/tools" + cp -r ${monorepoSrc}/polly "$out/${pname}/tools" + ''); + + sourceRoot = "${src.name}/${pname}"; + + outputs = [ "out" "lib" "dev" "python" ]; + + nativeBuildInputs = [ cmake ninja python ] + ++ optionals enableManpages [ python3.pkgs.sphinx python3.pkgs.recommonmark ]; + + buildInputs = [ libxml2 libffi ] + ++ optional enablePFM libpfm; # exegesis + + propagatedBuildInputs = [ ncurses zlib ]; + + nativeCheckInputs = [ + which + ] ++ lib.optional stdenv.isDarwin sysctl; + + patches = [ + ./gnu-install-dirs.patch + + # Running the tests involves invoking binaries (like `opt`) that depend on + # the LLVM dylibs and reference them by absolute install path (i.e. their + # nix store path). + # + # Because we have not yet run the install phase (we're running these tests + # as part of `checkPhase` instead of `installCheckPhase`) these absolute + # paths do not exist yet; to work around this we point the loader (`ld` on + # unix, `dyld` on macOS) at the `lib` directory which will later become this + # package's `lib` output. + # + # Previously we would just set `LD_LIBRARY_PATH` to include the build `lib` + # dir but: + # - this doesn't generalize well to other platforms; `lit` doesn't forward + # `DYLD_LIBRARY_PATH` (macOS): + # + https://github.com/llvm/llvm-project/blob/0d89963df354ee309c15f67dc47c8ab3cb5d0fb2/llvm/utils/lit/lit/TestingConfig.py#L26 + # - even if `lit` forwarded this env var, we actually cannot set + # `DYLD_LIBRARY_PATH` in the child processes `lit` launches because + # `DYLD_LIBRARY_PATH` (and `DYLD_FALLBACK_LIBRARY_PATH`) is cleared for + # "protected processes" (i.e. the python interpreter that runs `lit`): + # https://stackoverflow.com/a/35570229 + # - other LLVM subprojects deal with this issue by having their `lit` + # configuration set these env vars for us; it makes sense to do the same + # for LLVM: + # + https://github.com/llvm/llvm-project/blob/4c106cfdf7cf7eec861ad3983a3dd9a9e8f3a8ae/clang-tools-extra/test/Unit/lit.cfg.py#L22-L31 + # + # !!! TODO: look into upstreaming this patch + ./llvm-lit-cfg-add-libs-to-dylib-path.patch + + # `lit` has a mode where it executes run lines as a shell script which is + # constructs; this is problematic for macOS because it means that there's + # another process in between `lit` and the binaries being tested. As noted + # above, this means that `DYLD_LIBRARY_PATH` is cleared which means that our + # tests fail with dyld errors. + # + # To get around this we patch `lit` to reintroduce `DYLD_LIBRARY_PATH`, when + # present in the test configuration. + # + # It's not clear to me why this isn't an issue for LLVM developers running + # on macOS (nothing about this _seems_ nix specific).. + ./lit-shell-script-runner-set-dyld-library-path.patch + + # Fix musl build. + (fetchpatch { + url = "https://github.com/llvm/llvm-project/commit/5cd554303ead0f8891eee3cd6d25cb07f5a7bf67.patch"; + relative = "llvm"; + hash = "sha256-XPbvNJ45SzjMGlNUgt/IgEvM2dHQpDOe6woUJY+nUYA="; + }) + ] ++ lib.optionals enablePolly [ + ./gnu-install-dirs-polly.patch + + # Just like the `llvm-lit-cfg` patch, but for `polly`. + ./polly-lit-cfg-add-libs-to-dylib-path.patch + ]; + + postPatch = optionalString stdenv.isDarwin '' + substituteInPlace cmake/modules/AddLLVM.cmake \ + --replace 'set(_install_name_dir INSTALL_NAME_DIR "@rpath")' "set(_install_name_dir)" \ + --replace 'set(_install_rpath "@loader_path/../''${CMAKE_INSTALL_LIBDIR}''${LLVM_LIBDIR_SUFFIX}" ''${extra_libdir})' "" + # As of LLVM 15, marked as XFAIL on arm64 macOS but lit doesn't seem to pick + # this up: https://github.com/llvm/llvm-project/blob/c344d97a125b18f8fed0a64aace73c49a870e079/llvm/test/MC/ELF/cfi-version.ll#L7 + rm test/MC/ELF/cfi-version.ll + + # This test tries to call `sw_vers` by absolute path (`/usr/bin/sw_vers`) + # and thus fails under the sandbox: + substituteInPlace unittests/Support/Host.cpp \ + --replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }" + '' + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86) '' + # This test tries to call the intrinsics `@llvm.roundeven.f32` and + # `@llvm.roundeven.f64` which seem to (incorrectly?) lower to `roundevenf` + # and `roundeven` on x86_64 macOS. + # + # However these functions are glibc specific so the test fails: + # - https://www.gnu.org/software/gnulib/manual/html_node/roundevenf.html + # - https://www.gnu.org/software/gnulib/manual/html_node/roundeven.html + # + # TODO(@rrbutani): this seems to run fine on `aarch64-darwin`, why does it + # pass there? + substituteInPlace test/ExecutionEngine/Interpreter/intrinsics.ll \ + --replace "%roundeven32 = call float @llvm.roundeven.f32(float 0.000000e+00)" "" \ + --replace "%roundeven64 = call double @llvm.roundeven.f64(double 0.000000e+00)" "" + + # This test fails on darwin x86_64 because `sw_vers` reports a different + # macOS version than what LLVM finds by reading + # `/System/Library/CoreServices/SystemVersion.plist` (which is passed into + # the sandbox on macOS). + # + # The `sw_vers` provided by nixpkgs reports the macOS version associated + # with the `CoreFoundation` framework with which it was built. Because + # nixpkgs pins the SDK for `aarch64-darwin` and `x86_64-darwin` what + # `sw_vers` reports is not guaranteed to match the macOS version of the host + # that's building this derivation. + # + # Astute readers will note that we only _patch_ this test on aarch64-darwin + # (to use the nixpkgs provided `sw_vers`) instead of disabling it outright. + # So why does this test pass on aarch64? + # + # Well, it seems that `sw_vers` on aarch64 actually links against the _host_ + # CoreFoundation framework instead of the nixpkgs provided one. + # + # Not entirely sure what the right fix is here. I'm assuming aarch64 + # `sw_vers` doesn't intentionally link against the host `CoreFoundation` + # (still digging into how this ends up happening, will follow up) but that + # aside I think the more pertinent question is: should we be patching LLVM's + # macOS version detection logic to use `sw_vers` instead of reading host + # paths? This *is* a way in which details about builder machines can creep + # into the artifacts that are produced, affecting reproducibility, but it's + # not clear to me when/where/for what this even gets used in LLVM. + # + # TODO(@rrbutani): fix/follow-up + substituteInPlace unittests/Support/Host.cpp \ + --replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion" + + # This test fails with a `dysmutil` crash; have not yet dug into what's + # going on here (TODO(@rrbutani)). + rm test/tools/dsymutil/ARM/obfuscated.test + '' + '' + # FileSystem permissions tests fail with various special bits + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "Path.cpp" "" + rm unittests/Support/Path.cpp + substituteInPlace unittests/IR/CMakeLists.txt \ + --replace "PassBuilderCallbacksTest.cpp" "" + rm unittests/IR/PassBuilderCallbacksTest.cpp + rm test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test + '' + optionalString stdenv.hostPlatform.isMusl '' + patch -p1 -i ${../../TLI-musl.patch} + substituteInPlace unittests/Support/CMakeLists.txt \ + --replace "add_subdirectory(DynamicLibrary)" "" + rm unittests/Support/DynamicLibrary/DynamicLibraryTest.cpp + # valgrind unhappy with musl or glibc, but fails w/musl only + rm test/CodeGen/AArch64/wineh4.mir + '' + optionalString stdenv.hostPlatform.isAarch32 '' + # skip failing X86 test cases on 32-bit ARM + rm test/DebugInfo/X86/convert-debugloc.ll + rm test/DebugInfo/X86/convert-inlined.ll + rm test/DebugInfo/X86/convert-linked.ll + rm test/tools/dsymutil/X86/op-convert.test + rm test/tools/gold/X86/split-dwarf.ll + rm test/tools/llvm-dwarfdump/X86/prettyprint_types.s + rm test/tools/llvm-dwarfdump/X86/simplified-template-names.s + '' + optionalString (stdenv.hostPlatform.system == "armv6l-linux") '' + # Seems to require certain floating point hardware (NEON?) + rm test/ExecutionEngine/frem.ll + '' + '' + patchShebangs test/BugPoint/compile-custom.ll.py + ''; + + preConfigure = '' + # Workaround for configure flags that need to have spaces + cmakeFlagsArray+=( + -DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar" + ) + ''; + + # Defensive check: some paths (that we make symlinks to) depend on the release + # version, for example: + # - https://github.com/llvm/llvm-project/blob/406bde9a15136254f2b10d9ef3a42033b3cb1b16/clang/lib/Headers/CMakeLists.txt#L185 + # + # So we want to sure that the version in the source matches the release + # version we were given. + # + # We do this check here, in the LLVM build, because it happens early. + postConfigure = let + v = lib.versions; + major = v.major release_version; + minor = v.minor release_version; + patch = v.patch release_version; + in '' + # $1: part, $2: expected + check_version() { + part="''${1^^}" + part="$(cat include/llvm/Config/llvm-config.h | grep "#define LLVM_VERSION_''${part} " | cut -d' ' -f3)" + + if [[ "$part" != "$2" ]]; then + echo >&2 \ + "mismatch in the $1 version! we have version ${release_version}" \ + "and expected the $1 version to be '$2'; the source has '$part' instead" + exit 3 + fi + } + + check_version major ${major} + check_version minor ${minor} + check_version patch ${patch} + ''; + + # E.g. mesa.drivers use the build-id as a cache key (see #93946): + LDFLAGS = optionalString (enableSharedLibraries && !stdenv.isDarwin) "-Wl,--build-id=sha1"; + + cmakeBuildType = if debugVersion then "Debug" else "Release"; + + cmakeFlags = with stdenv; let + # These flags influence llvm-config's BuildVariables.inc in addition to the + # general build. We need to make sure these are also passed via + # CROSS_TOOLCHAIN_FLAGS_NATIVE when cross-compiling or llvm-config-native + # will return different results from the cross llvm-config. + # + # Some flags don't need to be repassed because LLVM already does so (like + # CMAKE_BUILD_TYPE), others are irrelevant to the result. + flagsForLlvmConfig = [ + "-DLLVM_INSTALL_PACKAGE_DIR=${placeholder "dev"}/lib/cmake/llvm" + "-DLLVM_ENABLE_RTTI=ON" + ] ++ optionals enableSharedLibraries [ + "-DLLVM_LINK_LLVM_DYLIB=ON" + ]; + in flagsForLlvmConfig ++ [ + "-DLLVM_INSTALL_UTILS=ON" # Needed by rustc + "-DLLVM_BUILD_TESTS=${if doCheck then "ON" else "OFF"}" + "-DLLVM_ENABLE_FFI=ON" + "-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}" + "-DLLVM_ENABLE_DUMP=ON" + ] ++ optionals stdenv.hostPlatform.isStatic [ + # Disables building of shared libs, -fPIC is still injected by cc-wrapper + "-DLLVM_ENABLE_PIC=OFF" + "-DLLVM_BUILD_STATIC=ON" + "-DLLVM_LINK_LLVM_DYLIB=off" + # libxml2 needs to be disabled because the LLVM build system ignores its .la + # file and doesn't link zlib as well. + # https://github.com/ClangBuiltLinux/tc-build/issues/150#issuecomment-845418812 + "-DLLVM_ENABLE_LIBXML2=OFF" + ] ++ optionals enableManpages [ + "-DLLVM_BUILD_DOCS=ON" + "-DLLVM_ENABLE_SPHINX=ON" + "-DSPHINX_OUTPUT_MAN=ON" + "-DSPHINX_OUTPUT_HTML=OFF" + "-DSPHINX_WARNINGS_AS_ERRORS=OFF" + ] ++ optionals (enableGoldPlugin) [ + "-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include" + ] ++ optionals isDarwin [ + "-DLLVM_ENABLE_LIBCXX=ON" + "-DCAN_TARGET_i386=false" + ] ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "-DCMAKE_CROSSCOMPILING=True" + "-DLLVM_TABLEGEN=${buildLlvmTools.llvm}/bin/llvm-tblgen" + ( + let + nativeCC = pkgsBuildBuild.targetPackages.stdenv.cc; + nativeBintools = nativeCC.bintools.bintools; + nativeToolchainFlags = [ + "-DCMAKE_C_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}cc" + "-DCMAKE_CXX_COMPILER=${nativeCC}/bin/${nativeCC.targetPrefix}c++" + "-DCMAKE_AR=${nativeBintools}/bin/${nativeBintools.targetPrefix}ar" + "-DCMAKE_STRIP=${nativeBintools}/bin/${nativeBintools.targetPrefix}strip" + "-DCMAKE_RANLIB=${nativeBintools}/bin/${nativeBintools.targetPrefix}ranlib" + ]; + # We need to repass the custom GNUInstallDirs values, otherwise CMake + # will choose them for us, leading to wrong results in llvm-config-native + nativeInstallFlags = [ + "-DCMAKE_INSTALL_PREFIX=${placeholder "out"}" + "-DCMAKE_INSTALL_BINDIR=${placeholder "out"}/bin" + "-DCMAKE_INSTALL_INCLUDEDIR=${placeholder "dev"}/include" + "-DCMAKE_INSTALL_LIBDIR=${placeholder "lib"}/lib" + "-DCMAKE_INSTALL_LIBEXECDIR=${placeholder "lib"}/libexec" + ]; + in "-DCROSS_TOOLCHAIN_FLAGS_NATIVE:list=" + + lib.concatStringsSep ";" (lib.concatLists [ + flagsForLlvmConfig + nativeToolchainFlags + nativeInstallFlags + ]) + ) + ]; + + postInstall = '' + mkdir -p $python/share + mv $out/share/opt-viewer $python/share/opt-viewer + moveToOutput "bin/llvm-config*" "$dev" + substituteInPlace "$dev/lib/cmake/llvm/LLVMExports-${if debugVersion then "debug" else "release"}.cmake" \ + --replace "\''${_IMPORT_PREFIX}/lib/lib" "$lib/lib/lib" \ + --replace "$out/bin/llvm-config" "$dev/bin/llvm-config" + substituteInPlace "$dev/lib/cmake/llvm/LLVMConfig.cmake" \ + --replace 'set(LLVM_BINARY_DIR "''${LLVM_INSTALL_PREFIX}")' 'set(LLVM_BINARY_DIR "'"$lib"'")' + '' + + optionalString (stdenv.isDarwin && enableSharedLibraries) '' + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${shortVersion}.dylib + ln -s $lib/lib/libLLVM.dylib $lib/lib/libLLVM-${release_version}.dylib + '' + + optionalString (stdenv.buildPlatform != stdenv.hostPlatform) '' + cp NATIVE/bin/llvm-config $dev/bin/llvm-config-native + ''; + + inherit doCheck; + + checkTarget = "check-all"; + + # For the update script: + passthru.monorepoSrc = monorepoSrc; + + requiredSystemFeatures = [ "big-parallel" ]; + meta = llvm_meta // { + homepage = "https://llvm.org/"; + description = "A collection of modular and reusable compiler and toolchain technologies"; + longDescription = '' + The LLVM Project is a collection of modular and reusable compiler and + toolchain technologies. Despite its name, LLVM has little to do with + traditional virtual machines. The name "LLVM" itself is not an acronym; it + is the full name of the project. + LLVM began as a research project at the University of Illinois, with the + goal of providing a modern, SSA-based compilation strategy capable of + supporting both static and dynamic compilation of arbitrary programming + languages. Since then, LLVM has grown to be an umbrella project consisting + of a number of subprojects, many of which are being used in production by + a wide variety of commercial and open source projects as well as being + widely used in academic research. Code in the LLVM project is licensed + under the "Apache 2.0 License with LLVM exceptions". + ''; + }; +} // lib.optionalAttrs enableManpages { + pname = "llvm-manpages"; + + propagatedBuildInputs = []; + + ninjaFlags = [ "docs-llvm-man" ]; + installTargets = [ "install-docs-llvm-man" ]; + + postPatch = null; + postInstall = null; + + outputs = [ "out" ]; + + doCheck = false; + + meta = llvm_meta // { + description = "man pages for LLVM ${version}"; + }; +}) diff --git a/llvm/git/llvm/gnu-install-dirs-polly.patch b/llvm/git/llvm/gnu-install-dirs-polly.patch new file mode 100644 index 0000000..b01363e --- /dev/null +++ b/llvm/git/llvm/gnu-install-dirs-polly.patch @@ -0,0 +1,19 @@ +This is the one remaining Polly install dirs related change that hasn't made it +into upstream yet; previously this patch file also included: +https://reviews.llvm.org/D117541 + +diff --git a/tools/polly/cmake/polly_macros.cmake b/tools/polly/cmake/polly_macros.cmake +index 518a09b45a42..bd9d6f5542ad 100644 +--- a/tools/polly/cmake/polly_macros.cmake ++++ b/tools/polly/cmake/polly_macros.cmake +@@ -44,8 +44,8 @@ macro(add_polly_library name) + if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LLVMPolly") + install(TARGETS ${name} + EXPORT LLVMExports +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) ++ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + endif() + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS ${name}) + endmacro(add_polly_library) diff --git a/llvm/git/llvm/gnu-install-dirs.patch b/llvm/git/llvm/gnu-install-dirs.patch new file mode 100644 index 0000000..0ef317a --- /dev/null +++ b/llvm/git/llvm/gnu-install-dirs.patch @@ -0,0 +1,138 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 45399dc0537e..5d946e9e6583 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -942,7 +942,7 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "") + add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src + ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime) + install(TARGETS tf_xla_runtime EXPORT LLVMExports +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) ++ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX} COMPONENT tf_xla_runtime) + set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS tf_xla_runtime) + # Once we add more modules, we should handle this more automatically. + if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL) +diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake +index 057431208322..56f0dcb258da 100644 +--- a/cmake/modules/AddLLVM.cmake ++++ b/cmake/modules/AddLLVM.cmake +@@ -844,8 +844,8 @@ macro(add_llvm_library name) + get_target_export_arg(${name} LLVM export_to_llvmexports ${umbrella}) + install(TARGETS ${name} + ${export_to_llvmexports} +- LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} +- ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX} COMPONENT ${name} ++ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" COMPONENT ${name} + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name}) + + if (NOT LLVM_ENABLE_IDE) +@@ -2007,7 +2007,7 @@ function(llvm_install_library_symlink name dest type) + set(full_name ${CMAKE_${type}_LIBRARY_PREFIX}${name}${CMAKE_${type}_LIBRARY_SUFFIX}) + set(full_dest ${CMAKE_${type}_LIBRARY_PREFIX}${dest}${CMAKE_${type}_LIBRARY_SUFFIX}) + +- set(output_dir lib${LLVM_LIBDIR_SUFFIX}) ++ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}) + if(WIN32 AND "${type}" STREQUAL "SHARED") + set(output_dir "${CMAKE_INSTALL_BINDIR}") + endif() +@@ -2271,15 +2271,15 @@ function(llvm_setup_rpath name) + + if (APPLE) + set(_install_name_dir INSTALL_NAME_DIR "@rpath") +- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "@loader_path/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(${CMAKE_SYSTEM_NAME} MATCHES "AIX" AND BUILD_SHARED_LIBS) + # $ORIGIN is not interpreted at link time by aix ld. + # Since BUILD_SHARED_LIBS is only recommended for use by developers, + # hardcode the rpath to build/install lib dir first in this mode. + # FIXME: update this when there is better solution. +- set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + elseif(UNIX) +- set(_install_rpath "\$ORIGIN/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) ++ set(_install_rpath "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}" ${extra_libdir}) + if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)") + set_property(TARGET ${name} APPEND_STRING PROPERTY + LINK_FLAGS " -Wl,-z,origin ") +diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake +index 891c9e6d618c..8d963f3b0069 100644 +--- a/cmake/modules/AddOCaml.cmake ++++ b/cmake/modules/AddOCaml.cmake +@@ -147,9 +147,9 @@ function(add_ocaml_library name) + endforeach() + + if( APPLE ) +- set(ocaml_rpath "@executable_path/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "@executable_path/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + elseif( UNIX ) +- set(ocaml_rpath "\\$ORIGIN/../../../lib${LLVM_LIBDIR_SUFFIX}") ++ set(ocaml_rpath "\\$ORIGIN/../../../${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + endif() + list(APPEND ocaml_flags "-ldopt" "-Wl,-rpath,${ocaml_rpath}") + +diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt +index d4b0ab959148..26ed981fd09f 100644 +--- a/cmake/modules/CMakeLists.txt ++++ b/cmake/modules/CMakeLists.txt +@@ -128,7 +128,7 @@ set(LLVM_CONFIG_INCLUDE_DIRS + ) + list(REMOVE_DUPLICATES LLVM_CONFIG_INCLUDE_DIRS) + +-extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "lib\${LLVM_LIBDIR_SUFFIX}") ++extend_path(LLVM_CONFIG_LIBRARY_DIR "\${LLVM_INSTALL_PREFIX}" "${CMAKE_INSTALL_LIBDIR}\${LLVM_LIBDIR_SUFFIX}") + set(LLVM_CONFIG_LIBRARY_DIRS + "${LLVM_CONFIG_LIBRARY_DIR}" + # FIXME: Should there be other entries here? +diff --git a/docs/CMake.rst b/docs/CMake.rst +index 879b7b231d4c..9c31d14e8950 100644 +--- a/docs/CMake.rst ++++ b/docs/CMake.rst +@@ -250,7 +250,7 @@ description is in `LLVM-related variables`_ below. + **LLVM_LIBDIR_SUFFIX**:STRING + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` +- to install libraries to ``/usr/lib64``. ++ to install libraries to ``/usr/lib64``. See also ``CMAKE_INSTALL_LIBDIR``. + + **LLVM_PARALLEL_{COMPILE,LINK}_JOBS**:STRING + Building the llvm toolchain can use a lot of resources, particularly +@@ -284,6 +284,10 @@ manual, or execute ``cmake --help-variable VARIABLE_NAME``. + The path to install executables, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "bin". + ++**CMAKE_INSTALL_LIBDIR**:PATH ++ The path to install libraries, relative to the *CMAKE_INSTALL_PREFIX*. ++ Defaults to "lib". ++ + **CMAKE_INSTALL_INCLUDEDIR**:PATH + The path to install header files, relative to the *CMAKE_INSTALL_PREFIX*. + Defaults to "include". +diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in +index 370005cd8d7d..7e790bc52111 100644 +--- a/tools/llvm-config/BuildVariables.inc.in ++++ b/tools/llvm-config/BuildVariables.inc.in +@@ -23,6 +23,7 @@ + #define LLVM_CXXFLAGS "@LLVM_CXXFLAGS@" + #define LLVM_BUILDMODE "@LLVM_BUILDMODE@" + #define LLVM_LIBDIR_SUFFIX "@LLVM_LIBDIR_SUFFIX@" ++#define LLVM_INSTALL_LIBDIR "@CMAKE_INSTALL_LIBDIR@" + #define LLVM_INSTALL_INCLUDEDIR "@CMAKE_INSTALL_INCLUDEDIR@" + #define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@" + #define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@" +diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp +index 2c6c55f89d38..f6d2068a0827 100644 +--- a/tools/llvm-config/llvm-config.cpp ++++ b/tools/llvm-config/llvm-config.cpp +@@ -369,7 +369,11 @@ int main(int argc, char **argv) { + sys::fs::make_absolute(ActivePrefix, Path); + ActiveBinDir = std::string(Path.str()); + } +- ActiveLibDir = ActivePrefix + "/lib" + LLVM_LIBDIR_SUFFIX; ++ { ++ SmallString<256> Path(LLVM_INSTALL_LIBDIR LLVM_LIBDIR_SUFFIX); ++ sys::fs::make_absolute(ActivePrefix, Path); ++ ActiveLibDir = std::string(Path.str()); ++ } + { + SmallString<256> Path(LLVM_INSTALL_PACKAGE_DIR); + sys::fs::make_absolute(ActivePrefix, Path); diff --git a/llvm/git/llvm/lit-shell-script-runner-set-dyld-library-path.patch b/llvm/git/llvm/lit-shell-script-runner-set-dyld-library-path.patch new file mode 100644 index 0000000..32f1d13 --- /dev/null +++ b/llvm/git/llvm/lit-shell-script-runner-set-dyld-library-path.patch @@ -0,0 +1,26 @@ +diff --git a/utils/lit/lit/TestRunner.py b/utils/lit/lit/TestRunner.py +index 0242e0b75af3..d732011306f7 100644 +--- a/utils/lit/lit/TestRunner.py ++++ b/utils/lit/lit/TestRunner.py +@@ -1029,6 +1029,12 @@ def executeScript(test, litConfig, tmpBase, commands, cwd): + f.write('@echo off\n') + f.write('\n@if %ERRORLEVEL% NEQ 0 EXIT\n'.join(commands)) + else: ++ # This env var is *purged* when invoking subprocesses so we have to ++ # manually set it from within the bash script in order for the commands ++ # in run lines to see this var: ++ if "DYLD_LIBRARY_PATH" in test.config.environment: ++ f.write(f'export DYLD_LIBRARY_PATH="{test.config.environment["DYLD_LIBRARY_PATH"]}"\n') ++ + for i, ln in enumerate(commands): + match = re.match(kPdbgRegex, ln) + if match: +@@ -1363,7 +1369,7 @@ def applySubstitutions(script, substitutions, conditions={}, + return processed + + process = processLine if recursion_limit is None else processLineToFixedPoint +- ++ + return [unescapePercents(process(ln)) for ln in script] + + diff --git a/llvm/git/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch b/llvm/git/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000..d824516 --- /dev/null +++ b/llvm/git/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,79 @@ +diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py +index 81e8dc04acea..479ff95681e2 100644 +--- a/test/Unit/lit.cfg.py ++++ b/test/Unit/lit.cfg.py +@@ -3,6 +3,7 @@ + # Configuration file for the 'lit' test runner. + + import os ++import platform + import subprocess + + import lit.formats +@@ -55,3 +56,26 @@ if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir): + # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate. + if sys.platform == 'win32' and 'SYSTEMDRIVE' in os.environ: + config.environment['SYSTEMDRIVE'] = os.environ['SYSTEMDRIVE'] ++ ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = os.path.pathsep.join( ++ (config.shlibdir, ++ config.environment.get(shlibpath_var, ''))) ++ config.environment[shlibpath_var] = shlibpath ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) +diff --git a/test/lit.cfg.py b/test/lit.cfg.py +index 75a38b4c5dad..856fc75c9d74 100644 +--- a/test/lit.cfg.py ++++ b/test/lit.cfg.py +@@ -42,6 +42,26 @@ llvm_config.with_environment('PATH', config.llvm_tools_dir, append_path=True) + llvm_config.with_system_environment( + ['HOME', 'INCLUDE', 'LIB', 'TMP', 'TEMP']) + ++# Add the LLVM dynamic libs to the platform-specific loader search path env var: ++# ++# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify.. ++def find_shlibpath_var(): ++ if platform.system() in ['Linux', 'FreeBSD', 'NetBSD', 'OpenBSD', 'SunOS']: ++ yield 'LD_LIBRARY_PATH' ++ elif platform.system() == 'Darwin': ++ yield 'DYLD_LIBRARY_PATH' ++ elif platform.system() == 'Windows': ++ yield 'PATH' ++ elif platform.system() == 'AIX': ++ yield 'LIBPATH' ++ ++for shlibpath_var in find_shlibpath_var(): ++ shlibpath = config.llvm_shlib_dir ++ llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True) ++ break ++else: ++ lit_config.warning("unable to inject shared library path on '{}'" ++ .format(platform.system())) + + # Set up OCAMLPATH to include newly built OCaml libraries. + top_ocaml_lib = os.path.join(config.llvm_lib_dir, 'ocaml') +@@ -318,7 +338,7 @@ def have_cxx_shared_library(): + + try: + readobj_cmd = subprocess.Popen( +- [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE) ++ [readobj_exe, '--needed-libs', readobj_exe], stdout=subprocess.PIPE, env=config.environment) + except OSError: + print('could not exec llvm-readobj') + return False diff --git a/llvm/git/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch b/llvm/git/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch new file mode 100644 index 0000000..1354ad2 --- /dev/null +++ b/llvm/git/llvm/polly-lit-cfg-add-libs-to-dylib-path.patch @@ -0,0 +1,24 @@ +diff --git a/tools/polly/test/lit.cfg b/tools/polly/test/lit.cfg +index 41e3a589c61e..09f3b17498b0 100644 +--- a/tools/polly/test/lit.cfg ++++ b/tools/polly/test/lit.cfg +@@ -36,9 +36,17 @@ base_paths = [config.llvm_tools_dir, config.environment['PATH']] + path = os.path.pathsep.join(base_paths + config.extra_paths) + config.environment['PATH'] = path + ++# (Copied from polly/test/Unit/lit.cfg) ++if platform.system() == 'Darwin': ++ shlibpath_var = 'DYLD_LIBRARY_PATH' ++elif platform.system() == 'Windows': ++ shlibpath_var = 'PATH' ++else: ++ shlibpath_var = 'LD_LIBRARY_PATH' ++ + path = os.path.pathsep.join((config.llvm_libs_dir, +- config.environment.get('LD_LIBRARY_PATH',''))) +-config.environment['LD_LIBRARY_PATH'] = path ++ config.environment.get(shlibpath_var,''))) ++config.environment[shlibpath_var] = path + + llvm_config.use_default_substitutions() + diff --git a/llvm/git/openmp/default.nix b/llvm/git/openmp/default.nix new file mode 100644 index 0000000..52aeb4b --- /dev/null +++ b/llvm/git/openmp/default.nix @@ -0,0 +1,71 @@ +{ lib +, stdenv +, llvm_meta +, monorepoSrc +, runCommand +, cmake +, ninja +, llvm +, targetLlvm +, lit +, clang-unwrapped +, perl +, pkg-config +, version +}: + +stdenv.mkDerivation rec { + pname = "openmp"; + inherit version; + + src = runCommand "${pname}-src-${version}" {} '' + mkdir -p "$out" + cp -r ${monorepoSrc}/cmake "$out" + cp -r ${monorepoSrc}/${pname} "$out" + ''; + + sourceRoot = "${src.name}/${pname}"; + + patches = [ + ./fix-find-tool.patch + ./gnu-install-dirs.patch + ./run-lit-directly.patch + ]; + + outputs = [ "out" "dev" ]; + + nativeBuildInputs = [ cmake ninja perl pkg-config lit ]; + buildInputs = [ + (if stdenv.buildPlatform == stdenv.hostPlatform then llvm else targetLlvm) + ]; + + # Unsup:Pass:XFail:Fail + # 26:267:16:8 + doCheck = false; + checkTarget = "check-openmp"; + + preCheck = '' + patchShebangs ../tools/archer/tests/deflake.bash + ''; + + cmakeFlags = [ + "-DCLANG_TOOL=${clang-unwrapped}/bin/clang" + "-DOPT_TOOL=${llvm}/bin/opt" + "-DLINK_TOOL=${llvm}/bin/llvm-link" + ]; + + meta = llvm_meta // { + homepage = "https://openmp.llvm.org/"; + description = "Support for the OpenMP language"; + longDescription = '' + The OpenMP subproject of LLVM contains the components required to build an + executable OpenMP program that are outside the compiler itself. + Contains the code for the runtime library against which code compiled by + "clang -fopenmp" must be linked before it can run and the library that + supports offload to target devices. + ''; + # "All of the code is dual licensed under the MIT license and the UIUC + # License (a BSD-like license)": + license = with lib.licenses; [ mit ncsa ]; + }; +} diff --git a/llvm/git/openmp/fix-find-tool.patch b/llvm/git/openmp/fix-find-tool.patch new file mode 100644 index 0000000..103b054 --- /dev/null +++ b/llvm/git/openmp/fix-find-tool.patch @@ -0,0 +1,18 @@ +diff --git a/libomptarget/DeviceRTL/CMakeLists.txt b/libomptarget/DeviceRTL/CMakeLists.txt +index ce66214822a2..6ab7b33c95da 100644 +--- a/libomptarget/DeviceRTL/CMakeLists.txt ++++ b/libomptarget/DeviceRTL/CMakeLists.txt +@@ -27,10 +27,10 @@ endif() + if (LLVM_DIR) + # Builds that use pre-installed LLVM have LLVM_DIR set. + # A standalone or LLVM_ENABLE_RUNTIMES=openmp build takes this route +- find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ find_program(CLANG_TOOL clang PATHS ${LLVM_TOOLS_BINARY_DIR}) + find_program(LINK_TOOL llvm-link PATHS ${LLVM_TOOLS_BINARY_DIR} +- NO_DEFAULT_PATH) +- find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH) ++ ) ++ find_program(OPT_TOOL opt PATHS ${LLVM_TOOLS_BINARY_DIR}) + if ((NOT CLANG_TOOL) OR (NOT LINK_TOOL) OR (NOT OPT_TOOL)) + libomptarget_say("Not building DeviceRTL. Missing clang: ${CLANG_TOOL}, llvm-link: ${LINK_TOOL} or opt: ${OPT_TOOL}") + return() diff --git a/llvm/git/openmp/gnu-install-dirs.patch b/llvm/git/openmp/gnu-install-dirs.patch new file mode 100644 index 0000000..77a9320 --- /dev/null +++ b/llvm/git/openmp/gnu-install-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index b6ddbe90516d..311ab1d50e7f 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -29,7 +29,7 @@ if (OPENMP_STANDALONE_BUILD) + set(OPENMP_LIBDIR_SUFFIX "" CACHE STRING + "Suffix of lib installation directory, e.g. 64 => lib64") + # Do not use OPENMP_LIBDIR_SUFFIX directly, use OPENMP_INSTALL_LIBDIR. +- set(OPENMP_INSTALL_LIBDIR "lib${OPENMP_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${OPENMP_LIBDIR_SUFFIX}") + + # Group test settings. + set(OPENMP_TEST_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING +@@ -40,7 +40,7 @@ if (OPENMP_STANDALONE_BUILD) + else() + set(OPENMP_ENABLE_WERROR ${LLVM_ENABLE_WERROR}) + # If building in tree, we honor the same install suffix LLVM uses. +- set(OPENMP_INSTALL_LIBDIR "lib${LLVM_LIBDIR_SUFFIX}") ++ set(OPENMP_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}${LLVM_LIBDIR_SUFFIX}") + + if (NOT MSVC) + set(OPENMP_TEST_C_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) diff --git a/llvm/git/openmp/run-lit-directly.patch b/llvm/git/openmp/run-lit-directly.patch new file mode 100644 index 0000000..1e952fd --- /dev/null +++ b/llvm/git/openmp/run-lit-directly.patch @@ -0,0 +1,12 @@ +diff --git a/cmake/OpenMPTesting.cmake b/cmake/OpenMPTesting.cmake +--- a/cmake/OpenMPTesting.cmake ++++ b/cmake/OpenMPTesting.cmake +@@ -185,7 +185,7 @@ function(add_openmp_testsuite target comment) + if (${OPENMP_STANDALONE_BUILD}) + set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS}) + add_custom_target(${target} +- COMMAND ${PYTHON_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} ++ COMMAND ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS} + COMMENT ${comment} + DEPENDS ${ARG_DEPENDS} + USES_TERMINAL diff --git a/llvm/libcxx-0001-musl-hacks.patch b/llvm/libcxx-0001-musl-hacks.patch new file mode 100644 index 0000000..bcb5ad8 --- /dev/null +++ b/llvm/libcxx-0001-musl-hacks.patch @@ -0,0 +1,39 @@ +From 1c936d7fda3275265e37f93697232a1ed652390f Mon Sep 17 00:00:00 2001 +From: Will Dietz +Date: Sat, 9 Jul 2016 19:22:54 -0500 +Subject: [PATCH] musl fixes/hacks + +Conflicts: + + include/__config + include/locale + src/locale.cpp +--- + include/locale | 4 ++-- + 1 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/include/locale b/include/locale +index 3d804e8..9b01f5b 100644 +--- a/include/locale ++++ b/include/locale +@@ -695,7 +695,7 @@ __num_get_signed_integral(const char* __a, const char* __a_end, + typename remove_reference::type __save_errno = errno; + errno = 0; + char *__p2; +- long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); ++ long long __ll = strtoll(__a, &__p2, __base); + typename remove_reference::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; +@@ -735,7 +735,7 @@ __num_get_unsigned_integral(const char* __a, const char* __a_end, + typename remove_reference::type __save_errno = errno; + errno = 0; + char *__p2; +- unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE); ++ unsigned long long __ll = strtoull(__a, &__p2, __base); + typename remove_reference::type __current_errno = errno; + if (__current_errno == 0) + errno = __save_errno; +-- +1.7.1 + diff --git a/llvm/llvm-7-musl.patch b/llvm/llvm-7-musl.patch new file mode 100644 index 0000000..0dac12c --- /dev/null +++ b/llvm/llvm-7-musl.patch @@ -0,0 +1,92 @@ +From 8c747d3157df2830eed9205e7caf1203b345de17 Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Sat, 4 Feb 2023 13:54:41 -0800 +Subject: [PATCH] cmake: Enable 64bit off_t on 32bit glibc systems + +Pass -D_FILE_OFFSET_BITS=64 to compiler flags on 32bit glibc based +systems. This will make sure that 64bit versions of LFS functions are +used e.g. seek will behave same as lseek64. Also revert [1] partially +because this added a cmake test to detect lseek64 but then forgot to +pass the needed macro to actual compile, this test was incomplete too +since libc implementations like musl has 64bit off_t by default on 32bit +systems and does not bundle[2] -D_LARGEFILE64_SOURCE under -D_GNU_SOURCE +like glibc, which means the compile now fails on musl because the cmake +check passes but we do not have _LARGEFILE64_SOURCE defined. Using the +*64 function was transitional anyways so use -D_FILE_OFFSET_BITS=64 +instead + +[1] https://github.com/llvm/llvm-project/commit/8db7e5e4eed4c4e697dc3164f2c9351d8c3e942b +[2] https://git.musl-libc.org/cgit/musl/commit/?id=25e6fee27f4a293728dd15b659170e7b9c7db9bc + +Reviewed By: MaskRay + +Differential Revision: https://reviews.llvm.org/D139752 + +(cherry picked from commit 5cd554303ead0f8891eee3cd6d25cb07f5a7bf67) +--- + cmake/config-ix.cmake | 13 ++++++++++--- + include/llvm/Config/config.h.cmake | 3 --- + lib/Support/raw_ostream.cpp | 2 -- + 3 files changed, 10 insertions(+), 8 deletions(-) + +diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake +index 18977d9950ff..b558aa83fa62 100644 +--- a/cmake/config-ix.cmake ++++ b/cmake/config-ix.cmake +@@ -197,9 +197,6 @@ check_symbol_exists(posix_fallocate fcntl.h HAVE_POSIX_FALLOCATE) + if( HAVE_SIGNAL_H AND NOT LLVM_USE_SANITIZER MATCHES ".*Address.*" AND NOT APPLE ) + check_symbol_exists(sigaltstack signal.h HAVE_SIGALTSTACK) + endif() +-set(CMAKE_REQUIRED_DEFINITIONS "-D_LARGEFILE64_SOURCE") +-check_symbol_exists(lseek64 "sys/types.h;unistd.h" HAVE_LSEEK64) +-set(CMAKE_REQUIRED_DEFINITIONS "") + check_symbol_exists(mallctl malloc_np.h HAVE_MALLCTL) + check_symbol_exists(mallinfo malloc.h HAVE_MALLINFO) + check_symbol_exists(malloc_zone_statistics malloc/malloc.h +@@ -237,6 +234,16 @@ if( PURE_WINDOWS ) + check_function_exists(__main HAVE___MAIN) + check_function_exists(__cmpdi2 HAVE___CMPDI2) + endif() ++ ++check_symbol_exists(__GLIBC__ stdio.h LLVM_USING_GLIBC) ++if( LLVM_USING_GLIBC ) ++# enable 64bit off_t on 32bit systems using glibc ++ if (CMAKE_SIZEOF_VOID_P EQUAL 4) ++ add_compile_definitions(_FILE_OFFSET_BITS=64) ++ list(APPEND CMAKE_REQUIRED_DEFINITIONS "-D_FILE_OFFSET_BITS=64") ++ endif() ++endif() ++ + if( HAVE_DLFCN_H ) + if( HAVE_LIBDL ) + list(APPEND CMAKE_REQUIRED_LIBRARIES dl) +diff --git a/include/llvm/Config/config.h.cmake b/include/llvm/Config/config.h.cmake +index e934617d7ec7..3c39c373b3c1 100644 +--- a/include/llvm/Config/config.h.cmake ++++ b/include/llvm/Config/config.h.cmake +@@ -112,9 +112,6 @@ + /* Define to 1 if you have the header file. */ + #cmakedefine HAVE_LINK_H ${HAVE_LINK_H} + +-/* Define to 1 if you have the `lseek64' function. */ +-#cmakedefine HAVE_LSEEK64 ${HAVE_LSEEK64} +- + /* Define to 1 if you have the header file. */ + #cmakedefine HAVE_MACH_MACH_H ${HAVE_MACH_MACH_H} + +diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp +index 038ad00bd608..921ab8409008 100644 +--- a/lib/Support/raw_ostream.cpp ++++ b/lib/Support/raw_ostream.cpp +@@ -677,8 +677,6 @@ uint64_t raw_fd_ostream::seek(uint64_t off) { + flush(); + #ifdef _WIN32 + pos = ::_lseeki64(FD, off, SEEK_SET); +-#elif defined(HAVE_LSEEK64) +- pos = ::lseek64(FD, off, SEEK_SET); + #else + pos = ::lseek(FD, off, SEEK_SET); + #endif +-- +2.37.1 + diff --git a/llvm/llvm-config-link-static.patch b/llvm/llvm-config-link-static.patch new file mode 100644 index 0000000..3881cc5 --- /dev/null +++ b/llvm/llvm-config-link-static.patch @@ -0,0 +1,12 @@ +diff --git llvm/tools/llvm-config/CMakeLists.txt llvm/tools/llvm-config/CMakeLists.txt +index 16ba54c0cf2f..20b017195e84 100644 +--- llvm/tools/llvm-config/CMakeLists.txt ++++ llvm/tools/llvm-config/CMakeLists.txt +@@ -6,6 +6,7 @@ set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc) + # Add the llvm-config tool. + add_llvm_tool(llvm-config + llvm-config.cpp ++ DISABLE_LLVM_LINK_LLVM_DYLIB + ) + + # Compute the substitution values for various items. diff --git a/llvm/multi.nix b/llvm/multi.nix new file mode 100644 index 0000000..136e13b --- /dev/null +++ b/llvm/multi.nix @@ -0,0 +1,60 @@ +{ runCommand, +clang, +gcc64, +gcc32, +glibc_multi +}: + +let + combine = basegcc: runCommand "combine-gcc-libc" {} '' + mkdir -p $out + cp -r ${basegcc.cc}/lib $out/lib + + chmod u+rw -R $out/lib + cp -r ${basegcc.libc}/lib/* $(ls -d $out/lib/gcc/*/*) + ''; + gcc_multi_sysroot = runCommand "gcc-multi-sysroot" { + passthru = { + inherit (gcc64) version; + lib = gcc_multi_sysroot; + }; + } '' + mkdir -p $out/lib{,64}/gcc + + ln -s ${combine gcc64}/lib/gcc/* $out/lib64/gcc/ + ln -s ${combine gcc32}/lib/gcc/* $out/lib/gcc/ + # XXX: This shouldn't be needed, clang just doesn't look for "i686-unknown" + ln -s $out/lib/gcc/i686-unknown-linux-gnu $out/lib/gcc/i686-pc-linux-gnu + + + # includes + mkdir -p $out/include + ln -s ${glibc_multi.dev}/include/* $out/include + ln -s ${gcc64.cc}/include/c++ $out/include/c++ + + # dynamic linkers + mkdir -p $out/lib/32 + ln -s ${glibc_multi.out}/lib/ld-linux* $out/lib + ln -s ${glibc_multi.out}/lib/32/ld-linux* $out/lib/32/ + ''; + + clangMulti = clang.override { + # Only used for providing expected structure re:dynamic linkers, AFAIK Most + # of the magic is done by setting the --gcc-toolchain option via + # `gccForLibs`. + libc = gcc_multi_sysroot; + + bintools = clang.bintools.override { + libc = gcc_multi_sysroot; + }; + + gccForLibs = gcc_multi_sysroot // { + inherit (glibc_multi) libgcc; + langCC = + assert (gcc64.cc.langCC != gcc32.cc.langCC) + -> throw "(gcc64.cc.langCC=${gcc64.cc.langCC}) != (gcc32.cc.langCC=${gcc32.cc.langCC})"; + gcc64.cc.langCC; + }; + }; + +in clangMulti diff --git a/llvm/update-git.py b/llvm/update-git.py new file mode 100755 index 0000000..b5e900d --- /dev/null +++ b/llvm/update-git.py @@ -0,0 +1,88 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i python3 -p python3 nix + +import csv +import fileinput +import json +import os +import re +import subprocess +import sys + +from codecs import iterdecode +from datetime import datetime +from urllib.request import urlopen, Request + + +DEFAULT_NIX = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'git/default.nix') + + +def get_latest_chromium_build(): + RELEASES_URL = 'https://versionhistory.googleapis.com/v1/chrome/platforms/linux/channels/dev/versions/all/releases?filter=endtime=none&order_by=version%20desc' + print(f'GET {RELEASES_URL}') + with urlopen(RELEASES_URL) as resp: + return json.load(resp)['releases'][0] + + +def get_file_revision(revision, file_path): + """Fetches the requested Git revision of the given Chromium file.""" + url = f'https://raw.githubusercontent.com/chromium/chromium/{revision}/{file_path}' + with urlopen(url) as http_response: + return http_response.read().decode() + + +def get_commit(ref): + url = f'https://api.github.com/repos/llvm/llvm-project/commits/{ref}' + headers = {'Accept': 'application/vnd.github.v3+json'} + request = Request(url, headers=headers) + with urlopen(request) as http_response: + return json.loads(http_response.read().decode()) + + +def get_current_revision(): + """Get the current revision of llvmPackages_git.""" + with open(DEFAULT_NIX) as f: + for line in f: + rev = re.search(r'^ rev = "(.*)";', line) + if rev: + return rev.group(1) + sys.exit(1) + + +def nix_prefetch_url(url, algo='sha256'): + """Prefetches the content of the given URL.""" + print(f'nix-prefetch-url {url}') + out = subprocess.check_output(['nix-prefetch-url', '--type', algo, '--unpack', url]) + return out.decode('utf-8').rstrip() + + +chromium_build = get_latest_chromium_build() +chromium_version = chromium_build['version'] +print(f'chromiumDev version: {chromium_version}') +print('Getting LLVM commit...') +clang_update_script = get_file_revision(chromium_version, 'tools/clang/scripts/update.py') +clang_revision = re.search(r"^CLANG_REVISION = '(.+)'$", clang_update_script, re.MULTILINE).group(1) +clang_commit_short = re.search(r"llvmorg-[0-9]+-init-[0-9]+-g([0-9a-f]{8})", clang_revision).group(1) +release_version = re.search(r"^RELEASE_VERSION = '(.+)'$", clang_update_script, re.MULTILINE).group(1) +commit = get_commit(clang_commit_short) +if get_current_revision() == commit["sha"]: + print('No new update available.') + sys.exit(0) +date = datetime.fromisoformat(commit['commit']['committer']['date'].rstrip('Z')).date().isoformat() +version = f'unstable-{date}' +print('Prefetching source tarball...') +hash = nix_prefetch_url(f'https://github.com/llvm/llvm-project/archive/{commit["sha"]}.tar.gz') +print('Updating default.nix...') +with fileinput.FileInput(DEFAULT_NIX, inplace=True) as f: + for line in f: + if match := re.search(r'^ rev-version = "unstable-(.+)";', line): + old_date = match.group(1) + result = re.sub(r'^ release_version = ".+";', f' release_version = "{release_version}";', line) + result = re.sub(r'^ rev = ".*";', f' rev = "{commit["sha"]}";', result) + result = re.sub(r'^ rev-version = ".+";', f' rev-version = "{version}";', result) + result = re.sub(r'^ sha256 = ".+";', f' sha256 = "{hash}";', result) + print(result, end='') +# Commit the result: +commit_message = f"llvmPackages_git: {old_date} -> {date}" +subprocess.run(['git', 'add', DEFAULT_NIX], check=True) +subprocess.run(['git', 'commit', '--file=-'], input=commit_message.encode(), check=True) diff --git a/llvm/update.sh b/llvm/update.sh new file mode 100755 index 0000000..95ad356 --- /dev/null +++ b/llvm/update.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +set -eu + +# Example usage: ./pkgs/development/compilers/llvm/update.sh 12.0.0-rc4 + +readonly VERSION="$1" +readonly VERSION_MAJOR="${VERSION%%.*}" +readonly VERSION_MAIN="${VERSION%%-*}" +declare VERSION_PATCH="${VERSION/$VERSION_MAIN/}" +readonly VERSION_PATCH="${VERSION_PATCH/-/}" + +readonly DIR="pkgs/development/compilers/llvm/$VERSION_MAJOR" +readonly FILE="$DIR/default.nix" + +sed -Ei \ + -e "s/release_version = \".+\";/release_version = \"$VERSION_MAIN\";/" \ + -e "s/candidate = \".*\";/candidate = \"$VERSION_PATCH\";/" \ + "$FILE" + +readonly ATTRSET="llvmPackages_$VERSION_MAJOR" + +if [ "$VERSION_MAJOR" -ge "14" ]; then + readonly SOURCES=( + "llvm.monorepoSrc" + ) +elif [ "$VERSION_MAJOR" -eq "13" ]; then + readonly SOURCES=( + "llvm.src" + ) +else + readonly SOURCES=( + "clang-unwrapped.src" + "compiler-rt.src" + "clang-unwrapped.clang-tools-extra_src" + "libcxx.src" + "libcxxabi.src" + "libunwind.src" + "lld.src" + "lldb.src" + "llvm.src" + "llvm.polly_src" + "openmp.src" + ) +fi + +for SOURCE in "${SOURCES[@]}"; do + echo "Updating the hash of $SOURCE:" + declare ATTR="$ATTRSET.$SOURCE" + declare OLD_HASH="$(nix --extra-experimental-features nix-command eval -f . $ATTR.outputHash)" + declare NEW_HASH="\"$(nix-prefetch-url -A $ATTR)\"" + find "$DIR" -type f -exec sed -i "s/$OLD_HASH/$NEW_HASH/" {} + +done + +echo OK