From c69ed5a4ad2e625dbe2206b170822f6b5154bd5e Mon Sep 17 00:00:00 2001 From: Juan Hoyos Date: Fri, 19 Mar 2021 01:08:23 -0700 Subject: Disable looking for PaxCtl on non Linux/BSD distros (#49746) --- eng/native/functions.cmake | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'eng/native/functions.cmake') diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index f39fb67bd0c..3e01c275025 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -392,19 +392,24 @@ endfunction() # - creating executable pages from anonymous memory, # - making read-only-after-relocations (RELRO) data pages writable again. function(disable_pax_mprotect targetName) - # Try to locate the paxctl tool. Failure to find it is not fatal, - # but the generated executables won't work on a system where PAX is set - # to prevent applications to create executable memory mappings. - find_program(PAXCTL paxctl) - - if (NOT PAXCTL STREQUAL "PAXCTL-NOTFOUND") - add_custom_command( - TARGET ${targetName} - POST_BUILD - VERBATIM - COMMAND ${PAXCTL} -c -m $ - ) - endif() + # Disabling PAX hardening only makes sense in systems that use Elf image formats. Particularly, looking + # for paxctl in macOS is problematic as it collides with popular software for that OS that performs completely + # unrelated functionality. Only look for it when we'll generate Elf images. + if (CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) + # Try to locate the paxctl tool. Failure to find it is not fatal, + # but the generated executables won't work on a system where PAX is set + # to prevent applications to create executable memory mappings. + find_program(PAXCTL paxctl) + + if (NOT PAXCTL STREQUAL "PAXCTL-NOTFOUND") + add_custom_command( + TARGET ${targetName} + POST_BUILD + VERBATIM + COMMAND ${PAXCTL} -c -m $ + ) + endif() + endif(CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_FREEBSD OR CLR_CMAKE_HOST_NETBSD OR CLR_CMAKE_HOST_SUNOS) endfunction() if (CMAKE_VERSION VERSION_LESS "3.12") -- cgit v1.2.3