1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 fetchpatch,
6 autoreconfHook,
7 libunwind,
8 perl,
9}:
10
11stdenv.mkDerivation rec {
12 pname = "gperftools";
13 version = "2.15";
14
15 src = fetchFromGitHub {
16 owner = "gperftools";
17 repo = "gperftools";
18 rev = "gperftools-${version}";
19 sha256 = "sha256-3ibr8AHzo7txX1U+9oOWA60qeeJs/OGeevv+sgBwQa0=";
20 };
21
22 patches = [
23 # Add the --disable-general-dynamic-tls configure option:
24 # https://bugzilla.redhat.com/show_bug.cgi?id=1483558
25 (fetchpatch {
26 url = "https://src.fedoraproject.org/rpms/gperftools/raw/f62d87a34f56f64fb8eb86727e34fbc2d3f5294a/f/gperftools-2.7.90-disable-generic-dynamic-tls.patch";
27 sha256 = "02falhpaqkl27hl1dib4yvmhwsddmgbw0krb46w31fyf3awb2ydv";
28 })
29 ];
30
31 nativeBuildInputs = [ autoreconfHook ];
32
33 # tcmalloc uses libunwind in a way that works correctly only on non-ARM dynamically linked linux
34 buildInputs = [
35 perl
36 ]
37 ++ lib.optional (
38 stdenv.hostPlatform.isLinux && !(stdenv.hostPlatform.isAarch || stdenv.hostPlatform.isStatic)
39 ) libunwind;
40
41 # Disable general dynamic TLS on AArch to support dlopen()'ing the library:
42 # https://bugzilla.redhat.com/show_bug.cgi?id=1483558
43 configureFlags = lib.optional stdenv.hostPlatform.isAarch "--disable-general-dynamic-tls";
44
45 prePatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
46 substituteInPlace Makefile.am --replace stdc++ c++
47 '';
48
49 env.NIX_CFLAGS_COMPILE = lib.optionalString stdenv.hostPlatform.isDarwin "-D_XOPEN_SOURCE";
50
51 # some packages want to link to the static tcmalloc_minimal
52 # to drop the runtime dependency on gperftools
53 dontDisableStatic = true;
54
55 enableParallelBuilding = true;
56
57 meta = with lib; {
58 homepage = "https://github.com/gperftools/gperftools";
59 description = "Fast, multi-threaded malloc() and nifty performance analysis tools";
60 platforms = platforms.all;
61 license = licenses.bsd3;
62 maintainers = with maintainers; [ vcunat ];
63 };
64}