summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2016-04-16 15:08:43 +0100
committerJose Fonseca <jfonseca@vmware.com>2016-04-16 15:08:43 +0100
commit49dfaaf14098fedd6b3791a0ef2ad32b9291bcf8 (patch)
tree34b8f90fa7c9003dbf30d4f0ff03495bfdbb9a17
parenta7caf011c7ae5a6d8fd65165db0e1b1c62851659 (diff)
cmake: Add option to build with Address Sanitizer.
Also remove SSP: it was only being used in Debug builds, and it never found a bug.
-rw-r--r--CMakeLists.txt17
-rw-r--r--wrappers/CMakeLists.txt23
2 files changed, 21 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7edf761f..26ded14d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,8 @@ option (ENABLE_WAFFLE "Enable WAFFLE support." OFF)
option (ENABLE_FRAME_POINTER "Disable frame pointer omission" ON)
+option (ENABLE_ASAN "Enable Address Sanitizer" OFF)
+
# Proprietary Linux games often ship their own libraries (zlib, libstdc++,
# etc.) in order to ship a single set of binaries across multiple
# distributions. Given that apitrace wrapper modules will be loaded into those
@@ -291,17 +293,10 @@ else ()
# Disable C++ exceptions
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
- # Enable stack protection
- if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_COMPILER_IS_GNUCXX)
- set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fstack-protector-all")
- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fstack-protector-all")
- if (MINGW)
- # MinGW doesn't link against libssp automatically, and furthermore
- # we want static linking.
- set (SSP_LIBRARY "-Wl,-Bstatic -lssp -Wl,-Bdynamic")
- set (CMAKE_C_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_C_STANDARD_LIBRARIES}")
- set (CMAKE_CXX_STANDARD_LIBRARIES "${SSP_LIBRARY} ${CMAKE_CXX_STANDARD_LIBRARIES}")
- endif ()
+ # Enable Address Sanitizer
+ if (ENABLE_ASAN)
+ add_compiler_flags (-fsanitize=address)
+ add_linker_flags (-fsanitize=address)
endif ()
# Enable SSE2 intrinsics on x86
diff --git a/wrappers/CMakeLists.txt b/wrappers/CMakeLists.txt
index 4a3f7e34..2f0d1cf4 100644
--- a/wrappers/CMakeLists.txt
+++ b/wrappers/CMakeLists.txt
@@ -56,6 +56,21 @@ include_directories (
${CMAKE_SOURCE_DIR}/guids
)
+if (NOT WIN32 AND NOT APPLE)
+ # Prevent symbol relocations internal to our wrapper library to be
+ # overwritten by the application. And fail if there are missing
+ # symbols.
+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic -Wl,-Bsymbolic-functions")
+ set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-Bsymbolic -Wl,-Bsymbolic-functions")
+
+ # Fail if there are missing symbols, except when using Address Sanitizer
+ # since libasan symbols are supposed to be preloaded.
+ if (NOT ENABLE_ASAN)
+ set (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,defs")
+ set (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,-z,defs")
+ endif ()
+endif ()
+
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_convenience_library (trace
@@ -351,10 +366,6 @@ elseif (X11_FOUND)
set_target_properties (glxtrace PROPERTIES
# avoid the default "lib" prefix
PREFIX ""
- # Prevent symbol relocations internal to our wrapper library to be
- # overwritten by the application. And fail if there are missing
- # symbols.
- LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions -Wl,-z,defs"
)
target_link_libraries (glxtrace
@@ -402,10 +413,6 @@ if (ENABLE_EGL AND NOT WIN32 AND NOT APPLE)
set_target_properties (egltrace PROPERTIES
# avoid the default "lib" prefix
PREFIX ""
- # Prevent symbol relocations internal to our wrapper library to be
- # overwritten by the application. And fail if there are missing
- # symbols.
- LINK_FLAGS "-Wl,-Bsymbolic -Wl,-Bsymbolic-functions -Wl,-z,defs"
)
target_link_libraries (egltrace