Skip to content

Commit

Permalink
Fix compile & linker warnings (#8356)
Browse files Browse the repository at this point in the history
Fix warnings emitted during the Filament compilation using CLion and
./build.sh script.

BUGS=[390207431]
  • Loading branch information
z3moon authored Jan 17, 2025
1 parent c49d72e commit 4c3a324
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
13 changes: 11 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -475,7 +484,7 @@ if (APPLE)
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> qc -S <TARGET> <LINK_FLAGS> <OBJECTS>")
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)
Expand Down
41 changes: 24 additions & 17 deletions third_party/libassimp/tnt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
15 changes: 11 additions & 4 deletions third_party/libz/tnt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c3a324

Please sign in to comment.