From 7c980f5e9c2c9c6bc58a5bdbe4009458a38d9e84 Mon Sep 17 00:00:00 2001 From: Periklis Tsirakidis Date: Thu, 2 Mar 2017 15:19:45 +0100 Subject: [PATCH] valgrind: enable darwin build --- .../tools/analysis/valgrind/default.nix | 27 ++++++++++++-- .../analysis/valgrind/valgrind-bzero.patch | 37 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 5 ++- 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 pkgs/development/tools/analysis/valgrind/valgrind-bzero.patch diff --git a/pkgs/development/tools/analysis/valgrind/default.nix b/pkgs/development/tools/analysis/valgrind/default.nix index 2ecb5eaa132..80e3fdfc807 100644 --- a/pkgs/development/tools/analysis/valgrind/default.nix +++ b/pkgs/development/tools/analysis/valgrind/default.nix @@ -1,4 +1,4 @@ -{ stdenv, fetchurl, fetchpatch, perl, gdb }: +{ stdenv, fetchurl, fetchpatch, perl, gdb, llvm, cctools, xnu, bootstrap_cmds }: stdenv.mkDerivation rec { name = "valgrind-3.12.0"; @@ -14,11 +14,13 @@ stdenv.mkDerivation rec { # Perl is needed for `cg_annotate'. # GDB is needed to provide a sane default for `--db-command'. - buildInputs = [ perl ] ++ stdenv.lib.optional (!stdenv.isDarwin) gdb; + buildInputs = [ perl gdb ] ++ stdenv.lib.optionals (stdenv.isDarwin) [ bootstrap_cmds xnu ]; enableParallelBuilding = true; - postPatch = + patches = stdenv.lib.optionals (stdenv.isDarwin) [ ./valgrind-bzero.patch ]; + + postPatch = stdenv.lib.optionalString (stdenv.isDarwin) # Apple's GCC doesn't recognize `-arch' (as of version 4.2.1, build 5666). '' echo "getting rid of the \`-arch' GCC option..." @@ -27,6 +29,23 @@ stdenv.mkDerivation rec { sed -i coregrind/link_tool_exe_darwin.in \ -e 's/^my \$archstr = .*/my $archstr = "x86_64";/g' + + echo "substitute hardcoded /usr/include/mach with ${xnu}/include/mach" + substituteInPlace coregrind/Makefile.in \ + --replace /usr/include/mach ${xnu}/include/mach + + echo "substitute hardcoded dsymutil with ${llvm}/bin/llvm-dsymutil" + find -name "Makefile.in" | while read file; do + substituteInPlace "$file" \ + --replace dsymutil ${llvm}/bin/llvm-dsymutil + done + + substituteInPlace coregrind/m_debuginfo/readmacho.c \ + --replace /usr/bin/dsymutil ${llvm}/bin/llvm-dsymutil + + echo "substitute hardcoded /usr/bin/ld with ${cctools}/bin/ld" + substituteInPlace coregrind/link_tool_exe_darwin.in \ + --replace /usr/bin/ld ${cctools}/bin/ld ''; configureFlags = @@ -58,6 +77,6 @@ stdenv.mkDerivation rec { license = stdenv.lib.licenses.gpl2Plus; maintainers = [ stdenv.lib.maintainers.eelco ]; - platforms = stdenv.lib.platforms.linux; + platforms = stdenv.lib.platforms.unix; }; } diff --git a/pkgs/development/tools/analysis/valgrind/valgrind-bzero.patch b/pkgs/development/tools/analysis/valgrind/valgrind-bzero.patch new file mode 100644 index 00000000000..f56a277ad71 --- /dev/null +++ b/pkgs/development/tools/analysis/valgrind/valgrind-bzero.patch @@ -0,0 +1,37 @@ +Index: coregrind/m_main.c +=================================================================== +--- a/coregrind/m_main.c (revision 16102) ++++ b/coregrind/m_main.c (revision 16103) +@@ -3489,6 +3489,10 @@ + // skip check + return VG_(memset)(s,c,n); + } ++void __bzero(void* s, UWord n); ++void __bzero(void* s, UWord n) { ++ (void)VG_(memset)(s,0,n); ++} + void bzero(void *s, SizeT n); + void bzero(void *s, SizeT n) { + VG_(memset)(s,0,n); +@@ -4058,20 +4062,7 @@ + + #endif + +-#if defined(VGO_darwin) && DARWIN_VERS == DARWIN_10_10 + +-/* This might also be needed for > DARWIN_10_10, but I have no way +- to test for that. Hence '==' rather than '>=' in the version +- test above. */ +-void __bzero ( void* s, UWord n ); +-void __bzero ( void* s, UWord n ) +-{ +- (void) VG_(memset)( s, 0, n ); +-} +- +-#endif +- +- + /*--------------------------------------------------------------------*/ + /*--- end ---*/ + /*--------------------------------------------------------------------*/ + diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d98ce26aff4..dc3924c5829 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -6862,7 +6862,10 @@ with pkgs; gdb-multitarget = lowPrio (gdb.override { multitarget = true; }); - valgrind = callPackage ../development/tools/analysis/valgrind { }; + valgrind = callPackage ../development/tools/analysis/valgrind { + inherit (darwin) xnu bootstrap_cmds cctools; + llvm = llvm_39; + }; valkyrie = callPackage ../development/tools/analysis/valkyrie { };