···1+diff --git a/CMakeLists.txt b/CMakeLists.txt
2+index c5003b5efa1d..4fffb9721284 100644
3+--- a/CMakeLists.txt
4++++ b/CMakeLists.txt
5+@@ -5,6 +5,8 @@
6+7+ cmake_minimum_required(VERSION 3.13.4)
8+9++include(GNUInstallDirs)
10++
11+ # Check if compiler-rt is built as a standalone project.
12+ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR COMPILER_RT_STANDALONE_BUILD)
13+ project(CompilerRT C CXX ASM)
14+diff --git a/cmake/base-config-ix.cmake b/cmake/base-config-ix.cmake
15+index 1ada0ab30ba0..b4be6c4a3c73 100644
16+--- a/cmake/base-config-ix.cmake
17++++ b/cmake/base-config-ix.cmake
18+@@ -66,7 +66,7 @@ if (LLVM_TREE_AVAILABLE)
19+ else()
20+ # Take output dir and install path from the user.
21+ set(COMPILER_RT_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH
22+- "Path where built compiler-rt libraries should be stored.")
23++ "Path where built compiler-rt build artifacts should be stored.")
24+ set(COMPILER_RT_EXEC_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH
25+ "Path where built compiler-rt executables should be stored.")
26+ set(COMPILER_RT_INSTALL_PATH "" CACHE PATH
27+@@ -98,23 +98,23 @@ endif()
28+ if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
29+ set(COMPILER_RT_OUTPUT_LIBRARY_DIR
30+ ${COMPILER_RT_OUTPUT_DIR}/lib)
31+- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" lib)
32++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}")
33+ set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
34+ "Path where built compiler-rt libraries should be installed.")
35+ else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
36+ set(COMPILER_RT_OUTPUT_LIBRARY_DIR
37+ ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
38+- extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "lib/${COMPILER_RT_OS_DIR}")
39++ extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_LIBDIR}/${COMPILER_RT_OS_DIR}")
40+ set(COMPILER_RT_INSTALL_LIBRARY_DIR "${default_install_path}" CACHE PATH
41+ "Path where built compiler-rt libraries should be installed.")
42+ endif()
43+-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" bin)
44++extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_BINDIR}")
45+ set(COMPILER_RT_INSTALL_BINARY_DIR "${default_install_path}" CACHE PATH
46+ "Path where built compiler-rt executables should be installed.")
47+-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" include)
48++extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_INCLUDEDIR}")
49+ set(COMPILER_RT_INSTALL_INCLUDE_DIR "${default_install_path}" CACHE PATH
50+ "Path where compiler-rt headers should be installed.")
51+-extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" share)
52++extend_path(default_install_path "${COMPILER_RT_INSTALL_PATH}" "${CMAKE_INSTALL_DATADIR}")
53+ set(COMPILER_RT_INSTALL_DATA_DIR "${default_install_path}" CACHE PATH
54+ "Path where compiler-rt data files should be installed.")
55+
···1+{ lib, stdenv, llvm_meta
2+, buildLlvmTools
3+, monorepoSrc, runCommand
4+, cmake
5+, libxml2
6+, libllvm
7+, version
8+}:
9+10+stdenv.mkDerivation rec {
11+ pname = "lld";
12+ inherit version;
13+14+ # Blank llvm dir just so relative path works
15+ src = runCommand "${pname}-src-${version}" {} ''
16+ mkdir -p "$out"
17+ cp -r ${monorepoSrc}/cmake "$out"
18+ cp -r ${monorepoSrc}/${pname} "$out"
19+ mkdir -p "$out/libunwind"
20+ cp -r ${monorepoSrc}/libunwind/include "$out/libunwind"
21+ mkdir -p "$out/llvm"
22+ '';
23+24+ sourceRoot = "${src.name}/${pname}";
25+26+ patches = [
27+ ./gnu-install-dirs.patch
28+ # On Darwin the llvm-config is perhaps not working fine as the
29+ # LLVM_MAIN_SRC_DIR is not getting set correctly, and the build fails as
30+ # the include path is not correct.
31+ ./fix-root-src-dir.patch
32+ ];
33+34+ nativeBuildInputs = [ cmake ];
35+ buildInputs = [ libllvm libxml2 ];
36+37+ cmakeFlags = lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
38+ "-DLLVM_TABLEGEN_EXE=${buildLlvmTools.llvm}/bin/llvm-tblgen"
39+ ];
40+41+ outputs = [ "out" "lib" "dev" ];
42+43+ meta = llvm_meta // {
44+ homepage = "https://lld.llvm.org/";
45+ description = "The LLVM linker";
46+ longDescription = ''
47+ LLD is a linker from the LLVM project that is a drop-in replacement for
48+ system linkers and runs much faster than them. It also provides features
49+ that are useful for toolchain developers.
50+ The linker supports ELF (Unix), PE/COFF (Windows), Mach-O (macOS), and
51+ WebAssembly in descending order of completeness. Internally, LLD consists
52+ of several different linkers.
53+ '';
54+ };
55+}
···1+diff --git a/lldb/cmake/modules/LLDBConfig.cmake b/lldb/cmake/modules/LLDBConfig.cmake
2+index 37364341ff8b..7f74c1a3e257 100644
3+--- a/cmake/modules/LLDBConfig.cmake
4++++ b/cmake/modules/LLDBConfig.cmake
5+@@ -257,7 +257,7 @@ if (NOT TARGET clang-resource-headers)
6+ # Iterate over the possible places where the external resource directory
7+ # could be and pick the first that exists.
8+ foreach(CANDIDATE "${Clang_DIR}/../.." "${LLVM_DIR}" "${LLVM_LIBRARY_DIRS}"
9+- "${LLVM_BUILD_LIBRARY_DIR}"
10++ "${LLVM_BUILD_LIBRARY_DIR}" "@clangLibDir@"
11+ "${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}")
12+ # Build the resource directory path by appending 'clang/<version number>'.
13+ set(CANDIDATE_RESOURCE_DIR "${CANDIDATE}/clang/${LLDB_CLANG_RESOURCE_DIR_NAME}")