Skip to content

Commit 57048b2

Browse files
Merged PR 7183884: Explicitly include __stack_chk_fail reference in Linux
+ This enables linking __stack_chk_fail without PLT entry with clang, which is required to enable -fstack-protector-strong on OpenEnclave Related work items: #38920996
1 parent 8777b1c commit 57048b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/env_linuxUserMode.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ SymCryptInitEnvLinuxUsermode( UINT32 version )
5656
SymCryptInitEnvCommon( version );
5757
}
5858

59+
// UGLY HACK: Forward declare __stack_chk_fail introduced by -fstack-protector-strong
60+
// For OpenEnclave binaries we cannot have any PLT entries, but clang ignores -fno-plt for
61+
// __stack_chk_fail.
62+
// Opened issue against clang here: https://github.com/llvm/llvm-project/issues/54816
63+
// If we introduce a direct reference to it in our code then clang does figure out it must be linked
64+
// without PLT
65+
void __stack_chk_fail();
66+
5967
_Analysis_noreturn_
6068
VOID
6169
SYMCRYPT_CALL
@@ -83,6 +91,10 @@ SymCryptFatalEnvLinuxUsermode( ULONG fatalCode )
8391
SYMCRYPT_FORCE_WRITE32( (volatile UINT32 *)NULL, fatalCode );
8492

8593
SymCryptFatalHang( fatalCode );
94+
95+
// Never reached - call is to force clang not to use PLT entry for this function
96+
// See forward declaration above
97+
__stack_chk_fail();
8698
}
8799

88100
#if SYMCRYPT_CPU_AMD64

0 commit comments

Comments
 (0)