From fa8ce61acd0d057dd3859f9518d2545ecd1d52e8 Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Thu, 31 Oct 2024 19:12:47 -0700 Subject: [PATCH 1/4] llvmPackages_19.compiler_rt: don't codesign The codesign binary is part of the bootstrapTools and is incompatible with the version required by the compiler_rt build. Remove find_program(.., codesign) from the cmake files to prevent the build from using and then breaking due to an incompatible codesign --- .../compilers/llvm/common/compiler-rt/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix index 9c634650dff2..30212e18bcaf 100644 --- a/pkgs/development/compilers/llvm/common/compiler-rt/default.nix +++ b/pkgs/development/compilers/llvm/common/compiler-rt/default.nix @@ -188,6 +188,13 @@ stdenv.mkDerivation ({ substituteInPlace ../libcxx/utils/merge_archives.py \ --replace-fail "import distutils.spawn" "from shutil import which as find_executable" \ --replace-fail "distutils.spawn." "" + '' + lib.optionalString (lib.versionAtLeast release_version "19") + # codesign in sigtool doesn't support the various options used by the build + # and is present in the bootstrap-tools. Removing find_program prevents the + # build from trying to use it and failing. + '' + substituteInPlace cmake/Modules/AddCompilerRT.cmake \ + --replace-fail 'find_program(CODESIGN codesign)' "" ''; # Hack around weird upsream RPATH bug From 0efe75ec20e0275a4b8de31aabd713613f56bfe7 Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Thu, 31 Oct 2024 19:34:17 -0700 Subject: [PATCH 2/4] libffi: move label before .cfi_starproc after https://github.com/llvm/llvm-project/commit/0b0672773e8b2ed01ad3fce103f4d84becfdd1ed clang_19 will produce errors if the function label comes after .cfi_starproc. Vendor upstream commit https://github.com/libffi/libffi/commit/8308bed5b2423878aa20d7884a99cf2e30b8daf7 to fix the issue --- pkgs/development/libraries/libffi/default.nix | 3 ++ .../libffi/label-before-cfi_startproc.patch | 47 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 pkgs/development/libraries/libffi/label-before-cfi_startproc.patch diff --git a/pkgs/development/libraries/libffi/default.nix b/pkgs/development/libraries/libffi/default.nix index 9293077b1aa7..021776ed3856 100644 --- a/pkgs/development/libraries/libffi/default.nix +++ b/pkgs/development/libraries/libffi/default.nix @@ -22,6 +22,9 @@ stdenv.mkDerivation (finalAttrs: { # cgit) that are needed here should be included directly in Nixpkgs as # files. patches = [ + # https://github.com/libffi/libffi/pull/857 + # function label needs to come before .cfi_startproc + ./label-before-cfi_startproc.patch ]; strictDeps = true; diff --git a/pkgs/development/libraries/libffi/label-before-cfi_startproc.patch b/pkgs/development/libraries/libffi/label-before-cfi_startproc.patch new file mode 100644 index 000000000000..379c670b4546 --- /dev/null +++ b/pkgs/development/libraries/libffi/label-before-cfi_startproc.patch @@ -0,0 +1,47 @@ +From 3065c530d3aa50c2b5ee9c01f88a9c0b61732805 Mon Sep 17 00:00:00 2001 +From: Ivan Tadeu Ferreira Antunes Filho +Date: Mon, 16 Sep 2024 16:10:39 -0400 +Subject: [PATCH] Move cfi_startproc after CNAME(label) + +This is a fix for https://github.com/libffi/libffi/issues/852: error: invalid CFI advance_loc expression on apple targets. + +The CFI for darwin arm64 was broken because the CNAME macro was being used after the +cfi_startproc macro. +--- + src/aarch64/sysv.S | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/aarch64/sysv.S b/src/aarch64/sysv.S +index 6a9a5611f..e83bc65de 100644 +--- a/src/aarch64/sysv.S ++++ b/src/aarch64/sysv.S +@@ -89,8 +89,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + x5 closure + */ + +- cfi_startproc + CNAME(ffi_call_SYSV): ++ cfi_startproc + BTI_C + PAC_CFI_WINDOW_SAVE + /* Sign the lr with x1 since that is the CFA which is the modifer used in auth instructions */ +@@ -348,8 +348,8 @@ CNAME(ffi_closure_SYSV_V): + #endif + + .align 4 +- cfi_startproc + CNAME(ffi_closure_SYSV): ++ cfi_startproc + BTI_C + SIGN_LR + PAC_CFI_WINDOW_SAVE +@@ -647,8 +647,8 @@ CNAME(ffi_go_closure_SYSV_V): + #endif + + .align 4 +- cfi_startproc + CNAME(ffi_go_closure_SYSV): ++ cfi_startproc + BTI_C + SIGN_LR_LINUX_ONLY + PAC_CFI_WINDOW_SAVE From f91487fa13dd5d5cd5ff95982e7c00cebb744f02 Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Sat, 2 Nov 2024 00:08:21 -0700 Subject: [PATCH 3/4] ld64: fix build with llvm19 remove unused and incomplete function --- pkgs/by-name/ld/ld64/package.nix | 1 + .../remove-unused-and-incomplete-blob-clone.diff | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 pkgs/by-name/ld/ld64/remove-unused-and-incomplete-blob-clone.diff diff --git a/pkgs/by-name/ld/ld64/package.nix b/pkgs/by-name/ld/ld64/package.nix index d3dfe3b8b7e6..b050c2ac647b 100644 --- a/pkgs/by-name/ld/ld64/package.nix +++ b/pkgs/by-name/ld/ld64/package.nix @@ -128,6 +128,7 @@ stdenv.mkDerivation (finalAttrs: { ./0006-Add-libcd_is_blob_a_linker_signature-implementation.patch # Add OpenSSL implementation of CoreCrypto digest functions. Avoids use of private and non-free APIs. ./0007-Add-OpenSSL-based-CoreCrypto-digest-functions.patch + ./remove-unused-and-incomplete-blob-clone.diff ]; postPatch = '' diff --git a/pkgs/by-name/ld/ld64/remove-unused-and-incomplete-blob-clone.diff b/pkgs/by-name/ld/ld64/remove-unused-and-incomplete-blob-clone.diff new file mode 100644 index 000000000000..88dd4304f6f7 --- /dev/null +++ b/pkgs/by-name/ld/ld64/remove-unused-and-incomplete-blob-clone.diff @@ -0,0 +1,14 @@ +diff --git a/src/ld/code-sign-blobs/blob.h b/src/ld/code-sign-blobs/blob.h +index 19c63a9..1dfb380 100644 +--- a/src/ld/code-sign-blobs/blob.h ++++ b/src/ld/code-sign-blobs/blob.h +@@ -180,9 +180,6 @@ public: + return NULL; + } + +- BlobType *clone() const +- { assert(validateBlob()); return specific(this->BlobCore::clone()); } +- + static BlobType *readBlob(int fd) + { return specific(BlobCore::readBlob(fd, _magic, sizeof(BlobType), 0), true); } + From 0fc9787683e6fef5eaf1b6de5f1f2592c2ab0b19 Mon Sep 17 00:00:00 2001 From: Reno Dakota Date: Sat, 2 Nov 2024 14:48:50 -0700 Subject: [PATCH 4/4] darwin.stdenv: add file to early stdenv stages file is part of the final stdenv and llvm_19 requires it for tests. add file to the path to the early stage stdenv's for the upcoming switch to llvm_19 --- pkgs/stdenv/darwin/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/stdenv/darwin/default.nix b/pkgs/stdenv/darwin/default.nix index 60eca7f72de8..35ad94c41633 100644 --- a/pkgs/stdenv/darwin/default.nix +++ b/pkgs/stdenv/darwin/default.nix @@ -191,6 +191,7 @@ let shell = bash + "/bin/bash"; initialPath = [ bash + prevStage.file bootstrapTools ]; @@ -370,6 +371,7 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check ld64 = null; coreutils = null; + file = null; gnugrep = null; pbzx = null; @@ -416,6 +418,7 @@ assert bootstrapTools.passthru.isFromBootstrapFiles or false; # sanity check coreutils = bootstrapTools; cpio = bootstrapTools; + file = null; gnugrep = bootstrapTools; pbzx = bootstrapTools;