From ac2306c5ad0ea4d456adfeb7436db985f481f43e Mon Sep 17 00:00:00 2001 From: dan Date: Sat, 11 Oct 2025 11:42:43 +0800 Subject: [PATCH] gnu: clang-17: Fix build with gcc-14 on ARM. * gnu/packages/patches/clang-17.0-fix-build-with-gcc-14-on-arm.patch: New file. * gnu/local.mk: Register it. * gnu/packages/llvm.scm (clang-from-llvm): Treat patches as additional patches when no hash provided. (clang-17): Apply the patch. Change-Id: I2c6580958c6d646703143872bbc59fd390e9cc95 Signed-off-by: Hilton Chain --- gnu/local.mk | 1 + gnu/packages/llvm.scm | 11 +++- ...ng-17.0-fix-build-with-gcc-14-on-arm.patch | 66 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 gnu/packages/patches/clang-17.0-fix-build-with-gcc-14-on-arm.patch diff --git a/gnu/local.mk b/gnu/local.mk index f939fefa0c4..a3bc00b6db9 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -1100,6 +1100,7 @@ dist_patch_DATA = \ %D%/packages/patches/clang-16-remove-crypt-interceptors.patch \ %D%/packages/patches/clang-17.0-libc-search-path.patch \ %D%/packages/patches/clang-17.0-link-dsymutil-latomic.patch \ + %D%/packages/patches/clang-17.0-fix-build-with-gcc-14-on-arm.patch \ %D%/packages/patches/clang-18.0-libc-search-path.patch \ %D%/packages/patches/clang-runtime-esan-build-fixes.patch \ %D%/packages/patches/clang-runtime-12-remove-crypt-interceptors.patch \ diff --git a/gnu/packages/llvm.scm b/gnu/packages/llvm.scm index 03c3c47e9ec..15f337cfbb0 100644 --- a/gnu/packages/llvm.scm +++ b/gnu/packages/llvm.scm @@ -30,6 +30,7 @@ ;;; Copyright © 2024, 2025 Janneke Nieuwenhuizen ;;; Copyright © 2025 Andreas Enge ;;; Copyright © 2025 Liam Hupfer +;;; Copyright © 2025 dan ;;; ;;; This file is part of GNU Guix. ;;; @@ -266,7 +267,14 @@ until LLVM/Clang 14." version)) (sha256 (base32 hash)) (patches (map search-patch patches))) - (llvm-monorepo (package-version llvm)))) + (if patches + (let ((llvm-source (llvm-monorepo (package-version llvm)))) + (origin + (inherit llvm-source) + (patches + (append (origin-patches llvm-source) + (map search-patch patches))))) + (llvm-monorepo (package-version llvm))))) ;; 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 ;; build system. @@ -1080,6 +1088,7 @@ Library.") (define-public clang-17 (clang-from-llvm llvm-17 clang-runtime-17 + #:patches '("clang-17.0-fix-build-with-gcc-14-on-arm.patch") #:tools-extra (origin (method url-fetch) diff --git a/gnu/packages/patches/clang-17.0-fix-build-with-gcc-14-on-arm.patch b/gnu/packages/patches/clang-17.0-fix-build-with-gcc-14-on-arm.patch new file mode 100644 index 00000000000..52eef8a0286 --- /dev/null +++ b/gnu/packages/patches/clang-17.0-fix-build-with-gcc-14-on-arm.patch @@ -0,0 +1,66 @@ +Source: https://src.fedoraproject.org/rpms/clang17/raw/rawhide/f/0001-Clang-Fix-build-with-GCC-14-on-ARM.patch +From bd2e848f15c0f25231126eb10cb0ab350717dfc0 Mon Sep 17 00:00:00 2001 +From: Nikita Popov +Date: Fri, 19 Jan 2024 12:09:13 +0100 +Subject: [PATCH] [Clang] Fix build with GCC 14 on ARM + +GCC 14 defines `__arm_streaming` as a macro expanding to +`[[arm::streaming]]`. Due to the nested macro use, this gets +expanded prior to concatenation. + +It doesn't look like C++ has a really clean way to prevent +macro expansion. The best I have found is to use `EMPTY ## X` where +`EMPTY` is an empty macro argument, so this is the hack I'm +implementing here. + +Fixes https://github.com/llvm/llvm-project/issues/78691. +--- + clang/include/clang/Basic/TokenKinds.def | 3 ++- + clang/include/clang/Basic/TokenKinds.h | 2 +- + clang/utils/TableGen/ClangAttrEmitter.cpp | 2 +- + 3 files changed, 4 insertions(+), 3 deletions(-) + +diff --git a/clang/include/clang/Basic/TokenKinds.def b/clang/include/clang/Basic/TokenKinds.def +index ef0dad0f2dcd..3add13c079f3 100644 +--- a/clang/include/clang/Basic/TokenKinds.def ++++ b/clang/include/clang/Basic/TokenKinds.def +@@ -752,8 +752,9 @@ KEYWORD(__builtin_available , KEYALL) + KEYWORD(__builtin_sycl_unique_stable_name, KEYSYCL) + + // Keywords defined by Attr.td. ++// The "EMPTY ## X" is used to prevent early macro-expansion of the keyword. + #ifndef KEYWORD_ATTRIBUTE +-#define KEYWORD_ATTRIBUTE(X) KEYWORD(X, KEYALL) ++#define KEYWORD_ATTRIBUTE(X, EMPTY) KEYWORD(EMPTY ## X, KEYALL) + #endif + #include "clang/Basic/AttrTokenKinds.inc" + +diff --git a/clang/include/clang/Basic/TokenKinds.h b/clang/include/clang/Basic/TokenKinds.h +index e4857405bc7f..ff117bd5afc5 100644 +--- a/clang/include/clang/Basic/TokenKinds.h ++++ b/clang/include/clang/Basic/TokenKinds.h +@@ -109,7 +109,7 @@ bool isPragmaAnnotation(TokenKind K); + + inline constexpr bool isRegularKeywordAttribute(TokenKind K) { + return (false +-#define KEYWORD_ATTRIBUTE(X) || (K == tok::kw_##X) ++#define KEYWORD_ATTRIBUTE(X, ...) || (K == tok::kw_##X) + #include "clang/Basic/AttrTokenKinds.inc" + ); + } +diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp b/clang/utils/TableGen/ClangAttrEmitter.cpp +index b5813c6abc2b..79db17501b64 100644 +--- a/clang/utils/TableGen/ClangAttrEmitter.cpp ++++ b/clang/utils/TableGen/ClangAttrEmitter.cpp +@@ -3430,7 +3430,7 @@ void EmitClangAttrTokenKinds(RecordKeeper &Records, raw_ostream &OS) { + "RegularKeyword attributes with arguments are not " + "yet supported"); + OS << "KEYWORD_ATTRIBUTE(" +- << S.getSpellingRecord().getValueAsString("Name") << ")\n"; ++ << S.getSpellingRecord().getValueAsString("Name") << ", )\n"; + } + OS << "#undef KEYWORD_ATTRIBUTE\n"; + } +-- +2.43.0 +