[llvm] cd20a18 - Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView"
Sylvestre Ledru via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 01:54:37 PDT 2022
Author: Sylvestre Ledru
Date: 2022-09-13T10:53:59+02:00
New Revision: cd20a1828605887699579789b5433111d5bc0319
URL: https://github.com/llvm/llvm-project/commit/cd20a1828605887699579789b5433111d5bc0319
DIFF: https://github.com/llvm/llvm-project/commit/cd20a1828605887699579789b5433111d5bc0319.diff
LOG: Revert "[clang, llvm] Add __declspec(safebuffers), support it in CodeView"
Causing:
https://github.com/llvm/llvm-project/issues/57709
This reverts commit ab56719acd98778fb2e48fa425ac7c8d27bdea86.
Added:
Modified:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/Parser/MicrosoftExtensions.c
llvm/include/llvm/BinaryFormat/COFF.h
llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/X86/X86AsmPrinter.cpp
llvm/test/DebugInfo/COFF/frameproc-flags.ll
llvm/test/DebugInfo/COFF/multifunction.ll
llvm/test/DebugInfo/COFF/simple.ll
llvm/test/DebugInfo/COFF/vframe-fpo.ll
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index af0e08654014..0ad59b2c153a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -2080,19 +2080,12 @@ def NotTailCalled : InheritableAttr {
def : MutualExclusions<[AlwaysInline, NotTailCalled]>;
def NoStackProtector : InheritableAttr {
- let Spellings = [Clang<"no_stack_protector">, Declspec<"safebuffers">];
+ let Spellings = [Clang<"no_stack_protector">];
let Subjects = SubjectList<[Function]>;
let Documentation = [NoStackProtectorDocs];
let SimpleHandler = 1;
}
-def StrictGuardStackCheck : InheritableAttr {
- let Spellings = [Declspec<"strict_gs_check">];
- let Subjects = SubjectList<[Function]>;
- let Documentation = [StrictGuardStackCheckDocs];
- let SimpleHandler = 1;
-}
-
def NoThrow : InheritableAttr {
let Spellings = [GCC<"nothrow">, Declspec<"nothrow">];
let Subjects = SubjectList<[FunctionLike]>;
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index b6c15c92d581..68f1268ed7da 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -4453,8 +4453,7 @@ spelled "XYZ" in the `OpenMP 5.1 Standard`_).
def NoStackProtectorDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
-Clang supports the ``__attribute__((no_stack_protector))`` and Microsoft style
-``__declspec(safebuffers)`` attribute which disables
+Clang supports the ``__attribute__((no_stack_protector))`` attribute which disables
the stack protector on the specified function. This attribute is useful for
selectively disabling the stack protector on some functions when building with
``-fstack-protector`` compiler option.
@@ -4473,27 +4472,6 @@ option.
}];
}
-def StrictGuardStackCheckDocs : Documentation {
- let Category = DocCatFunction;
- let Content = [{
-Clang supports the Microsoft style ``__declspec((strict_gs_check))`` attribute
-which upgrades the stack protector check from ``-fstack-protector`` to
-``-fstack-protector-strong``.
-
-For example, it upgrades the stack protector for the function ``foo`` to
-``-fstack-protector-strong`` but function ``bar`` will still be built with the
-stack protector with the ``-fstack-protector`` option.
-
-.. code-block:: c
-
- __declspec((strict_gs_check))
- int foo(int x); // stack protection will be upgraded for foo.
-
- int bar(int y); // bar can be built with the standard stack protector checks.
-
- }];
-}
-
def NotTailCalledDocs : Documentation {
let Category = DocCatFunction;
let Content = [{
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index bbd42956a4b0..9edd618d359b 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1970,17 +1970,14 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
if (!hasUnwindExceptions(LangOpts))
B.addAttribute(llvm::Attribute::NoUnwind);
- if (D && D->hasAttr<NoStackProtectorAttr>())
- ; // Do nothing.
- else if (D && D->hasAttr<StrictGuardStackCheckAttr>() &&
- LangOpts.getStackProtector() == LangOptions::SSPOn)
- B.addAttribute(llvm::Attribute::StackProtectStrong);
- else if (LangOpts.getStackProtector() == LangOptions::SSPOn)
- B.addAttribute(llvm::Attribute::StackProtect);
- else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
- B.addAttribute(llvm::Attribute::StackProtectStrong);
- else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
- B.addAttribute(llvm::Attribute::StackProtectReq);
+ if (!D || !D->hasAttr<NoStackProtectorAttr>()) {
+ if (LangOpts.getStackProtector() == LangOptions::SSPOn)
+ B.addAttribute(llvm::Attribute::StackProtect);
+ else if (LangOpts.getStackProtector() == LangOptions::SSPStrong)
+ B.addAttribute(llvm::Attribute::StackProtectStrong);
+ else if (LangOpts.getStackProtector() == LangOptions::SSPReq)
+ B.addAttribute(llvm::Attribute::StackProtectReq);
+ }
if (!D) {
// If we don't have a declaration to control inlining, the function isn't
diff --git a/clang/test/Parser/MicrosoftExtensions.c b/clang/test/Parser/MicrosoftExtensions.c
index 619f90990212..92cfb042ac22 100644
--- a/clang/test/Parser/MicrosoftExtensions.c
+++ b/clang/test/Parser/MicrosoftExtensions.c
@@ -5,7 +5,7 @@ typedef int (__cdecl *tptr)(void);
void (*__fastcall fastpfunc)(void);
extern __declspec(dllimport) void __stdcall VarR4FromDec(void);
__declspec(deprecated) __declspec(deprecated) char * __cdecl ltoa( long _Val, char * _DstBuf, int _Radix);
-__declspec(safebuffers) __declspec(noalias) __declspec(restrict) void * __cdecl xxx(void *_Memory);
+__declspec(safebuffers) __declspec(noalias) __declspec(restrict) void * __cdecl xxx(void *_Memory); /* expected-warning{{__declspec attribute 'safebuffers' is not supported}} */
typedef __w64 unsigned long ULONG_PTR, *PULONG_PTR;
void * __ptr64 PtrToPtr64(const void *p) {
diff --git a/llvm/include/llvm/BinaryFormat/COFF.h b/llvm/include/llvm/BinaryFormat/COFF.h
index c9b1174c9eaa..08a8b48bdcb8 100644
--- a/llvm/include/llvm/BinaryFormat/COFF.h
+++ b/llvm/include/llvm/BinaryFormat/COFF.h
@@ -772,23 +772,6 @@ enum CodeViewIdentifiers {
DEBUG_HASHES_SECTION_MAGIC = 0x133C9C5
};
-// These flags show up in the @feat.00 symbol. They appear to be some kind of
-// compiler features bitfield read by link.exe.
-enum Feat00Flags : uint32_t {
- // Object is compatible with /safeseh.
- SafeSEH = 0x1,
- // Object was compiled with /GS.
- GuardStack = 0x100,
- // Object was compiled with /sdl.
- SDL = 0x200,
- // Object was compiled with /guard:cf.
- GuardCF = 0x800,
- // Object was compiled with /guard:ehcont.
- GuardEHCont = 0x4000,
- // Object was compiled with /kernel.
- Kernel = 0x40000000,
-};
-
inline bool isReservedSectionNumber(int32_t SectionNumber) {
return SectionNumber <= 0;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
index a97eb9f7847e..16213aff4788 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -1498,16 +1498,8 @@ void CodeViewDebug::beginFunctionImpl(const MachineFunction *MF) {
FPO |= FrameProcedureOptions::MarkedInline;
if (GV.hasFnAttribute(Attribute::Naked))
FPO |= FrameProcedureOptions::Naked;
- if (MFI.hasStackProtectorIndex()) {
+ if (MFI.hasStackProtectorIndex())
FPO |= FrameProcedureOptions::SecurityChecks;
- if (GV.hasFnAttribute(Attribute::StackProtectStrong) ||
- GV.hasFnAttribute(Attribute::StackProtectReq)) {
- FPO |= FrameProcedureOptions::StrictSecurityChecks;
- }
- } else if (!GV.hasStackProtectorFnAttr()) {
- // __declspec(safebuffers) disables stack guards.
- FPO |= FrameProcedureOptions::SafeBuffers;
- }
FPO |= FrameProcedureOptions(uint32_t(CurFn->EncodedLocalFramePtrReg) << 14U);
FPO |= FrameProcedureOptions(uint32_t(CurFn->EncodedParamFramePtrReg) << 16U);
if (Asm->TM.getOptLevel() != CodeGenOpt::None &&
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 6a065871107e..9d0b4e2539cc 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -201,32 +201,30 @@ void AArch64AsmPrinter::emitStartOfAsmFile(Module &M) {
const Triple &TT = TM.getTargetTriple();
if (TT.isOSBinFormatCOFF()) {
- // Emit an absolute @feat.00 symbol
+ // Emit an absolute @feat.00 symbol. This appears to be some kind of
+ // compiler features bitfield read by link.exe.
MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
OutStreamer->beginCOFFSymbolDef(S);
OutStreamer->emitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
OutStreamer->emitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
OutStreamer->endCOFFSymbolDef();
- int64_t Feat00Value = 0;
+ int64_t Feat00Flags = 0;
if (M.getModuleFlag("cfguard")) {
- // Object is CFG-aware.
- Feat00Value |= COFF::Feat00Flags::GuardCF;
+ Feat00Flags |= 0x800; // Object is CFG-aware.
}
if (M.getModuleFlag("ehcontguard")) {
- // Object also has EHCont.
- Feat00Value |= COFF::Feat00Flags::GuardEHCont;
+ Feat00Flags |= 0x4000; // Object also has EHCont.
}
if (M.getModuleFlag("ms-kernel")) {
- // Object is compiled with /kernel.
- Feat00Value |= COFF::Feat00Flags::Kernel;
+ Feat00Flags |= 0x40000000; // Object is compiled with /kernel.
}
OutStreamer->emitSymbolAttribute(S, MCSA_Global);
OutStreamer->emitAssignment(
- S, MCConstantExpr::create(Feat00Value, MMI->getContext()));
+ S, MCConstantExpr::create(Feat00Flags, MMI->getContext()));
}
if (!TT.isOSBinFormatELF())
diff --git a/llvm/lib/Target/X86/X86AsmPrinter.cpp b/llvm/lib/Target/X86/X86AsmPrinter.cpp
index 1c8375dcd171..968e68050a40 100644
--- a/llvm/lib/Target/X86/X86AsmPrinter.cpp
+++ b/llvm/lib/Target/X86/X86AsmPrinter.cpp
@@ -792,13 +792,14 @@ void X86AsmPrinter::emitStartOfAsmFile(Module &M) {
OutStreamer->switchSection(getObjFileLowering().getTextSection());
if (TT.isOSBinFormatCOFF()) {
- // Emit an absolute @feat.00 symbol.
+ // Emit an absolute @feat.00 symbol. This appears to be some kind of
+ // compiler features bitfield read by link.exe.
MCSymbol *S = MMI->getContext().getOrCreateSymbol(StringRef("@feat.00"));
OutStreamer->beginCOFFSymbolDef(S);
OutStreamer->emitCOFFSymbolStorageClass(COFF::IMAGE_SYM_CLASS_STATIC);
OutStreamer->emitCOFFSymbolType(COFF::IMAGE_SYM_DTYPE_NULL);
OutStreamer->endCOFFSymbolDef();
- int64_t Feat00Value = 0;
+ int64_t Feat00Flags = 0;
if (TT.getArch() == Triple::x86) {
// According to the PE-COFF spec, the LSB of this value marks the object
@@ -806,27 +807,24 @@ void X86AsmPrinter::emitStartOfAsmFile(Module &M) {
// must be registered in .sxdata. Use of any unregistered handlers will
// cause the process to terminate immediately. LLVM does not know how to
// register any SEH handlers, so its object files should be safe.
- Feat00Value |= COFF::Feat00Flags::SafeSEH;
+ Feat00Flags |= 1;
}
if (M.getModuleFlag("cfguard")) {
- // Object is CFG-aware.
- Feat00Value |= COFF::Feat00Flags::GuardCF;
+ Feat00Flags |= 0x800; // Object is CFG-aware.
}
if (M.getModuleFlag("ehcontguard")) {
- // Object also has EHCont.
- Feat00Value |= COFF::Feat00Flags::GuardEHCont;
+ Feat00Flags |= 0x4000; // Object also has EHCont.
}
if (M.getModuleFlag("ms-kernel")) {
- // Object is compiled with /kernel.
- Feat00Value |= COFF::Feat00Flags::Kernel;
+ Feat00Flags |= 0x40000000; // Object is compiled with /kernel.
}
OutStreamer->emitSymbolAttribute(S, MCSA_Global);
OutStreamer->emitAssignment(
- S, MCConstantExpr::create(Feat00Value, MMI->getContext()));
+ S, MCConstantExpr::create(Feat00Flags, MMI->getContext()));
}
OutStreamer->emitSyntaxDirective();
diff --git a/llvm/test/DebugInfo/COFF/frameproc-flags.ll b/llvm/test/DebugInfo/COFF/frameproc-flags.ll
index 145886dadd0d..567000c24c9f 100644
--- a/llvm/test/DebugInfo/COFF/frameproc-flags.ll
+++ b/llvm/test/DebugInfo/COFF/frameproc-flags.ll
@@ -65,7 +65,7 @@
; CHECK-LABEL: S_GPROC32_ID [size = 52] `use_alloca`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = VFRAME, param fp reg = EBP
-; CHECK: flags = has alloca | secure checks | strict secure checks | opt speed
+; CHECK: flags = has alloca | secure checks | opt speed
; CHECK-LABEL: S_GPROC32_ID [size = 52] `call_setjmp`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = NONE, param fp reg = NONE
@@ -73,7 +73,7 @@
; CHECK-LABEL: S_GPROC32_ID [size = 56] `use_inlineasm`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = NONE, param fp reg = NONE
-; CHECK: flags = has inline asm | safe buffers | opt speed
+; CHECK: flags = has inline asm | opt speed
; CHECK-LABEL: S_GPROC32_ID [size = 48] `cpp_eh`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = EBP, param fp reg = EBP
@@ -81,11 +81,11 @@
; CHECK-LABEL: S_GPROC32_ID [size = 52] `use_inline`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = NONE, param fp reg = NONE
-; CHECK: flags = safe buffers | opt speed
+; CHECK: flags = opt speed
; CHECK-LABEL: S_LPROC32_ID [size = 56] `is_marked_inline`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = NONE, param fp reg = NONE
-; CHECK: flags = marked inline | safe buffers | opt speed
+; CHECK: flags = marked inline | opt speed
; CHECK-LABEL: S_GPROC32_ID [size = 44] `seh`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = EBP, param fp reg = EBP
@@ -93,15 +93,15 @@
; CHECK-LABEL: S_LPROC32_ID [size = 56] `?filt$0 at 0@seh@@`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = EBP, param fp reg = EBP
-; CHECK: flags = safe buffers | opt speed
+; CHECK: flags = opt speed
; CHECK-LABEL: S_GPROC32_ID [size = 52] `use_naked`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = NONE, param fp reg = NONE
-; CHECK: flags = has inline asm | naked | safe buffers | opt speed
+; CHECK: flags = has inline asm | naked | opt speed
; CHECK-LABEL: S_GPROC32_ID [size = 52] `stack_guard`
; CHECK: S_FRAMEPROC [size = 32]
; CHECK: local fp reg = VFRAME, param fp reg = EBP
-; CHECK: flags = secure checks | strict secure checks | opt speed
+; CHECK: flags = secure checks | opt speed
; ModuleID = 'frameproc-flags.cpp'
source_filename = "frameproc-flags.cpp"
diff --git a/llvm/test/DebugInfo/COFF/multifunction.ll b/llvm/test/DebugInfo/COFF/multifunction.ll
index 98b0e4b2d8a0..fa93b1349756 100644
--- a/llvm/test/DebugInfo/COFF/multifunction.ll
+++ b/llvm/test/DebugInfo/COFF/multifunction.ll
@@ -91,7 +91,7 @@
; X86-NEXT: .long 0 # Bytes of callee saved registers
; X86-NEXT: .long 0 # Exception handler offset
; X86-NEXT: .short 0 # Exception handler section
-; X86-NEXT: .long 8192 # Flags (defines frame register)
+; X86-NEXT: .long 0 # Flags (defines frame register)
; X86-NEXT: .p2align 2
; X86-NEXT: [[FPROC_END]]:
; X86-NEXT: .short 2
@@ -130,7 +130,7 @@
; X86-NEXT: .long 0 # Bytes of callee saved registers
; X86-NEXT: .long 0 # Exception handler offset
; X86-NEXT: .short 0 # Exception handler section
-; X86-NEXT: .long 8192 # Flags (defines frame register)
+; X86-NEXT: .long 0 # Flags (defines frame register)
; X86-NEXT: .p2align 2
; X86-NEXT: [[FPROC_END]]:
; X86-NEXT: .short 2
@@ -169,7 +169,7 @@
; X86-NEXT: .long 0 # Bytes of callee saved registers
; X86-NEXT: .long 0 # Exception handler offset
; X86-NEXT: .short 0 # Exception handler section
-; X86-NEXT: .long 8192 # Flags (defines frame register)
+; X86-NEXT: .long 0 # Flags (defines frame register)
; X86-NEXT: .p2align 2
; X86-NEXT: [[FPROC_END]]:
; X86-NEXT: .short 2
@@ -403,7 +403,7 @@
; X64-NEXT: .long 0 # Bytes of callee saved registers
; X64-NEXT: .long 0 # Exception handler offset
; X64-NEXT: .short 0 # Exception handler section
-; X64-NEXT: .long 90112 # Flags (defines frame register)
+; X64-NEXT: .long 81920 # Flags (defines frame register)
; X64-NEXT: .p2align 2
; X64-NEXT: [[FPROC_END]]:
; X64-NEXT: .short 2
@@ -441,7 +441,7 @@
; X64-NEXT: .long 0 # Bytes of callee saved registers
; X64-NEXT: .long 0 # Exception handler offset
; X64-NEXT: .short 0 # Exception handler section
-; X64-NEXT: .long 90112 # Flags (defines frame register)
+; X64-NEXT: .long 81920 # Flags (defines frame register)
; X64-NEXT: .p2align 2
; X64-NEXT: [[FPROC_END]]:
; X64-NEXT: .short 2
@@ -479,7 +479,7 @@
; X64-NEXT: .long 0 # Bytes of callee saved registers
; X64-NEXT: .long 0 # Exception handler offset
; X64-NEXT: .short 0 # Exception handler section
-; X64-NEXT: .long 90112 # Flags (defines frame register)
+; X64-NEXT: .long 81920 # Flags (defines frame register)
; X64-NEXT: .p2align 2
; X64-NEXT: [[FPROC_END]]:
; X64-NEXT: .short 2
diff --git a/llvm/test/DebugInfo/COFF/simple.ll b/llvm/test/DebugInfo/COFF/simple.ll
index 85819b0d990e..70878ac33ef1 100644
--- a/llvm/test/DebugInfo/COFF/simple.ll
+++ b/llvm/test/DebugInfo/COFF/simple.ll
@@ -71,7 +71,7 @@
; X86-NEXT: .long 0 # Bytes of callee saved registers
; X86-NEXT: .long 0 # Exception handler offset
; X86-NEXT: .short 0 # Exception handler section
-; X86-NEXT: .long 8192 # Flags (defines frame register)
+; X86-NEXT: .long 0 # Flags (defines frame register)
; X86-NEXT: .p2align 2
; X86-NEXT: [[FPROC_END]]:
; X86-NEXT: .short 2
@@ -201,7 +201,7 @@
; X64-NEXT: .long 0 # Bytes of callee saved registers
; X64-NEXT: .long 0 # Exception handler offset
; X64-NEXT: .short 0 # Exception handler section
-; X64-NEXT: .long 90112 # Flags (defines frame register)
+; X64-NEXT: .long 81920 # Flags (defines frame register)
; X64-NEXT: .p2align 2
; X64-NEXT: [[FPROC_END]]:
; X64-NEXT: .short 2
diff --git a/llvm/test/DebugInfo/COFF/vframe-fpo.ll b/llvm/test/DebugInfo/COFF/vframe-fpo.ll
index 2e3d8754968a..599d9f07f9d5 100644
--- a/llvm/test/DebugInfo/COFF/vframe-fpo.ll
+++ b/llvm/test/DebugInfo/COFF/vframe-fpo.ll
@@ -125,8 +125,7 @@
; CODEVIEW-NEXT: BytesOfCalleeSavedRegisters: 0xC
; CODEVIEW-NEXT: OffsetOfExceptionHandler: 0x0
; CODEVIEW-NEXT: SectionIdOfExceptionHandler: 0x0
-; CODEVIEW-NEXT: Flags [ (0x16000)
-; CODEVIEW-NEXT: SafeBuffers (0x2000)
+; CODEVIEW-NEXT: Flags [ (0x14000)
; CODEVIEW-NEXT: ]
; CODEVIEW-NEXT: LocalFramePtrReg: VFRAME (0x7536)
; CODEVIEW-NEXT: ParamFramePtrReg: VFRAME (0x7536)
More information about the llvm-commits
mailing list