From de7131f3bc4d2e75cf986ca66915eaf67174aa8f Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:12:21 +0000 Subject: [PATCH 01/12] llvmPackages_git.llvm: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/git/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/git/llvm/default.nix b/pkgs/development/compilers/llvm/git/llvm/default.nix index ae8e1385bd8fe..634cd78295334 100644 --- a/pkgs/development/compilers/llvm/git/llvm/default.nix +++ b/pkgs/development/compilers/llvm/git/llvm/default.nix @@ -134,6 +134,13 @@ in stdenv.mkDerivation (rec { # 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 From 7d3ced431c2327b0a17398a9a07d1b5b092d80c4 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:12:45 +0000 Subject: [PATCH 02/12] llvm_15: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/15/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/15/llvm/default.nix b/pkgs/development/compilers/llvm/15/llvm/default.nix index de98c43615314..7742fc0a186cf 100644 --- a/pkgs/development/compilers/llvm/15/llvm/default.nix +++ b/pkgs/development/compilers/llvm/15/llvm/default.nix @@ -142,6 +142,13 @@ in stdenv.mkDerivation (rec { # 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 From 11c011a530644d144a8011f6ae9bbd2d131b4a56 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:12:54 +0000 Subject: [PATCH 03/12] llvm_14: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/14/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/14/llvm/default.nix b/pkgs/development/compilers/llvm/14/llvm/default.nix index e4c004d24ac31..06b5499835273 100644 --- a/pkgs/development/compilers/llvm/14/llvm/default.nix +++ b/pkgs/development/compilers/llvm/14/llvm/default.nix @@ -87,6 +87,13 @@ in stdenv.mkDerivation (rec { 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 '' From 52b497b8ce83ebc1507a32607fa9dfe2117d4b9d Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:13:02 +0000 Subject: [PATCH 04/12] llvm_13: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/13/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/13/llvm/default.nix b/pkgs/development/compilers/llvm/13/llvm/default.nix index f3a9ced70e19b..0977f2f2cafff 100644 --- a/pkgs/development/compilers/llvm/13/llvm/default.nix +++ b/pkgs/development/compilers/llvm/13/llvm/default.nix @@ -91,6 +91,13 @@ in stdenv.mkDerivation (rec { 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="; + }) ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin '' From 15bba8e3a9b3873e7ba26c1c3d64d1aa986132db Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:13:17 +0000 Subject: [PATCH 05/12] llvm_12: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/12/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/12/llvm/default.nix b/pkgs/development/compilers/llvm/12/llvm/default.nix index 2d7f70540dd8d..5edc5c136d577 100644 --- a/pkgs/development/compilers/llvm/12/llvm/default.nix +++ b/pkgs/development/compilers/llvm/12/llvm/default.nix @@ -100,6 +100,13 @@ in stdenv.mkDerivation (rec { 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="; + }) ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin '' From dc8fc0bcdc3bbd85cdcdff387cbd42dbed35529e Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:13:27 +0000 Subject: [PATCH 06/12] llvm_11: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/11/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/11/llvm/default.nix b/pkgs/development/compilers/llvm/11/llvm/default.nix index df9749fe1c27a..beab3c885ab15 100644 --- a/pkgs/development/compilers/llvm/11/llvm/default.nix +++ b/pkgs/development/compilers/llvm/11/llvm/default.nix @@ -116,6 +116,13 @@ in stdenv.mkDerivation (rec { 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="; + }) ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin '' From 920e6c220c6c113c89f915f648ce4c1ba289b189 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:13:36 +0000 Subject: [PATCH 07/12] llvm_10: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/10/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/10/llvm/default.nix b/pkgs/development/compilers/llvm/10/llvm/default.nix index fba387adf8677..ec494f4afce53 100644 --- a/pkgs/development/compilers/llvm/10/llvm/default.nix +++ b/pkgs/development/compilers/llvm/10/llvm/default.nix @@ -118,6 +118,13 @@ in stdenv.mkDerivation (rec { 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="; + }) ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin '' From b7f35e39e3669ef0ded392ba4d88c938769bc201 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:13:51 +0000 Subject: [PATCH 08/12] llvm_9: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/9/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/9/llvm/default.nix b/pkgs/development/compilers/llvm/9/llvm/default.nix index 0838fd8c5844a..b7259ac191503 100644 --- a/pkgs/development/compilers/llvm/9/llvm/default.nix +++ b/pkgs/development/compilers/llvm/9/llvm/default.nix @@ -108,6 +108,13 @@ in stdenv.mkDerivation (rec { 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 '' From 36c60f1c40a1c215adfce09182d5eb38e8f2ea46 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:13:59 +0000 Subject: [PATCH 09/12] llvm_8: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/8/llvm/default.nix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pkgs/development/compilers/llvm/8/llvm/default.nix b/pkgs/development/compilers/llvm/8/llvm/default.nix index 3b0877115e060..f95cefb9addd6 100644 --- a/pkgs/development/compilers/llvm/8/llvm/default.nix +++ b/pkgs/development/compilers/llvm/8/llvm/default.nix @@ -110,6 +110,13 @@ in stdenv.mkDerivation (rec { 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 '' From 74aa8c53d9beabfcd452d9b6f8c1d7ab7cc9be0e Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:14:06 +0000 Subject: [PATCH 10/12] llvm_7: backport patch for musl 1.2.4 --- .../compilers/llvm/7/llvm/default.nix | 2 + .../compilers/llvm/llvm-7-musl.patch | 92 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 pkgs/development/compilers/llvm/llvm-7-musl.patch diff --git a/pkgs/development/compilers/llvm/7/llvm/default.nix b/pkgs/development/compilers/llvm/7/llvm/default.nix index 185ae884442e4..7bfaef7d00b0c 100644 --- a/pkgs/development/compilers/llvm/7/llvm/default.nix +++ b/pkgs/development/compilers/llvm/7/llvm/default.nix @@ -108,6 +108,8 @@ in stdenv.mkDerivation (rec { sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; stripLen = 1; }) + + ../../llvm-7-musl.patch ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin '' diff --git a/pkgs/development/compilers/llvm/llvm-7-musl.patch b/pkgs/development/compilers/llvm/llvm-7-musl.patch new file mode 100644 index 0000000000000..0dac12cc20d62 --- /dev/null +++ b/pkgs/development/compilers/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 + From 135c81b588e679cbe6c8437f3916c7d2b0a8399e Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:14:29 +0000 Subject: [PATCH 11/12] llvm_6: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/6/llvm/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/compilers/llvm/6/llvm/default.nix b/pkgs/development/compilers/llvm/6/llvm/default.nix index 22a3970f76ce3..1c75660c20f52 100644 --- a/pkgs/development/compilers/llvm/6/llvm/default.nix +++ b/pkgs/development/compilers/llvm/6/llvm/default.nix @@ -105,6 +105,8 @@ stdenv.mkDerivation (rec { sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; stripLen = 1; }) + + ../../llvm-7-musl.patch ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin '' From cd9f932fec8ec80af6e956552f68a34de15a604a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sun, 30 Apr 2023 20:14:37 +0000 Subject: [PATCH 12/12] llvm_5: backport patch for musl 1.2.4 --- pkgs/development/compilers/llvm/5/llvm/default.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkgs/development/compilers/llvm/5/llvm/default.nix b/pkgs/development/compilers/llvm/5/llvm/default.nix index 31b88098c83a8..219ae190e955b 100644 --- a/pkgs/development/compilers/llvm/5/llvm/default.nix +++ b/pkgs/development/compilers/llvm/5/llvm/default.nix @@ -82,6 +82,8 @@ stdenv.mkDerivation (rec { sha256 = "0zjfjgavqzi2ypqwqnlvy6flyvdz8hi1anwv0ybwnm2zqixg7za3"; stripLen = 1; }) + + ../../llvm-7-musl.patch ] ++ lib.optional enablePolly ./gnu-install-dirs-polly.patch; postPatch = optionalString stdenv.isDarwin ''