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