projects/aports·blob master · refs

89 lines · 4.1 KiB

1diff --git a/lib/Driver/ToolChains/Gnu.cpp b/lib/Driver/ToolChains/Gnu.cpp
2index 4f23403..da6883e 100644
3--- a/lib/Driver/ToolChains/Gnu.cpp
4+++ b/lib/Driver/ToolChains/Gnu.cpp
5@@ -565,6 +565,10 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
6 CmdArgs.push_back("-lm");
7 }
8
9+ if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, options::OPT_nodefaultlibs)) {
10+ CmdArgs.push_back("-lssp_nonshared");
11+ }
12+
13 // Silence warnings when linking C code with a C++ '-stdlib' argument.
14 Args.ClaimAllArgs(options::OPT_stdlib_EQ);
15
16diff --git a/lib/Driver/ToolChains/Linux.h b/lib/Driver/ToolChains/Linux.h
17index 52439174..d754b543 100644
18--- a/lib/Driver/ToolChains/Linux.h
19+++ b/lib/Driver/ToolChains/Linux.h
20@@ -11,6 +11,7 @@
21
22 #include "Gnu.h"
23 #include "clang/Driver/ToolChain.h"
24+#include "clang/Basic/LangOptions.h"
25
26 namespace clang {
27 namespace driver {
28@@ -60,6 +61,14 @@ public:
29 std::vector<std::string> ExtraOpts;
30
31 const char *getDefaultLinker() const override;
32+ LangOptions::StackProtectorMode
33+ GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
34+ StringRef VendorName = Linux::getTriple().getVendorName();
35+ if (VendorName.compare("alpine") == 0)
36+ return LangOptions::SSPStrong;
37+
38+ return LangOptions::SSPOff;
39+ }
40
41 protected:
42 Tool *buildAssembler() const override;
43diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c
44index 8ad6dc25..1619b59a 100644
45--- a/test/Driver/fsanitize.c
46+++ b/test/Driver/fsanitize.c
47@@ -715,12 +715,12 @@
48 // RUN: %clang -fno-sanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NOSP
49 // NOSP-NOT: "-fsanitize=safe-stack"
50
51-// RUN: %clang --target=x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
52+// RUN: %clang --target=x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
53 // RUN: not %clang --target=x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP-ASAN
54 // RUN: %clang --target=x86_64-linux-gnu -fstack-protector -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
55 // RUN: %clang --target=x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP
56-// RUN: %clang --target=arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
57-// RUN: %clang --target=aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP
58+// RUN: %clang --target=arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
59+// RUN: %clang --target=aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP
60 // NO-SP-NOT: stack-protector
61 // NO-SP: "-fsanitize=safe-stack"
62 // SP-ASAN: error: invalid argument '-fsanitize=safe-stack' not allowed with '-fsanitize=address'
63diff --git a/test/Driver/stack-protector.c b/test/Driver/stack-protector.c
64index 16937691..80987f67 100644
65--- a/test/Driver/stack-protector.c
66+++ b/test/Driver/stack-protector.c
67@@ -33,6 +33,22 @@
68 // SSP-PS4-BUF: "-stack-protector" "2"
69 // SSP-PS4-BUF: "-stack-protector-buffer-size" "16"
70
71+// Test default stack protector values for Alpine
72+
73+// RUN: %clang -target x86_64-alpine-linux-musl -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE
74+// ALPINE: "-stack-protector" "2"
75+
76+// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_SPS
77+// ALPINE_SPS: "-stack-protector" "2"
78+
79+// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_ALL
80+// ALPINE_ALL: "-stack-protector" "3"
81+// ALPINE_ALL-NOT: "-stack-protector-buffer-size"
82+
83+// RUN: %clang -target x86_64-alpine-linux-musl -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_NOSSP
84+// ALPINE_NOSSP-NOT: "-stack-protector"
85+// ALPINE_NOSSP-NOT: "-stack-protector-buffer-size"
86+
87 // Test default stack protector values for Darwin platforms
88
89 // RUN: %clang -target armv7k-apple-watchos2.0 -### %s 2>&1 | FileCheck %s -check-prefix=SSP_WATCHOS