[libc-commits] [libc] 24d44ff - [libc] __stack_chk_fail post submit test failures (#75962)
via libc-commits
libc-commits at lists.llvm.org
Tue Dec 19 11:59:46 PST 2023
Author: Nick Desaulniers
Date: 2023-12-19T11:59:42-08:00
New Revision: 24d44ff473c73891a4085c2cd777108d9d7bb50a
URL: https://github.com/llvm/llvm-project/commit/24d44ff473c73891a4085c2cd777108d9d7bb50a
DIFF: https://github.com/llvm/llvm-project/commit/24d44ff473c73891a4085c2cd777108d9d7bb50a.diff
LOG: [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.
Added:
Modified:
libc/src/compiler/__stack_chk_fail.h
libc/src/compiler/generic/__stack_chk_fail.cpp
libc/test/integration/src/unistd/CMakeLists.txt
libc/test/src/compiler/stack_chk_guard_test.cpp
Removed:
################################################################################
diff --git a/libc/src/compiler/__stack_chk_fail.h b/libc/src/compiler/__stack_chk_fail.h
index 2e3d849ff8c67c..56b6042c37f5df 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 0ca02071f2a997..639204d29590ab 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 10aac212af355e..3f18231209512a 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 1de2d1b7357f70..84c54ddeccc956 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));
}
More information about the libc-commits
mailing list