me
/
guix
Archived
1
0
Fork 0

gnu: LLVM, Clang: Add 14.0.0.

* gnu/packages/llvm.scm (%llvm-monorepo-hashes, %llvm-patches, llvm-monorepo):
New variables.
(clang-runtime-from-llvm): Make HASH optional; use monorepo when not present.
(clang-from-llvm): Likewise.
(llvm-14, clang-runtime-14, clang-14, clang-toolchain-14, lld-14): New variables.
(llvm-13): Inherit from LLVM-14.
(lld-13): Inherit from LLD-14.
(lld): Turn into alias for LLD-14.
* gnu/packages/patches/clang-14.0-libc-search-path.patch: New file.
* gnu/local.mk (dist_patch_DATA): Adjust accordingly.
* gnu/packages/zig.scm (zig): Change from LLD to LLD-13.
master
Marius Bakke 2022-04-05 13:27:09 +02:00
parent 4e4a79601c
commit e9473ed49b
No known key found for this signature in database
GPG Key ID: A2A06DF2A33A54FA
4 changed files with 255 additions and 71 deletions

View File

@ -953,6 +953,7 @@ dist_patch_DATA = \
%D%/packages/patches/clang-11.0-libc-search-path.patch \ %D%/packages/patches/clang-11.0-libc-search-path.patch \
%D%/packages/patches/clang-12.0-libc-search-path.patch \ %D%/packages/patches/clang-12.0-libc-search-path.patch \
%D%/packages/patches/clang-13.0-libc-search-path.patch \ %D%/packages/patches/clang-13.0-libc-search-path.patch \
%D%/packages/patches/clang-14.0-libc-search-path.patch \
%D%/packages/patches/clang-runtime-asan-build-fixes.patch \ %D%/packages/patches/clang-runtime-asan-build-fixes.patch \
%D%/packages/patches/clang-runtime-esan-build-fixes.patch \ %D%/packages/patches/clang-runtime-esan-build-fixes.patch \
%D%/packages/patches/clang-runtime-9-libsanitizer-mode-field.patch \ %D%/packages/patches/clang-runtime-9-libsanitizer-mode-field.patch \

View File

