summaryrefslogtreecommitdiff
path: root/main/clang15
diff options
context:
space:
mode:
authorpsykose <alice@ayaya.dev>2023-07-11 12:37:07 +0000
committerpsykose <alice@ayaya.dev>2023-07-11 16:36:20 +0200
commit314d661ecd03638afb1ee746f7f1fa424c32d3b0 (patch)
tree7a46c08e6cbaa87ac14eda0a59aedaea04cdfa92 /main/clang15
parent9e52d6d06b35579a5d1f2a8f9221e17a26348a43 (diff)
downloadaports-314d661ecd03638afb1ee746f7f1fa424c32d3b0.zip
main/clang15: move from community
needed back in main for libclc
Diffstat (limited to 'main/clang15')
-rw-r--r--main/clang15/10-add-musl-triples.patch39
-rw-r--r--main/clang15/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch82
-rw-r--r--main/clang15/APKBUILD387
-rw-r--r--main/clang15/clang-001-fortify-include.patch36
-rw-r--r--main/clang15/clang-002-fortify-enable.patch29
-rw-r--r--main/clang15/clang-003-as-needed.patch31
-rw-r--r--main/clang15/clang-default-fno-semantic-interposition.patch39
7 files changed, 643 insertions, 0 deletions
diff --git a/main/clang15/10-add-musl-triples.patch b/main/clang15/10-add-musl-triples.patch
new file mode 100644
index 00000000000..0ed9c81675f
--- /dev/null
+++ b/main/clang15/10-add-musl-triples.patch
@@ -0,0 +1,39 @@
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -2073,7 +2073,7 @@
+ static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
+ static const char *const AArch64Triples[] = {
+ "aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
+- "aarch64-suse-linux"};
++ "aarch64-suse-linux", "aarch64-linux-musl"};
+ static const char *const AArch64beLibDirs[] = {"/lib"};
+ static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
+ "aarch64_be-linux-gnu"};
+@@ -2085,7 +2085,9 @@
+ "armv7l-linux-musleabihf",
+ "armv7hl-redhat-linux-gnueabi",
+ "armv6hl-suse-linux-gnueabi",
+- "armv7hl-suse-linux-gnueabi"};
++ "armv7hl-suse-linux-gnueabi",
++ "arm-linux-musleabihf",
++ "armv7l-linux-musleabihf"};
+ static const char *const ARMebLibDirs[] = {"/lib"};
+ static const char *const ARMebTriples[] = {"armeb-linux-gnueabi"};
+ static const char *const ARMebHFTriples[] = {
+@@ -2101,7 +2103,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-amazon-linux"};
++ "x86_64-amazon-linux", "x86_64-linux-musl"};
+ static const char *const X32Triples[] = {"x86_64-linux-gnux32",
+ "x86_64-pc-linux-gnux32"};
+ static const char *const X32LibDirs[] = {"/libx32", "/lib"};
+@@ -2110,6 +2112,7 @@
+ "i586-linux-gnu", "i686-linux-gnu", "i686-pc-linux-gnu",
+ "i386-redhat-linux6E", "i686-redhat-linux", "i386-redhat-linux",
+ "i586-suse-linux", "i686-montavista-linux", "i686-gnu",
++ "i686-linux-musl",
+ };
+
+ static const char *const M68kLibDirs[] = {"/lib"};
diff --git a/main/clang15/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch b/main/clang15/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
new file mode 100644
index 00000000000..bae4532c16a
--- /dev/null
+++ b/main/clang15/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
@@ -0,0 +1,82 @@
+--- 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 {
+@@ -60,6 +61,15 @@
+ llvm::DenormalMode getDefaultDenormalModeForType(
+ const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
+ const llvm::fltSemantics *FPType = nullptr) 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;
++ }
+
+ protected:
+ Tool *buildAssembler() const override;
+--- a/test/Driver/fsanitize.c
++++ b/test/Driver/fsanitize.c
+@@ -666,12 +666,12 @@
+ // 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"
+--- a/test/Driver/stack-protector.c
++++ b/test/Driver/stack-protector.c
+@@ -33,6 +33,22 @@
+ // SSP-PS4-BUF: "-stack-protector" "2"
+ // SSP-PS4-BUF: "-stack-protector-buffer-size" "16"
+
++// Test default stack protector values for Alpine
++
++// 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"
++
+ // Test default stack protector values for Darwin platforms
+
+ // RUN: %clang -target armv7k-apple-watchos2.0 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_WATCHOS
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -563,6 +563,10 @@
+ // The profile runtime also needs access to system libraries.
+ getToolChain().addProfileRTLibs(Args, CmdArgs);
+
++ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_nodefaultlibs)) {
++ CmdArgs.push_back("-lssp_nonshared");
++ }
++
+ if (D.CCCIsCXX() &&
+ !Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
+ options::OPT_r)) {
diff --git a/main/clang15/APKBUILD b/main/clang15/APKBUILD
new file mode 100644
index 00000000000..9b16fef0267
--- /dev/null
+++ b/main/clang15/APKBUILD
@@ -0,0 +1,387 @@
+# Contributor Eric Molitor <eric@molitor.org>
+# Contributor Patrick Gansterer <paroga@paroga.com>
+# Contributor Travis Tilley <ttilley@gmail.com>
+# Contributor omni <omni+alpine@hack.org>
+# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
+pkgname=clang15
+pkgver=15.0.7
+pkgrel=16
+_llvmver=${pkgver%%.*}
+pkgdesc="A C language family front-end for LLVM"
+arch="all"
+url="https://llvm.org/"
+license="Apache-2.0 WITH LLVM-Exception"
+options="!check" # fail to build
+makedepends="
+ cmake
+ help2man
+ libxml2-dev
+ llvm$_llvmver-dev
+ llvm$_llvmver-static
+ llvm$_llvmver-test-utils
+ samurai
+ python3
+ "
+checkdepends="diffutils bash gtest-dev"
+depends="fortify-headers>=1.1-r2"
+depends_dev="$pkgname=$pkgver-r$pkgrel"
+subpackages="
+ $pkgname-static
+ $pkgname-libclang
+ $pkgname-libs
+ $pkgname-dev
+ $pkgname-ccache
+ "
+source="https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/clang-$pkgver.src.tar.xz
+ https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/clang-tools-extra-$pkgver.src.tar.xz
+ https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/cmake-$pkgver.src.tar.xz
+ 10-add-musl-triples.patch
+ 30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
+
+ clang-default-fno-semantic-interposition.patch
+ clang-001-fortify-include.patch
+ clang-002-fortify-enable.patch
+ clang-003-as-needed.patch
+ "
+builddir="$srcdir/clang-$pkgver.src"
+
+prepare() {
+ mv "$srcdir/clang-tools-extra-$pkgver.src" "$builddir/tools/extra"
+ default_prepare
+}
+
+# Whether is this package the default (latest) clang version.
+_default_clang="no"
+
+if [ "$_default_clang" = yes ]; then
+ subpackages="
+ $pkgname-doc
+ $pkgname-analyzer::noarch
+ $pkgname-bash-completion:bash:noarch
+ $pkgname-emacs::noarch
+ $pkgname-extra-tools:extra
+ py3-$pkgname:python:noarch
+ "
+ provides="clang=$pkgver-r$pkgrel"
+ replaces="clang"
+ depends_dev="$depends_dev $pkgname-extra-tools=$pkgver-r$pkgrel"
+fi
+
+build() {
+ local python_version=$(python3 -V | sed 's/.*\([0-9]\{1,\}\.[0-9]\{1,\}\)\..*/\1/')
+
+ if [ $_default_clang = yes ]; then
+ local extras=ON
+ else
+ local extras=OFF
+ fi
+
+ cmake -B build -G Ninja -Wno-dev \
+ -DCMAKE_BUILD_TYPE=Release \
+ -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm$_llvmver \
+ -DCMAKE_MODULE_PATH="$srcdir/cmake-$pkgver.src/Modules" \
+ -DCLANG_BUILT_STANDALONE=ON \
+ -DCLANG_ENABLE_ARCMT=$extras \
+ -DCLANG_ENABLE_STATIC_ANALYZER=$extras \
+ -DCLANG_INCLUDE_TESTS="$(want_check && echo ON || echo OFF)" \
+ -DCLANG_LINK_CLANG_DYLIB=ON \
+ -DCLANG_PLUGIN_SUPPORT=ON \
+ -DCLANG_PYTHON_BINDINGS_VERSIONS="$python_version" \
+ -DCLANG_VENDOR=Alpine \
+ -DENABLE_LINKER_BUILD_ID=ON \
+ -DLIBCLANG_BUILD_STATIC=ON
+
+ ninja -C build clang-tblgen
+ ninja -C build
+
+ if [ "$_default_clang" = yes ]; then
+ help2man --no-info \
+ --source "Alpine" \
+ --name "Alpine Clang $pkgver-r$pkgrel" \
+ --version-string "$pkgver-r$pkgrel" \
+ --help-option "--help-hidden" \
+ ./build/bin/clang > clang.1
+ fi
+}
+
+check() {
+ ninja -C build check-all
+}
+
+package() {
+ # the libraries should always exactly match, not just by soname
+ depends="$pkgname-libs=$pkgver-r$pkgrel gcc libstdc++-dev"
+
+ DESTDIR="$pkgdir" cmake --install build
+ mkdir -p "$pkgdir"/usr/bin
+
+ install -Dm644 build/lib/libclang.a -t "$pkgdir"/usr/lib/llvm$_llvmver/lib/
+
+ if [ $_default_clang = "yes" ]; then
+ rm "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/clang-format-bbedit.applescript \
+ "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/clang-doc-default-stylesheet.css \
+ "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/index.js
+
+ mkdir -p "$pkgdir"/usr/share/bash-completion/completions
+ mv "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/bash-autocomplete.sh \
+ "$pkgdir"/usr/share/bash-completion/completions/clang
+
+ mkdir -p "$pkgdir"/usr/share/emacs/site-lisp
+ mv "$pkgdir"/usr/lib/llvm$_llvmver/share/clang/clang-*.el \
+ "$pkgdir"/usr/share/emacs/site-lisp
+ rmdir -p usr/lib/llvm$_llvmver/share/emacs || true
+
+ mv "$pkgdir"/usr/lib/llvm$_llvmver/share/man "$pkgdir"/usr/share/
+ # XXX: scan-build specifically needs to stay in llvm path, but scan-view has to not be
+ # everything uses different path lookup logic..
+ mv "$pkgdir"/usr/lib/llvm$_llvmver/share/scan-view "$pkgdir"/usr/share/
+
+ local sitedir=$(python3 -c "import site; print(site.getsitepackages()[0])")
+ mv "$pkgdir"/usr/lib/llvm$_llvmver/lib/python3* "$pkgdir"/usr/lib
+ mkdir -p "$pkgdir"/"$sitedir"
+ mv "$pkgdir"/usr/lib/llvm$_llvmver/lib/libscanbuild "$pkgdir"/"$sitedir"
+
+ # symlink everything in the bin dir,
+ # into /usr/bin.
+ local clangexes="
+ analyze-build
+ c-index-test
+ clang
+ clang-cl
+ clang-cpp
+ clang-linker-wrapper
+ clang-nvlink-wrapper
+ clang-pseudo
+ clang++
+ clang-$_llvmver
+ clang-apply-replacements
+ clang-change-namespace
+ clang-check
+ clang-doc
+ clang-extdef-mapping
+ clang-format
+ clang-include-fixer
+ clang-move
+ clang-offload-bundler
+ clang-offload-packager
+ clang-offload-wrapper
+ clang-query
+ clang-refactor
+ clang-rename
+ clang-reorder-fields
+ clang-repl
+ clang-scan-deps
+ clang-tidy
+ clangd
+ diagtool
+ find-all-symbols
+ git-clang-format
+ hmaptool
+ intercept-build
+ modularize
+ pp-trace
+ run-clang-tidy
+ scan-build
+ scan-build-py
+ scan-view
+ "
+ for clangexe in $clangexes; do
+ ln -sfv ../lib/llvm$_llvmver/bin/$clangexe "$pkgdir"/usr/bin/$clangexe
+ done
+ ln -sfv ../lib/llvm$_llvmver/bin/clang-$_llvmver "$pkgdir"/usr/bin/clang++-$_llvmver
+
+ install -Dm644 "$builddir"/clang.1 -t "$pkgdir"/usr/share/man/man1/
+ else
+ ln -sfv ../lib/llvm$_llvmver/bin/clang-$_llvmver "$pkgdir"/usr/bin/clang-$_llvmver
+ ln -sfv ../lib/llvm$_llvmver/bin/clang-$_llvmver "$pkgdir"/usr/bin/clang++-$_llvmver
+
+ # delete things we don't want non-latest of
+ rm -r "$pkgdir"/usr/lib/llvm$_llvmver/share
+ rm -r "$pkgdir"/usr/lib/llvm$_llvmver/lib/python3*
+ fi
+
+ local libs="
+ libclang-cpp.so
+ libclang-cpp.so.$_llvmver
+ libclang.so
+ libclang.so.$_llvmver
+ libclang.so.$pkgver
+ "
+ for lib in $libs; do
+ ln -sfv ../lib/llvm$_llvmver/lib/$lib "$pkgdir"/usr/lib/$lib
+ done
+
+ # compat symlink back to fix clang with -no-canonical-prefixes
+ mkdir -p "$pkgdir"/usr/lib/clang
+ ln -sfv ../../lib/llvm$_llvmver/lib/clang/$pkgver "$pkgdir"/usr/lib/clang/$pkgver
+}
+
+dev() {
+ default_dev
+ _default_replace
+
+ # move back usr/lib/llvm*/lib/clang/x.y.z/include with files such as altivec.h, msa.h etc
+ # these are needed to build programs *with* clang, not *against* it.
+ mv "$subpkgdir"/usr/lib/llvm$_llvmver/lib/clang "$pkgdir"/usr/lib/llvm$_llvmver/lib/
+
+ # create cmakedir symlinks, so find_package works
+ # llvm does the same thing- versioned, plus unversioned default.
+ mkdir -p "$subpkgdir"/usr/lib/cmake
+ ln -sfv ../llvm$_llvmver/lib/cmake/clang "$subpkgdir"/usr/lib/cmake/clang$_llvmver
+ if [ $_default_clang = yes ]; then
+ ln -sfv clang$_llvmver "$subpkgdir"/usr/lib/cmake/clang
+ fi
+}
+
+static() {
+ default_static
+ _default_replace
+}
+
+bash() {
+ default_bashcomp
+ _default_replace
+}
+
+libs() {
+ default_libs
+ # this can fail depending on the symlinks and is already moved
+ amove usr/lib/libclang-cpp.so.* || true
+ amove usr/lib/llvm$_llvmver/lib/libclang-cpp.so.*
+ _default_replace
+}
+
+libclang() {
+ _default_replace
+ replaces="$replaces clang-libs"
+
+ # we add an extra subpackage for this so things that link to libclang don't
+ # have to pull libclang-cpp too (separate)
+ amove usr/lib/libclang.so.*
+ amove usr/lib/llvm$_llvmver/lib/libclang.so.*
+}
+
+analyzer() {
+ pkgdesc="Clang source code analysis framework"
+ depends="$pkgname=$pkgver-r$pkgrel py3-$pkgname=$pkgver-r$pkgrel perl python3"
+ _default_replace
+
+ amove \
+ usr/bin/scan* \
+ usr/bin/analyze-build* \
+ usr/bin/intercept-build* \
+ usr/lib/llvm$_llvmver/bin/scan* \
+ usr/lib/llvm$_llvmver/bin/analyze-build* \
+ usr/lib/llvm$_llvmver/bin/intercept-build* \
+ usr/lib/llvm$_llvmver/libexec/*-analyzer* \
+ usr/lib/llvm$_llvmver/libexec/analyze-* \
+ usr/lib/llvm$_llvmver/libexec/intercept-* \
+ usr/lib/llvm$_llvmver/lib/libear* \
+ usr/lib/llvm$_llvmver/share/scan-build \
+ usr/share/scan-view
+}
+
+extra() {
+ pkgdesc="Extra tools built using Clang’s tooling APIs"
+ _default_replace
+
+ amove \
+ usr/bin/clang-apply-replacements* \
+ usr/bin/clang-change-namespace* \
+ usr/bin/clang-check* \
+ usr/bin/clang-doc* \
+ usr/bin/clang-extdef-mapping* \
+ usr/bin/clang-format* \
+ usr/bin/clang-include-fixer* \
+ usr/bin/clang-move* \
+ usr/bin/clang-offload-bundler* \
+ usr/bin/clang-offload-wrapper* \
+ usr/bin/clang-query* \
+ usr/bin/clang-refactor* \
+ usr/bin/clang-rename* \
+ usr/bin/clang-reorder-fields* \
+ usr/bin/clang-repl* \
+ usr/bin/clang-scan-deps* \
+ usr/bin/clang-tidy* \
+ usr/bin/clangd* \
+ usr/bin/c-index-test* \
+ usr/bin/diagtool* \
+ usr/bin/find-all-symbols* \
+ usr/bin/git-clang-format* \
+ usr/bin/hmaptool* \
+ usr/bin/modularize* \
+ usr/bin/pp-trace* \
+ usr/bin/run-clang-tidy* \
+ usr/lib/llvm$_llvmver/bin/clang-apply-replacements* \
+ usr/lib/llvm$_llvmver/bin/clang-change-namespace* \
+ usr/lib/llvm$_llvmver/bin/clang-check* \
+ usr/lib/llvm$_llvmver/bin/clang-doc* \
+ usr/lib/llvm$_llvmver/bin/clang-extdef-mapping* \
+ usr/lib/llvm$_llvmver/bin/clang-format* \
+ usr/lib/llvm$_llvmver/bin/clang-include-fixer* \
+ usr/lib/llvm$_llvmver/bin/clang-move* \
+ usr/lib/llvm$_llvmver/bin/clang-offload-bundler* \
+ usr/lib/llvm$_llvmver/bin/clang-offload-wrapper* \
+ usr/lib/llvm$_llvmver/bin/clang-query* \
+ usr/lib/llvm$_llvmver/bin/clang-refactor* \
+ usr/lib/llvm$_llvmver/bin/clang-rename* \
+ usr/lib/llvm$_llvmver/bin/clang-reorder-fields* \
+ usr/lib/llvm$_llvmver/bin/clang-repl* \
+ usr/lib/llvm$_llvmver/bin/clang-scan-deps* \
+ usr/lib/llvm$_llvmver/bin/clang-tidy* \
+ usr/lib/llvm$_llvmver/bin/clangd* \
+ usr/lib/llvm$_llvmver/bin/c-index-test* \
+ usr/lib/llvm$_llvmver/bin/diagtool* \
+ usr/lib/llvm$_llvmver/bin/find-all-symbols* \
+ usr/lib/llvm$_llvmver/bin/git-clang-format* \
+ usr/lib/llvm$_llvmver/bin/hmaptool* \
+ usr/lib/llvm$_llvmver/bin/modularize* \
+ usr/lib/llvm$_llvmver/bin/pp-trace* \
+ usr/lib/llvm$_llvmver/bin/run-clang-tidy* \
+ usr/lib/llvm$_llvmver/share/clang/clang* \
+ usr/lib/llvm$_llvmver/share/clang/run-find-all-symbols.py
+}
+
+emacs() {
+ pkgdesc="clang plugin for emacs"
+ install_if="$pkgname-extra-tools=$pkgver-r$pkgrel emacs"
+
+ amove usr/share/emacs
+}
+
+python() {
+ pkgdesc="Clang Python Bindings"
+ depends="$pkgname-libs=$pkgver-r$pkgrel python3"
+ provides="py3-clang=$pkgver-r$pkgrel"
+ replaces="py3-clang"
+
+ amove usr/lib/python*
+}
+
+ccache() {
+ pkgdesc="$pkgdesc (ccache symlinks)"
+ install_if="$pkgname=$pkgver-r$pkgrel ccache"
+
+ mkdir -p "$subpkgdir"/usr/lib/ccache/bin
+ ln -sfv /usr/bin/ccache "$subpkgdir"/usr/lib/ccache/bin/clang-$_llvmver
+ ln -sfv /usr/bin/ccache "$subpkgdir"/usr/lib/ccache/bin/clang++-$_llvmver
+}
+
+_default_replace() {
+ if [ "$_default_clang" = yes ]; then
+ replaces="clang${subpkgname#"$pkgname"}"
+ provides="$replaces=$pkgver-r$pkgrel"
+ fi
+}
+
+sha512sums="
+9fd2736a9f5993ddbb5b3c507fe497234a6def64f6f418f379d1ca56c9c361ad1ae9a5445ab938230fbc1671ec00b4f802a412b048569023863c20dc6bb46a1f clang-15.0.7.src.tar.xz
+dd95d261d3a1618967b698e97ac0b41204d872d7479c0c832fcf5a91fe447af6a97fa794de07b3e271285867b30b905688f090e98f516b9df4cdfb3bad9defc6 clang-tools-extra-15.0.7.src.tar.xz
+85097a6eaee0df004567905f7e5ce8ca02e3b46c6fc66fa552fe99734642e6ee61685de4e5e6e8b505963334d7b91d98ecd9c5870e6bdd3f0018ee5b963ffa96 cmake-15.0.7.src.tar.xz
+5809d931656cac13b91bc91aac63df072b0403708ac718bf01546d9d520ff2c4163ee11411439dce5bb683a3bfa044b62443b6f66a1419c9086d20e79a018071 10-add-musl-triples.patch
+b9b5529bcf460767796ddbc6f7d8c479b62d63c74d39297b3c7c79a2f6898272ac52a2f2d1ea2bd601e869cecf23c0cd69fbcd613b8c6299b14a1be8203fd089 30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
+6896d6c5358b8b83c97c7cb31f60042f33a1326cfad093a0f23dcacd10ef418f845964f6de948a5873494dae5180e51a4b2b0cec937aa5597765362779da6f35 clang-default-fno-semantic-interposition.patch
+aa2dff990278e0258763934eaa528827baa1733eeb7dc36cc7f1500a4919b8d11870a0522f20f210d454322e3faf5945e9afaeffc9f3a3c4fd422b706370a663 clang-001-fortify-include.patch
+751f8acef2bfd1b50c065dea2ad0c3a20cadd4ff4c842ae519b5085c48372127b49a75d3fd0bd32291f5a69119340e5568a9fba6d94e6f354b14233986f61328 clang-002-fortify-enable.patch
+5f98f147d7d66315e9a56ae6fee602a053d40e57a8b1ee4f2ef1764203bb6fdb9082c8e825c535a9388213a38b49d2702b1e936fcf56560c4a2a56b7e6dd232c clang-003-as-needed.patch
+"
diff --git a/main/clang15/clang-001-fortify-include.patch b/main/clang15/clang-001-fortify-include.patch
new file mode 100644
index 00000000000..968c26e5131
--- /dev/null
+++ b/main/clang15/clang-001-fortify-include.patch
@@ -0,0 +1,36 @@
+From eca9994181dc355cfba61e726c038832d5ff6975 Mon Sep 17 00:00:00 2001
+From: Daniel Kolesa <daniel@octaforge.org>
+Date: Sun, 23 Oct 2022 00:47:57 +0200
+Subject: [PATCH 1/4] clang: add fortify include paths for musl triplets
+
+When we have fortify headers this lets them get included.
+---
+ lib/Driver/ToolChains/Linux.cpp | 12 ++++++++----
+ 1 file changed, 8 insertions(+), 4 deletions(-)
+
+diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp
+index 7fcdcf125..d5df4a240 100644
+--- a/lib/Driver/ToolChains/Linux.cpp
++++ b/lib/Driver/ToolChains/Linux.cpp
+@@ -622,10 +622,14 @@ void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
+ if (getTriple().getOS() == llvm::Triple::RTEMS)
+ return;
+
+- // Add an include of '/include' directly. This isn't provided by default by
+- // system GCCs, but is often used with cross-compiling GCCs, and harmless to
+- // add even when Clang is acting as-if it were a system compiler.
+- addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include"));
++ if (getTriple().isMusl()) {
++ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include/fortify"));
++ } else {
++ // Preserve original clang behavior for non-musl triples, but for musl
++ // this just gets in the way and none of our crosstoolchains are ever
++ // actually built this way (and we'd have to figure out fortify for it)
++ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/include"));
++ }
+
+ addExternCSystemInclude(DriverArgs, CC1Args, concat(SysRoot, "/usr/include"));
+
+--
+2.38.0
+
diff --git a/main/clang15/clang-002-fortify-enable.patch b/main/clang15/clang-002-fortify-enable.patch
new file mode 100644
index 00000000000..30100c9cba4
--- /dev/null
+++ b/main/clang15/clang-002-fortify-enable.patch
@@ -0,0 +1,29 @@
+From 0a876ce2825f1e54bec7059a387e43a2e0386665 Mon Sep 17 00:00:00 2001
+From: Daniel Kolesa <daniel@octaforge.org>
+Date: Sun, 23 Oct 2022 01:02:35 +0200
+Subject: [PATCH 2/4] clang: enable fortify by default on optimizing musl
+ targets
+
+---
+ lib/Frontend/InitPreprocessor.cpp | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
+index 20bfbf144..9095c0f2f 100644
+--- a/lib/Frontend/InitPreprocessor.cpp
++++ b/lib/Frontend/InitPreprocessor.cpp
+@@ -1288,6 +1288,11 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
+ Builder.defineMacro("__GLIBCXX_BITSIZE_INT_N_0", "128");
+ }
+
++ // Enable fortify by default on musl when optimizing, but not with asan
++ if (TI.getTriple().isMusl() && LangOpts.Optimize &&
++ !LangOpts.Sanitize.has(SanitizerKind::Address))
++ Builder.defineMacro("_FORTIFY_SOURCE", "2");
++
+ // Get other target #defines.
+ TI.getTargetDefines(LangOpts, Builder);
+ }
+--
+2.38.0
+
diff --git a/main/clang15/clang-003-as-needed.patch b/main/clang15/clang-003-as-needed.patch
new file mode 100644
index 00000000000..a92836fe07a
--- /dev/null
+++ b/main/clang15/clang-003-as-needed.patch
@@ -0,0 +1,31 @@
+forces as-needed regardless of ldflags
+From f59f126a9344f265e3766003766d7a66b6a638e3 Mon Sep 17 00:00:00 2001
+From: Daniel Kolesa <daniel@octaforge.org>
+Date: Sun, 23 Oct 2022 01:26:37 +0200
+Subject: [PATCH 3/4] clang: use --as-needed by default
+
+---
+ clang/lib/Driver/ToolChains/Gnu.cpp | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
+index f203cae1d..9e181a79a 100644
+--- a/lib/Driver/ToolChains/Gnu.cpp
++++ b/lib/Driver/ToolChains/Gnu.cpp
+@@ -560,6 +560,13 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
+ bool NeedsSanitizerDeps = addSanitizerRuntimes(ToolChain, Args, CmdArgs);
+ bool NeedsXRayDeps = addXRayRuntime(ToolChain, Args, CmdArgs);
+ addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
++
++ // Use --as-needed by default for all explicit linker inputs on Linux
++ // We don't reset it afterwards because explicit argument does not
++ // get reset either (and that is permitted, so it should be fine)
++ if (Triple.isOSLinux())
++ CmdArgs.push_back("--as-needed");
++
+ AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
+
+ addHIPRuntimeLibArgs(ToolChain, Args, CmdArgs);
+--
+2.38.0
+
diff --git a/main/clang15/clang-default-fno-semantic-interposition.patch b/main/clang15/clang-default-fno-semantic-interposition.patch
new file mode 100644
index 00000000000..01022aff209
--- /dev/null
+++ b/main/clang15/clang-default-fno-semantic-interposition.patch
@@ -0,0 +1,39 @@
+Patch-Source: https://github.com/chimera-linux/cports/commit/77fdf96a59bddfca32b6737335f01afaf64ff380
+reference: https://maskray.me/blog/2021-05-09-fno-semantic-interposition
+
+in general, this is not '100% safe'.
+however:
+- we only use clang in a few places
+- chimera has had good success with this flag and not seen issues
+so, it should be fine to default in our clang too. it should bring some
+noticable performance gains paired with pic.
+
+--
+From 73b8ed17fed2145b29bde40a0c658712e34d48c3 Mon Sep 17 00:00:00 2001
+From: Daniel Kolesa <daniel@octaforge.org>
+Date: Tue, 28 Feb 2023 01:59:26 +0100
+Subject: [PATCH] clang: default to -fno-semantic-interposition on supported
+ targets
+
+---
+ clang/lib/Driver/ToolChains/Clang.cpp | 4 +---
+ 1 file changed, 1 insertion(+), 3 deletions(-)
+
+diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
+index 3704ed85..d3d67a22 100644
+--- a/lib/Driver/ToolChains/Clang.cpp
++++ b/lib/Driver/ToolChains/Clang.cpp
+@@ -5072,9 +5072,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
+ // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
+ bool SupportsLocalAlias =
+ Triple.isAArch64() || Triple.isRISCV() || Triple.isX86();
+- if (!A)
+- CmdArgs.push_back("-fhalf-no-semantic-interposition");
+- else if (A->getOption().matches(options::OPT_fsemantic_interposition))
++ if (A && A->getOption().matches(options::OPT_fsemantic_interposition))
+ A->render(Args, CmdArgs);
+ else if (!SupportsLocalAlias)
+ CmdArgs.push_back("-fhalf-no-semantic-interposition");
+--
+2.39.0
+