-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
126 lines (109 loc) · 4.01 KB
/
Copy pathCMakeLists.txt
File metadata and controls
126 lines (109 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
cmake_minimum_required(VERSION 3.20)
project(c2pancake)
set(CMAKE_CXX_STANDARD 26)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
option(SECURE_BUILD_FOR_PRODUCTION "Enable production-specific hardening" OFF)
option(SECURE_BUILD_FOR_DEVELOPMENT "Enable development-specific strictness" ON)
include(CheckPIESupported)
check_pie_supported()
find_package(LLVM REQUIRED CONFIG)
find_package(Clang REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
if(NOT LLVM_VERSION_MAJOR EQUAL 22)
message(FATAL_ERROR "LLVM 22 required")
endif()
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
add_definitions(${LLVM_DEFINITIONS})
set(GCC_TOOLCHAIN_PATH
"/usr/lib/gcc/x86_64-linux-gnu/16"
CACHE PATH "Path to the GCC/libstdc++ 16+ toolchain directory")
set(GCC_BASE_INCLUDE_PATH
"/usr/include/c++/16"
CACHE PATH "Path to the main GCC/libstdc++ 16+ include directory")
set(GCC_ARCH_INCLUDE_PATH
"/usr/include/x86_64-linux-gnu/c++/16"
CACHE
PATH
"Path to the architecture-specific GCC/libstdc++ 16+ include directory")
foreach(PATH_VAR GCC_TOOLCHAIN_PATH GCC_BASE_INCLUDE_PATH GCC_ARCH_INCLUDE_PATH)
if(NOT EXISTS "${${PATH_VAR}}")
message(FATAL_ERROR "Path does not exist: ${PATH_VAR} -> ${${PATH_VAR}}")
endif()
endforeach()
add_executable(
c2pancake
src/Utils.cpp
src/Pipeline.cpp
src/Pass_InjectHeaders.cpp
src/Pass_FunctionCalling.cpp
src/Pass_LowerBitfieldOps.cpp
src/Pass_IntegerConversion.cpp
src/Pass_TransformLogicalExpressions.cpp
src/Pass_NormaliseIfStatements.cpp
src/Pass_SwitchToIf.cpp
src/Pass_LoopsToWhile.cpp
src/Pass_PromoteRecords.cpp
src/Pass_HoistArraysAndAddresses.cpp
src/CodeGen.cpp
src/IRBuilder.cpp
src/main.cpp)
target_include_directories(c2pancake PRIVATE include)
target_include_directories(c2pancake SYSTEM PRIVATE include/llvm-project)
# recommended security hardening flags
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
target_compile_options(
c2pancake
PRIVATE -O2
-Wall
-Wformat
-Wformat=2
-Wconversion
-Wimplicit-fallthrough
-Werror=format-security
-fstrict-flex-arrays=3
-fstack-clash-protection
-fstack-protector-strong
-U_FORTIFY_SOURCE)
target_compile_definitions(c2pancake PRIVATE _FORTIFY_SOURCE=3
_GLIBCXX_ASSERTIONS)
target_link_options(
c2pancake
PRIVATE
-Wl,-z,nodlopen
-Wl,-z,noexecstack
-Wl,-z,relro
-Wl,-z,now
-Wl,--as-needed
-Wl,--no-copy-dt-needed-entries)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")
target_compile_options(
c2pancake PRIVATE -Wtrampolines -fzero-init-padding-bits=all
-Wbidi-chars=any)
endif()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64|amd64|AMD64)")
target_compile_options(c2pancake PRIVATE -fcf-protection=full)
target_link_options(c2pancake PRIVATE -fcf-protection=full)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(aarch64|arm64|ARM64)")
target_compile_options(c2pancake PRIVATE -mbranch-protection=standard)
target_link_options(c2pancake PRIVATE -mbranch-protection=standard)
endif()
if(SECURE_BUILD_FOR_PRODUCTION)
target_compile_options(
c2pancake PRIVATE -fno-delete-null-pointer-checks -fno-strict-overflow
-fno-strict-aliasing -ftrivial-auto-var-init=zero)
endif()
# if(SECURE_BUILD_FOR_DEVELOPMENT) target_compile_options(c2pancake PRIVATE
# -Werror) endif()
target_compile_options(
c2pancake
PRIVATE $<$<COMPILE_LANGUAGE:C>: -Werror=implicit
-Werror=incompatible-pointer-types -Werror=int-conversion >
$<$<COMPILE_LANGUAGE:C>:-fexceptions>)
# end of recommended security hardening flags
target_compile_definitions(c2pancake
PRIVATE GCC_TOOLCHAIN="${GCC_TOOLCHAIN_PATH}")
target_include_directories(
c2pancake SYSTEM PRIVATE ${GCC_BASE_INCLUDE_PATH} ${GCC_ARCH_INCLUDE_PATH}
${LLVM_INCLUDE_DIRS} ${CLANG_INCLUDE_DIRS})
target_link_libraries(c2pancake PRIVATE clangDaemon)