Description: Use system libsnappy for retracers
 The tracers run LD_PRELOADed into arbitrary, often closed-source binaries,
 so statically-link libsnappy to minimise the possibility of symbol conflicts,
 but the retracers don't have that constraint and are used to process untrusted
 data.
Forwarded: not-needed
Author: Christopher James Halse Rogers <raof@ubuntu.com>

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -403,11 +403,18 @@
     find_package (SNAPPY)
 endif ()
 if (ENABLE_STATIC_SNAPPY OR NOT SNAPPY_FOUND)
-    set (SNAPPY_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
-    set (SNAPPY_LIBRARIES snappy_bundled)
+    # We want to use the system snappy for the retracers, as they run on
+    # potentially-untrusted input, but we need static snappy for the
+    # LD_PRELOADed tracers to avoid symbol collisions in the tracee.
+    #
+    # Predictably, the system libsnappy.a is built without PIC, so
+    # useless for us. So do both: find the system libsnappy for the
+    # retracers and and build the bundled libsnappy for the tracers.
+    find_package (SNAPPY REQUIRED)
+    set (SNAPPY_STATIC_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/snappy)
+    set (SNAPPY_STATIC_LIBRARIES snappy_bundled)
     add_subdirectory (thirdparty/snappy)
 endif ()
-include_directories (${SNAPPY_INCLUDE_DIRS})
 
 if (NOT WIN32)
     # zlib 1.2.4-1.2.5 made it impossible to read the last block of incomplete
--- a/wrappers/CMakeLists.txt
+++ b/wrappers/CMakeLists.txt
@@ -2,6 +2,8 @@
 # API tracers
 
 
+include_directories (${SNAPPY_STATIC_INCLUDE_DIRS})
+
 if (ENABLE_STATIC_LIBGCC)
     add_linker_flags (-static-libgcc)
 endif ()
@@ -62,7 +64,7 @@
 )
 target_link_libraries (trace
     common
-    ${SNAPPY_LIBRARIES}
+    ${SNAPPY_STATIC_LIBRARIES}
 )
 
 if (WIN32)
--- a/cli/CMakeLists.txt
+++ b/cli/CMakeLists.txt
@@ -14,6 +14,8 @@
     add_definitions (-DAPITRACE_PYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}")
 endif ()
 
+include_directories(${SNAPPY_INCLUDE_DIRS})
+
 add_executable (apitrace
     cli_main.cpp
     cli_diff.cpp
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -82,6 +82,7 @@
 #add_app_icon(qapitrace_SRCS ../icons/hi*-qapitrace.png)
 include_directories(
     ${CMAKE_SOURCE_DIR} # for image/*
+    ${SNAPPY_INCLUDE_DIRS}
 )
 
 add_executable (qapitrace ${qapitrace_SRCS} ${qapitrace_UIS_H})
--- a/retrace/CMakeLists.txt
+++ b/retrace/CMakeLists.txt
@@ -8,6 +8,7 @@
     ${CMAKE_SOURCE_DIR}/dispatch
     ${CMAKE_SOURCE_DIR}/image
     ${CMAKE_SOURCE_DIR}/thirdparty/dxerr
+    ${SNAPPY_INCLUDE_DIRS}
 )
 
 add_definitions (-DRETRACE)
