Skip to content

Commit c5ee2f0

Browse files
[libc] enable stack protectors and frame pointers on default
1 parent 3b3de48 commit c5ee2f0

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

libc/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ set(LIBC_NAMESPACE ${default_namespace}
4747
CACHE STRING "The namespace to use to enclose internal implementations. Must start with '__llvm_libc'."
4848
)
4949

50+
# Codegen options.
51+
option(LLVM_LIBC_KEEP_FRAME_POINTER "Keep frame pointers in LLVM libc" ON)
52+
option(LLVM_LIBC_ENABLE_STACK_PROTECTOR "Enable stack protector for LLVM libc" ON)
53+
5054
if(LLVM_LIBC_FULL_BUILD OR LLVM_LIBC_GPU_BUILD)
5155
if(NOT LIBC_HDRGEN_EXE)
5256
# We need to set up hdrgen first since other targets depend on it.

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ function(_get_common_compile_options output_var flags)
6060
if (LIBC_CC_SUPPORTS_PATTERN_INIT)
6161
list(APPEND compile_options "-ftrivial-auto-var-init=pattern")
6262
endif()
63+
if (LLVM_LIBC_KEEP_FRAME_POINTER)
64+
list(APPEND compile_options "-fno-omit-frame-pointer")
65+
if (LIBC_TARGET_ARCHITECTURE_IS_X86)
66+
list(APPEND compile_options "-mno-omit-leaf-frame-pointer")
67+
endif()
68+
endif()
69+
if (LLVM_LIBC_ENABLE_STACK_PROTECTOR)
70+
list(APPEND compile_options "-fstack-protector-strong")
71+
endif()
6372
list(APPEND compile_options "-Wall")
6473
list(APPEND compile_options "-Wextra")
6574
# -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.

utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,20 @@ def libc_function(
7878
its deps.
7979
**kwargs: Other attributes relevant for a cc_library. For example, deps.
8080
"""
81-
81+
# x86 targets have -mno-omit-leaf-frame-pointer.
82+
copts = selects.with_or({
83+
PLATFORM_CPU_X86_64: ["-mno-omit-leaf-frame-pointer"],
84+
"//conditions:default": []
85+
})
8286
# We use the explicit equals pattern here because append and += mutate the
8387
# original list, where this creates a new list and stores it in deps.
84-
copts = copts or []
8588
copts = copts + [
8689
"-O3",
8790
"-fno-builtin",
8891
"-fno-lax-vector-conversions",
8992
"-ftrivial-auto-var-init=pattern",
93+
"-fno-omit-frame-pointer",
94+
"-fstack-protector-strong",
9095
]
9196

9297
# We compile the code twice, the first target is suffixed with ".__internal__" and contains the

0 commit comments

Comments
 (0)