hi,
currently building mozillas, i get tons of this on stderr:
warning: clang-13: warning: argument unused during compilation:
'-fstack-clash-protection' [-Wunused-command-line-argument]
filed an upstream issue about it
(https://bugzilla.mozilla.org/show_bug.cgi?id=1852202) to realize its an
llvm feature that was originally added in llvm 11
(https://reviews.llvm.org/D68720), but only enabled on
linux, and later on (14 or 15) in FreeBSD
(https://github.com/llvm/llvm-project/blob/b0ea2790c41db65b3c283f78a5f534bc26fc6f8f/clang/lib/Driver/ToolChains/Clang.cpp#L3476)
- according to
https://reviews.llvm.org/D68720#2415629 it should have been enabled
everywhere. In mozilla-land of course the flag is added if clang > 11 is
found on non-osx/non-windows, which includes OpenBSD, which triggers the
-Wunused-command-line-argument warning.
it's to protect against
https://www.qualys.com/2017/06/19/stack-clash/stack-clash.txt
the attached patch enables it in both ports llvm flavors. Been able to
build firefox with way less noise on stderr with that.
ofc, this can/should also be enabled in base llvm.
Landry
Index: 13/Makefile
===================================================================
RCS file: /cvs/ports/devel/llvm/13/Makefile,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile
--- 13/Makefile 8 Sep 2023 14:11:33 -0000 1.6
+++ 13/Makefile 11 Sep 2023 06:44:34 -0000
@@ -2,7 +2,7 @@ LLVM_MAJOR = 13
LLVM_VERSION = ${LLVM_MAJOR}.0.0
LLVM_PKGSPEC = >=13,<14
-REVISION-main = 11
+REVISION-main = 12
REVISION-lldb = 4
REVISION-python = 3
Index: 13/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp
===================================================================
RCS file:
/cvs/ports/devel/llvm/13/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-clang_lib_Driver_ToolChains_Clang_cpp
--- 13/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp 3 Sep 2023
15:59:27 -0000 1.1.1.1
+++ 13/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp 11 Sep 2023
06:44:34 -0000
@@ -39,6 +39,7 @@
- Turn on pointer-authentication on arm64 as well by default. This means
we effectively enable -mbranch-protection=standard on arm64 now.
- Make sure -msign-return-address doesn't disable BTI support.
+- Enable -fstack-clash-protection on OpenBSD
Index: clang/lib/Driver/ToolChains/Clang.cpp
--- clang/lib/Driver/ToolChains/Clang.cpp.orig
@@ -80,6 +81,15 @@ Index: clang/lib/Driver/ToolChains/Clang
MipsTargetFeature = llvm::StringSwitch<const char *>(Value)
.Case("-mips1", "+mips1")
+@@ -3180,7 +3194,7 @@ static void RenderSCPOptions(const ToolChain &TC, cons
+ ArgStringList &CmdArgs) {
+ const llvm::Triple &EffectiveTriple = TC.getEffectiveTriple();
+
+- if (!EffectiveTriple.isOSLinux())
++ if (!EffectiveTriple.isOSOpenBSD() && !EffectiveTriple.isOSLinux())
+ return;
+
+ if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
@@ -4943,9 +4957,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
// We turn strict aliasing off by default if we're in CL mode, since MSVC
Index: 16/Makefile
===================================================================
RCS file: /cvs/ports/devel/llvm/16/Makefile,v
retrieving revision 1.7
diff -u -p -r1.7 Makefile
--- 16/Makefile 8 Sep 2023 14:11:33 -0000 1.7
+++ 16/Makefile 11 Sep 2023 06:44:34 -0000
@@ -2,7 +2,7 @@ LLVM_MAJOR = 16
LLVM_VERSION = ${LLVM_MAJOR}.0.6
LLVM_PKGSPEC = >=16,<17
-REVISION-main = 5
+REVISION-main = 6
REVISION-lldb = 1
REVISION-python = 0
Index: 16/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp
===================================================================
RCS file:
/cvs/ports/devel/llvm/16/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 patch-clang_lib_Driver_ToolChains_Clang_cpp
--- 16/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp 3 Sep 2023
16:00:03 -0000 1.1.1.1
+++ 16/patches/patch-clang_lib_Driver_ToolChains_Clang_cpp 11 Sep 2023
06:44:34 -0000
@@ -27,7 +27,17 @@ Index: clang/lib/Driver/ToolChains/Clang
MipsTargetFeature = llvm::StringSwitch<const char *>(Value)
.Case("-mips1", "+mips1")
-@@ -5289,9 +5301,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -3363,7 +3375,8 @@ static void RenderSCPOptions(const ToolChain &TC, cons
+ ArgStringList &CmdArgs) {
+ const llvm::Triple &EffectiveTriple = TC.getEffectiveTriple();
+
+- if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSLinux())
++ if (!EffectiveTriple.isOSFreeBSD() && !EffectiveTriple.isOSOpenBSD() &&
++ !EffectiveTriple.isOSLinux())
+ return;
+
+ if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
+@@ -5289,9 +5302,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
// We turn strict aliasing off by default if we're in CL mode, since MSVC
// doesn't do any TBAA.
@@ -42,7 +52,7 @@ Index: clang/lib/Driver/ToolChains/Clang
CmdArgs.push_back("-relaxed-aliasing");
if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
options::OPT_fno_struct_path_tbaa, true))
-@@ -6321,7 +6336,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6321,7 +6337,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
options::OPT_fno_strict_overflow)) {
if (A->getOption().matches(options::OPT_fno_strict_overflow))
CmdArgs.push_back("-fwrapv");
@@ -52,7 +62,7 @@ Index: clang/lib/Driver/ToolChains/Clang
if (Arg *A = Args.getLastArg(options::OPT_freroll_loops,
options::OPT_fno_reroll_loops))
-@@ -6342,7 +6358,48 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6342,7 +6359,48 @@ void Clang::ConstructJob(Compilation &C, const JobActi
Args.addOptInFlag(CmdArgs, options::OPT_mspeculative_load_hardening,
options::OPT_mno_speculative_load_hardening);
@@ -102,7 +112,7 @@ Index: clang/lib/Driver/ToolChains/Clang
RenderSCPOptions(TC, Args, CmdArgs);
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);
-@@ -6417,6 +6474,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6417,6 +6475,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
CmdArgs.push_back(
Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
@@ -114,7 +124,7 @@ Index: clang/lib/Driver/ToolChains/Clang
}
if (Arg *A = Args.getLastArg(options::OPT_mfunction_return_EQ))
-@@ -6895,6 +6957,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -6895,6 +6958,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
options::OPT_fno_rewrite_imports, false);
if (RewriteImports)
CmdArgs.push_back("-frewrite-imports");