From 7b856e3028518109eb34019e215802cda7cbafc1 Mon Sep 17 00:00:00 2001 From: Victor Zhang Date: Tue, 4 Feb 2025 15:20:39 -0800 Subject: [PATCH] Add noexecstack flag for gcc/clang C and CPP in Meson The `-Wl,-z,noexecstack` and `-Wa,--noexecstack` flags are already set for CMake, but not for Meson. This brings the flags to the Meson build as well. Note that this maintains the discrepancy in behavior between CMake and Meson when it comes to enabling ASM: on CMake, the ZSTD_HAS_NOEXECSTACK variable is set and these flags added for GCC/Clang and MinGW. Then later, the ZSTD_HAS_NOEXECSTACK variable is checked (along with some other conditions) to enable or disable ASM. However on Meson, this logic is restricted to simply checking for GCC/Clang. This patch maintains this behavior; noexecstack is dependent on GCC/Clang only. --- build/meson/meson.build | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build/meson/meson.build b/build/meson/meson.build index 7ddca2e79..5c35478d5 100644 --- a/build/meson/meson.build +++ b/build/meson/meson.build @@ -116,10 +116,16 @@ if [compiler_gcc, compiler_clang].contains(cc_id) if cc_id == compiler_clang common_warning_flags += ['-Wconversion', '-Wno-sign-conversion', '-Wdocumentation'] endif - cc_compile_flags = cc.get_supported_arguments(common_warning_flags + ['-Wstrict-prototypes']) - cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags) + noexecstack_flags = ['-Wa,--noexecstack' ] + noexecstack_link_flags = ['-Wl,-z,noexecstack'] + cc_compile_flags = cc.get_supported_arguments(common_warning_flags + noexecstack_flags + ['-Wstrict-prototypes']) + cxx_compile_flags = cxx.get_supported_arguments(common_warning_flags + noexecstack_flags) add_project_arguments(cc_compile_flags, language : 'c') add_project_arguments(cxx_compile_flags, language : 'cpp') + cc_link_flags = cc.get_supported_link_arguments(noexecstack_link_flags) + cxx_link_flags = cxx.get_supported_link_arguments(noexecstack_link_flags) + add_project_link_arguments(cc_link_flags, language: 'c') + add_project_link_arguments(cxx_link_flags, language: 'cpp') elif cc_id == compiler_msvc msvc_compile_flags = [ '/D_UNICODE', '/DUNICODE' ] if use_multi_thread -- 2.47.2