Skip to content

Commit

Permalink
Correctly detect if linker supports noexecstack
Browse files Browse the repository at this point in the history
When testing for support of multiple flags, the flags must be separated
by semicolons not spaces.

See https://gitlab.kitware.com/cmake/cmake/-/issues/26024

When referenced elsewhere, enclose the flag variable in quotation marks
so that it is passed through unmodified.

Closes facebook#4056
  • Loading branch information
ryandesign committed Jun 3, 2024
1 parent f70fb7c commit 1b9b1f6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions build/cmake/CMakeModules/AddZstdCompilationFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ function(EnableCompilerFlag _flag _C _CXX _LD)
string(REGEX REPLACE "^_+" "" varname "${varname}")
string(TOUPPER "${varname}" varname)
if (_C)
CHECK_C_COMPILER_FLAG(${_flag} C_FLAG_${varname})
CHECK_C_COMPILER_FLAG("${_flag}" C_FLAG_${varname})
if (C_FLAG_${varname})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${_flag}" PARENT_SCOPE)
endif ()
endif ()
if (_CXX)
CHECK_CXX_COMPILER_FLAG(${_flag} CXX_FLAG_${varname})
CHECK_CXX_COMPILER_FLAG("${_flag}" CXX_FLAG_${varname})
if (CXX_FLAG_${varname})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_flag}" PARENT_SCOPE)
endif ()
Expand All @@ -39,7 +39,7 @@ function(EnableCompilerFlag _flag _C _CXX _LD)
# results for this configuration,
# see: https://gitlab.kitware.com/cmake/cmake/-/issues/22023
if (ZSTD_HAVE_CHECK_LINKER_FLAG AND NOT MSVC)
CHECK_LINKER_FLAG(C ${_flag} LD_FLAG_${varname})
CHECK_LINKER_FLAG(C "${_flag}" LD_FLAG_${varname})
else ()
set(LD_FLAG_${varname} false)
endif ()
Expand Down Expand Up @@ -76,7 +76,7 @@ macro(ADD_ZSTD_COMPILATION_FLAGS)
endif ()
# Add noexecstack flags
# LDFLAGS
EnableCompilerFlag("-z noexecstack" false false true)
EnableCompilerFlag("-z;noexecstack" false false true)
# CFLAGS & CXXFLAGS
EnableCompilerFlag("-Qunused-arguments" true true false)
EnableCompilerFlag("-Wa,--noexecstack" true true false)
Expand Down

0 comments on commit 1b9b1f6

Please sign in to comment.