summaryrefslogtreecommitdiff
path: root/MdePkg/Library/StackCheckLibNull
diff options
context:
space:
mode:
Diffstat (limited to 'MdePkg/Library/StackCheckLibNull')
-rw-r--r--MdePkg/Library/StackCheckLibNull/IA32/StackCheckFunctionsMsvc.nasm21
-rw-r--r--MdePkg/Library/StackCheckLibNull/StackCheckLibHostApplicationMsvc.c13
-rw-r--r--MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf41
-rw-r--r--MdePkg/Library/StackCheckLibNull/StackCheckLibNullGcc.c23
-rw-r--r--MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf34
-rw-r--r--MdePkg/Library/StackCheckLibNull/StackCheckLibNullMsvc.c10
-rw-r--r--MdePkg/Library/StackCheckLibNull/X64/StackCheckFunctionsMsvc.nasm21
7 files changed, 163 insertions, 0 deletions
diff --git a/MdePkg/Library/StackCheckLibNull/IA32/StackCheckFunctionsMsvc.nasm b/MdePkg/Library/StackCheckLibNull/IA32/StackCheckFunctionsMsvc.nasm
new file mode 100644
index 000000000000..4addecd7322c
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/IA32/StackCheckFunctionsMsvc.nasm
@@ -0,0 +1,21 @@
+;------------------------------------------------------------------------------
+; IA32/StackCheckFunctionsMsvc.nasm
+;
+; Copyright (c) Microsoft Corporation.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;------------------------------------------------------------------------------
+
+ DEFAULT REL
+ SECTION .text
+
+global ASM_PFX(__report_rangecheckfailure)
+ASM_PFX(__report_rangecheckfailure):
+ ret
+
+global ASM_PFX(__GSHandlerCheck)
+ASM_PFX(__GSHandlerCheck):
+ ret
+
+global @__security_check_cookie@4
+@__security_check_cookie@4:
+ ret
diff --git a/MdePkg/Library/StackCheckLibNull/StackCheckLibHostApplicationMsvc.c b/MdePkg/Library/StackCheckLibNull/StackCheckLibHostApplicationMsvc.c
new file mode 100644
index 000000000000..3492d17c66d2
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/StackCheckLibHostApplicationMsvc.c
@@ -0,0 +1,13 @@
+/** @file
+ This file is empty to allow host applications
+ to use the MSVC C runtime lib that provides
+ stack cookie definitions without breaking the
+ build.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+
+extern VOID *__security_cookie;
diff --git a/MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf b/MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf
new file mode 100644
index 000000000000..a78d2e4aa4d2
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/StackCheckLibNull.inf
@@ -0,0 +1,41 @@
+## @file
+# Null library instance for StackCheckLib which can be included
+# when a build needs to include stack check functions but does
+# not want to generate stack check failures.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = StackCheckLibNull
+ FILE_GUID = f6ef2763-ca3b-4c6f-a931-2a48de3ce352
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = StackCheckLib
+
+[Sources]
+ StackCheckLibNullGcc.c | GCC
+ StackCheckLibNullMsvc.c | MSFT
+
+[Sources.IA32]
+ IA32/StackCheckFunctionsMsvc.nasm | MSFT
+
+[Sources.X64]
+ X64/StackCheckFunctionsMsvc.nasm | MSFT
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[BuildOptions]
+ # We cannot build the MSVC version with /GL (whole program optimization) because we run into linker error
+ # LNK1237, which is a failure to link against a symbol from a library compiled with /GL. The whole program
+ # optimization tries to do away with references to this symbol. The solution is to not compile the stack
+ # check libs with /GL
+ MSFT:*_*_*_CC_FLAGS = /GL-
+
+ # We cannot build the GCC version with LTO (link time optimization) because we run into linker errors where
+ # the stack cookie variable has been optimized away, as it looks to GCC like the variable is not used, because
+ # the compiler inserts the usage.
+ GCC:*_*_*_CC_FLAGS = -fno-lto
diff --git a/MdePkg/Library/StackCheckLibNull/StackCheckLibNullGcc.c b/MdePkg/Library/StackCheckLibNull/StackCheckLibNullGcc.c
new file mode 100644
index 000000000000..5c4278d60bf4
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/StackCheckLibNullGcc.c
@@ -0,0 +1,23 @@
+/** @file
+ Defines the stack cookie variable for GCC and Clang compilers.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+
+VOID *__stack_chk_guard = (VOID *)(UINTN)0x0;
+
+/**
+ This function gets called when a gcc/clang generated stack cookie fails. This implementation does nothing when
+ a stack cookie failure occurs.
+
+**/
+VOID
+EFIAPI
+__stack_chk_fail (
+ VOID
+ )
+{
+}
diff --git a/MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf b/MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf
new file mode 100644
index 000000000000..43b0b2e889a4
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf
@@ -0,0 +1,34 @@
+## @file
+# Null library instance for StackCheckLib which can be included
+# when a build needs to include stack check functions but does
+# not want to generate stack check failures. This instance is used
+# for HOST_APPLICATIONS specifically, as MSVC host applications link
+# to the C runtime lib that contains the stack cookie definitions, so
+# must link to a completely null version of this lib, whereas GCC host
+# host applications do not link to a C runtime lib that contains the stack
+# cookie definitions, so we must link against our version.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = StackCheckLibNullHostApplication
+ FILE_GUID = 7EBE7BD1-0D92-4609-89AA-6EA3815CB844
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = StackCheckLib|HOST_APPLICATION
+
+[Sources]
+ StackCheckLibHostApplicationMsvc.c | MSFT
+ StackCheckLibNullGcc.c | GCC
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+[BuildOptions]
+ # We cannot build the GCC version with LTO (link time optimization) because we run into linker errors where
+ # the stack cookie variable has been optimized away, as it looks to GCC like the variable is not used, because
+ # the compiler inserts the usage. We do not worry about the MSVC version here as it is a no-op.
+ GCC:*_*_*_CC_FLAGS = -fno-lto
diff --git a/MdePkg/Library/StackCheckLibNull/StackCheckLibNullMsvc.c b/MdePkg/Library/StackCheckLibNull/StackCheckLibNullMsvc.c
new file mode 100644
index 000000000000..a9c26dc36b21
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/StackCheckLibNullMsvc.c
@@ -0,0 +1,10 @@
+/** @file
+ Defines the stack cookie variable for GCC, Clang and MSVC compilers.
+
+ Copyright (c) Microsoft Corporation.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <Uefi.h>
+
+VOID *__security_cookie = (VOID *)(UINTN)0x0;
diff --git a/MdePkg/Library/StackCheckLibNull/X64/StackCheckFunctionsMsvc.nasm b/MdePkg/Library/StackCheckLibNull/X64/StackCheckFunctionsMsvc.nasm
new file mode 100644
index 000000000000..4841c6ecb805
--- /dev/null
+++ b/MdePkg/Library/StackCheckLibNull/X64/StackCheckFunctionsMsvc.nasm
@@ -0,0 +1,21 @@
+;------------------------------------------------------------------------------
+; X64/StackCheckFunctionsMsvc.nasm
+;
+; Copyright (c) Microsoft Corporation.
+; SPDX-License-Identifier: BSD-2-Clause-Patent
+;------------------------------------------------------------------------------
+
+ DEFAULT REL
+ SECTION .text
+
+global ASM_PFX(__report_rangecheckfailure)
+ASM_PFX(__report_rangecheckfailure):
+ ret
+
+global ASM_PFX(__GSHandlerCheck)
+ASM_PFX(__GSHandlerCheck):
+ ret
+
+global ASM_PFX(__security_check_cookie)
+ASM_PFX(__security_check_cookie):
+ ret