From f463b467ce8b5fdd7cb98fa1240ac8aade180a93 Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Sat, 6 Feb 2021 16:28:03 +0100 Subject: [PATCH] Use GCC runtime libraries with LLVM toolchain Use the GCC runtime library from the prebuild Genode toolchain. --- overlay/default.nix | 1 - overlay/llvm-11/clang/default.nix | 2 +- overlay/llvm-11/compiler-rt.patch | 13 ------- overlay/llvm-11/default.nix | 59 ++++++++++++++--------------- overlay/llvm-11/libc++/default.nix | 5 --- overlay/llvm-11/libc++/genode.patch | 34 ----------------- overlay/llvm-11/libc++abi.nix | 2 - 7 files changed, 30 insertions(+), 86 deletions(-) delete mode 100644 overlay/llvm-11/compiler-rt.patch delete mode 100644 overlay/llvm-11/libc++/genode.patch diff --git a/overlay/default.nix b/overlay/default.nix index b0f8975..20c238f 100644 --- a/overlay/default.nix +++ b/overlay/default.nix @@ -134,7 +134,6 @@ in nullPkgs // { inherit (stdenvAdapters) overrideCC; buildLlvmTools = buildPackages.llvmPackages_11.tools; targetLlvmLibraries = targetPackages.llvmPackages_11.libraries; - inherit (final.genodePackages.genodeSources) genodeBase; } // stdenv.lib.optionalAttrs (stdenv.hostPlatform.isi686 && buildPackages.stdenv.cc.isGNU) { stdenv = gcc7Stdenv; diff --git a/overlay/llvm-11/clang/default.nix b/overlay/llvm-11/clang/default.nix index 675a789..5fdf71a 100644 --- a/overlay/llvm-11/clang/default.nix +++ b/overlay/llvm-11/clang/default.nix @@ -49,7 +49,7 @@ let # Patch for standalone doc building sed -i '1s,^,find_package(Sphinx REQUIRED)\n,' docs/CMakeLists.txt - '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl '' + '' + stdenv.lib.optionalString (stdenv.hostPlatform.isMusl || stdenv.targetPlatform.isGenode) '' sed -i -e 's/lgcc_s/lgcc_eh/' lib/Driver/ToolChains/*.cpp '' + stdenv.lib.optionalString stdenv.hostPlatform.isDarwin '' substituteInPlace tools/extra/clangd/CMakeLists.txt \ diff --git a/overlay/llvm-11/compiler-rt.patch b/overlay/llvm-11/compiler-rt.patch deleted file mode 100644 index 816d71b..0000000 --- a/overlay/llvm-11/compiler-rt.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/lib/builtins/assembly.h b/lib/builtins/assembly.h -index 3f5e59b2544..97d06d6ccd1 100644 ---- a/lib/builtins/assembly.h -+++ b/lib/builtins/assembly.h -@@ -45,7 +45,7 @@ - #define CONST_SECTION .section .rodata - - #if defined(__GNU__) || defined(__FreeBSD__) || defined(__Fuchsia__) || \ -- defined(__linux__) -+ defined(__linux__) || defined(__GENODE__) - #define NO_EXEC_STACK_DIRECTIVE .section .note.GNU-stack,"",%progbits - #else - #define NO_EXEC_STACK_DIRECTIVE diff --git a/overlay/llvm-11/default.nix b/overlay/llvm-11/default.nix index 9275b7f..c291eb7 100644 --- a/overlay/llvm-11/default.nix +++ b/overlay/llvm-11/default.nix @@ -3,7 +3,7 @@ , buildPackages , buildLlvmTools # tools, but from the previous stage, for cross , targetLlvmLibraries # libraries, but from the next stage, for cross -, genodeBase ? null +, genodePackages ? null }: let @@ -93,31 +93,35 @@ let bintools = callPackage ./bintools.nix {}; - lldClang = wrapCCWith rec { - cc = tools.clang-unwrapped; - libcxx = targetLlvmLibraries.libcxx; - bintools = wrapBintoolsWith { - inherit (tools) bintools; + lldClang = if stdenv.targetPlatform.isGenode then + wrapCCWith rec { + cc = tools.clang-unwrapped; + bintools = wrapBintoolsWith { inherit (tools) bintools; }; + extraBuildCommands = with genodePackages.genodeSources; '' + echo "--gcc-toolchain=${toolchain.cc}" >> $out/nix-support/cc-cflags + echo "--sysroot=${genodeBase}" >> $out/nix-support/cc-cflags + echo "-I${genodeBase}/include" >> $out/nix-support/cc-cflags + echo "-L ${genodeBase}" >> $out/nix-support/cc-cflags + ''; + } + else + wrapCCWith rec { + cc = tools.clang-unwrapped; + libcxx = targetLlvmLibraries.libcxx; + bintools = wrapBintoolsWith { inherit (tools) bintools; }; + extraPackages = + [ targetLlvmLibraries.libcxxabi targetLlvmLibraries.compiler-rt ] + ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) + [ targetLlvmLibraries.libunwind ]; + extraBuildCommands = '' + echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags + echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags + '' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) '' + echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags + '' + stdenv.lib.optionalString stdenv.targetPlatform.isWasm '' + echo "-fno-exceptions" >> $out/nix-support/cc-cflags + '' + mkExtraBuildCommands cc; }; - extraPackages = [ - targetLlvmLibraries.libcxxabi - targetLlvmLibraries.compiler-rt - ] ++ stdenv.lib.optionals (!stdenv.targetPlatform.isWasm) [ - targetLlvmLibraries.libunwind - ]; - extraBuildCommands = '' - echo "-rtlib=compiler-rt -Wno-unused-command-line-argument" >> $out/nix-support/cc-cflags - echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags - '' + stdenv.lib.optionalString (!stdenv.targetPlatform.isWasm) '' - echo "--unwindlib=libunwind" >> $out/nix-support/cc-cflags - '' + stdenv.lib.optionalString stdenv.targetPlatform.isWasm '' - echo "-fno-exceptions" >> $out/nix-support/cc-cflags - '' + stdenv.lib.optionalString stdenv.targetPlatform.isGenode '' - echo "-I${genodeBase}/include" >> $out/nix-support/cc-cflags - echo "--sysroot=${genodeBase}" >> $out/nix-support/cc-cflags - echo "-L ${genodeBase}" >> $out/nix-support/cc-cflags - '' + mkExtraBuildCommands cc; - }; lldClangNoLibcxx = wrapCCWith rec { cc = tools.clang-unwrapped; @@ -132,11 +136,6 @@ let echo "-rtlib=compiler-rt" >> $out/nix-support/cc-cflags echo "-B${targetLlvmLibraries.compiler-rt}/lib" >> $out/nix-support/cc-cflags echo "-nostdlib++" >> $out/nix-support/cc-cflags - '' + stdenv.lib.optionalString stdenv.targetPlatform.isGenode '' - echo "-I${genodeBase}/include" >> $out/nix-support/cc-cflags - echo "--sysroot=${genodeBase}" >> $out/nix-support/cc-cflags - echo "-L${genodeBase}" >> $out/nix-support/cc-cflags - echo "-noposix" >> $out/nix-support/cc-cflags '' + mkExtraBuildCommands cc; }; diff --git a/overlay/llvm-11/libc++/default.nix b/overlay/llvm-11/libc++/default.nix index 0e6f1e1..0457b0f 100644 --- a/overlay/llvm-11/libc++/default.nix +++ b/overlay/llvm-11/libc++/default.nix @@ -14,11 +14,6 @@ stdenv.mkDerivation { mv llvm-* llvm ''; - patches = - stdenv.lib.optionals stdenv.targetPlatform.isGenode [ - ./genode.patch ./genode-locale.patch - ]; - preConfigure = lib.optionalString stdenv.hostPlatform.isMusl '' patchShebangs utils/cat_files.py ''; diff --git a/overlay/llvm-11/libc++/genode.patch b/overlay/llvm-11/libc++/genode.patch deleted file mode 100644 index 8876a1b..0000000 --- a/overlay/llvm-11/libc++/genode.patch +++ /dev/null @@ -1,34 +0,0 @@ -diff --git a/include/__config b/include/__config -index 575147cead42..8f0bb7248113 100644 ---- a/include/__config -+++ b/include/__config -@@ -921,7 +921,7 @@ typedef unsigned int char32_t; - - #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) - // Most unix variants have catopen. These are the specific ones that don't. --# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) -+# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__GENODE__) - # define _LIBCPP_HAS_CATOPEN 1 - # endif - #endif -@@ -1130,6 +1130,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( - defined(__APPLE__) || \ - defined(__CloudABI__) || \ - defined(__sun__) || \ -+ defined(__GENODE__) || \ - (defined(__MINGW32__) && __has_include()) - # define _LIBCPP_HAS_THREAD_API_PTHREAD - # elif defined(__Fuchsia__) -diff --git a/utils/google-benchmark/src/internal_macros.h b/utils/google-benchmark/src/internal_macros.h -index 5dbf4fd27521..4699c5ed9139 100644 ---- a/utils/google-benchmark/src/internal_macros.h -+++ b/utils/google-benchmark/src/internal_macros.h -@@ -70,6 +70,8 @@ - #define BENCHMARK_OS_FUCHSIA 1 - #elif defined (__SVR4) && defined (__sun) - #define BENCHMARK_OS_SOLARIS 1 -+#elif defined(__GENODE__) -+ #define BENCHMARK_OS_GENODE 1 - #endif - - #if defined(__ANDROID__) && defined(__GLIBCXX__) diff --git a/overlay/llvm-11/libc++abi.nix b/overlay/llvm-11/libc++abi.nix index 093c47a..edf8319 100644 --- a/overlay/llvm-11/libc++abi.nix +++ b/overlay/llvm-11/libc++abi.nix @@ -33,8 +33,6 @@ stdenv.mkDerivation { patch -p1 -d libcxx -i ${../libcxx-0001-musl-hacks.patch} '' + stdenv.lib.optionalString stdenv.hostPlatform.isWasm '' patch -p1 -d llvm -i ${./libcxxabi-wasm.patch} - '' + stdenv.lib.optionalString stdenv.targetPlatform.isGenode '' - patch -p1 -d libcxx -i ${./libc++/genode.patch} ''; installPhase = if stdenv.isDarwin