Skip to content

Commit f2dd991

Browse files
committed
build: prevent the toolchain from emitting an executable stack
Signed-off-by: Eduardo Silva <[email protected]>
1 parent 200ad59 commit f2dd991

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ if (MSVC)
8383
add_compile_options(/MT)
8484
else()
8585
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
86+
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
87+
# Prevent the toolchain from emitting an executable stack on Linux targets,
88+
# which triggers kernel warnings (e.g. "started with executable stack") and
89+
# weakens security hardening. The linker flag is not supported on macOS.
90+
add_compile_options(-Wa,--noexecstack)
91+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,noexecstack")
92+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack")
93+
endif()
8694
# The following flags are to enhance security, but it may impact performance,
8795
# we disable them by default.
8896
if (FLB_WASM_STACK_PROTECT)

0 commit comments

Comments
 (0)