File tree Expand file tree Collapse file tree 15 files changed +131
-12
lines changed Expand file tree Collapse file tree 15 files changed +131
-12
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ set(TARGET_LIBC_ENTRYPOINTS
17
17
libc.src.ctype.tolower
18
18
libc.src.ctype.toupper
19
19
20
+ # compiler entrypoints (no corresponding header)
21
+ libc.src.compiler.__stack_chk_fail
22
+
20
23
# errno.h entrypoints
21
24
libc.src.errno.errno
22
25
@@ -69,7 +72,7 @@ set(TARGET_LIBC_ENTRYPOINTS
69
72
libc.src.stdio.snprintf
70
73
libc.src.stdio.vsprintf
71
74
libc.src.stdio.vsnprintf
72
-
75
+
73
76
# stdlib.h entrypoints
74
77
libc.src.stdlib.abs
75
78
libc.src.stdlib.atoi
Original file line number Diff line number Diff line change @@ -17,6 +17,9 @@ set(TARGET_LIBC_ENTRYPOINTS
17
17
libc.src.ctype.tolower
18
18
libc.src.ctype.toupper
19
19
20
+ # compiler entrypoints (no corresponding header)
21
+ libc.src.compiler.__stack_chk_fail
22
+
20
23
# errno.h entrypoints
21
24
libc.src.errno.errno
22
25
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ set(TARGET_LIBC_ENTRYPOINTS
16
16
libc.src.ctype.toascii
17
17
libc.src.ctype.tolower
18
18
libc.src.ctype.toupper
19
-
19
+
20
20
# errno.h entrypoints
21
21
libc.src.errno.errno
22
22
@@ -239,7 +239,7 @@ set(TARGET_LIBM_ENTRYPOINTS
239
239
libc.src.math.asinf
240
240
libc.src.math.asinhf
241
241
libc.src.math.atanf
242
- libc.src.math.atanhf
242
+ libc.src.math.atanhf
243
243
libc.src.math.copysign
244
244
libc.src.math.copysignf
245
245
libc.src.math.copysignl
@@ -353,6 +353,9 @@ set(TARGET_LIBM_ENTRYPOINTS
353
353
354
354
if(LLVM_LIBC_FULL_BUILD)
355
355
list(APPEND TARGET_LIBC_ENTRYPOINTS
356
+ # compiler entrypoints (no corresponding header)
357
+ libc.src.compiler.__stack_chk_fail
358
+
356
359
# network.h entrypoints
357
360
libc.src.network.htonl
358
361
libc.src.network.htons
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ set(TARGET_LIBC_ENTRYPOINTS
66
66
libc.src.inttypes.imaxdiv
67
67
libc.src.inttypes.strtoimax
68
68
libc.src.inttypes.strtoumax
69
-
69
+
70
70
# stdlib.h entrypoints
71
71
libc.src.stdlib.abs
72
72
libc.src.stdlib.atoi
@@ -88,7 +88,7 @@ set(TARGET_LIBC_ENTRYPOINTS
88
88
libc.src.stdlib.strtoll
89
89
libc.src.stdlib.strtoul
90
90
libc.src.stdlib.strtoull
91
-
91
+
92
92
# sys/mman.h entrypoints
93
93
libc.src.sys.mman.mmap
94
94
libc.src.sys.mman.munmap
Original file line number Diff line number Diff line change @@ -362,6 +362,9 @@ set(TARGET_LIBM_ENTRYPOINTS
362
362
363
363
if(LLVM_LIBC_FULL_BUILD)
364
364
list(APPEND TARGET_LIBC_ENTRYPOINTS
365
+ # compiler entrypoints (no corresponding header)
366
+ libc.src.compiler.__stack_chk_fail
367
+
365
368
# assert.h entrypoints
366
369
libc.src.assert.__assert_fail
367
370
Original file line number Diff line number Diff line change @@ -375,6 +375,9 @@ if(LLVM_LIBC_FULL_BUILD)
375
375
# assert.h entrypoints
376
376
libc.src.assert.__assert_fail
377
377
378
+ # compiler entrypoints (no corresponding header)
379
+ libc.src.compiler.__stack_chk_fail
380
+
378
381
# dirent.h entrypoints
379
382
libc.src.dirent.closedir
380
383
libc.src.dirent.dirfd
Original file line number Diff line number Diff line change @@ -29,10 +29,11 @@ if(NOT LLVM_LIBC_FULL_BUILD)
29
29
endif ()
30
30
31
31
add_subdirectory (assert )
32
+ add_subdirectory (compiler )
32
33
add_subdirectory (network )
34
+ add_subdirectory (search )
33
35
add_subdirectory (setjmp )
34
36
add_subdirectory (signal )
35
37
add_subdirectory (spawn )
36
38
add_subdirectory (threads )
37
39
add_subdirectory (time )
38
- add_subdirectory (search )
Original file line number Diff line number Diff line change
1
+ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR} /${LIBC_TARGET_OS} )
2
+ add_subdirectory (${CMAKE_CURRENT_SOURCE_DIR} /${LIBC_TARGET_OS} )
3
+ else ()
4
+ add_subdirectory (generic )
5
+ endif ()
6
+
7
+ if (TARGET libc.src.compiler.${LIBC_TARGET_OS}.__stack_chk_fail )
8
+ set (stack_chk_fail_dep libc.src.compiler.${LIBC_TARGET_OS}.__stack_chk_fail )
9
+ else ()
10
+ set (stack_chk_fail_dep libc.src.compiler.generic.__stack_chk_fail )
11
+ endif ()
12
+
13
+ add_entrypoint_object (
14
+ __stack_chk_fail
15
+ ALIAS
16
+ DEPENDS
17
+ ${stack_chk_fail_dep}
18
+ )
Original file line number Diff line number Diff line change
1
+ // ===-- Internal header for __stack_chk_fail --------------------*- C++ -*-===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #ifndef LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
10
+ #define LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
11
+
12
+ namespace LIBC_NAMESPACE {
13
+
14
+ [[noreturn]] void __stack_chk_fail ();
15
+
16
+ } // namespace LIBC_NAMESPACE
17
+
18
+ #endif // LLVM_LIBC_SRC_COMPILER___STACK_CHK_FAIL_H
Original file line number Diff line number Diff line change
1
+ add_entrypoint_object (
2
+ __stack_chk_fail
3
+ SRCS
4
+ __stack_chk_fail.cpp
5
+ HDRS
6
+ ../__stack_chk_fail.h
7
+ DEPENDS
8
+ libc.include.assert
9
+ libc.src.__support.OSUtil.osutil
10
+ libc.src.stdlib.abort
11
+ )
Original file line number Diff line number Diff line change
1
+ // ===-- Implementation of __stack_chk_fail --------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #include " src/compiler/__stack_chk_fail.h"
10
+ #include " src/__support/OSUtil/io.h"
11
+ #include " src/stdlib/abort.h"
12
+
13
+ namespace LIBC_NAMESPACE {
14
+
15
+ LLVM_LIBC_FUNCTION (void , __stack_chk_fail, (void )) {
16
+ LIBC_NAMESPACE::write_to_stderr (" stack smashing detected" );
17
+ LIBC_NAMESPACE::abort ();
18
+ }
19
+
20
+ } // namespace LIBC_NAMESPACE
Original file line number Diff line number Diff line change 25
25
26
26
extern " C" int main (int , char **, char **);
27
27
28
- extern " C" void __stack_chk_fail () {
29
- LIBC_NAMESPACE::write_to_stderr (" stack smashing detected" );
30
- LIBC_NAMESPACE::abort ();
31
- }
32
-
33
28
namespace LIBC_NAMESPACE {
34
29
35
30
#ifdef SYS_mmap2
Original file line number Diff line number Diff line change @@ -60,8 +60,9 @@ if(NOT LLVM_LIBC_FULL_BUILD)
60
60
return ()
61
61
endif ()
62
62
63
- add_subdirectory (dirent )
64
63
add_subdirectory (assert )
64
+ add_subdirectory (compiler )
65
+ add_subdirectory (dirent )
65
66
add_subdirectory (network )
66
67
add_subdirectory (setjmp )
67
68
add_subdirectory (signal )
Original file line number Diff line number Diff line change
1
+ add_custom_target (libc_stack_chk_guard_unittests )
2
+
3
+ add_libc_unittest (
4
+ stack_chk_guard_test
5
+ SUITE
6
+ libc_stack_chk_guard_unittests
7
+ SRCS
8
+ stack_chk_guard_test.cpp
9
+ DEPENDS
10
+ libc.src.compiler.__stack_chk_fail
11
+ libc.src.string.memset
12
+ COMPILE_OPTIONS
13
+ -fstack-protector-all
14
+ )
Original file line number Diff line number Diff line change
1
+ // ===-- Unittests for __stack_chk_fail ------------------------------------===//
2
+ //
3
+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
+ // See https://llvm.org/LICENSE.txt for license information.
5
+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
+ //
7
+ // ===----------------------------------------------------------------------===//
8
+
9
+ #include " llvm-libc-macros/signal-macros.h"
10
+ #include " src/compiler/__stack_chk_fail.h"
11
+ #include " src/string/memset.h"
12
+ #include " test/UnitTest/Test.h"
13
+
14
+ TEST (LlvmLibcStackChkFail, Death) {
15
+ EXPECT_DEATH ([] { LIBC_NAMESPACE::__stack_chk_fail (); },
16
+ WITH_SIGNAL (SIGABRT));
17
+ }
18
+
19
+ TEST (LlvmLibcStackChkFail, Smash) {
20
+ EXPECT_DEATH (
21
+ [] {
22
+ int arr[20 ];
23
+ LIBC_NAMESPACE::memset (arr, 0xAA , 9001 );
24
+ },
25
+ WITH_SIGNAL (SIGABRT));
26
+ }
You can’t perform that action at this time.
0 commit comments