Skip to content

Commit f4c6080

Browse files
Revert "[IR] add fn attr for no_stack_protector; prevent inlining on mismatch"
This reverts commit b7926ce. Going with a simpler approach.
1 parent dd6087c commit f4c6080

File tree

30 files changed

+17
-293
lines changed

30 files changed

+17
-293
lines changed

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3938,10 +3938,6 @@ option.
39383938

39393939
int bar(int y); // bar can be built with the stack protector.
39403940

3941-
A callee that has a stack protector will not be inlined into a
3942-
``__attribute__((no_stack_protector))`` caller, and vice-versa, even if the
3943-
callee is marked ``__attribute__((always_inline))``.
3944-
39453941
}];
39463942
}
39473943

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,14 +1642,14 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
16421642
if (!hasUnwindExceptions(LangOpts))
16431643
B.addAttribute(llvm::Attribute::NoUnwind);
16441644

1645-
if (D && D->hasAttr<NoStackProtectorAttr>())
1646-
B.addAttribute(llvm::Attribute::NoStackProtect);
1647-
else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
1648-
B.addAttribute(llvm::Attribute::StackProtect);
1649-
else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
1650-
B.addAttribute(llvm::Attribute::StackProtectStrong);
1651-
else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
1652-
B.addAttribute(llvm::Attribute::StackProtectReq);
1645+
if (!D || !D->hasAttr<NoStackProtectorAttr>()) {
1646+
if (LangOpts.getStackProtector() == LangOptions::SSPOn)
1647+
B.addAttribute(llvm::Attribute::StackProtect);
1648+
else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
1649+
B.addAttribute(llvm::Attribute::StackProtectStrong);
1650+
else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
1651+
B.addAttribute(llvm::Attribute::StackProtectReq);
1652+
}
16531653

