diff options
Diffstat (limited to 'pkgs/development/compilers/llvm/common/libcxx/default.nix')
-rw-r--r-- | pkgs/development/compilers/llvm/common/libcxx/default.nix | 43 |
1 files changed, 36 insertions, 7 deletions
diff --git a/pkgs/development/compilers/llvm/common/libcxx/default.nix b/pkgs/development/compilers/llvm/common/libcxx/default.nix index 0e91f50551c55..b2c23f35f0a18 100644 --- a/pkgs/development/compilers/llvm/common/libcxx/default.nix +++ b/pkgs/development/compilers/llvm/common/libcxx/default.nix @@ -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 @@ -67,6 +71,12 @@ let cxxCMakeFlags = [ "-DLIBCXX_CXX_ABI=${cxxabiName}" + ] ++ lib.optionals (cxxabi == null && lib.versionAtLeast release_version "16") [ + # Note: llvm < 16 doesn't support this flag (or it's broken); handled in postInstall instead. + # Include libc++abi symbols within libc++.a for static linking libc++; + # dynamic linking includes them through libc++.so being a linker script + # which includes both shared objects. + "-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON" ] ++ lib.optionals (cxxabi != null) [ "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${lib.getDev cxxabi}/include" ] ++ lib.optionals (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) [ @@ -87,12 +97,6 @@ let cmakeFlags = [ "-DLLVM_ENABLE_RUNTIMES=${lib.concatStringsSep ";" runtimes}" - ] ++ lib.optionals (useLLVM && !stdenv.hostPlatform.isWasm) [ - # libcxxabi's CMake looks as though it treats -nostdlib++ as implying -nostdlib, - # but that does not appear to be the case for example when building - # pkgsLLVM.libcxxabi (which uses clangNoCompilerRtWithLibc). - "-DCMAKE_EXE_LINKER_FLAGS=-nostdlib" - "-DCMAKE_SHARED_LINKER_FLAGS=-nostdlib" ] ++ lib.optionals stdenv.hostPlatform.isWasm [ "-DCMAKE_C_COMPILER_WORKS=ON" "-DCMAKE_CXX_COMPILER_WORKS=ON" @@ -126,6 +130,31 @@ stdenv.mkDerivation (rec { postInstall = lib.optionalString (cxxabi != null) '' lndir ${lib.getDev cxxabi}/include $dev/include/c++/v1 lndir ${lib.getLib cxxabi}/lib $out/lib + libcxxabi=$out/lib/lib${cxxabi.libName}.a + '' + # LIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON doesn't work for LLVM < 16 or + # external cxxabi libraries so merge libc++abi.a into libc++.a ourselves. + + # GNU binutils emits objects in LIFO order in MRI scripts so after the merge + # the objects are in reversed order so a second MRI script is required so the + # objects in the archive are listed in proper order (libc++.a, libc++abi.a) + + lib.optionalString (cxxabi != null || lib.versionOlder release_version "16") '' + libcxxabi=''${libcxxabi-$out/lib/libc++abi.a} + if [[ -f $out/lib/libc++.a && -e $libcxxabi ]]; then + $AR -M <<MRI + create $out/lib/libc++.a + addlib $out/lib/libc++.a + addlib $libcxxabi + save + end + MRI + $AR -M <<MRI + create $out/lib/libc++.a + addlib $out/lib/libc++.a + save + end + MRI + fi ''; passthru = { |