From 49cec2be42835f6b4c5ff1bad4710e20db422b87 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Thu, 4 Oct 2018 21:09:36 +0000 Subject: user/llvm6: Fix ELFv2 patch, more secure PLT fixes for ppc32 --- user/llvm6/APKBUILD | 8 +++--- user/llvm6/more-secure-plt.patch | 38 ++++++++++++++++++++++++++++ user/llvm6/musl-ppc64-elfv2.patch | 52 ++++++++++++++++++++++++++++++--------- 3 files changed, 84 insertions(+), 14 deletions(-) create mode 100644 user/llvm6/more-secure-plt.patch diff --git a/user/llvm6/APKBUILD b/user/llvm6/APKBUILD index f3bc9acc7..c4eb242d8 100644 --- a/user/llvm6/APKBUILD +++ b/user/llvm6/APKBUILD @@ -12,7 +12,7 @@ arch="all" options="!checkroot !dbg" url="https://llvm.org/" license="NCSA" -depends_dev="$pkgname=$pkgver-r$pkgrel" +depends_dev="$pkgname=$pkgver-r$pkgrel libexecinfo-dev libxml2-dev" makedepends="binutils-dev chrpath cmake file libexecinfo-dev libffi-dev libxml2-dev python3 zlib-dev" subpackages="$pkgname-static $pkgname-libs $pkgname-dev @@ -24,6 +24,7 @@ source="http://llvm.org/releases/$pkgver/llvm-$pkgver.src.tar.xz disable-dlclose-test.patch musl-ppc64-elfv2.patch secure-plt.patch + more-secure-plt.patch " builddir="$srcdir/$_pkgname-$pkgver.src" @@ -245,5 +246,6 @@ f84cd65d7042e89826ba6e8d48c4c302bf4980da369d7f19a55f217e51c00ca8ed178d453df3a3ce 6d1a716e5aa24e6b9a3acf4cc11e2504b1b01abf574074e9e5617b991de87d5e4e687eb18e85e73d5e632568afe2fc357771c4c96f9e136502071991496fb78c cmake-fix-libLLVM-name.patch 49c47f125014b60d0ea7870f981a2c1708ad705793f89287ed846ee881a837a4dc0170bf467e03f2ef56177473128945287749ac80dc2d13cfabcf8b929ba58a disable-FileSystemTest.CreateDir-perms-assert.patch caeec8e4dbd92f5f74940780b69075f3879a267a8623822cbdc193fd14706eb089071e3a5a20d60cc2eca59e4c5b2a61d29827a2f3362ee7c5f74f11d9ace200 disable-dlclose-test.patch -bde743960003a2a39868af9f665d86fadb0a7b1e7eb51c16ebbd74ce4c5220bbc400b1d5211c02fc2643863f49ee961e9a18dffa0eb813a0e1723613396512ab musl-ppc64-elfv2.patch -35d289641fa4d200b5a3f62f1d51da600a734641356b0dc6c54a3080dd89aec3b031e36af8b53be49c35346c1cbcce00268de7ec9b4f552bfd7bf84d3504d1c4 secure-plt.patch" +e5ddbc4b6c4928e79846dc3c022eb7928aaa8fed40515c78f5f03b8ab8264f34f1eb8aa8bfc0f436450932f4917e54ad261603032092ea271d9590f11a37cf1e musl-ppc64-elfv2.patch +35d289641fa4d200b5a3f62f1d51da600a734641356b0dc6c54a3080dd89aec3b031e36af8b53be49c35346c1cbcce00268de7ec9b4f552bfd7bf84d3504d1c4 secure-plt.patch +3d4a0a478bf800ea262c577451e22a1dbd5a4258226e49c66a697559263c8aa4fc0fff642a3c80ac3dfbb3efd6d9c0dbeb41dae1250fc7946de821cfef1ce1f0 more-secure-plt.patch" diff --git a/user/llvm6/more-secure-plt.patch b/user/llvm6/more-secure-plt.patch new file mode 100644 index 000000000..1cc08a9a8 --- /dev/null +++ b/user/llvm6/more-secure-plt.patch @@ -0,0 +1,38 @@ +diff --git a/lib/Target/PowerPC/PPCSubtarget.cpp b/lib/Target/PowerPC/PPCSubtarget.cpp +index c0cbfd779cb..5d7a021c3e2 100644 +--- a/lib/Target/PowerPC/PPCSubtarget.cpp ++++ b/lib/Target/PowerPC/PPCSubtarget.cpp +@@ -106,6 +106,7 @@ + HasFloat128 = false; + IsISA3_0 = false; + UseLongCalls = false; ++ SecurePlt = false; + + HasPOPCNTD = POPCNTD_Unavailable; + } +@@ -136,6 +137,10 @@ + if (isDarwin()) + HasLazyResolverStubs = true; + ++ // Set up musl-specific properties. ++ if (TargetTriple.getEnvironment() == Triple::Musl) ++ SecurePlt = true; ++ + // QPX requires a 32-byte aligned stack. Note that we need to do this if + // we're compiling for a BG/Q system regardless of whether or not QPX + // is enabled because external functions will assume this alignment. +diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp +index c583fba8cab..6a9eedf89c5 100644 +--- a/lib/Target/PowerPC/PPCTargetMachine.cpp ++++ b/lib/Target/PowerPC/PPCTargetMachine.cpp +@@ -222,6 +222,10 @@ static Reloc::Model getEffectiveRelocModel(const Triple &TT, + if (TT.getArch() == Triple::ppc64 || TT.getArch() == Triple::ppc64le) + return Reloc::PIC_; + ++ // musl needs SecurePlt, which depends on PIC. ++ if (TT.getEnvironment() == Triple::Musl) ++ return Reloc::PIC_; ++ + // 32-bit is static by default. + return Reloc::Static; + } diff --git a/user/llvm6/musl-ppc64-elfv2.patch b/user/llvm6/musl-ppc64-elfv2.patch index 6fa65526b..016be5dad 100644 --- a/user/llvm6/musl-ppc64-elfv2.patch +++ b/user/llvm6/musl-ppc64-elfv2.patch @@ -1,13 +1,43 @@ ---- llvm-6.0.1.src/lib/Target/PowerPC/PPCTargetMachine.cpp.orig 2018-09-13 03:51:11.900000000 +0000 -+++ llvm-6.0.1.src/lib/Target/PowerPC/PPCTargetMachine.cpp 2018-09-13 03:56:10.740000000 +0000 -@@ -191,6 +191,10 @@ - if (TT.isMacOSX()) - return PPCTargetMachine::PPC_ABI_UNKNOWN; - -+ // musl uses ELFv2 ABI on both endians. -+ if (TT.getEnvironment() == Triple::Musl) -+ return PPCTargetMachine::PPC_ABI_ELFv2; -+ - switch (TT.getArch()) { +From 750d323a6060ad92c3d247f85d6555041f55b4a5 Mon Sep 17 00:00:00 2001 +From: "A. Wilcox" +Date: Thu, 4 Oct 2018 15:26:59 -0500 +Subject: [PATCH] Add support for powerpc64-*-linux-musl targets + +This patch ensures that 64-bit PowerPC musl targets use ELFv2 ABI on both +endians. It additionally adds a test that big endian PPC64 uses ELFv2 on +musl. +--- + lib/Target/PowerPC/PPCTargetMachine.cpp | 4 ++++ + test/CodeGen/PowerPC/ppc64-elf-abi.ll | 1 + + 2 files changed, 5 insertions(+) + +diff --git a/lib/Target/PowerPC/PPCTargetMachine.cpp b/lib/Target/PowerPC/PPCTargetMachine.cpp +index 34410393ef6..c583fba8cab 100644 +--- a/lib/Target/PowerPC/PPCTargetMachine.cpp ++++ b/lib/Target/PowerPC/PPCTargetMachine.cpp +@@ -199,6 +199,10 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT, case Triple::ppc64le: return PPCTargetMachine::PPC_ABI_ELFv2; + case Triple::ppc64: ++ // musl uses ELFv2 ABI on both endians. ++ if (TT.getEnvironment() == Triple::Musl) ++ return PPCTargetMachine::PPC_ABI_ELFv2; ++ + return PPCTargetMachine::PPC_ABI_ELFv1; + 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 1e17930304b..aa594b37b47 100644 +--- a/test/CodeGen/PowerPC/ppc64-elf-abi.ll ++++ b/test/CodeGen/PowerPC/ppc64-elf-abi.ll +@@ -1,6 +1,7 @@ + ; 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 -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=powerpc64-unknown-linux-musl < %s | FileCheck %s -check-prefix=CHECK-ELFv2 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu < %s | FileCheck %s -check-prefix=CHECK-ELFv2 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 + ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 +-- +2.18.0 + -- cgit v1.2.3-70-g09d2