Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkgs/development/compilers/llvm/16/compiler-rt/asan-offset.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/lib/asan/CMakeLists.txt 2022-06-22 16:46:24.000000000 +0000
+++ b/lib/asan/CMakeLists.txt
@@ -46,7 +46,7 @@ set(ASAN_STATIC_SOURCES
asan_rtl_static.cpp
)

-if (NOT WIN32 AND NOT APPLE)
+if (LINUX)
list(APPEND ASAN_STATIC_SOURCES
asan_rtl_x86_64.S
)
21 changes: 21 additions & 0 deletions pkgs/development/compilers/llvm/16/compiler-rt/freebsd-i386.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- a/lib/builtins/fp_lib.h 1969-12-31 16:00:01.000000000 -0800
+++ b/lib/builtins/fp_lib.h 2023-12-21 23:39:36.066927293 -0800
@@ -26,18 +26,6 @@
#include <stdbool.h>
#include <stdint.h>

-// x86_64 FreeBSD prior v9.3 define fixed-width types incorrectly in
-// 32-bit mode.
-#if defined(__FreeBSD__) && defined(__i386__)
-#include <sys/param.h>
-#if __FreeBSD_version < 903000 // v9.3
-#define uint64_t unsigned long long
-#define int64_t long long
-#undef UINT64_C
-#define UINT64_C(c) (c##ULL)
-#endif
-#endif
-
#if defined SINGLE_PRECISION

typedef uint16_t half_rep_t;
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,17 @@ stdenv.mkDerivation ({
'') + ''
substituteInPlace lib/builtins/int_util.c \
--replace "#include <stdlib.h>" ""
'' + (if stdenv.hostPlatform.isFreeBSD then
# As per above, but in FreeBSD assert is a macro and simply allowing it to be implicitly declared causes Issues!!!!!
''
substituteInPlace lib/builtins/clear_cache.c lib/builtins/cpu_model.c \
--replace "#include <assert.h>" "#define assert(e) ((e)?(void)0:__assert(__FUNCTION__,__FILE__,__LINE__,#e))"
'' else ''
substituteInPlace lib/builtins/clear_cache.c \
--replace "#include <assert.h>" ""
substituteInPlace lib/builtins/cpu_model${lib.optionalString (lib.versionAtLeast version "18") "/x86"}.c \
--replace "#include <assert.h>" ""
'');
''));

# Hack around weird upsream RPATH bug
postInstall = lib.optionalString (stdenv.hostPlatform.isDarwin) ''
Expand Down
6 changes: 5 additions & 1 deletion pkgs/development/compilers/llvm/common/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@
, python3
, fixDarwinDylibNames
, version
, cxxabi ? if stdenv.hostPlatform.isFreeBSD then libcxxrt else null
, cxxabi ? null
, libcxxrt
, libunwind
, enableShared ? !stdenv.hostPlatform.isStatic
}:

# note: our setup using libcxxabi instead of libcxxrt on FreeBSD diverges from
# normal FreeBSD. This may cause issues with binary patching down the line.
# If this becomes an issue, try adding as symlink libcxxrt.so -> libc++abi.so

# external cxxabi is not supported on Darwin as the build will not link libcxx
# properly and not re-export the cxxabi symbols into libcxx
# https://github.com/NixOS/nixpkgs/issues/166205
Expand Down
86 changes: 50 additions & 36 deletions pkgs/development/compilers/llvm/common/llvm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# broken for the armv7l builder
&& !stdenv.hostPlatform.isAarch
, enablePolly ? lib.versionAtLeast release_version "14"
, enableTerminfo ? true
}:

