main/clang16: new aport

https://llvm.org/
A C language family front-end for LLVM
This commit is contained in:
psykose 2023-02-09 04:44:06 +00:00
parent 96c06fa11e
commit f3ea45a72c
7 changed files with 646 additions and 0 deletions

View file

@ -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"};

View file

@ -0,0 +1,90 @@
diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
index 4f234031..a8f501a1 100644
--- a/lib/Driver/ToolChains/Gnu.cpp
+++ b/lib/Driver/ToolChains/Gnu.cpp
@@ -573,6 +573,10 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
// 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/lib/Driver/ToolChains/Linux.h b/lib/Driver/ToolChains/Linux.h
index 52439174..d754b543 100644
--- 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 {
@@ -63,7 +64,15 @@ public:
const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
const llvm::fltSemantics *FPType = nullptr) const override;
const char *getDefaultLinker() 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;
diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c
index 8ad6dc25..1619b59a 100644
--- a/test/Driver/fsanitize.c
+++ b/test/Driver/fsanitize.c
@@ -695,12 +695,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"
diff --git a/test/Driver/stack-protector.c b/test/Driver/stack-protector.c
index 16937691..80987f67 100644
--- 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

382
main/clang16/APKBUILD Normal file
View file

@ -0,0 +1,382 @@
# 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=clang16
pkgver=16.0.0
pkgrel=0
_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
"
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
mv "$srcdir"/cmake-${pkgver//_/}.src "$srcdir"/cmake
}
# Whether is this package the default (latest) clang version.
_default_clang="yes"
if [ "$_default_clang" = yes ]; then
subpackages="
$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
local onlymain=OFF
else
local extras=OFF
local onlymain=ON
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 \
-DLLVM_INSTALL_TOOLCHAIN_ONLY=$onlymain
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
amdgpu-arch
c-index-test
clang
clang-cl
clang-cpp
clang-linker-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-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
nvptx-arch
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
install -Dm644 "$builddir"/clang.1 -t "$pkgdir"/usr/share/man/man1/
else
# only has things we want to put in the main version
# rm -rf "$pkgdir"/usr/share
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 Clangs tooling APIs"
_default_replace
amove \
usr/bin/amdgpu-arch \
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-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/nvptx-arch \
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-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*
}
_default_replace() {
if [ "$_default_clang" = yes ]; then
replaces="clang${subpkgname#"$pkgname"}"
provides="$replaces=$pkgver-r$pkgrel"
fi
}
sha512sums="
2a6ff3b4d61b4e9fcb60a6d9dae451170cd91acc25f924a29c18c579ee78af76d2d5eebb2940d61676e2e791fb247ccf9f5377b5528f3a0fa7dd0ac8e72816ba clang-16.0.0.src.tar.xz
a96498a3ce72cfa1be783455bbdbbde22ee3842652c584cabbae8ca0658ad394ede479cad1d8535bc1c5dc95a52551a059394e968d69b3e9745a95229aecdcc2 clang-tools-extra-16.0.0.src.tar.xz
4f21461aa8165061dbea47dcda4f098957e16bd307484bcb66884cf5a0776197f69a74002d5601229c4630db53ac44049f3f2ce1e96a6bb16ba3df828d387932 cmake-16.0.0.src.tar.xz
5809d931656cac13b91bc91aac63df072b0403708ac718bf01546d9d520ff2c4163ee11411439dce5bb683a3bfa044b62443b6f66a1419c9086d20e79a018071 10-add-musl-triples.patch
92653a1197e2fab42ba81c00cb5f8b3a6c42c8f88d4cf3d0eff71db50f8c7c745f816681540d8b0e2275c8fa7f82bc3af33623eb1c81028a62269ea21821142f 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
"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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