16541654
if (!D) {
16551655
// If we don't have a declaration to control inlining, the function isn't

clang/test/CodeGen/stack-protector.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ void test2(const char *msg) {
3636
// SSPREQ: attributes #[[A]] = {{.*}} sspreq
3737

3838
// SAFESTACK-NOSSP: attributes #[[A]] = {{.*}} safestack
39-
// SAFESTACK-NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
39+
// SAFESTACK-NOSSP-NOT: ssp
4040

4141
// SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp{{ }}
4242
// SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
@@ -47,11 +47,6 @@ void test2(const char *msg) {
4747
// SSPSTRONG-NOT: attributes #[[B]] = {{.*}} sspstrong
4848
// SSPREQ-NOT: attributes #[[B]] = {{.*}} sspreq
4949

50-
// NOSSP: attributes #[[B]] = {{.*}} nossp
51-
// SSP: attributes #[[B]] = {{.*}} nossp
52-
// SSPSTRONG: attributes #[[B]] = {{.*}} nossp
53-
// SSPREQ: attributes #[[B]] = {{.*}} nossp
54-
5550
// SAFESTACK-SSP: attributes #[[B]] = {{.*}} safestack
5651
// SAFESTACK-SSP-NOT: attributes #[[B]] = {{.*}} safestack ssp{{ }}
5752
// SAFESTACK-SSPSTRONG: attributes #[[B]] = {{.*}} safestack

clang/test/Frontend/optimization-remark-missed-inline-stack-protectors.c

Lines changed: 0 additions & 34 deletions
This file was deleted.

llvm/bindings/go/llvm/ir_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func TestAttributes(t *testing.T) {
7878
"returns_twice",
7979
"signext",
8080
"safestack",
81-
"nossp",
8281
"ssp",
8382
"sspreq",
8483
"sspstrong",

llvm/bindings/ocaml/llvm/llvm.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ module Attribute = struct
122122
| Noinline
123123
| Alwaysinline
124124
| Optsize
125-
| Nossp
126125
| Ssp
127126
| Sspreq
128127
| Alignment of int

llvm/docs/BitCodeFormat.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,6 @@ The integer codes are mapped to well-known attributes as follows.
10701070
* code 68: ``noundef``
10711071
* code 69: ``byref``
10721072
* code 70: ``mustprogress``
1073-
* code 71: ``nossp``
10741073

10751074
.. note::
10761075
The ``allocsize`` attribute has a special encoding for its arguments. Its two

llvm/docs/LangRef.rst

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,22 +1825,6 @@ example:
18251825
undefined behavior, the undefined behavior may be observed even
18261826
if the call site is dead code.
18271827

1828-
``nossp``
1829-
This attribute indicates the function should not emit a stack smashing
1830-
protector. This is useful for code that intentionally manipulates the stack
1831-
canary, such as operating system kernel code that must save/restore such
1832-
canary values on context switch.
1833-
1834-
If a function with the ``nossp`` attribute calls a callee function that has
1835-
a stack protector function attribute, such as ``ssp``, ``sspreq``, or
1836-
``sspstrong`` (or vice-versa), then the callee will not be inline
1837-
substituted into the caller. Even when the callee is ``alwaysinline``, the
1838-
above holds.
1839-
1840-
Such inlining might break assumptions in the function that was built
1841-
without stack protection. This permits the functions that would have stack
1842-
protection to retain their stack protector.
1843-
18441828
``ssp``
18451829
This attribute indicates that the function should emit a stack
18461830
smashing protector. It is in the form of a "canary" --- a random value

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,6 @@ enum AttributeKindCodes {
652652
ATTR_KIND_NOUNDEF = 68,
653653
ATTR_KIND_BYREF = 69,
654654
ATTR_KIND_MUSTPROGRESS = 70,
655-
ATTR_KIND_NO_STACK_PROTECT = 71,
656655
};
657656

658657
enum ComdatSelectionKindCodes {

llvm/include/llvm/IR/Attributes.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ def StackAlignment : IntAttr<"alignstack">;
191191
/// Function can be speculated.
192192
def Speculatable : EnumAttr<"speculatable">;
193193

194-
/// Stack protection explicitly disabled.
195-
def NoStackProtect : EnumAttr<"nossp">;
196-
197194
/// Stack protection.
198195
def StackProtect : EnumAttr<"ssp">;
199196

llvm/lib/AsmParser/LLLexer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ lltok::Kind LLLexer::LexIdentifier() {
679679
KEYWORD(signext);
680680
KEYWORD(speculatable);
681681
KEYWORD(sret);
682-
KEYWORD(nossp);
683682
KEYWORD(ssp);
684683
KEYWORD(sspreq);
685684
KEYWORD(sspstrong);

llvm/lib/AsmParser/LLParser.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,9 +1377,6 @@ bool LLParser::parseFnAttributeValuePairs(AttrBuilder &B,
13771377
case lltok::kw_returns_twice:
13781378
B.addAttribute(Attribute::ReturnsTwice); break;
13791379
case lltok::kw_speculatable: B.addAttribute(Attribute::Speculatable); break;
1380-
case lltok::kw_nossp:
1381-
B.addAttribute(Attribute::NoStackProtect);
1382-
break;
13831380
case lltok::kw_ssp: B.addAttribute(Attribute::StackProtect); break;
13841381
case lltok::kw_sspreq: B.addAttribute(Attribute::StackProtectReq); break;
13851382
case lltok::kw_sspstrong:
@@ -1791,7 +1788,6 @@ bool LLParser::parseOptionalParamAttrs(AttrBuilder &B) {
17911788
case lltok::kw_sanitize_memory:
17921789
case lltok::kw_sanitize_thread:
17931790
case lltok::kw_speculative_load_hardening:
1794-
case lltok::kw_nossp:
17951791
case lltok::kw_ssp:
17961792
case lltok::kw_sspreq:
17971793
case lltok::kw_sspstrong:
@@ -1900,7 +1896,6 @@ bool LLParser::parseOptionalReturnAttrs(AttrBuilder &B) {
19001896
case lltok::kw_sanitize_memory:
19011897
case lltok::kw_sanitize_thread:
19021898
case lltok::kw_speculative_load_hardening:
1903-
case lltok::kw_nossp:
19041899
case lltok::kw_ssp:
19051900
case lltok::kw_sspreq:
19061901
case lltok::kw_sspstrong:

llvm/lib/AsmParser/LLToken.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ enum Kind {
224224
kw_returns_twice,
225225
kw_signext,
226226
kw_speculatable,
227-
kw_nossp,
228227
kw_ssp,
229228
kw_sspreq,
230229
kw_sspstrong,

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,8 +700,6 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
700700
return bitc::ATTR_KIND_SPECULATABLE;
701701
case Attribute::StackAlignment:
702702
return bitc::ATTR_KIND_STACK_ALIGNMENT;
703-
case Attribute::NoStackProtect:
704-
return bitc::ATTR_KIND_NO_STACK_PROTECT;
705703
case Attribute::StackProtect:
706704
return bitc::ATTR_KIND_STACK_PROTECT;
707705
case Attribute::StackProtectReq:

llvm/lib/CodeGen/StackProtector.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,13 @@ static const CallInst *findStackProtectorIntrinsic(Function &F) {
270270
/// regardless of size, functions with any buffer regardless of type and size,
271271
/// functions with aggregates that contain any buffer regardless of type and
272272
/// size, and functions that contain stack-based variables that have had their
273-
/// address taken. The heuristic will be disregarded for functions explicitly
274-
/// marked nossp.
273+
/// address taken.
275274
bool StackProtector::RequiresStackProtector() {
276275
bool Strong = false;
277276
bool NeedsProtector = false;
278277
HasPrologue = findStackProtectorIntrinsic(*F);
279278

280-
if (F->hasFnAttribute(Attribute::SafeStack) ||
281-
F->hasFnAttribute(Attribute::NoStackProtect))
279+
if (F->hasFnAttribute(Attribute::SafeStack))
282280
return false;
283281

284282
// We are constructing the OptimizationRemarkEmitter on the fly rather than

llvm/lib/IR/Attributes.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,6 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
425425
return "speculative_load_hardening";
426426
if (hasAttribute(Attribute::Speculatable))
427427
return "speculatable";
428-
if (hasAttribute(Attribute::NoStackProtect))
429-
return "nossp";
430428
if (hasAttribute(Attribute::StackProtect))
431429
return "ssp";
432430
if (hasAttribute(Attribute::StackProtectReq))
@@ -1941,17 +1939,9 @@ static void setOR(Function &Caller, const Function &Callee) {
19411939
/// If the inlined function had a higher stack protection level than the
19421940
/// calling function, then bump up the caller's stack protection level.
19431941
static void adjustCallerSSPLevel(Function &Caller, const Function &Callee) {
1944-
assert(!(Callee.hasFnAttribute(Attribute::NoStackProtect) &&
1945-
(Caller.hasFnAttribute(Attribute::StackProtect) ||
1946-
Caller.hasFnAttribute(Attribute::StackProtectStrong) ||
1947-
Caller.hasFnAttribute(Attribute::StackProtectReq))) &&
1948-
"stack protected caller but callee requested no stack protector");
1949-
assert(!(Caller.hasFnAttribute(Attribute::NoStackProtect) &&
1950-
(Callee.hasFnAttribute(Attribute::StackProtect) ||
1951-
Callee.hasFnAttribute(Attribute::StackProtectStrong) ||
1952-
Callee.hasFnAttribute(Attribute::StackProtectReq))) &&
1953-
"stack protected callee but caller requested no stack protector");
19541942
// If upgrading the SSP attribute, clear out the old SSP Attributes first.
1943+
// Having multiple SSP attributes doesn't actually hurt, but it adds useless
1944+
// clutter to the IR.
19551945
AttrBuilder OldSSPAttr;
19561946
OldSSPAttr.addAttribute(Attribute::StackProtect)
19571947
.addAttribute(Attribute::StackProtectStrong)

llvm/lib/IR/Verifier.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,6 @@ static bool isFuncOnlyAttr(Attribute::AttrKind Kind) {
16021602
case Attribute::NoInline:
16031603
case Attribute::AlwaysInline:
16041604
case Attribute::OptimizeForSize:
1605-
case Attribute::NoStackProtect:
16061605
case Attribute::StackProtect:
16071606
case Attribute::StackProtectReq:
16081607
case Attribute::StackProtectStrong:
@@ -1998,19 +1997,6 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, AttributeList Attrs,
19981997
CheckFailed(
19991998
"\"patchable-function-entry\" takes an unsigned integer: " + S, V);
20001999
}
2001-
{
2002-
unsigned N = 0;
2003-
if (Attrs.hasFnAttribute(Attribute::NoStackProtect))
2004-
++N;
2005-
if (Attrs.hasFnAttribute(Attribute::StackProtect))
2006-
++N;
2007-
if (Attrs.hasFnAttribute(Attribute::StackProtectReq))
2008-
++N;
2009-
if (Attrs.hasFnAttribute(Attribute::StackProtectStrong))
2010-
++N;
2011-
Assert(N < 2,
2012-
"nossp, ssp, sspreq, sspstrong fn attrs are mutually exclusive", V);
2013-
}
20142000
}
20152001

20162002
void Verifier::verifyFunctionMetadata(

llvm/lib/Transforms/IPO/ForceFunctionAttrs.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ static Attribute::AttrKind parseAttrKind(StringRef Kind) {
6868
.Case("sanitize_thread", Attribute::SanitizeThread)
6969
.Case("sanitize_memtag", Attribute::SanitizeMemTag)
7070
.Case("speculative_load_hardening", Attribute::SpeculativeLoadHardening)
71-
.Case("nossp", Attribute::NoStackProtect)
7271
.Case("ssp", Attribute::StackProtect)
7372
.Case("sspreq", Attribute::StackProtectReq)
7473
.Case("sspstrong", Attribute::StackProtectStrong)

llvm/lib/Transforms/Utils/CodeExtractor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,6 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
965965
case Attribute::SanitizeHWAddress:
966966
case Attribute::SanitizeMemTag:
967967
case Attribute::SpeculativeLoadHardening:
968-
case Attribute::NoStackProtect:
969968
case Attribute::StackProtect:
970969
case Attribute::StackProtectReq:
971970
case Attribute::StackProtectStrong:

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,22 +1667,6 @@ llvm::InlineResult llvm::InlineFunction(CallBase &CB, InlineFunctionInfo &IFI,
16671667
return InlineResult::failure("incompatible GC");
16681668
}
16691669

1670-
// Inlining a function that explicitly should not have a stack protector may
1671-
// break the code if inlined into a function that does have a stack
1672-
// protector.
1673-
if (LLVM_UNLIKELY(Caller->hasFnAttribute(Attribute::NoStackProtect)))
1674-
if (CalledFunc->hasFnAttribute(Attribute::StackProtect) ||
1675-
CalledFunc->hasFnAttribute(Attribute::StackProtectStrong) ||
1676-
CalledFunc->hasFnAttribute(Attribute::StackProtectReq))
1677-
return InlineResult::failure(
1678-
"stack protected callee but caller requested no stack protector");
1679-
if (LLVM_UNLIKELY(CalledFunc->hasFnAttribute(Attribute::NoStackProtect)))
1680-
if (Caller->hasFnAttribute(Attribute::StackProtect) ||
1681-
Caller->hasFnAttribute(Attribute::StackProtectStrong) ||
1682-
Caller->hasFnAttribute(Attribute::StackProtectReq))
1683-
return InlineResult::failure(
1684-
"stack protected caller but callee requested no stack protector");
1685-
16861670
// Get the personality function from the callee if it contains a landing pad.
16871671
Constant *CalledPersonality =
16881672
CalledFunc->hasPersonalityFn()

llvm/test/CodeGen/X86/stack-protector-2.ll

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: llc -mtriple=x86_64-pc-linux-gnu -start-before=stack-protector -stop-after=stack-protector -o - < %s | FileCheck %s
2-
; Bugs 42238/43308/47479: Test some additional situations not caught previously.
2+
; Bugs 42238/43308: Test some additional situations not caught previously.
33

44
define void @store_captures() #0 {
55
; CHECK-LABEL: @store_captures(
@@ -162,31 +162,4 @@ entry:
162162

163163
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg)
164164

165-
166-
; Test that the same function does not get a canary if nossp fn attr is set.
167-
declare dso_local void @foo(i8*)
168-
169-
define dso_local void @bar_sspstrong(i64 %0) #0 {
170-
; CHECK-LABEL: @bar_sspstrong
171-
; CHECK-NEXT: %StackGuardSlot = alloca i8*
172-
%2 = alloca i64, align 8
173-
store i64 %0, i64* %2, align 8
174-
%3 = load i64, i64* %2, align 8
175-
%4 = alloca i8, i64 %3, align 16
176-
call void @foo(i8* %4)
177-
ret void
178-
}
179-
180-
define dso_local void @bar_nossp(i64 %0) #1 {
181-
; CHECK-LABEL: @bar_nossp
182-
; CHECK-NEXT: %2 = alloca i64
183-
%2 = alloca i64, align 8
184-
store i64 %0, i64* %2, align 8
185-
%3 = load i64, i64* %2, align 8
186-
%4 = alloca i8, i64 %3, align 16
187-
call void @foo(i8* %4)
188-
ret void
189-
}
190-
191165
attributes #0 = { sspstrong }
192-
attributes #1 = { nossp }

llvm/test/Transforms/CodeExtractor/PartialInlineAttributes.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ entry:
7373
attributes #0 = {
7474
inlinehint minsize noduplicate noimplicitfloat norecurse noredzone nounwind
7575
nonlazybind optsize safestack sanitize_address sanitize_hwaddress sanitize_memory
76-
sanitize_thread sspstrong strictfp uwtable "foo"="bar"
76+
sanitize_thread ssp sspreq sspstrong strictfp uwtable "foo"="bar"
7777
"patchable-function"="prologue-short-redirect" "probe-stack"="_foo_guard" "stack-probe-size"="4096" }
7878

79-
; CHECK: attributes [[FN_ATTRS]] = { inlinehint minsize noduplicate noimplicitfloat norecurse noredzone nounwind nonlazybind optsize safestack sanitize_address sanitize_hwaddress sanitize_memory sanitize_thread sspstrong strictfp uwtable "foo"="bar" "patchable-function"="prologue-short-redirect" "probe-stack"="_foo_guard" "stack-probe-size"="4096" }
79+
; CHECK: attributes [[FN_ATTRS]] = { inlinehint minsize noduplicate noimplicitfloat norecurse noredzone nounwind nonlazybind optsize safestack sanitize_address sanitize_hwaddress sanitize_memory sanitize_thread ssp sspreq sspstrong strictfp uwtable "foo"="bar" "patchable-function"="prologue-short-redirect" "probe-stack"="_foo_guard" "stack-probe-size"="4096" }
8080

8181
; attributes to drop
8282
attributes #1 = {

0 commit comments

Comments
 (0)