aboutsummaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorNick Desaulniers <nickdesaulniers@users.noreply.github.com>2023-12-19 11:59:42 -0800
committerGitHub <noreply@github.com>2023-12-19 11:59:42 -0800
commit24d44ff473c73891a4085c2cd777108d9d7bb50a (patch)
tree59057237a30cf385cd76643a16285462126eb4a4 /libc
parent1e91f32ef777eb2a868acac99d25cba6d54feb02 (diff)
downloadllvm-24d44ff473c73891a4085c2cd777108d9d7bb50a.zip
llvm-24d44ff473c73891a4085c2cd777108d9d7bb50a.tar.gz
llvm-24d44ff473c73891a4085c2cd777108d9d7bb50a.tar.bz2
[libc] __stack_chk_fail post submit test failures (#75962)
Use a size smaller than the smallest supported page size so that we don't clobber over any guard pages, which may result in a segfault before __stack_chk_fail can be called. Also, move __stack_chk_fail outside of our namespace.
Diffstat (limited to 'libc')
-rw-r--r--libc/src/compiler/__stack_chk_fail.h10
-rw-r--r--libc/src/compiler/generic/__stack_chk_fail.cpp6
-rw-r--r--libc/test/integration/src/unistd/CMakeLists.txt1
-rw-r--r--libc/test/src/compiler/stack_chk_guard_test.cpp5
4 files changed, 12 insertions, 10 deletions
diff --git a/libc/src/compiler/__stack_chk_fail.h b/libc/src/compiler/__stack_chk_fail.h
index 2e3d849..56b6042 100644
--- a/libc/src/compiler/__stack_chk_fail.h
+++ b/libc/src/compiler/__stack_chk_fail.h
@@ -9,10 +9,12 @@
#ifndef LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
#define LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
-namespace LIBC_NAMESPACE {
-
+// The compiler will emit calls implicitly to a non-namespaced version.
+// TODO: can we additionally provide a namespaced alias so that tests can
+// explicitly call the namespaced variant rather than the non-namespaced
+// definition?
+extern "C" {
[[noreturn]] void __stack_chk_fail();
-
-} // namespace LIBC_NAMESPACE
+} // extern "C"
#endif // LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
diff --git a/libc/src/compiler/generic/__stack_chk_fail.cpp b/libc/src/compiler/generic/__stack_chk_fail.cpp
index 0ca0207..639204d 100644
--- a/libc/src/compiler/generic/__stack_chk_fail.cpp
+++ b/libc/src/compiler/generic/__stack_chk_fail.cpp
@@ -10,11 +10,11 @@
#include "src/__support/OSUtil/io.h"
#include "src/stdlib/abort.h"
-namespace LIBC_NAMESPACE {
+extern "C" {
-LLVM_LIBC_FUNCTION(void, __stack_chk_fail, (void)) {
+void __stack_chk_fail(void) {
LIBC_NAMESPACE::write_to_stderr("stack smashing detected");
LIBC_NAMESPACE::abort();
}
-} // namespace LIBC_NAMESPACE
+} // extern "C"
diff --git a/libc/test/integration/src/unistd/CMakeLists.txt b/libc/test/integration/src/unistd/CMakeLists.txt
index 10aac21..3f18231 100644
--- a/libc/test/integration/src/unistd/CMakeLists.txt
+++ b/libc/test/integration/src/unistd/CMakeLists.txt
@@ -45,6 +45,7 @@ if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_ARCHITECTURE_IS_X86})
libc.include.signal
libc.include.sys_wait
libc.include.unistd
+ libc.src.compiler.__stack_chk_fail
libc.src.pthread.pthread_atfork
libc.src.signal.raise
libc.src.sys.wait.wait
diff --git a/libc/test/src/compiler/stack_chk_guard_test.cpp b/libc/test/src/compiler/stack_chk_guard_test.cpp
index 1de2d1b..84c54dd 100644
--- a/libc/test/src/compiler/stack_chk_guard_test.cpp
+++ b/libc/test/src/compiler/stack_chk_guard_test.cpp
@@ -12,15 +12,14 @@
#include "test/UnitTest/Test.h"
TEST(LlvmLibcStackChkFail, Death) {
- EXPECT_DEATH([] { LIBC_NAMESPACE::__stack_chk_fail(); },
- WITH_SIGNAL(SIGABRT));
+ EXPECT_DEATH([] { __stack_chk_fail(); }, WITH_SIGNAL(SIGABRT));
}
TEST(LlvmLibcStackChkFail, Smash) {
EXPECT_DEATH(
[] {
int arr[20];
- LIBC_NAMESPACE::memset(arr, 0xAA, 9001);
+ LIBC_NAMESPACE::memset(arr, 0xAA, 2001);
},
WITH_SIGNAL(SIGABRT));
}