summaryrefslogtreecommitdiff
path: root/repo/devel/clang
diff options
context:
space:
mode:
Diffstat (limited to 'repo/devel/clang')
-rw-r--r--repo/devel/clang/clang.xibuild57
-rw-r--r--repo/devel/clang/patches/10-add-musl-triples.patch35
-rw-r--r--repo/devel/clang/patches/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch81
3 files changed, 173 insertions, 0 deletions
diff --git a/repo/devel/clang/clang.xibuild b/repo/devel/clang/clang.xibuild
new file mode 100644
index 0000000..3b93ba3
--- /dev/null
+++ b/repo/devel/clang/clang.xibuild
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+MAKEDEPS="cmake llvm libxml2 ninja python python-markupsafe python-pygments"
+DEPS="curl gcc libssh2 openssl"
+
+PKG_VER=13.0.0
+SOURCE=https://github.com/llvm/llvm-project/releases/download/llvmorg-$PKG_VER/clang-$PKG_VER.src.tar.xz
+DESC="Systems programming language focused on safety, speed and concurrency"
+
+ADDITIONAL="
+ patches/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
+ patches/10-add-musl-triples.patch
+"
+
+prepare () {
+ apply_patches
+
+ # link in /usr/inlcude/llvm to include
+ ln -s /usr/include/llvm include/llvm
+ # (there should be a better way to do this, since tblgen does look in /include rather than /usr/include)
+
+}
+
+build () {
+ mkdir build
+ cd build
+
+ python_version=$(python3 -V | sed 's/.*\([0-9]\{1,\}\.[0-9]\{1,\}\)\..*/\1/')
+
+ cmake .. -G Ninja -Wno-dev \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_C_FLAGS_RELEASE_INIT="$CFLAGS -O2" \
+ -DCMAKE_CXX_FLAGS_RELEASE_INIT="$CXXFLAGS" \
+ -DCMAKE_EXE_LINKER_FLAGS_RELEASE_INIT="$LDFLAGS -Wl,-z,stack-size=2097152" \
+ -DCMAKE_INSTALL_PREFIX=/usr \
+ -DCMAKE_VERBOSE_MAKEFILE=OFF \
+ -DCLANG_VENDOR=XiLinux \
+ -DLLVM_EXTERNAL_LIT=/usr/bin/lit \
+ -DCLANG_BUILD_EXAMPLES=OFF \
+ -DCLANG_INCLUDE_DOCS=ON \
+ -DCLANG_PYTHON_BINDINGS_VERSIONS="$python_version" \
+ -DLLVM_BUILD_DOCS=ON \
+ -DLLVM_ENABLE_SPHINX=ON \
+ -DSPHINX_WARNINGS_AS_ERRORS=OFF \
+ -DCLANG_INCLUDE_TESTS=ON \
+ -DCLANG_PLUGIN_SUPPORT=ON \
+ -DLIBCLANG_BUILD_STATIC=ON \
+ -DLLVM_ENABLE_EH=ON \
+ -DLLVM_ENABLE_RTTI=ON
+
+ ninja clang-tblgen
+ ninja
+}
+
+package () {
+ DESTDIR=$PKG_DEST ninja install
+}
diff --git a/repo/devel/clang/patches/10-add-musl-triples.patch b/repo/devel/clang/patches/10-add-musl-triples.patch
new file mode 100644
index 0000000..b11ca84
--- /dev/null
+++ b/repo/devel/clang/patches/10-add-musl-triples.patch
@@ -0,0 +1,35 @@
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -2077,6 +2077,7 @@
+ static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
+ static const char *const AArch64Triples[] = {
+ "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
++ "aarch64-linux-musl",
+ "aarch64-suse-linux", "aarch64-linux-android"};
+ static const char *const AArch64beLibDirs[] = {"/lib"};
+ static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
+@@ -2086,6 +2087,8 @@
+ static const char *const ARMTriples[] = {"arm-linux-gnueabi",
+ "arm-linux-androideabi"};
+ static const char *const ARMHFTriples[] = {"arm-linux-gnueabihf",
++ "arm-linux-musleabihf",
++ "armv7l-linux-musleabihf",
+ "armv7hl-redhat-linux-gnueabi",
+ "armv6hl-suse-linux-gnueabi",
+ "armv7hl-suse-linux-gnueabi"};
+@@ -2105,6 +2108,7 @@
+ "x86_64-redhat-linux", "x86_64-suse-linux",
+ "x86_64-manbo-linux-gnu", "x86_64-linux-gnu",
+ "x86_64-slackware-linux", "x86_64-unknown-linux",
++ "x86_64-linux-musl",
+ "x86_64-amazon-linux", "x86_64-linux-android"};
+ static const char *const X32Triples[] = {"x86_64-linux-gnux32",
+ "x86_64-pc-linux-gnux32"};
+@@ -2116,6 +2120,7 @@
+ "i686-redhat-linux", "i386-redhat-linux",
+ "i586-suse-linux", "i686-montavista-linux",
+ "i686-linux-android", "i686-gnu",
++ "i686-linux-musl",
+ };
+
+ static const char *const M68kLibDirs[] = {"/lib"};
diff --git a/repo/devel/clang/patches/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch b/repo/devel/clang/patches/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
new file mode 100644
index 0000000..f2895ce
--- /dev/null
+++ b/repo/devel/clang/patches/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
@@ -0,0 +1,81 @@
+Based on original patchset from Jakub Jirutka <jakub@jirutka.cz>
+Updated by Eric Molitor <eric@molitor.org>
+Updated by Natanael Copa <ncopa@alpinelinux.org>
+Updated by omni <omni+alpine@hack.org>
+
+--- a/lib/Driver/ToolChains/Linux.h
++++ b/lib/Driver/ToolChains/Linux.h
+@@ -11,6 +11,7 @@
+
+ #include "Gnu.h"
+ #include "clang/Driver/ToolChain.h"
++#include "clang/Basic/LangOptions.h"
+
+ namespace clang {
+ namespace driver {
+@@ -38,6 +39,18 @@
+ CXXStdlibType GetDefaultCXXStdlibType() const override;
+ bool isPIEDefault() const override;
+ bool isNoExecStackDefault() const override;
++
++ LangOptions::StackProtectorMode
++ GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
++ StringRef VendorName = Linux::getTriple().getVendorName();
++ if (VendorName.compare("alpine") == 0)
++ return LangOptions::SSPStrong;
++
++ return LangOptions::SSPOff;
++ }
++
++
++
+ bool IsMathErrnoDefault() const override;
+ SanitizerMask getSupportedSanitizers() const override;
+ void addProfileRTLibs(const llvm::opt::ArgList &Args,
+--- a/test/Driver/fsanitize.c
++++ b/test/Driver/fsanitize.c
+@@ -667,18 +667,17 @@
+ // RUN: %clang -fno-sanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NOSP
+ // NOSP-NOT: "-fsanitize=safe-stack"
+
+-// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
++// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
+ // RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP-ASAN
+ // RUN: %clang -target x86_64-linux-gnu -fstack-protector -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
+ // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
+-// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
+-// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
++// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
++// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
+ // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
+ // NO-SP-NOT: stack-protector
+ // NO-SP: "-fsanitize=safe-stack"
+ // SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with '-fsanitize=address'
+ // SP: "-fsanitize=safe-stack"
+-// SP: -stack-protector
+ // NO-SP-NOT: stack-protector
+
+ // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM
+--- a/test/Driver/stack-protector.c
++++ b/test/Driver/stack-protector.c
+@@ -35,6 +35,20 @@
+
+ // Test default stack protector values for Darwin platforms
+
++// RUN: %clang -target x86_64-alpine-linux-musl -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE
++// ALPINE: "-stack-protector" "2"
++
++// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_SPS
++// ALPINE_SPS: "-stack-protector" "2"
++
++// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_ALL
++// ALPINE_ALL: "-stack-protector" "3"
++// ALPINE_ALL-NOT: "-stack-protector-buffer-size"
++
++// RUN: %clang -target x86_64-alpine-linux-musl -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_NOSSP
++// ALPINE_NOSSP-NOT: "-stack-protector"
++// ALPINE_NOSSP-NOT: "-stack-protector-buffer-size"
++
+ // RUN: %clang -target armv7k-apple-watchos2.0 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_WATCHOS
+ // RUN: %clang -ffreestanding -target armv7k-apple-watchos2.0 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_WATCHOS
+ // SSP_WATCHOS: "-stack-protector" "1"