diff --git a/build-scripts/llvm12.build b/build-scripts/llvm12.build new file mode 100644 index 0000000..5c6a1d5 --- /dev/null +++ b/build-scripts/llvm12.build @@ -0,0 +1,161 @@ +#! /bin/bash + +# LLVM 12.0.0 +# Source: https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/llvm-12.0.0.src.tar.xz +# Source: https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/clang-12.0.0.src.tar.xz +# Source: https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/compiler-rt-12.0.0.src.tar.xz +# Source: https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/lld-12.0.0.src.tar.xz +# +# $BUILD = Directory to temporarily install +# $PKGS = Directory to store built packages +# +# DEPS +# Required: CMake +# Recommended: NONE +# Optional: Doxygen, git, Graphviz, libxml2, Python2, rsync(for tests), +# Optional: texlive-20200406 (or install-tl-unx), Valgrind, PyYAML, +# Optional: Zip, OCaml, psutil, recommonmark, Sphinx, and Z3 + +# Unpack the sources: +cd projects && \ +tar xf ../../pkgs/compiler-rt-12.0.0.src.tar.xz && \ +mv compiler-rt-12.0.0.src compiler-rt && \ +cd - && \ +cd tools && \ +tar xf ../../pkgs/clang-12.0.0.src.tar.xz && \ +mv clang-12.0.0.src clang && \ +tar xf ../../pkgs/lld-12.0.0.src.tar.xz && \ +mv lld-12.0.0.src lld && \ +cd - + +# Apply patches from Void Linux +cd projects/compiler-rt +patch -Np1 -i ../../../patches/llvm12-compiler-rt-void/compiler-rt-aarch64-ucontext.patch && \ +patch -Np1 -i ../../../patches/llvm12-compiler-rt-void/compiler-rt-sanitizer-ppc64-musl.patch && \ +patch -Np1 -i ../../../patches/llvm12-compiler-rt-void/compiler-rt-size_t.patch && \ +patch -Np1 -i ../../../patches/llvm12-compiler-rt-void/compiler-rt-xray-ppc64-musl.patch && \ +cd - +cd tools/clang +patch -Np1 -i ../../../patches/llvm12-clang-void/clang-001-fix-unwind-chain-inclusion.patch && \ +patch -Np1 -i ../../../patches/llvm12-clang-void/clang-002-add-musl-triples.patch && \ +patch -Np1 -i ../../../patches/llvm12-clang-void/clang-003-ppc64-dynamic-linker-path.patch && \ +patch -Np1 -i ../../../patches/llvm12-clang-void/clang-004-ppc64-musl-elfv2.patch && \ +cd - +patch -Np1 -i ../patches/llvm12-void/llvm-001-musl.patch && \ +patch -Np1 -i ../patches/llvm12-void/llvm-002-musl-ppc64-elfv2.patch && \ +patch -Np1 -i ../patches/llvm12-void/llvm-003-ppc-secureplt.patch && \ +patch -Np1 -i ../patches/llvm12-void/llvm-004-override-opt.patch && \ +patch -Np1 -i ../patches/llvm12-void/llvm-005-ppc-bigpic.patch && \ +patch -Np1 -i ../patches/llvm12-void/llvm-006-aarch64-mf_exec.patch + +# Disable sanitizers for musl-based systems +sed -i 's/set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)/set(COMPILER_RT_HAS_SANITIZER_COMMON FALSE)/' projects/compiler-rt/cmake/config-ix.cmake && + +# Update host/target triple detection +cp -v ../files/config.guess-musl cmake/config.guess + +# Fix missing header for lld, https://bugs.llvm.org/show_bug.cgi?id=49228 +mkdir -pv tools/lld/include/mach-o +cp -v ../files/libunwind-llvm12/compact_unwind_encoding.h tools/lld/include/mach-o + +# some sanitizer currently only on x86_64 stuff needs backtrace +#sed -i 's,# Set common link flags.,list(APPEND SANITIZER_COMMON_LINK_LIBS execinfo),' \ +# projects/compiler-rt/CMakeLists.txt + +# Vastly reduce size of debugging symbols: +export CFLAGS=" -g -g1" +export CXXFLAGS=" -g -g1" + +# If building with binutils in /opt/gnu instead of /usr (CMLFS): +export CFLAGS="$CFLAGS -I/opt/gnu/include" +export CXXFLAGS="$CXXFLAGS -I/opt/gnu/include" + +case $(uname -m) in + i686*) export BARCH="X86" + export B_TARGETS="AMDGPU" + export B_TRUPLE="i686-unknown-linux-musl" + ;; + x86_64*) export BARCH="X86" + export B_TARGETS="AMDGPU" + export B_TRUPLE="x86_64-unknown-linux-musl" + ;; + armv5*) export BARCH="Armv5te" + export B_TARGETS="ARM" + export B_TRUPLE="armv5l-unknown-linux-musleabi" + ;; + armv6*) export BARCH="Armv6" + export B_TARGETS="ARM" + export B_TRUPLE="armv6l-unknown-linux-musleabi" + ;; + armv7*) export BARCH="Armv7" + export B_TARGETS="ARM" + export B_TRUPLE="armv7l-unknown-linux-musleabihf" + ;; + aarch64*) export BARCH="AArch64" + export B_TARGETS="ARM;AArch64" + export B_TRUPLE="aarch64-unknown-linux-musleabihf" + ;; +esac + + +mkdir -v build && +cd build && + +CC=gcc CXX=g++ \ +cmake -DCMAKE_INSTALL_PREFIX=/usr \ + -DLLVM_ENABLE_FFI=ON \ + -DCMAKE_BUILD_TYPE=Release \ + -DLLVM_BUILD_LLVM_DYLIB=ON \ + -DLLVM_LINK_LLVM_DYLIB=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_BUILD_TESTS=ON \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_BINUTILS_INCDIR="/usr/include" \ + -DLLVM_TARGET_ARCH=${BARCH} \ + -DLLVM_TARGETS_TO_BUILD="host;BPF;${B_TARGETS}" \ + -DLLVM_HOST_TRIPLE="${B_TRUPLE}" \ + -DLLVM_DEFAULT_TARGET_TRIPLE="${B_TRUPLE}" \ + -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE="${B_TRUPLE}" \ + -Wno-dev -G Ninja .. + +unset CFLAGS CXXFLAGS BARCH B_TARGETS + +read -p "Compile?" && time { ninja -j2 ; } && + +read -p "Press Enter to install" && +# if not using a package manager: +# ninja install +# OR +# cmake -DCMAKE_INSTALL_PREFIX=/usr -P cmake_install.cmake + +# if using pkgtools from Slackware, then: +sudo -S cmake -DCMAKE_INSTALL_PREFIX=${BUILD}/usr -P cmake_install.cmake + +read -p "Press Enter to create pakage description." +cd $BUILD && sudo mkdir -v install && +cat > /tmp/slack-desc << "EOF" +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. Line +# up the first '|' above the ':' following the base package name, and the '|' +# on the right side marks the last column you can put a character in. You must +# make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + + |-----handy-ruler------------------------------------------------------| +llvm: llvm (LLVM compiler toolkit) +llvm: +llvm: Low Level Virtual Machine is a toolkit for the construction of highly +llvm: optimized compilers, optimizers, and runtime environments. +llvm: +llvm: This package also includes the clang frontend for the C family of +llvm: languages: C, C++, Objective-C, and Objective-C++ +llvm: +llvm: +llvm: Homepage: http://llvm.org/ +llvm: +EOF +sudo mv /tmp/slack-desc install/ && + +read -p "Enter to build and install package" && +sudo makepkg -l y -c n $PKGS/llvm-12.0.0-$(uname -m)-mlfs.txz && +sudo rm -rf $BUILD/* diff --git a/patches/llvm12-clang-void/clang-001-fix-unwind-chain-inclusion.patch b/patches/llvm12-clang-void/clang-001-fix-unwind-chain-inclusion.patch new file mode 100644 index 0000000..04244bc --- /dev/null +++ b/patches/llvm12-clang-void/clang-001-fix-unwind-chain-inclusion.patch @@ -0,0 +1,44 @@ +From 352974169f0d2b5da3d5321f588f5e3b5941330e Mon Sep 17 00:00:00 2001 +From: Andrea Brancaleoni +Date: Tue, 8 Sep 2015 22:14:57 +0200 +Subject: [PATCH 2/7] fix unwind chain inclusion + +--- + lib/Headers/unwind.h | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/lib/Headers/unwind.h b/lib/Headers/unwind.h +index 303d792..44e10cc 100644 +--- a/lib/Headers/unwind.h ++++ b/lib/Headers/unwind.h +@@ -9,9 +9,6 @@ + + /* See "Data Definitions for libgcc_s" in the Linux Standard Base.*/ + +-#ifndef __CLANG_UNWIND_H +-#define __CLANG_UNWIND_H +- + #if defined(__APPLE__) && __has_include_next() + /* Darwin (from 11.x on) provide an unwind.h. If that's available, + * use it. libunwind wraps some of its definitions in #ifdef _GNU_SOURCE, +@@ -39,6 +36,9 @@ + # endif + #else + ++#ifndef __CLANG_UNWIND_H ++#define __CLANG_UNWIND_H ++ + #include + + #ifdef __cplusplus +@@ -322,6 +322,7 @@ _Unwind_Ptr _Unwind_GetTextRelBase(struct _Unwind_Context *); + } + #endif + ++#endif /* __CLANG_UNWIND_H */ ++ + #endif + +-#endif /* __CLANG_UNWIND_H */ +-- +2.5.1 diff --git a/patches/llvm12-clang-void/clang-002-add-musl-triples.patch b/patches/llvm12-clang-void/clang-002-add-musl-triples.patch new file mode 100644 index 0000000..6945e7f --- /dev/null +++ b/patches/llvm12-clang-void/clang-002-add-musl-triples.patch @@ -0,0 +1,110 @@ +--- a/lib/Driver/ToolChains/Gnu.cpp ++++ b/lib/Driver/ToolChains/Gnu.cpp +@@ -2086,7 +2086,8 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( + static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf", + "armv7hl-redhat-linux-gnueabi", + "armv6hl-suse-linux-gnueabi", +- "armv7hl-suse-linux-gnueabi"}; ++ "armv7hl-suse-linux-gnueabi", ++ "armv7l-linux-gnueabihf"}; + static const char *const ARMebLibDirs[] = {"/lib"}; + static const char *const ARMebTriples[] = {"armeb-linux-gnueabi", + "armeb-linux-androideabi"}; +@@ -2153,8 +2154,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( + "powerpc64-suse-linux", "powerpc-montavista-linuxspe"}; + static const char *const PPCLELibDirs[] = {"/lib32", "/lib"}; + static const char *const PPCLETriples[] = {"powerpcle-linux-gnu", +- "powerpcle-unknown-linux-gnu", +- "powerpcle-linux-musl"}; ++ "powerpcle-unknown-linux-gnu"}; + + static const char *const PPC64LibDirs[] = {"/lib64", "/lib"}; + static const char *const PPC64Triples[] = { +@@ -2235,6 +2235,87 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( + return; + } + ++ if (TargetTriple.isMusl()) { ++ static const char *const AArch64MuslTriples[] = {"aarch64-linux-musl"}; ++ static const char *const ARMHFMuslTriples[] = { ++ "arm-linux-musleabihf", "armv7l-linux-musleabihf" ++ }; ++ static const char *const ARMMuslTriples[] = {"arm-linux-musleabi"}; ++ static const char *const X86_64MuslTriples[] = {"x86_64-linux-musl"}; ++ static const char *const X86MuslTriples[] = {"i686-linux-musl"}; ++ static const char *const MIPSMuslTriples[] = { ++ "mips-linux-musl", "mipsel-linux-musl", ++ "mipsel-linux-muslhf", "mips-linux-muslhf" ++ }; ++ static const char *const PPCMuslTriples[] = {"powerpc-linux-musl"}; ++ static const char *const PPCLEMuslTriples[] = {"powerpcle-linux-musl"}; ++ static const char *const PPC64MuslTriples[] = {"powerpc64-linux-musl"}; ++ static const char *const PPC64LEMuslTriples[] = {"powerpc64le-linux-musl"}; ++ ++ switch (TargetTriple.getArch()) { ++ case llvm::Triple::aarch64: ++ LibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); ++ TripleAliases.append(begin(AArch64MuslTriples), end(AArch64MuslTriples)); ++ BiarchLibDirs.append(begin(AArch64LibDirs), end(AArch64LibDirs)); ++ BiarchTripleAliases.append(begin(AArch64MuslTriples), end(AArch64MuslTriples)); ++ break; ++ case llvm::Triple::arm: ++ LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs)); ++ if (TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF) { ++ TripleAliases.append(begin(ARMHFMuslTriples), end(ARMHFMuslTriples)); ++ } else { ++ TripleAliases.append(begin(ARMMuslTriples), end(ARMMuslTriples)); ++ } ++ break; ++ case llvm::Triple::x86_64: ++ LibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); ++ TripleAliases.append(begin(X86_64MuslTriples), end(X86_64MuslTriples)); ++ BiarchLibDirs.append(begin(X86LibDirs), end(X86LibDirs)); ++ BiarchTripleAliases.append(begin(X86MuslTriples), end(X86MuslTriples)); ++ break; ++ case llvm::Triple::x86: ++ LibDirs.append(begin(X86LibDirs), end(X86LibDirs)); ++ TripleAliases.append(begin(X86MuslTriples), end(X86MuslTriples)); ++ BiarchLibDirs.append(begin(X86_64LibDirs), end(X86_64LibDirs)); ++ BiarchTripleAliases.append(begin(X86_64MuslTriples), end(X86_64MuslTriples)); ++ break; ++ case llvm::Triple::mips: ++ LibDirs.append(begin(MIPSLibDirs), end(MIPSLibDirs)); ++ TripleAliases.append(begin(MIPSMuslTriples), end(MIPSMuslTriples)); ++ break; ++ case llvm::Triple::ppc: ++ LibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); ++ TripleAliases.append(begin(PPCMuslTriples), end(PPCMuslTriples)); ++ BiarchLibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); ++ BiarchTripleAliases.append(begin(PPC64MuslTriples), end(PPC64MuslTriples)); ++ break; ++ case llvm::Triple::ppcle: ++ LibDirs.append(begin(PPCLELibDirs), end(PPCLELibDirs)); ++ TripleAliases.append(begin(PPCLEMuslTriples), end(PPCLEMuslTriples)); ++ BiarchLibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); ++ BiarchTripleAliases.append(begin(PPC64LEMuslTriples), end(PPC64LEMuslTriples)); ++ break; ++ case llvm::Triple::ppc64: ++ LibDirs.append(begin(PPC64LibDirs), end(PPC64LibDirs)); ++ TripleAliases.append(begin(PPC64MuslTriples), end(PPC64MuslTriples)); ++ BiarchLibDirs.append(begin(PPCLibDirs), end(PPCLibDirs)); ++ BiarchTripleAliases.append(begin(PPCMuslTriples), end(PPCMuslTriples)); ++ break; ++ case llvm::Triple::ppc64le: ++ LibDirs.append(begin(PPC64LELibDirs), end(PPC64LELibDirs)); ++ TripleAliases.append(begin(PPC64LEMuslTriples), end(PPC64LEMuslTriples)); ++ BiarchLibDirs.append(begin(PPCLELibDirs), end(PPCLELibDirs)); ++ BiarchTripleAliases.append(begin(PPCLEMuslTriples), end(PPCLEMuslTriples)); ++ break; ++ default: ++ break; ++ } ++ TripleAliases.push_back(TargetTriple.str()); ++ if (TargetTriple.str() != BiarchTriple.str()) ++ BiarchTripleAliases.push_back(BiarchTriple.str()); ++ return; ++ } ++ + // Android targets should not use GNU/Linux tools or libraries. + if (TargetTriple.isAndroid()) { + static const char *const AArch64AndroidTriples[] = { diff --git a/patches/llvm12-clang-void/clang-003-ppc64-dynamic-linker-path.patch b/patches/llvm12-clang-void/clang-003-ppc64-dynamic-linker-path.patch new file mode 100644 index 0000000..afc0810 --- /dev/null +++ b/patches/llvm12-clang-void/clang-003-ppc64-dynamic-linker-path.patch @@ -0,0 +1,13 @@ +--- a/lib/Driver/ToolChains/Linux.cpp ++++ b/lib/Driver/ToolChains/Linux.cpp +@@ -504,10 +504,6 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const { + Loader = "ld.so.1"; + break; + case llvm::Triple::ppc64: +- LibDir = "lib64"; +- Loader = +- (tools::ppc::hasPPCAbiArg(Args, "elfv2")) ? "ld64.so.2" : "ld64.so.1"; +- break; + case llvm::Triple::ppc64le: + LibDir = "lib64"; + Loader = diff --git a/patches/llvm12-clang-void/clang-004-ppc64-musl-elfv2.patch b/patches/llvm12-clang-void/clang-004-ppc64-musl-elfv2.patch new file mode 100644 index 0000000..912094e --- /dev/null +++ b/patches/llvm12-clang-void/clang-004-ppc64-musl-elfv2.patch @@ -0,0 +1,48 @@ +--- a/lib/Basic/Targets/PPC.h ++++ b/lib/Basic/Targets/PPC.h +@@ -415,11 +415,10 @@ public: + LongDoubleFormat = &llvm::APFloat::IEEEdouble(); + } else if ((Triple.getArch() == llvm::Triple::ppc64le)) { + DataLayout = "e-m:e-i64:64-n32:64"; +- ABI = "elfv2"; + } else { + DataLayout = "E-m:e-i64:64-n32:64"; +- ABI = "elfv1"; + } ++ ABI = "elfv2"; + + if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() || Triple.isMusl()) { + LongDoubleWidth = LongDoubleAlign = 64; +--- a/lib/CodeGen/TargetInfo.cpp ++++ b/lib/CodeGen/TargetInfo.cpp +@@ -10927,9 +10927,9 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { + return SetCGInfo(new AIXTargetCodeGenInfo(Types, /*Is64Bit*/ true)); + + if (Triple.isOSBinFormatELF()) { +- PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv1; +- if (getTarget().getABI() == "elfv2") +- Kind = PPC64_SVR4_ABIInfo::ELFv2; ++ PPC64_SVR4_ABIInfo::ABIKind Kind = PPC64_SVR4_ABIInfo::ELFv2; ++ if (getTarget().getABI() == "elfv1") ++ Kind = PPC64_SVR4_ABIInfo::ELFv1; + bool IsSoftFloat = CodeGenOpts.FloatABI == "soft"; + + return SetCGInfo( +--- a/lib/Driver/ToolChains/Clang.cpp ++++ b/lib/Driver/ToolChains/Clang.cpp +@@ -1920,14 +1920,7 @@ void Clang::AddPPCTargetArgs(const ArgList &Args, + const llvm::Triple &T = getToolChain().getTriple(); + if (T.isOSBinFormatELF()) { + switch (getToolChain().getArch()) { +- case llvm::Triple::ppc64: { +- if ((T.isOSFreeBSD() && T.getOSMajorVersion() >= 13) || +- T.isOSOpenBSD() || T.isMusl()) +- ABIName = "elfv2"; +- else +- ABIName = "elfv1"; +- break; +- } ++ case llvm::Triple::ppc64: + case llvm::Triple::ppc64le: + ABIName = "elfv2"; + break; diff --git a/patches/llvm12-compiler-rt-void/compiler-rt-aarch64-ucontext.patch b/patches/llvm12-compiler-rt-void/compiler-rt-aarch64-ucontext.patch new file mode 100644 index 0000000..49689ca --- /dev/null +++ b/patches/llvm12-compiler-rt-void/compiler-rt-aarch64-ucontext.patch @@ -0,0 +1,11 @@ +--- compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp.orig ++++ compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp +@@ -1799,7 +1799,7 @@ + + static bool Aarch64GetESR(ucontext_t *ucontext, u64 *esr) { + static const u32 kEsrMagic = 0x45535201; +- u8 *aux = ucontext->uc_mcontext.__reserved; ++ u8 *aux = reinterpret_cast(ucontext->uc_mcontext.__reserved); + while (true) { + _aarch64_ctx *ctx = (_aarch64_ctx *)aux; + if (ctx->size == 0) break; diff --git a/patches/llvm12-compiler-rt-void/compiler-rt-sanitizer-ppc64-musl.patch b/patches/llvm12-compiler-rt-void/compiler-rt-sanitizer-ppc64-musl.patch new file mode 100644 index 0000000..a776e82 --- /dev/null +++ b/patches/llvm12-compiler-rt-void/compiler-rt-sanitizer-ppc64-musl.patch @@ -0,0 +1,35 @@ +--- a/lib/sanitizer_common/sanitizer_linux.cpp ++++ b/lib/sanitizer_common/sanitizer_linux.cpp +@@ -74,6 +74,10 @@ + #include + #endif + ++#if SANITIZER_LINUX && defined(__powerpc__) ++#include ++#endif ++ + #if SANITIZER_LINUX && !SANITIZER_ANDROID + #include + #endif +--- a/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp ++++ b/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp +@@ -92,7 +92,7 @@ + # include + # include + #if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \ +- SANITIZER_RISCV64 ++ defined(__powerpc__) || SANITIZER_RISCV64 + # include + # ifdef __arm__ + typedef struct user_fpregs elf_fpregset_t; +--- a/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp ++++ b/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp +@@ -31,7 +31,7 @@ + #include // for pid_t + #include // for iovec + #include // for NT_PRSTATUS +-#if (defined(__aarch64__) || SANITIZER_RISCV64) && !SANITIZER_ANDROID ++#if (defined(__aarch64__) || defined(__powerpc__) || SANITIZER_RISCV64) && !SANITIZER_ANDROID + // GLIBC 2.20+ sys/user does not include asm/ptrace.h + # include + #endif diff --git a/patches/llvm12-compiler-rt-void/compiler-rt-size_t.patch b/patches/llvm12-compiler-rt-void/compiler-rt-size_t.patch new file mode 100644 index 0000000..2c943d9 --- /dev/null +++ b/patches/llvm12-compiler-rt-void/compiler-rt-size_t.patch @@ -0,0 +1,10 @@ +--- compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp.orig ++++ compiler-rt/lib/fuzzer/FuzzerInterceptors.cpp +@@ -25,6 +25,7 @@ + } + + #include ++#include + #include + #include // for dlsym() + diff --git a/patches/llvm12-compiler-rt-void/compiler-rt-xray-ppc64-musl.patch b/patches/llvm12-compiler-rt-void/compiler-rt-xray-ppc64-musl.patch new file mode 100644 index 0000000..6db37ce --- /dev/null +++ b/patches/llvm12-compiler-rt-void/compiler-rt-xray-ppc64-musl.patch @@ -0,0 +1,62 @@ +--- a/lib/xray/xray_powerpc64.inc ++++ b/lib/xray/xray_powerpc64.inc +@@ -12,7 +12,13 @@ + + #include + #include ++#ifdef __GLIBC__ + #include ++#else ++#include ++#include ++#include ++#endif + + #include "xray_defs.h" + +@@ -20,13 +26,45 @@ namespace __xray { + + ALWAYS_INLINE uint64_t readTSC(uint8_t &CPU) XRAY_NEVER_INSTRUMENT { + CPU = 0; ++#ifdef __GLIBC__ + return __ppc_get_timebase(); ++#else ++ return __builtin_ppc_get_timebase(); ++#endif + } + + inline uint64_t getTSCFrequency() XRAY_NEVER_INSTRUMENT { + static std::mutex M; + std::lock_guard Guard(M); ++#ifdef __GLIBC__ + return __ppc_get_timebase_freq(); ++#else ++ /* FIXME: a less dirty implementation? */ ++ static uint64_t base; ++ if (!base) { ++ FILE *f = fopen("/proc/cpuinfo", "rb"); ++ if (f) { ++ ssize_t nr; ++ /* virtually always big enough to hold the line */ ++ char buf[512]; ++ while (fgets(buf, sizeof(buf), f)) { ++ char *ret = strstr(buf, "timebase"); ++ if (!ret) { ++ continue; ++ } ++ ret += sizeof("timebase") - 1; ++ ret = strchr(ret, ':'); ++ if (!ret) { ++ continue; ++ } ++ base = strtoul(ret + 1, nullptr, 10); ++ break; ++ } ++ fclose(f); ++ } ++ } ++ return base; ++#endif + } + + inline bool probeRequiredCPUFeatures() XRAY_NEVER_INSTRUMENT { diff --git a/patches/llvm12-void/llvm-001-musl.patch b/patches/llvm12-void/llvm-001-musl.patch new file mode 100644 index 0000000..0204a89 --- /dev/null +++ b/patches/llvm12-void/llvm-001-musl.patch @@ -0,0 +1,57 @@ +From faca3fbd15d0c3108493c3c54cd93138e049ac43 Mon Sep 17 00:00:00 2001 +From: Andrea Brancaleoni +Date: Tue, 8 Sep 2015 22:03:02 +0200 +Subject: [PATCH 3/3] musl + +--- + include/llvm/Analysis/TargetLibraryInfo.h | 9 +++++++++ + lib/Support/DynamicLibrary.cpp | 2 +- + lib/Support/Unix/Signals.inc | 6 +++--- + utils/unittest/googletest/src/gtest.cc | 1 + + 5 files changed, 17 insertions(+), 6 deletions(-) + +diff --git a/include/llvm/Analysis/TargetLibraryInfo.h b/include/llvm/Analysis/TargetLibraryInfo.h +index 34a8a1e3..1214ece5 100644 +--- a/include/llvm/Analysis/TargetLibraryInfo.h ++++ b/include/llvm/Analysis/TargetLibraryInfo.h +@@ -18,6 +18,15 @@ + #include "llvm/IR/PassManager.h" + #include "llvm/Pass.h" + ++#undef fopen64 ++#undef fseeko64 ++#undef fstat64 ++#undef fstatvfs64 ++#undef ftello64 ++#undef lstat64 ++#undef stat64 ++#undef tmpfile64 ++ + namespace llvm { + template class ArrayRef; + class Triple; +diff --git a/lib/Support/Unix/DynamicLibrary.inc b/lib/Support/Unix/DynamicLibrary.inc +index a2a37996..2f86c470 100644 +--- a/lib/Support/Unix/DynamicLibrary.inc ++++ b/lib/Support/Unix/DynamicLibrary.inc +@@ -102,7 +102,7 @@ static void *DoSearch(const char* SymbolName) { + + // This macro returns the address of a well-known, explicit symbol + #define EXPLICIT_SYMBOL(SYM) \ +- if (!strcmp(SymbolName, #SYM)) return &SYM ++ if (!strcmp(SymbolName, #SYM)) return (void *)&SYM + + // Under glibc we have a weird situation. The stderr/out/in symbols are both + // macros and global variables because of standards requirements. So, we +diff --git a/utils/unittest/googletest/src/gtest.cc b/utils/unittest/googletest/src/gtest.cc +index d882ab2e..f1fb12d0 100644 +--- a/utils/unittest/googletest/src/gtest.cc ++++ b/utils/unittest/googletest/src/gtest.cc +@@ -128,6 +128,7 @@ + + #if GTEST_CAN_STREAM_RESULTS_ + # include // NOLINT ++# include // NOLINT + # include // NOLINT + # include // NOLINT + # include // NOLINT diff --git a/patches/llvm12-void/llvm-002-musl-ppc64-elfv2.patch b/patches/llvm12-void/llvm-002-musl-ppc64-elfv2.patch new file mode 100644 index 0000000..fb842cf --- /dev/null +++ b/patches/llvm12-void/llvm-002-musl-ppc64-elfv2.patch @@ -0,0 +1,30 @@ +This patches LLVM to use ELFv2 on ppc64 unconditionally unless overridden. We +need this because unlike most distros we use ELFv2 for both glibc and musl +on big endian ppc64. + +diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp +index 0634833e..b7cbc2e7 100644 +--- a/lib/Target/PowerPC/PPCTargetMachine.cpp ++++ b/lib/Target/PowerPC/PPCTargetMachine.cpp +@@ -222,9 +222,8 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, + + switch (TT.getArch()) { + case Triple::ppc64le: +- return PPCTargetMachine::PPC_ABI_ELFv2; + case Triple::ppc64: +- return PPCTargetMachine::PPC_ABI_ELFv1; ++ return PPCTargetMachine::PPC_ABI_ELFv2; + default: + return PPCTargetMachine::PPC_ABI_UNKNOWN; + } +diff --git a/test/CodeGen/PowerPC/ppc64-elf-abi.ll b/test/CodeGen/PowerPC/ppc64-elf-abi.ll +index 8b1cf6b5..296a2afa 100644 +--- a/test/CodeGen/PowerPC/ppc64-elf-abi.ll ++++ b/test/CodeGen/PowerPC/ppc64-elf-abi.ll +@@ -1,4 +1,5 @@ +-; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv1 ++; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv2 ++; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-musl < %s | FileCheck %s -check-prefix=CHECK-ELFv2 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv2 diff --git a/patches/llvm12-void/llvm-003-ppc-secureplt.patch b/patches/llvm12-void/llvm-003-ppc-secureplt.patch new file mode 100644 index 0000000..b9e60d5 --- /dev/null +++ b/patches/llvm12-void/llvm-003-ppc-secureplt.patch @@ -0,0 +1,11 @@ +--- llvm/lib/Target/PowerPC/PPCSubtarget.cpp ++++ llvm/lib/Target/PowerPC/PPCSubtarget.cpp +@@ -165,7 +165,7 @@ void PPCSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { + + if ((TargetTriple.isOSFreeBSD() && TargetTriple.getOSMajorVersion() >= 13) || + TargetTriple.isOSNetBSD() || TargetTriple.isOSOpenBSD() || +- TargetTriple.isMusl()) ++ isTargetLinux()) + SecurePlt = true; + + if (HasSPE && IsPPC64) diff --git a/patches/llvm12-void/llvm-004-override-opt.patch b/patches/llvm12-void/llvm-004-override-opt.patch new file mode 100644 index 0000000..3f5276c --- /dev/null +++ b/patches/llvm12-void/llvm-004-override-opt.patch @@ -0,0 +1,18 @@ +This allows us to override the optimization level as not all platforms can +deal with -O3. + +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -918,6 +918,12 @@ if( MINGW AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" ) + llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "-O2") + endif() + ++set(VOID_CXX_OPT_FLAGS "" CACHE STRING "Optimization level to use") ++ ++if (NOT VOID_CXX_OPT_FLAGS STREQUAL "") ++ llvm_replace_compiler_option(CMAKE_CXX_FLAGS_RELEASE "-O3" "${VOID_CXX_OPT_FLAGS}") ++endif() ++ + # Put this before tblgen. Else we have a circular dependence. + add_subdirectory(lib/Demangle) + add_subdirectory(lib/Support) diff --git a/patches/llvm12-void/llvm-005-ppc-bigpic.patch b/patches/llvm12-void/llvm-005-ppc-bigpic.patch new file mode 100644 index 0000000..d0c0cdb --- /dev/null +++ b/patches/llvm12-void/llvm-005-ppc-bigpic.patch @@ -0,0 +1,36 @@ +From f3dbdd49c06bfafc1d6138094cf42889c14d38b6 Mon Sep 17 00:00:00 2001 +From: Samuel Holland +Date: Sun, 3 Nov 2019 10:57:27 -0600 +Subject: [PATCH] [LLVM][PowerPC] Assume BigPIC if no PIC level is specified + +--- + llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp | 2 +- + llvm/lib/Target/PowerPC/PPCMCInstLower.cpp | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/lib/Target/PowerPC/PPCAsmPrinter.cpp b/lib/Target/PowerPC/PPCAsmPrinter.cpp +index cce21f32..87ca5f9b 100644 +--- a/lib/Target/PowerPC/PPCAsmPrinter.cpp ++++ b/lib/Target/PowerPC/PPCAsmPrinter.cpp +@@ -520,7 +520,7 @@ void PPCAsmPrinter::EmitTlsCall(const MachineInstr *MI, + + // Add 32768 offset to the symbol so we follow up the latest GOT/PLT ABI. + if (Kind == MCSymbolRefExpr::VK_PLT && Subtarget->isSecurePlt() && +- M->getPICLevel() == PICLevel::BigPIC) ++ M->getPICLevel() != PICLevel::SmallPIC) + TlsRef = MCBinaryExpr::createAdd( + TlsRef, MCConstantExpr::create(32768, OutContext), OutContext); + const MachineOperand &MO = MI->getOperand(2); +diff --git a/lib/Target/PowerPC/PPCMCInstLower.cpp b/lib/Target/PowerPC/PPCMCInstLower.cpp +index 5cc180d7..a5b02565 100644 +--- a/lib/Target/PowerPC/PPCMCInstLower.cpp ++++ b/lib/Target/PowerPC/PPCMCInstLower.cpp +@@ -117,7 +117,7 @@ static MCOperand GetSymbolRef(const MachineOperand &MO, const MCSymbol *Symbol, + const MCExpr *Expr = MCSymbolRefExpr::create(Symbol, RefKind, Ctx); + // If -msecure-plt -fPIC, add 32768 to symbol. + if (Subtarget->isSecurePlt() && TM.isPositionIndependent() && +- M->getPICLevel() == PICLevel::BigPIC && ++ M->getPICLevel() != PICLevel::SmallPIC && + MO.getTargetFlags() == PPCII::MO_PLT) + Expr = + MCBinaryExpr::createAdd(Expr, MCConstantExpr::create(32768, Ctx), Ctx); diff --git a/patches/llvm12-void/llvm-006-aarch64-mf_exec.patch b/patches/llvm12-void/llvm-006-aarch64-mf_exec.patch new file mode 100644 index 0000000..098d748 --- /dev/null +++ b/patches/llvm12-void/llvm-006-aarch64-mf_exec.patch @@ -0,0 +1,25 @@ +Fix failures in AllocationTests/MappedMemoryTest.* on aarch64: + + Failing Tests (8): + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.AllocAndRelease/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.DuplicateNear/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.EnabledWrite/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.MultipleAllocAndRelease/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.SuccessiveNear/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.UnalignedNear/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.ZeroNear/3 + LLVM-Unit :: Support/./SupportTests/AllocationTests/MappedMemoryTest.ZeroSizeNear/3 + +Upstream-Issue: https://bugs.llvm.org/show_bug.cgi?id=14278#c10 + +--- a/lib/Support/Unix/Memory.inc ++++ b/lib/Support/Unix/Memory.inc +@@ -58,7 +58,7 @@ static int getPosixProtectionFlags(unsigned Flags) { + return PROT_READ | PROT_WRITE | PROT_EXEC; + case llvm::sys::Memory::MF_EXEC: + #if (defined(__FreeBSD__) || defined(__POWERPC__) || defined (__ppc__) || \ +- defined(_POWER) || defined(_ARCH_PPC)) ++ defined(_POWER) || defined(_ARCH_PPC) || (defined(__linux__) && defined(__aarch64__))) + // On PowerPC, having an executable page that has no read permission + // can have unintended consequences. The function InvalidateInstruction- + // Cache uses instructions dcbf and icbi, both of which are treated by