1 # Check whether the stack can be marked nonexecutable by passing
2 # an option to the C compiler when acting on .s files.
4 # ASM_NOEXECSTACK_FLAG -- compiler option(s) for marking the stack
7 # CC='ccache gcc' => "${CMAKE_C_COMPILER_ARG1}" == " gcc"
8 # (notice the leading whitespace). Grrr!
9 string(STRIP "${CMAKE_C_COMPILER_ARG1}" _c_compiler_arg1)
11 set(_conftest_c "${CMAKE_BINARY_DIR}/conftest.c")
12 set(_conftest_s "${CMAKE_BINARY_DIR}/conftest.s")
13 set(_conftest_o "${CMAKE_BINARY_DIR}/conftest.o")
14 set(_need_noexecstack)
17 file(WRITE ${_conftest_c} "void foo() { }")
20 COMMAND ${CMAKE_C_COMPILER} ${_c_compiler_arg1} -S ${_conftest_c}
21 RESULT_VARIABLE _cc_ret
24 if ("${_cc_ret}" EQUAL "0")
25 file(STRINGS ${_conftest_s} _need_noexecstack REGEX "\\.note\\.GNU-stack")
28 if (_need_noexecstack)
29 execute_process(COMMAND ${CMAKE_C_COMPILER} ${_c_compiler_arg1} -Wa,--noexecstack -c ${_conftest_s}
30 RESULT_VARIABLE _cc_ret)
31 if ("${_cc_ret}" EQUAL "0")
32 set(ASM_NOEXECSTACK_FLAG "-Wa,--noexecstack")
35 file(REMOVE ${_conftest_o} ${_conftest_s} ${_conftest_c})