···11+diff --git a/CMakeLists.txt b/CMakeLists.txt
22+index c5003b5efa1d..4fffb9721284 100644
33+--- a/CMakeLists.txt
44++++ b/CMakeLists.txt
55+@@ -5,6 +5,8 @@
66+77+ cmake_minimum_required(VERSION 3.13.4)
88+99++include(GNUInstallDirs)
1010++
1111+ # Check if compiler-rt is built as a standalone project.
1212+ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
1313+ project(CompilerRT C CXX ASM)
1414+diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake
1515+index 1ada0ab30ba0..b4be6c4a3c73 100644
1616+--- a/cmake/base-config-ix.cmake
1717++++ b/cmake/base-config-ix.cmake
1818+@@ -66,7 +66,7 @@ if (LLVM_TREE_AVAILABLE)
1919+ else()
2020+ # Take output dir and install path from the user.
2121+ set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
2222+- "Path where built compiler-rt libraries should be stored.")
2323++ "Path where built compiler-rt build artifacts should be stored.")
2424+ set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
2525+ "Path where built compiler-rt executables should be stored.")
2626+ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
2727+@@ -98,23 +98,23 @@ endif()
2828+ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
2929+ set(COMPILER_RT_OUTPUT_LIBRARY_DIR
3030+ ${COMPILER_RT_OUTPUT_DIR}/lib)
3131+- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib)
3232++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}")
3333+ set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
3434+ "Path where built compiler-rt libraries should be installed.")
3535+ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
3636+ set(COMPILER_RT_OUTPUT_LIBRARY_DIR
3737+ ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
3838+- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}")
3939++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}")
4040+ set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
4141+ "Path where built compiler-rt libraries should be installed.")
4242+ endif()
4343+-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" bin)
4444++extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_BINDIR}")
4545+ set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH
4646+ "Path where built compiler-rt executables should be installed.")
4747+-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" include)
4848++extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_INCLUDEDIR}")
4949+ set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH
5050+ "Path where compiler-rt headers should be installed.")
5151+-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" share)
5252++extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_DATADIR}")
5353+ set(COMPILER_RT_INSTALL_DATA_DIR "${default_install_path}" CACHE PATH
5454+ "Path where compiler-rt data files should be installed.")
5555+
···11+{ lib, stdenv, llvm_meta
22+, buildLlvmTools
33+, monorepoSrc, runCommand
44+, cmake
55+, libxml2
66+, libllvm
77+, version
88+}:
99+1010+stdenv.mkDerivation rec {
1111+ pname = "lld";
1212+ inherit version;
1313+1414+ # Blank llvm dir just so relative path works
1515+ src = runCommand "${pname}-src-${version}" {} ''
1616+ mkdir -p "$out"
1717+ cp -r ${monorepoSrc}/cmake "$out"
1818+ cp -r ${monorepoSrc}/${pname} "$out"
1919+ mkdir -p "$out/libunwind"
2020+ cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
2121+ mkdir -p "$out/llvm"
2222+ '';
2323+2424+ sourceRoot = "${src.name}/${pname}";
2525+2626+ patches = [
2727+ ./gnu-install-dirs.patch
2828+ # On Darwin the llvm-config is perhaps not working fine as the
2929+ # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as
3030+ # the include path is not correct.
3131+ ./fix-root-src-dir.patch
3232+ ];
3333+3434+ nativeBuildInputs = [ cmake ];
3535+ buildInputs = [ libllvm libxml2 ];
3636+3737+ cmakeFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
3838+ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
3939+ ];
4040+4141+ outputs = [ "out" "lib" "dev" ];
4242+4343+ meta = llvm_meta // {
4444+ homepage = "https://lld.llvm.org/";
4545+ description = "The LLVM linker";
4646+ longDescription = ''
4747+ LLD is a linker from the LLVM project that is a drop-in replacement for
4848+ system linkers and runs much faster than them. It also provides features
4949+ that are useful for toolchain developers.
5050+ The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
5151+ WebAssembly in descending order of completeness. Internally, LLD consists
5252+ of several different linkers.
5353+ '';
5454+ };
5555+}
···11+diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
22+index 37364341ff8b..7f74c1a3e257 100644
33+--- a/cmake/modules/LLDBConfig.cmake
44++++ b/cmake/modules/LLDBConfig.cmake
55+@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers)
66+ # Iterate over the possible places where the external resource directory
77+ # could be and pick the first that exists.
88+ foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}"
99+- "${LLVM_BUILD_LIBRARY_DIR}"
1010++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@"
1111+ "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
1212+ # Build the resource directory path by appending 'clang/<version number>'.
1313+ set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}")