Skip to content

Commit

Permalink
rustc: fix build with unbundled jemalloc and llvm on darwin
Browse files Browse the repository at this point in the history
jemalloc with stripped prefix would cause segfaults in free:
NixOS#49557 (comment)

Thanks to @danieldk for darwin testing/debugging.
  • Loading branch information
symphorien committed Nov 8, 2018
1 parent 4b0d441 commit 973eca7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 4 additions & 1 deletion pkgs/development/compilers/rust/rustc.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let

llvmShared = llvm.override { enableSharedLibraries = true; };

prefixedJemalloc = jemalloc.override { stripPrefix = false; };

target = builtins.replaceStrings [" "] [","] (builtins.toString targets);
in

Expand All @@ -43,6 +45,7 @@ stdenv.mkDerivation {
NIX_LDFLAGS =
# when linking stage1 libstd: cc: undefined reference to `__cxa_begin_catch'
optional (stdenv.isLinux && !withBundledLLVM) "--push-state --as-needed -lstdc++ --pop-state"
++ optional (stdenv.isDarwin && !withBundledLLVM) "-lc++"
++ optional stdenv.isDarwin "-rpath ${llvmShared}/lib";

# Enable nightly features in stable compiles (used for
Expand All @@ -59,7 +62,7 @@ stdenv.mkDerivation {
configureFlags = configureFlags
++ [ "--enable-local-rust" "--local-rust-root=${rustPlatform.rust.rustc}" "--enable-rpath"
"--enable-vendor"
"--jemalloc-root=${jemalloc}/lib"
"--jemalloc-root=${prefixedJemalloc}/lib"
"--default-linker=${targetPackages.stdenv.cc}/bin/cc" ]
++ optional (!withBundledLLVM) [ "--enable-llvm-link-shared" "--llvm-root=${llvmShared}" ]
++ optional (targets != []) "--target=${target}";
Expand Down
19 changes: 12 additions & 7 deletions pkgs/development/libraries/jemalloc/common.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{ stdenv, fetchurl, version, sha256, ... }@args:
{ version, sha256 }:
{ stdenv, fetchurl,
# By default, jemalloc puts a je_ prefix onto all its symbols on OSX, which
# then stops downstream builds (mariadb in particular) from detecting it. This
# option should remove the prefix and give us a working jemalloc.
# Causes segfaults with some software (ex. rustc), but defaults to true for backward
# compatibility. Ignored on non OSX.
stripPrefix ? true }:

stdenv.mkDerivation (rec {
stdenv.mkDerivation rec {
name = "jemalloc-${version}";
inherit version;

Expand All @@ -9,10 +16,8 @@ stdenv.mkDerivation (rec {
inherit sha256;
};

# By default, jemalloc puts a je_ prefix onto all its symbols on OSX, which
# then stops downstream builds (mariadb in particular) from detecting it. This
# option should remove the prefix and give us a working jemalloc.
configureFlags = stdenv.lib.optional stdenv.isDarwin "--with-jemalloc-prefix=";
# see the comment on stripPrefix
configureFlags = stdenv.lib.optional (stdenv.isDarwin && stripPrefix) "--with-jemalloc-prefix=";
doCheck = true;

enableParallelBuilding = true;
Expand All @@ -28,4 +33,4 @@ stdenv.mkDerivation (rec {
platforms = platforms.all;
maintainers = with maintainers; [ wkennington ];
};
} // (builtins.removeAttrs args [ "stdenv" "fetchurl" "version" "sha256" ]))
}
2 changes: 0 additions & 2 deletions pkgs/development/libraries/jemalloc/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ stdenv, fetchurl, fetchpatch }:
import ./common.nix {
inherit stdenv fetchurl;
version = "5.1.0";
sha256 = "0s3jpcyhzia8d4k0xyc67is78kg416p9yc3c2f9w6fhhqqffd5jk";
}
4 changes: 1 addition & 3 deletions pkgs/development/libraries/jemalloc/jemalloc450.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
{ stdenv, fetchurl }:
import ./common.nix {
inherit stdenv fetchurl;
version = "4.5.0";
sha256 = "10373xhpc10pgmai9fkc1z0rs029qlcb3c0qfnvkbwdlcibdh2cl";
}
}

0 comments on commit 973eca7

Please sign in to comment.