let
Expand Down Expand Up @@ -124,59 +125,54 @@ stdenv.mkDerivation (rec {
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})' ""
'' + (optionalString (lib.versionAtLeast release_version "15") (''

'' +
# 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
(optionalString (lib.versionAtLeast release_version "15") (''
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:
'' + (if lib.versionAtLeast release_version "16" then ''
(if lib.versionAtLeast release_version "16" then ''
substituteInPlace unittests/TargetParser/Host.cpp \
--replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }"
'' else ''
substituteInPlace unittests/Support/Host.cpp \
--replace '/usr/bin/sw_vers' "${(builtins.toString darwin.DarwinTools) + "/bin/sw_vers" }"
'') + optionalString (lib.versionAtLeast release_version "16") ''

'') +
# 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.
# and `roundeven` on macOS and FreeBSD.
#
# 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?
optionalString (lib.versionAtLeast release_version "16") ''
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.hostPlatform.isx86 && lib.versionAtLeast release_version "18") ''

'' +
# fails when run in sandbox
optionalString (!stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "18") ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
''))) + optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "15") (optionalString (lib.versionOlder release_version "16") ''
# 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?
''))) +
# dup of above patch with different conditions
optionalString (stdenv.isDarwin && stdenv.hostPlatform.isx86 && lib.versionAtLeast release_version "15") (optionalString (lib.versionOlder release_version "16") ''
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 (lib.versionAtLeast release_version "18") ''

'' +
# fails when run in sandbox
((optionalString (lib.versionAtLeast release_version "18") ''
substituteInPlace unittests/Support/VirtualFileSystemTest.cpp \
--replace "PhysicalFileSystemWorkingDirFailure" "DISABLED_PhysicalFileSystemWorkingDirFailure"
'') + ''
'') +
# 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
Expand Down Expand Up @@ -205,19 +201,20 @@ stdenv.mkDerivation (rec {
# not clear to me when/where/for what this even gets used in LLVM.
#
# TODO(@rrbutani): fix/follow-up
'' + (if lib.versionAtLeast release_version "16" then ''
(if lib.versionAtLeast release_version "16" then ''
substituteInPlace unittests/TargetParser/Host.cpp \
--replace "getMacOSHostVersion" "DISABLED_getMacOSHostVersion"
'' else ''
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
Expand All @@ -229,22 +226,24 @@ stdenv.mkDerivation (rec {
'' + lib.optionalString (lib.versionOlder release_version "13") ''
# TODO: Fix failing tests:
rm test/DebugInfo/X86/vla-multi.ll
'' + lib.optionalString (lib.versionAtLeast release_version "16") (''

'' +
# Fails in the presence of anti-virus software or other intrusion-detection software that
# modifies the atime when run. See #284056.
lib.optionalString (lib.versionAtLeast release_version "16") (''
rm test/tools/llvm-objcopy/ELF/strip-preserve-atime.test
'' + lib.optionalString (lib.versionOlder release_version "17") ''

'') + lib.optionalString (lib.versionAtLeast release_version "15" && lib.versionOlder release_version "17") ''
'') +
# timing-based tests are trouble
lib.optionalString (lib.versionAtLeast release_version "15" && lib.versionOlder release_version "17") ''
rm utils/lit/tests/googletest-timeout.py
'' + optionalString stdenv.hostPlatform.isMusl ''
'' +
# valgrind unhappy with musl or glibc, but fails w/musl only
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
Expand All @@ -254,18 +253,28 @@ stdenv.mkDerivation (rec {
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?)
optionalString (stdenv.hostPlatform.system == "armv6l-linux") ''
rm test/ExecutionEngine/frem.ll
'' +
# 1. TODO: Why does this test fail on FreeBSD?
# It seems to reference /usr/local/lib/libfile.a, which is clearly a problem.
# 2. This test fails for the same reason it fails on MacOS, but the fix is
# not trivial to apply.
optionalString stdenv.isFreeBSD ''
rm test/tools/llvm-libtool-darwin/L-and-l.test
rm test/ExecutionEngine/Interpreter/intrinsics.ll
'' + ''
patchShebangs test/BugPoint/compile-custom.ll.py
'' + (lib.optionalString (lib.versionOlder release_version "13") ''
'' +
# 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.
(lib.optionalString (lib.versionOlder release_version "13") (''
for f in \
test/Other/new-pass-manager.ll \
test/Other/new-pm-O0-defaults.ll \
Expand All @@ -286,18 +295,19 @@ stdenv.mkDerivation (rec {
--replace 'Starting llvm::' 'Starting {{.*}}' \
--replace 'Finished llvm::' 'Finished {{.*}}'
done
'' +
# gcc-13 fix
''
sed -i '/#include <string>/i#include <cstdint>' \
include/llvm/DebugInfo/Symbolize/DIPrinter.h
'');
''));

# Workaround for configure flags that need to have spaces
preConfigure = if lib.versionAtLeast release_version "15" then ''
# Workaround for configure flags that need to have spaces
cmakeFlagsArray+=(
-DLLVM_LIT_ARGS="-svj''${NIX_BUILD_CORES} --no-progress-bar"
)
'' else ''
# Workaround for configure flags that need to have spaces
cmakeFlagsArray+=(
-DLLVM_LIT_ARGS='-svj''${NIX_BUILD_CORES} --no-progress-bar'
)
Expand Down Expand Up @@ -332,9 +342,13 @@ stdenv.mkDerivation (rec {
"-DLLVM_HOST_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_DEFAULT_TARGET_TRIPLE=${stdenv.hostPlatform.config}"
"-DLLVM_ENABLE_DUMP=ON"
(lib.cmakeBool "LLVM_ENABLE_TERMINFO" enableTerminfo)
] ++ optionals (!doCheck) [
"-DLLVM_INCLUDE_TESTS=OFF"
] ++ optionals stdenv.hostPlatform.isStatic [
# Disables building of shared libs, -fPIC is still injected by cc-wrapper
"-DLLVM_ENABLE_PIC=OFF"
"-DCMAKE_SKIP_INSTALL_RPATH=ON"
"-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.
Expand Down