diff --git a/CMakeLists.txt b/CMakeLists.txt index b8462d29f1e..f9de5b2a5e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,10 +457,19 @@ if (NOT WEBGL) set(GC_SECTIONS "-Wl,--gc-sections") endif() +# Prevents stacks from being made for executable by explicitly adding this linker flag. Otherwise, +# it generates warnings newly introduced as of GNU LD 2.39. Modern security practices strongly +# recommend marking the stack as non-executable using the -z noexecstack linker flag to prevent +# stack-based buffer overflow exploits. +# See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ffcf9c5700e49c0aee42dcba9a12ba21338e8136 +if (LINUX) + set(NO_EXEC_STACK "-Wl,-z,noexecstack") +endif() + set(B_SYMBOLIC_FUNCTIONS "-Wl,-Bsymbolic-functions") if (ANDROID) -set(BINARY_ALIGNMENT "-Wl,-z,max-page-size=16384") + set(BINARY_ALIGNMENT "-Wl,-z,max-page-size=16384") endif() if (APPLE) @@ -475,7 +484,7 @@ if (APPLE) set(CMAKE_CXX_ARCHIVE_CREATE " qc -S ") endif() -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GC_SECTIONS}") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GC_SECTIONS} ${NO_EXEC_STACK}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GC_SECTIONS} ${B_SYMBOLIC_FUNCTIONS} ${BINARY_ALIGNMENT}") if (WEBGL_PTHREADS) diff --git a/third_party/libassimp/tnt/CMakeLists.txt b/third_party/libassimp/tnt/CMakeLists.txt index 92fe227d69e..53754ff6ea5 100644 --- a/third_party/libassimp/tnt/CMakeLists.txt +++ b/third_party/libassimp/tnt/CMakeLists.txt @@ -262,24 +262,31 @@ include_directories(${PRIVATE_HDR_DIR}) add_library(${TARGET} STATIC ${PRIVATE_HDRS} ${PUBLIC_HDRS} ${SRCS}) if(NOT MSVC) - target_compile_options(${TARGET} - PRIVATE -Wno-deprecated-declarations - PRIVATE -Wno-deprecated-register - PRIVATE -Wno-incompatible-pointer-types - PRIVATE -Wno-ordered-compare-function-pointers - PRIVATE -Wno-parentheses - PRIVATE -Wno-sign-compare - PRIVATE -Wno-strict-aliasing - PRIVATE -Wno-strict-overflow - PRIVATE -Wno-tautological-compare - PRIVATE -Wno-tautological-undefined-compare - PRIVATE -Wno-undefined-var-template - PRIVATE -Wno-uninitialized - PRIVATE -Wno-unused-const-variable - PRIVATE -Wno-unused-private-field - PRIVATE -Wno-unused-variable - PRIVATE -Wno-deprecated-non-prototype # See https://github.com/madler/zlib/issues/633 + set(TARGET_FLAGS + -Wno-deprecated-declarations + -Wno-deprecated-register + -Wno-incompatible-pointer-types + -Wno-ordered-compare-function-pointers + -Wno-parentheses + -Wno-sign-compare + -Wno-strict-aliasing + -Wno-strict-overflow + -Wno-tautological-compare + -Wno-tautological-undefined-compare + -Wno-undefined-var-template + -Wno-uninitialized + -Wno-unused-const-variable + -Wno-unused-private-field + -Wno-unused-variable ) + + # -Wdeprecated-non-prototype is a new warning introduced in Clang 15. + # https://www.redhat.com/en/blog/new-warnings-and-errors-clang-15 + if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "15.0") + list(APPEND TARGET_FLAGS -Wno-deprecated-non-prototype) # See https://github.com/madler/zlib/issues/633 + endif() + + target_compile_options(${TARGET} PRIVATE ${TARGET_FLAGS}) else() target_compile_options(${TARGET} PRIVATE /bigobj) endif() diff --git a/third_party/libz/tnt/CMakeLists.txt b/third_party/libz/tnt/CMakeLists.txt index ae6033f320e..14e6e1c910f 100644 --- a/third_party/libz/tnt/CMakeLists.txt +++ b/third_party/libz/tnt/CMakeLists.txt @@ -50,11 +50,18 @@ set(SRCS add_library(${TARGET} STATIC ${PRIVATE_HDRS} ${PUBLIC_HDRS} ${SRCS}) if (NOT MSVC) - target_compile_options(${TARGET} - PRIVATE -Wno-implicit-function-declaration - PRIVATE -Wno-shift-negative-value - PRIVATE -Wno-deprecated-non-prototype # See https://github.com/madler/zlib/issues/633 + set(TARGET_FLAGS + -Wno-implicit-function-declaration + -Wno-shift-negative-value ) + + # -Wdeprecated-non-prototype is a new warning introduced in Clang 15. + # https://www.redhat.com/en/blog/new-warnings-and-errors-clang-15 + if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "15.0") + list(APPEND TARGET_FLAGS -Wno-deprecated-non-prototype) # See https://github.com/madler/zlib/issues/633 + endif() + + target_compile_options(${TARGET} PRIVATE ${TARGET_FLAGS}) endif() # specify where the public headers of this library are