Skip to content

Commit

Permalink
llvmPackages_16: Make the pkgsLLVM.stdenv work
Browse files Browse the repository at this point in the history
What changed:

* Fixed crtbeginS.o and crtendS.o missing
  (they may or may not be called crt{begin_end},{,_shared}.

* Fixed implicit function declaration causing build errors for various
  builds by supplying -Wno-implicit-function-declaration.

* Fixed __cxxabi_config.h missing, by adding -I${cxxabi}/include/c++/v1
  in the wrapper.

* Fixed libcxx failing to build due to missing libunwind symbols by
  making libunwind a propagated build input from libcxxabi, and setting
  -DLIBCXX_ADDITIONAL_LIBRARIES=unwind for stdenv.hostPlatform.useLLVM == true.

* libcxxabi wants to find libunwind at libunwind_shared.so, so symlink
  it there in libunwind.

What was tested:

* x86_64-linux, aarch64-linux, the stdenv builds.
  * Additionally I was able to get nix to build, with an overlay to fix
    a couple of minor issues in downstream packages (overlay supplied in
    PR #246577.
* aarch64-darwin fails spuriously in a single LLVM test
  strip-preserve-atime.test checking atime timestamps.
  • Loading branch information
pwaller committed Aug 1, 2023
1 parent b00c893 commit e125f5d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkgs/development/compilers/llvm/16/compiler-rt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ stdenv.mkDerivation {
'' + lib.optionalString (useLLVM) ''
ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbegin.o
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtend.o
# Note the history of crt{begin,end}S in previous versions of llvm in nixpkg:
# The presence of crtbegin_shared has been added and removed; it's possible
# people have added/removed it to get it working on their platforms.
# Try each in turn for now.
ln -s $out/lib/*/clang_rt.crtbegin-*.o $out/lib/crtbeginS.o
ln -s $out/lib/*/clang_rt.crtend-*.o $out/lib/crtendS.o
ln -s $out/lib/*/clang_rt.crtbegin_shared-*.o $out/lib/crtbeginS.o
ln -s $out/lib/*/clang_rt.crtend_shared-*.o $out/lib/crtendS.o
'' + lib.optionalString doFakeLibgcc ''
Expand Down
25 changes: 24 additions & 1 deletion pkgs/development/compilers/llvm/16/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,18 @@ in let
nixSupport.cc-cflags =
[ "-rtlib=compiler-rt"
"-Wno-unused-command-line-argument"
# The compiler got stricter about this, so a number of downstream
# things seem to fail with it switched on.
"-Wno-implicit-function-declaration"
"-B${targetLlvmLibraries.compiler-rt}/lib"

# Combat "__cxxabi_config.h not found". Maybe this could be fixed by
# copying these headers into libcxx? Note that building libcxx
# outside of monorepo isn't supported anymore, might be related to
# https://github.com/llvm/llvm-project/issues/55632
# ("16.0.3 libcxx, libcxxabi: circular build dependencies")
# Looks like the machinery changed in https://reviews.llvm.org/D120727.
"-I${lib.getDev targetLlvmLibraries.libcxx.cxxabi}/include/c++/v1"
]
++ lib.optional (!stdenv.targetPlatform.isWasm) "--unwindlib=libunwind"
++ lib.optional
Expand Down Expand Up @@ -297,7 +308,12 @@ in let
bintools = bintoolsNoLibc';
extraPackages = [ ];
extraBuildCommands = mkExtraBuildCommands0 cc;
nixSupport.cc-cflags = [ "-nostartfiles" ];
nixSupport.cc-cflags = [
"-nostartfiles"
# The compiler got stricter about this, so a number of downstream
# things seem to fail with it switched on.
"-Wno-implicit-function-declaration"
];
};

clangNoCompilerRtWithLibc = wrapCCWith rec {
Expand All @@ -306,6 +322,13 @@ in let
bintools = bintools';
extraPackages = [ ];
extraBuildCommands = mkExtraBuildCommands0 cc;
nixSupport.cc-cflags = [
# This appears to be necessary to build libcxxabi on x86_64.pkgsLLVM
# with llvmPackages_16.
"-nostdlib++"
"-nostartfiles"
"-nodefaultlibs"
];
};

});
Expand Down
11 changes: 9 additions & 2 deletions pkgs/development/compilers/llvm/16/libcxx/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,15 @@ stdenv.mkDerivation rec {
"-DLIBCXX_CXX_ABI=${if headersOnly then "none" else libcxx_cxx_abi_opt}"
] ++ lib.optional (!headersOnly && cxxabi.libName == "c++abi") "-DLIBCXX_CXX_ABI_INCLUDE_PATHS=${cxxabi.dev}/include/c++/v1"
++ lib.optional (stdenv.hostPlatform.isMusl || stdenv.hostPlatform.isWasi) "-DLIBCXX_HAS_MUSL_LIBC=1"
++ lib.optional (stdenv.hostPlatform.useLLVM or false) "-DLIBCXX_USE_COMPILER_RT=ON"
++ lib.optionals stdenv.hostPlatform.isWasm [
++ lib.optionals (stdenv.hostPlatform.useLLVM or false) [
"-DLIBCXX_USE_COMPILER_RT=ON"
# There's precedent for this in llvm-project/libcxx/cmake/caches.
# In a monorepo build you might do the following in the libcxxabi build:
# -DLLVM_ENABLE_PROJECTS=libcxxabi;libunwinder
# -DLIBCXXABI_STATICALLY_LINK_UNWINDER_IN_STATIC_LIBRARY=On
# libcxx appears to require unwind and doesn't pull it in via other means.
"-DLIBCXX_ADDITIONAL_LIBRARIES=unwind"
] ++ lib.optionals stdenv.hostPlatform.isWasm [
"-DLIBCXX_ENABLE_THREADS=OFF"
"-DLIBCXX_ENABLE_FILESYSTEM=OFF"
"-DLIBCXX_ENABLE_EXCEPTIONS=OFF"
Expand Down
2 changes: 1 addition & 1 deletion pkgs/development/compilers/llvm/16/libcxxabi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
'';

nativeBuildInputs = [ cmake ninja python3 ];
buildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind;
propagatedBuildInputs = lib.optional (!stdenv.isDarwin && !stdenv.hostPlatform.isWasm) libunwind;

cmakeFlags = [
"-DLLVM_ENABLE_RUNTIMES=libcxxabi"
Expand Down
5 changes: 5 additions & 0 deletions pkgs/development/compilers/llvm/16/libunwind/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ stdenv.mkDerivation rec {
cd ../runtimes
'';

postInstall = lib.optionalString (enableShared) ''
# libcxxabi wants to link to libunwind_shared.so (?).
ln -s $out/lib/libunwind.so $out/lib/libunwind_shared.so
'';

outputs = [ "out" "dev" ];

nativeBuildInputs = [ cmake ninja python3 ];
Expand Down

0 comments on commit e125f5d

Please sign in to comment.