@ -108,17 +108,21 @@ as \"x86_64-linux\"."
(define %llvm-release-monitoring-url (define %llvm-release-monitoring-url
"https://github.com/llvm/llvm-project/releases") "https://github.com/llvm/llvm-project/releases")
(define* (clang-runtime-from-llvm llvm hash (define* (clang-runtime-from-llvm llvm
#:optional (patches '())) #:optional
hash
(patches '()))
(package (package
(name "clang-runtime") (name "clang-runtime")
(version (package-version llvm)) (version (package-version llvm))
(source (source
(origin (if hash
(method url-fetch) (origin
(uri (llvm-uri "compiler-rt" version)) (method url-fetch)
(sha256 (base32 hash)) (uri (llvm-uri "compiler-rt" version))
(patches (map search-patch patches)))) (sha256 (base32 hash))
(patches (map search-patch patches)))
(llvm-monorepo (package-version llvm))))
(build-system cmake-build-system) (build-system cmake-build-system)
(native-inputs (package-native-inputs llvm)) (native-inputs (package-native-inputs llvm))
(inputs (inputs
@ -162,7 +166,8 @@ compiler. In LLVM this library is called \"compiler-rt\".")
;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported. ;; <https://compiler-rt.llvm.org/> doesn't list MIPS as supported.
(supported-systems (delete "mips64el-linux" %supported-systems)))) (supported-systems (delete "mips64el-linux" %supported-systems))))
(define* (clang-from-llvm llvm clang-runtime hash (define* (clang-from-llvm llvm clang-runtime
#:optional hash
#:key (patches '()) tools-extra #:key (patches '()) tools-extra
(properties (properties
(append `((release-monitoring-url (append `((release-monitoring-url
@ -176,14 +181,16 @@ given PATCHES. When TOOLS-EXTRA is given, it must point to the
(name "clang") (name "clang")
(version (package-version llvm)) (version (package-version llvm))
(source (source
(origin (if hash
(method url-fetch) (origin
(uri (llvm-uri (if (version>=? version "9.0.1") (method url-fetch)
"clang" (uri (llvm-uri (if (version>=? version "9.0.1")
"cfe") "clang"
version)) "cfe")
(sha256 (base32 hash)) version))
(patches (map search-patch patches)))) (sha256 (base32 hash))
(patches (map search-patch patches)))
(llvm-monorepo (package-version llvm))))
;; Using cmake allows us to treat llvm as an external library. There ;; Using cmake allows us to treat llvm as an external library. There
;; doesn't seem to be any way to do this with clang's autotools-based ;; doesn't seem to be any way to do this with clang's autotools-based
;; build system. ;; build system.
@ -519,17 +526,27 @@ output), and Binutils.")
("libc-debug" ,glibc "debug") ("libc-debug" ,glibc "debug")
("libc-static" ,glibc "static"))))) ("libc-static" ,glibc "static")))))
(define-public llvm-13 (define %llvm-monorepo-hashes
'(("14.0.0" . "1ixqzjzq4ad3mv1w44gwcg1shy34c2b3i9ja71vx1wa7l2ms2376")))
(define %llvm-patches
'(("14.0.0" . ("clang-14.0-libc-search-path.patch"))))
(define (llvm-monorepo version)
(origin
(method git-fetch)
(uri (git-reference
(url "https://github.com/llvm/llvm-project")
(commit (string-append "llvmorg-" version))))
(file-name (git-file-name "llvm-project" version))
(sha256 (base32 (assoc-ref %llvm-monorepo-hashes version)))
(patches (map search-patch (assoc-ref %llvm-patches version)))))
(define-public llvm-14
(package (package
(name "llvm") (name "llvm")
(version "13.0.1") (version "14.0.0")
(source (source (llvm-monorepo version))
(origin
(method url-fetch)
(uri (llvm-uri "llvm" version))
(sha256
(base32
"0d681xiixmx9inwvz14vi3xsznrcryk06a8rvk9cljiq5kc80szc"))))
(build-system cmake-build-system) (build-system cmake-build-system)
(outputs '("out" "opt-viewer")) (outputs '("out" "opt-viewer"))
(native-inputs (native-inputs
@ -538,42 +555,46 @@ output), and Binutils.")
(inputs (inputs
(list libffi)) (list libffi))
(propagated-inputs (propagated-inputs
(list zlib)) ;to use output from llvm-config (list zlib)) ;to use output from llvm-config
(arguments (arguments
`(#:configure-flags (list
,#~(quasiquote #:configure-flags
;; These options are required for cross-compiling LLVM according to #~(list
;; https://llvm.org/docs/HowToCrossCompileLLVM.html. ;; These options are required for cross-compiling LLVM according
(#$@(if (%current-target-system) ;; to <https://llvm.org/docs/HowToCrossCompileLLVM.html>.
#~(,(string-append "-DLLVM_TABLEGEN=" #$@(if (%current-target-system)
#+(file-append this-package #~(,(string-append "-DLLVM_TABLEGEN="
"/bin/llvm-tblgen")) #+(file-append this-package
#$(string-append "-DLLVM_DEFAULT_TARGET_TRIPLE=" "/bin/llvm-tblgen"))
(%current-target-system)) #$(string-append "-DLLVM_DEFAULT_TARGET_TRIPLE="
#$(string-append "-DLLVM_TARGET_ARCH=" (%current-target-system))
(system->llvm-target)) #$(string-append "-DLLVM_TARGET_ARCH="
#$(string-append "-DLLVM_TARGETS_TO_BUILD=" (system->llvm-target))
(system->llvm-target))) #$(string-append "-DLLVM_TARGETS_TO_BUILD="
#~()) (system->llvm-target)))
"-DCMAKE_SKIP_BUILD_RPATH=FALSE" '())
"-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE" "-DCMAKE_SKIP_BUILD_RPATH=FALSE"
"-DBUILD_SHARED_LIBS:BOOL=TRUE" "-DCMAKE_BUILD_WITH_INSTALL_RPATH=FALSE"
"-DLLVM_ENABLE_FFI:BOOL=TRUE" "-DBUILD_SHARED_LIBS:BOOL=TRUE"
"-DLLVM_REQUIRES_RTTI=1" ; For some third-party utilities "-DLLVM_ENABLE_FFI:BOOL=TRUE"
"-DLLVM_INSTALL_UTILS=ON")) ; Needed for rustc. "-DLLVM_REQUIRES_RTTI=1" ;for some third-party utilities
;; Don't use '-g' during the build, to save space. "-DLLVM_INSTALL_UTILS=ON") ;needed for rustc
#:build-type "Release" ;; Don't use '-g' during the build, to save space.
#:phases #:build-type "Release"
(modify-phases %standard-phases #:phases
(add-after 'install 'install-opt-viewer #~(modify-phases %standard-phases
(lambda* (#:key outputs #:allow-other-keys) (add-after 'unpack 'change-directory
(let* ((out (assoc-ref outputs "out")) (lambda _
(opt-viewer-out (assoc-ref outputs "opt-viewer")) (chdir "llvm")))
(opt-viewer-share-dir (string-append opt-viewer-out "/share")) (add-after 'install 'install-opt-viewer
(opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer"))) (lambda* (#:key outputs #:allow-other-keys)
(mkdir-p opt-viewer-share-dir) (let* ((out (assoc-ref outputs "out"))
(rename-file (string-append out "/share/opt-viewer") (opt-viewer-out (assoc-ref outputs "opt-viewer"))
opt-viewer-dir))))))) (opt-viewer-share-dir (string-append opt-viewer-out "/share"))
(opt-viewer-dir (string-append opt-viewer-share-dir "/opt-viewer")))
(mkdir-p opt-viewer-share-dir)
(rename-file (string-append out "/share/opt-viewer")
opt-viewer-dir)))))))
(home-page "https://www.llvm.org") (home-page "https://www.llvm.org")
(synopsis "Optimizing compiler infrastructure") (synopsis "Optimizing compiler infrastructure")
(description (description
@ -586,6 +607,55 @@ of programming tools as well as libraries with equivalent functionality.")
(license license:asl2.0) (license license:asl2.0)
(properties `((release-monitoring-url . ,%llvm-release-monitoring-url))))) (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
(define-public clang-runtime-14
(let ((template (clang-runtime-from-llvm llvm-14)))
(package
(inherit template)
(arguments
(substitute-keyword-arguments (package-arguments template)
((#:phases phases '(@ (guix build cmake-build-system) %standard-phases))
#~(modify-phases #$phases
(add-after 'unpack 'change-directory
(lambda _
(chdir "compiler-rt")))))))
(native-inputs
`(;; FIXME: libfuzzer fails to build with GCC 10.
("gcc" ,gcc-11)
,@(package-native-inputs template))))))
(define-public clang-14
(let ((template (clang-from-llvm llvm-14 clang-runtime-14)))
(package
(inherit template)
(arguments
(substitute-keyword-arguments (package-arguments template)
((#:phases phases '(@ (guix build cmake-build-system) %standard-phases))
#~(modify-phases #$phases
(add-after 'unpack 'change-directory
(lambda _
(chdir "clang"))))))))))
(define-public clang-toolchain-14
(make-clang-toolchain clang-14))
(define-public llvm-13
(package
(inherit llvm-14)
(version "13.0.1")
(source
(origin
(method url-fetch)
(uri (llvm-uri "llvm" version))
(sha256
(base32
"0d681xiixmx9inwvz14vi3xsznrcryk06a8rvk9cljiq5kc80szc"))))
(arguments
(substitute-keyword-arguments (package-arguments llvm-14)
((#:phases phases '%standard-phases)
#~(modify-phases #$phases
(delete 'change-directory)))))
(properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
(define-public clang-runtime-13 (define-public clang-runtime-13
(clang-runtime-from-llvm (clang-runtime-from-llvm
llvm-13 llvm-13
@ -1072,9 +1142,32 @@ of programming tools as well as libraries with equivalent functionality.")
(properties `((release-monitoring-url . ,%llvm-release-monitoring-url))) (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
(license license:asl2.0))) ;with LLVM exceptions (license license:asl2.0))) ;with LLVM exceptions
(define-public lld (define-public lld-14
(package (package
(name "lld") (name "lld")
(version "14.0.0")
(source (llvm-monorepo version))
(build-system cmake-build-system)
(inputs
(list llvm-14))
(arguments
'(#:build-type "Release"
;; TODO: Tests require the lit tool, which isn't installed by the LLVM
;; package.
#:tests? #f
#:phases (modify-phases %standard-phases
(add-after 'unpack 'change-directory
(lambda _
(chdir "lld"))))))
(home-page "https://lld.llvm.org/")
(synopsis "Linker from the LLVM project")
(description "LLD is a high-performance linker, built as a set of reusable
components which highly leverage existing libraries in the larger LLVM Project.")
(license license:asl2.0))) ; With LLVM exception
(define-public lld-13
(package
(inherit lld-14)
(version "13.0.1") (version "13.0.1")
(source (origin (source (origin
(method url-fetch) (method url-fetch)
@ -1082,7 +1175,6 @@ of programming tools as well as libraries with equivalent functionality.")
(sha256 (sha256
(base32 (base32
"1yscckcszfr234k4svhybdbsnz6w65x8pldl6c2nhyxzx12zfsk6")))) "1yscckcszfr234k4svhybdbsnz6w65x8pldl6c2nhyxzx12zfsk6"))))
(build-system cmake-build-system)
(native-inputs (native-inputs
;; Note: check <https://bugs.llvm.org/show_bug.cgi?id=49228> to see ;; Note: check <https://bugs.llvm.org/show_bug.cgi?id=49228> to see
;; whether this is still necessary. ;; whether this is still necessary.
@ -1090,20 +1182,15 @@ of programming tools as well as libraries with equivalent functionality.")
(inputs (inputs
(list llvm-13)) (list llvm-13))
(arguments (arguments
`(#:build-type "Release" '(#:build-type "Release"
;; TODO: Tests require the lit tool, which isn't installed by the LLVM ;; TODO: Tests require the lit tool, which isn't installed by the LLVM
;; package. ;; package.
#:tests? #f)) #:tests? #f))
(home-page "https://lld.llvm.org/") (properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))))
(synopsis "Linker from the LLVM project")
(description "LLD is a high-performance linker, built as a set of reusable
components which highly leverage existing libraries in the larger LLVM Project.")
(properties `((release-monitoring-url . ,%llvm-release-monitoring-url)))
(license license:asl2.0))) ; With LLVM exception
(define-public lld-12 (define-public lld-12
(package (package
(inherit lld) (inherit lld-13)
(version "12.0.1") (version "12.0.1")
(source (origin (source (origin
(method url-fetch) (method url-fetch)
@ -1114,6 +1201,8 @@ components which highly leverage existing libraries in the larger LLVM Project."
(inputs (modify-inputs (package-inputs lld) (inputs (modify-inputs (package-inputs lld)
(replace "llvm" llvm-12))))) (replace "llvm" llvm-12)))))
(define-public lld lld-14)
(define* (make-lld-wrapper lld #:key lld-as-ld?) (define* (make-lld-wrapper lld #:key lld-as-ld?)
"Return a LLD wrapper. When LLD-AS-LD? is true, create a 'ld' symlink that "Return a LLD wrapper. When LLD-AS-LD? is true, create a 'ld' symlink that
points to 'lld'." points to 'lld'."

View File

@ -0,0 +1,94 @@
Clang attempts to guess file names based on the OS and distro (yes!),
but unfortunately, that doesn't work for us.
This patch makes it easy to insert libc's $libdir so that Clang passes the
correct absolute file name of crt1.o etc. to 'ld'. It also disables all
the distro-specific stuff and removes the hard-coded FHS directory names
to make sure Clang also works on foreign distros.
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -96,6 +96,10 @@ static Distro::DistroType DetectLsbRelease(llvm::vfs::FileSystem &VFS) {
}
static Distro::DistroType DetectDistro(llvm::vfs::FileSystem &VFS) {
+ // The compiler should always behave the same, even when used via Guix on a
+ // foreign distro.
+ return Distro::UnknownDistro;
+
Distro::DistroType Version = Distro::UnknownDistro;
// Newer freedesktop.org's compilant systemd-based systems
diff --git a/clang/lib/Driver/ToolChains/Cuda.cpp b/clang/lib/Driver/ToolChains/Cuda.cpp
--- a/clang/lib/Driver/ToolChains/Cuda.cpp
+++ b/clang/lib/Driver/ToolChains/Cuda.cpp
@@ -117,6 +117,9 @@ CudaInstallationDetector::CudaInstallationDetector(
const Driver &D, const llvm::Triple &HostTriple,
const llvm::opt::ArgList &Args)
: D(D) {
+ // Don't look for CUDA in /usr.
+ return;
+
struct Candidate {
std::string Path;
bool StrictChecking;
diff --git a/clang/lib/Driver/ToolChains/Linux.cpp b/clang/lib/Driver/ToolChains/Linux.cpp
--- a/clang/lib/Driver/ToolChains/Linux.cpp
+++ b/clang/lib/Driver/ToolChains/Linux.cpp
@@ -186,6 +186,10 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
Generic_GCC::PushPPaths(PPaths);
+ // Comment out the distro-specific tweaks so that they don't bite when
+ // using Guix on a foreign distro.
+#if 0
+
Distro Distro(D.getVFS(), Triple);
if (Distro.IsAlpineLinux() || Triple.isAndroid()) {
@@ -250,6 +254,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
if (IsAndroid || Distro.IsOpenSUSE())
ExtraOpts.push_back("--enable-new-dtags");
+#endif
// The selection of paths to try here is designed to match the patterns which
// the GCC driver itself uses, as this is part of the GCC-compatible driver.
@@ -270,6 +275,7 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
}
Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
+#if 0
addPathIfExists(D, SysRoot + "/lib/" + MultiarchTriple, Paths);
addPathIfExists(D, SysRoot + "/lib/../" + OSLibDir, Paths);
@@ -298,9 +304,11 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
addPathIfExists(D, SysRoot + "/" + OSLibDir + "/" + ABIName, Paths);
addPathIfExists(D, SysRoot + "/usr/" + OSLibDir + "/" + ABIName, Paths);
}
+#endif
Generic_GCC::AddMultiarchPaths(D, SysRoot, OSLibDir, Paths);
+#if 0
// Similar to the logic for GCC above, if we are currently running Clang
// inside of the requested system root, add its parent library path to those
// searched.
@@ -313,9 +321,14 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
if (OSLibDir != "lib")
addPathIfExists(D, D.Dir + "/../" + OSLibDir, Paths);
}
+#endif
+
+ // Add libc's lib/ directory to the search path, so that crt1.o, crti.o,
+ // and friends can be found.
+ addPathIfExists(D, "@GLIBC_LIBDIR@", Paths);
- addPathIfExists(D, SysRoot + "/lib", Paths);
- addPathIfExists(D, SysRoot + "/usr/lib", Paths);
+ // Add GCC's lib/ directory so libstdc++.so can be found.
+ addPathIfExists(D, GCCInstallation.getParentLibPath(), Paths);
}
ToolChain::RuntimeLibType Linux::GetDefaultRuntimeLibType() const {

View File

@ -43,7 +43,7 @@
(build-system cmake-build-system) (build-system cmake-build-system)
(inputs (inputs
(list clang-13 ; Clang propagates llvm. (list clang-13 ; Clang propagates llvm.
lld)) lld-13))
;; Zig compiles fine with GCC, but also needs native LLVM libraries. ;; Zig compiles fine with GCC, but also needs native LLVM libraries.
(native-inputs (native-inputs
(list llvm-13)) (list llvm-13))