-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] move __stack_chk_fail to src/ from startup/ #75863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
60958c1
[libc] move __stack_chk_fail to src/ from startup/
nickdesaulniers 932af76
git format
nickdesaulniers 7c26cda
add header
nickdesaulniers 35d0759
add death test
nickdesaulniers f5e86b3
add explicit test for stack smashing
nickdesaulniers e4acf15
git clang-format HEAD~
nickdesaulniers 13df494
fix comment in test
nickdesaulniers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_OS}) | ||
else() | ||
add_subdirectory(generic) | ||
endif() | ||
|
||
if(TARGET libc.src.compiler.${LIBC_TARGET_OS}.__stack_chk_fail) | ||
set(stack_chk_fail_dep libc.src.compiler.${LIBC_TARGET_OS}.__stack_chk_fail) | ||
else() | ||
set(stack_chk_fail_dep libc.src.compiler.generic.__stack_chk_fail) | ||
endif() | ||
|
||
add_entrypoint_object( | ||
__stack_chk_fail | ||
ALIAS | ||
DEPENDS | ||
${stack_chk_fail_dep} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//===-- Internal header for __stack_chk_fail --------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H | ||
#define LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
[[noreturn]] void __stack_chk_fail(); | ||
|
||
} // namespace LIBC_NAMESPACE | ||
|
||
#endif // LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
add_entrypoint_object( | ||
__stack_chk_fail | ||
SRCS | ||
__stack_chk_fail.cpp | ||
HDRS | ||
../__stack_chk_fail.h | ||
DEPENDS | ||
libc.include.assert | ||
libc.src.__support.OSUtil.osutil | ||
libc.src.stdlib.abort | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===-- Implementation of __stack_chk_fail --------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/compiler/__stack_chk_fail.h" | ||
#include "src/__support/OSUtil/io.h" | ||
#include "src/stdlib/abort.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
|
||
LLVM_LIBC_FUNCTION(void, __stack_chk_fail, (void)) { | ||
LIBC_NAMESPACE::write_to_stderr("stack smashing detected"); | ||
LIBC_NAMESPACE::abort(); | ||
} | ||
|
||
} // namespace LIBC_NAMESPACE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
add_custom_target(libc_stack_chk_guard_unittests) | ||
|
||
add_libc_unittest( | ||
stack_chk_guard_test | ||
SUITE | ||
libc_stack_chk_guard_unittests | ||
SRCS | ||
stack_chk_guard_test.cpp | ||
DEPENDS | ||
libc.src.compiler.__stack_chk_fail | ||
libc.src.string.memset | ||
COMPILE_OPTIONS | ||
-fstack-protector-all | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//===-- Unittests for __stack_chk_fail ------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "llvm-libc-macros/signal-macros.h" | ||
#include "src/compiler/__stack_chk_fail.h" | ||
#include "src/string/memset.h" | ||
#include "test/UnitTest/Test.h" | ||
|
||
TEST(LlvmLibcStackChkFail, Death) { | ||
EXPECT_DEATH([] { LIBC_NAMESPACE::__stack_chk_fail(); }, | ||
WITH_SIGNAL(SIGABRT)); | ||
} | ||
|
||
TEST(LlvmLibcStackChkFail, Smash) { | ||
EXPECT_DEATH( | ||
[] { | ||
int arr[20]; | ||
LIBC_NAMESPACE::memset(arr, 0xAA, 9001); | ||
}, | ||
WITH_SIGNAL(SIGABRT)); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.