about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorMartin Nowack <m.nowack@imperial.ac.uk>2020-01-23 15:28:56 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2020-02-13 17:39:21 +0000
commit2e8d6aed747a988871b6836012301708950a74ef (patch)
tree35ac617795950d9d23672fdec50a6d78dba31d3e
parentdbda156217c532a7e1a65e8c216e593a64c0b8fc (diff)
downloadklee-2e8d6aed747a988871b6836012301708950a74ef.tar.gz
Use git repository to build LLVM
LLVM changed from svn to github. Use the github mirror to have faster build times.
Patches were updated to follow the new structure.

Patches also support building underr Ubuntu 18.04
-rw-r--r--scripts/build/p-llvm.inc37
-rw-r--r--scripts/build/patches/llvm38.patch112
-rw-r--r--scripts/build/patches/llvm39.patch76
-rw-r--r--scripts/build/patches/llvm40.patch78
-rw-r--r--scripts/build/patches/llvm50.patch21
-rw-r--r--scripts/build/patches/llvm60.patch13
-rw-r--r--scripts/build/patches/llvm70.patch13
-rw-r--r--scripts/build/patches/llvm80.patch12
-rw-r--r--scripts/build/patches/llvm90.patch12
9 files changed, 307 insertions, 67 deletions
diff --git a/scripts/build/p-llvm.inc b/scripts/build/p-llvm.inc
index d0c362c2..845f1b9d 100644
--- a/scripts/build/p-llvm.inc
+++ b/scripts/build/p-llvm.inc
@@ -93,21 +93,26 @@ download_llvm() {
   # Skip step if we already checked out code
   [[ -f "${LLVM_SRC_BASE}/.src_checked_out" ]] && return 0
 
-  # Checkout LLVM code
-  svn co "http://llvm.org/svn/llvm-project/llvm/branches/release_${LLVM_VERSION_SHORT}" "${LLVM_SRC_BASE}"
-  cd "${LLVM_SRC_BASE}/tools" || (echo "Directory does not exist"; exit 1)
-  svn co "http://llvm.org/svn/llvm-project/cfe/branches/release_${LLVM_VERSION_SHORT}" clang
-  cd "${LLVM_SRC_BASE}/projects" || (echo "Directory does not exist"; exit 1)
-  svn co "http://llvm.org/svn/llvm-project/compiler-rt/branches/release_${LLVM_VERSION_SHORT}" compiler-rt
-  cd "${LLVM_SRC_BASE}/projects" || (echo "Directory does not exist"; exit 1)
-  svn co "http://llvm.org/svn/llvm-project/libcxx/branches/release_${LLVM_VERSION_SHORT}" libcxx
-  cd "${LLVM_SRC_BASE}/projects" || (echo "Directory does not exist"; exit 1)
-  svn co "http://llvm.org/svn/llvm-project/libcxxabi/branches/release_${LLVM_VERSION_SHORT}" libcxxabi
+  source "${DIR}/common-functions"
+  local LLVM_VERSION_MAJOR="${LLVM_VERSION/.*/}"
+
+  branch_name="release/${LLVM_VERSION_MAJOR}.x"
+  if [[ "${LLVM_VERSION_MAJOR}" -le 3 ]]; then
+    branch_name="release/${LLVM_VERSION}.x"
+  fi
+  git_clone_or_update "https://github.com/llvm/llvm-project.git" "${LLVM_SRC_BASE}" "${branch_name}" || exit 1
+  if [[ "${LLVM_VERSION_MAJOR}" -le 8 ]]; then
+    # Fix the linking for older versions
+    ln -s "${LLVM_SRC_BASE}/clang" "${LLVM_SRC_BASE}/llvm/tools/"
+    ln -s "${LLVM_SRC_BASE}/compiler-rt" "${LLVM_SRC_BASE}/llvm/projects/"
+    ln -s "${LLVM_SRC_BASE}/libcxx" "${LLVM_SRC_BASE}/llvm/projects/"
+    ln -s "${LLVM_SRC_BASE}/libcxxabi" "${LLVM_SRC_BASE}/llvm/projects/"
+  fi
 
   # Apply existing patches if needed
   if [ -f "${DIR}/patches/llvm${LLVM_VERSION_SHORT}.patch" ]; then
      cd "${LLVM_SRC_BASE}" || (echo "Directory does not exist"; exit 1)
-     patch -p0 -i "${DIR}/patches/llvm${LLVM_VERSION_SHORT}.patch"
+     patch -p1 --follow-symlinks -i "${DIR}/patches/llvm${LLVM_VERSION_SHORT}.patch" || return 1
   fi
 
   touch "${LLVM_SRC_BASE}/.src_checked_out" 
@@ -124,7 +129,7 @@ build_llvm() {
        # Build uninstrumented compiler
        mkdir -p "${SANITIZER_LLVM_UNINSTRUMENTED}"
        cd "${SANITIZER_LLVM_UNINSTRUMENTED}"
-       cmake -GNinja -DCMAKE_BUILD_TYPE=Release "${LLVM_SRC_BASE}"
+       cmake -GNinja -DCMAKE_BUILD_TYPE=Release "${LLVM_SRC_BASE}/llvm"
        ninja
 
        # Build instrumented libc/libc++
@@ -134,7 +139,7 @@ build_llvm() {
         -DLLVM_USE_SANITIZER=MemoryWithOrigins \
         "${SANITIZER_CMAKE_C_COMPILER[@]}" \
         "${SANITIZER_CMAKE_CXX_COMPILER[@]}" \
-        "${LLVM_SRC_BASE}"
+        "${LLVM_SRC_BASE}/llvm"
        ninja cxx cxxabi
 
        # Build instrumented clang
@@ -154,7 +159,7 @@ build_llvm() {
           -DLLVM_ENABLE_LIBCXX=ON \
           -DCMAKE_EXE_LINKER_FLAGS="${LD_F}" \
           -DCMAKE_INSTALL_PREFIX="${LLVM_INSTALL}" \
-          "${LLVM_SRC_BASE}"
+          "${LLVM_SRC_BASE}/llvm"
       # Build clang as a dependency and install all needed packages
       ninja clang
       return 0
@@ -226,9 +231,9 @@ build_llvm() {
   fi
 
   if [[ -n "${variables[*]}" ]]; then
-    "${variables[*]}" cmake "${CONFIG[@]}" "${LLVM_SRC_BASE}"
+    "${variables[*]}" cmake "${CONFIG[@]}" "${LLVM_SRC_BASE}/llvm"
   else
-    cmake "${CONFIG[@]}" "${LLVM_SRC_BASE}"
+    cmake "${CONFIG[@]}" "${LLVM_SRC_BASE}/llvm"
   fi
 
   # Linking LLVM can require a lot of memory.
diff --git a/scripts/build/patches/llvm38.patch b/scripts/build/patches/llvm38.patch
index e6afcce9..f2de69b0 100644
--- a/scripts/build/patches/llvm38.patch
+++ b/scripts/build/patches/llvm38.patch
@@ -1,22 +1,7 @@
---- include/llvm/IR/ValueMap.h
-+++ include/llvm/IR/ValueMap.h
-@@ -99,7 +99,7 @@ public:
-   explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
-       : Map(NumInitBuckets), Data(Data) {}
- 
--  bool hasMD() const { return MDMap; }
-+  bool hasMD() const { return static_cast<bool>(MDMap); }
-   MDMapT &MD() {
-     if (!MDMap)
-       MDMap.reset(new MDMapT);
-
-
-Backport from https://reviews.llvm.org/rC330696 to include the detection of GCC
-versions without second and third component in path, such as
-"/usr/lib/gcc/x86_64-redhat-linux/8/". Support for single digit versions was
-introduced with https://reviews.llvm.org/D14727
---- tools/clang/lib/Driver/ToolChains.cpp
-+++ tools/clang/lib/Driver/ToolChains.cpp
+diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp
+index 99c7b8e6..f9a57b25 100644
+--- a/clang/lib/Driver/ToolChains.cpp
++++ b/clang/lib/Driver/ToolChains.cpp
 @@ -1241,20 +1241,31 @@ Generic_GCC::GCCVersion Linux::GCCVersion::Parse(StringRef VersionText) {
    if (First.first.getAsInteger(10, GoodVersion.Major) || GoodVersion.Major < 0)
      return BadVersion;
@@ -35,7 +20,7 @@ introduced with https://reviews.llvm.org/D14727
      return BadVersion;
 -  GoodVersion.MinorStr = Second.first.str();
 +  GoodVersion.MinorStr = MinorStr.str();
- 
+
    // First look for a number prefix and parse that if present. Otherwise just
    // stash the entire patch string in the suffix, and leave the number
    // unspecified. This covers versions strings such as:
@@ -52,4 +37,91 @@ introduced with https://reviews.llvm.org/D14727
    if (!PatchText.empty()) {
      if (size_t EndNumber = PatchText.find_first_not_of("0123456789")) {
        // Try to parse the number and any suffix.
+diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+index 70799663..b9ca8b9d 100644
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+@@ -565,8 +565,7 @@ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
+ }
+ #endif
+
+-uptr internal_sigaltstack(const struct sigaltstack *ss,
+-                         struct sigaltstack *oss) {
++uptr internal_sigaltstack(const void *ss, void *oss) {
+   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
+ }
+
+diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
+index 77bfbd15..5572793e 100644
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
+@@ -21,7 +21,6 @@
+ #include "sanitizer_platform_limits_posix.h"
 
+ struct link_map;  // Opaque type returned by dlopen().
+-struct sigaltstack;
+
+ namespace __sanitizer {
+ // Dirent structure for getdents(). Note that this structure is different from
+@@ -30,8 +29,7 @@ struct linux_dirent;
+
+ // Syscall wrappers.
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
+-uptr internal_sigaltstack(const struct sigaltstack* ss,
+-                          struct sigaltstack* oss);
++uptr internal_sigaltstack(const void* ss, void* oss);
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset);
+ void internal_sigfillset(__sanitizer_sigset_t *set);
+diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+index d1e2f6ac..2df7be58 100644
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+@@ -272,7 +272,7 @@ static int TracerThread(void* argument) {
+
+   // Alternate stack for signal handling.
+   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+-  struct sigaltstack handler_stack;
++  stack_t handler_stack;
+   internal_memset(&handler_stack, 0, sizeof(handler_stack));
+   handler_stack.ss_sp = handler_stack_memory.data();
+   handler_stack.ss_size = kHandlerStackSize;
+diff --git a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
+index 66025611..98a5b135 100644
+--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
++++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
+@@ -311,7 +311,7 @@ bool IsGlobalVar(uptr addr) {
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
+diff --git a/libcxx/include/__locale b/libcxx/include/__locale
+index 7bc701dd..ae0372fe 100644
+--- a/libcxx/include/__locale
++++ b/libcxx/include/__locale
+@@ -34,7 +34,7 @@
+ # include <support/solaris/xlocale.h>
+ #elif defined(_NEWLIB_VERSION)
+ # include <support/newlib/xlocale.h>
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+ #elif defined(_LIBCPP_HAS_MUSL_LIBC)
+diff --git a/llvm/include/llvm/IR/ValueMap.h b/llvm/include/llvm/IR/ValueMap.h
+index ad518ac0..d928f6a2 100644
+--- a/llvm/include/llvm/IR/ValueMap.h
++++ b/llvm/include/llvm/IR/ValueMap.h
+@@ -99,7 +99,7 @@ public:
+   explicit ValueMap(const ExtraData &Data, unsigned NumInitBuckets = 64)
+       : Map(NumInitBuckets), Data(Data) {}
+
+-  bool hasMD() const { return MDMap; }
++  bool hasMD() const { return static_cast<bool>(MDMap); }
+   MDMapT &MD() {
+     if (!MDMap)
+       MDMap.reset(new MDMapT);
\ No newline at end of file
diff --git a/scripts/build/patches/llvm39.patch b/scripts/build/patches/llvm39.patch
new file mode 100644
index 00000000..da2be4cd
--- /dev/null
+++ b/scripts/build/patches/llvm39.patch
@@ -0,0 +1,76 @@
+--- a/compiler-rt/lib/esan/esan_sideline_linux.cpp
++++ b/compiler-rt/lib/esan/esan_sideline_linux.cpp
+@@ -70,7 +70,7 @@ int SidelineThread::runSideline(void *Arg) {
+
+   // Set up a signal handler on an alternate stack for safety.
+   InternalScopedBuffer<char> StackMap(SigAltStackSize);
+-  struct sigaltstack SigAltStack;
++  stack_t SigAltStack;
+   SigAltStack.ss_sp = StackMap.data();
+   SigAltStack.ss_size = SigAltStackSize;
+   SigAltStack.ss_flags = 0;
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+@@ -607,8 +607,7 @@ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
+ }
+ #endif
+
+-uptr internal_sigaltstack(const struct sigaltstack *ss,
+-                         struct sigaltstack *oss) {
++uptr internal_sigaltstack(const void *ss, void *oss) {
+   return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
+ }
+
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
+@@ -21,7 +21,6 @@
+ #include "sanitizer_platform_limits_posix.h"
+
+ struct link_map;  // Opaque type returned by dlopen().
+-struct sigaltstack;
+
+ namespace __sanitizer {
+ // Dirent structure for getdents(). Note that this structure is different from
+@@ -30,8 +29,7 @@ struct linux_dirent;
+
+ // Syscall wrappers.
+ uptr internal_getdents(fd_t fd, struct linux_dirent *dirp, unsigned int count);
+-uptr internal_sigaltstack(const struct sigaltstack* ss,
+-                          struct sigaltstack* oss);
++uptr internal_sigaltstack(const void* ss, void* oss);
+ uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
+     __sanitizer_sigset_t *oldset);
+
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+@@ -273,7 +273,7 @@ static int TracerThread(void* argument) {
+
+   // Alternate stack for signal handling.
+   InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
+-  struct sigaltstack handler_stack;
++  stack_t handler_stack;
+   internal_memset(&handler_stack, 0, sizeof(handler_stack));
+   handler_stack.ss_sp = handler_stack_memory.data();
+   handler_stack.ss_size = kHandlerStackSize;
+--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
++++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
+@@ -282,7 +282,7 @@ void InitializePlatform() {
+ int ExtractResolvFDs(void *state, int *fds, int nfd) {
+ #if SANITIZER_LINUX && !SANITIZER_ANDROID
+   int cnt = 0;
+-  __res_state *statp = (__res_state*)state;
++  struct __res_state *statp = (struct __res_state*)state;
+   for (int i = 0; i < MAXNS && cnt < nfd; i++) {
+     if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
+       fds[cnt++] = statp->_u._ext.nssocks[i];
+--- a/libcxx/include/__locale
++++ b/libcxx/include/__locale
+@@ -34,7 +34,7 @@
+ # include <support/solaris/xlocale.h>
+ #elif defined(_NEWLIB_VERSION)
+ # include <support/newlib/xlocale.h>
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+ #elif defined(_LIBCPP_HAS_MUSL_LIBC)
\ No newline at end of file
diff --git a/scripts/build/patches/llvm40.patch b/scripts/build/patches/llvm40.patch
index 0f39a499..8e8481dd 100644
--- a/scripts/build/patches/llvm40.patch
+++ b/scripts/build/patches/llvm40.patch
@@ -1,6 +1,17 @@
---- projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
-+++ projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
-@@ -607,8 +607,7 @@ uptr internal_prctl(int option, uptr arg
+--- a/compiler-rt/lib/esan/esan_sideline_linux.cpp
++++ b/compiler-rt/lib/esan/esan_sideline_linux.cpp
+@@ -70,7 +70,7 @@ int SidelineThread::runSideline(void *Arg) {
+
+   // Set up a signal handler on an alternate stack for safety.
+   InternalScopedBuffer<char> StackMap(SigAltStackSize);
+-  struct sigaltstack SigAltStack;
++  stack_t SigAltStack;
+   SigAltStack.ss_sp = StackMap.data();
+   SigAltStack.ss_size = SigAltStackSize;
+   SigAltStack.ss_flags = 0;
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cc
+@@ -607,8 +607,7 @@ uptr internal_prctl(int option, uptr arg2, uptr arg3, uptr arg4, uptr arg5) {
  }
  #endif
 
@@ -10,8 +21,8 @@
    return internal_syscall(SYSCALL(sigaltstack), (uptr)ss, (uptr)oss);
  }
 
---- projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
-+++ projects/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
 @@ -21,7 +21,6 @@
  #include "sanitizer_platform_limits_posix.h"
 
@@ -30,9 +41,9 @@
  uptr internal_sigprocmask(int how, __sanitizer_sigset_t *set,
      __sanitizer_sigset_t *oldset);
 
---- projects/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
-+++ projects/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
-@@ -275,7 +275,7 @@ static int TracerThread(void* argument)
+--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
++++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
+@@ -275,7 +275,7 @@ static int TracerThread(void* argument) {
 
    // Alternate stack for signal handling.
    InternalScopedBuffer<char> handler_stack_memory(kHandlerStackSize);
@@ -41,8 +52,8 @@
    internal_memset(&handler_stack, 0, sizeof(handler_stack));
    handler_stack.ss_sp = handler_stack_memory.data();
    handler_stack.ss_size = kHandlerStackSize;
---- projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
-+++ projects/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
+--- a/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
++++ b/compiler-rt/lib/tsan/rtl/tsan_platform_linux.cc
 @@ -289,7 +289,7 @@ void InitializePlatform() {
  int ExtractResolvFDs(void *state, int *fds, int nfd) {
  #if SANITIZER_LINUX && !SANITIZER_ANDROID
@@ -52,8 +63,8 @@
    for (int i = 0; i < MAXNS && cnt < nfd; i++) {
      if (statp->_u._ext.nsaddrs[i] && statp->_u._ext.nssocks[i] != -1)
        fds[cnt++] = statp->_u._ext.nssocks[i];
---- projects/libcxx/include/__locale
-+++ projects/libcxx/include/__locale
+--- a/libcxx/include/__locale
++++ b/libcxx/include/__locale
 @@ -34,7 +34,7 @@
  # include <support/solaris/xlocale.h>
  #elif defined(_NEWLIB_VERSION)
@@ -63,25 +74,38 @@
      || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
  # include <xlocale.h>
  #elif defined(_LIBCPP_HAS_MUSL_LIBC)
---- projects/compiler-rt/lib/esan/esan_sideline_linux.cpp
-+++ projects/compiler-rt/lib/esan/esan_sideline_linux.cpp
-@@ -70,7 +70,7 @@ int SidelineThread::runSideline(void *Ar
-
-   // Set up a signal handler on an alternate stack for safety.
-   InternalScopedBuffer<char> StackMap(SigAltStackSize);
--  struct sigaltstack SigAltStack;
-+  stack_t SigAltStack;
-   SigAltStack.ss_sp = StackMap.data();
-   SigAltStack.ss_size = SigAltStackSize;
-   SigAltStack.ss_flags = 0;
---- include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
-+++ include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
+--- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
++++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
 @@ -687,7 +687,7 @@ private:
- 
+
    uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
- 
+
 -  Expected<std::vector<char>> readMem(char *Dst, JITTargetAddress Src,
 +  Expected<std::vector<unsigned char>> readMem(char *Dst, JITTargetAddress Src,
                                        uint64_t Size) {
      // Check for an 'out-of-band' error, e.g. from an MM destructor.
      if (ExistingError)
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -35,8 +35,9 @@ if(LLVM_DYLIB_EXPORTED_SYMBOL_FILE)
+ endif()
+
+ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
+-
++if(LIB_NAMES)
+ list(REMOVE_DUPLICATES LIB_NAMES)
++endif()
+ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR MINGW) # FIXME: It should be "GNU ld for elf"
+   # GNU ld doesn't resolve symbols in the version script.
+   set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
+--- a/libcxx/include/__locale
++++ b/libcxx/include/__locale
+@@ -34,7 +34,7 @@
+ # include <support/solaris/xlocale.h>
+ #elif defined(_NEWLIB_VERSION)
+ # include <support/newlib/xlocale.h>
+-#elif (defined(__GLIBC__) || defined(__APPLE__)      || defined(__FreeBSD__) \
++#elif (defined(__APPLE__)      || defined(__FreeBSD__) \
+     || defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
+ # include <xlocale.h>
+ #elif defined(_LIBCPP_HAS_MUSL_LIBC)
\ No newline at end of file
diff --git a/scripts/build/patches/llvm50.patch b/scripts/build/patches/llvm50.patch
index f10a47c7..d6ce652b 100644
--- a/scripts/build/patches/llvm50.patch
+++ b/scripts/build/patches/llvm50.patch
@@ -1,11 +1,24 @@
---- include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
-+++ include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
+--- a/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
++++ b/llvm/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h
 @@ -713,7 +713,7 @@ private:
- 
+
    uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
- 
+
 -  Expected<std::vector<char>> readMem(char *Dst, JITTargetAddress Src,
 +  Expected<std::vector<unsigned char>> readMem(char *Dst, JITTargetAddress Src,
                                        uint64_t Size) {
      // Check for an 'out-of-band' error, e.g. from an MM destructor.
      if (ExistingError)
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -36,7 +36,10 @@ endif()
+
+ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
+
++if(LIB_NAMES)
+ list(REMOVE_DUPLICATES LIB_NAMES)
++endif()
++
+ if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU) OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD") OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")) # FIXME: It should be "GNU ld for elf"
+   configure_file(
+   ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
diff --git a/scripts/build/patches/llvm60.patch b/scripts/build/patches/llvm60.patch
new file mode 100644
index 00000000..6a9f7eb7
--- /dev/null
+++ b/scripts/build/patches/llvm60.patch
@@ -0,0 +1,13 @@
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -36,7 +36,10 @@ endif()
+
+ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
+
++if(LIB_NAMES)
+ list(REMOVE_DUPLICATES LIB_NAMES)
++endif()
++
+ if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
+    OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
+    OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
\ No newline at end of file
diff --git a/scripts/build/patches/llvm70.patch b/scripts/build/patches/llvm70.patch
new file mode 100644
index 00000000..bb6462b7
--- /dev/null
+++ b/scripts/build/patches/llvm70.patch
@@ -0,0 +1,13 @@
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -36,7 +36,10 @@ endif()
+
+ add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
+
++if(LIB_NAMES)
+ list(REMOVE_DUPLICATES LIB_NAMES)
++endif()
++
+ if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
+    OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
+    OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
\ No newline at end of file
diff --git a/scripts/build/patches/llvm80.patch b/scripts/build/patches/llvm80.patch
new file mode 100644
index 00000000..dcc9f78c
--- /dev/null
+++ b/scripts/build/patches/llvm80.patch
@@ -0,0 +1,12 @@
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -41,7 +41,9 @@ if(LLVM_BUILD_LLVM_DYLIB)
+
+   add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
+
++  if(LIB_NAMES)
+   list(REMOVE_DUPLICATES LIB_NAMES)
++  endif()
+   if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
+      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
+      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
\ No newline at end of file
diff --git a/scripts/build/patches/llvm90.patch b/scripts/build/patches/llvm90.patch
new file mode 100644
index 00000000..dcc9f78c
--- /dev/null
+++ b/scripts/build/patches/llvm90.patch
@@ -0,0 +1,12 @@
+--- a/llvm/tools/llvm-shlib/CMakeLists.txt
++++ b/llvm/tools/llvm-shlib/CMakeLists.txt
+@@ -41,7 +41,9 @@ if(LLVM_BUILD_LLVM_DYLIB)
+
+   add_llvm_library(LLVM SHARED DISABLE_LLVM_LINK_LLVM_DYLIB SONAME ${SOURCES})
+
++  if(LIB_NAMES)
+   list(REMOVE_DUPLICATES LIB_NAMES)
++  endif()
+   if(("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") OR (MINGW) OR (HAIKU)
+      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
+      OR ("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
\ No newline at end of file