1
0
Fork 0
mirror of https://gitlab.alpinelinux.org/alpine/aports.git synced 2025-07-12 18:59:50 +03:00
aports/main/llvm18/30-Enable-stack-protector-by-default-for-Alpine-Linux.patch
Celeste 2d9bf42105 main/llvm18: include clang and lld in projects to build
-DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;lld"

also, sort Contributors by last name
2025-07-10 04:17:04 +00:00

84 lines
3.8 KiB
Diff

--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -561,6 +561,13 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-lm");
}
+ if (Triple.isMusl() &&
+ !Args.hasArg(options::OPT_nostdlib,
+ options::OPT_nostartfiles,
+ options::OPT_nodefaultlibs)) {
+ CmdArgs.push_back("-lssp_nonshared");
+ }
+
// Silence warnings when linking C code with a C++ '-stdlib' argument.
Args.ClaimAllArgs(options::OPT_stdlib_EQ);
--- a/clang/lib/Driver/ToolChains/Linux.h
+++ b/clang/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 {
@@ -64,6 +65,14 @@ public:
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;
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -700,12 +700,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: not %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
// NO-SP-NOT: stack-protector
// NO-SP: "-fsanitize=safe-stack"
// SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with '-fsanitize=address'
--- a/clang/test/Driver/stack-protector.c
+++ b/clang/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