Fix protecting exported symbols from overrides.

While all symbols except for the ones in the version script are hidden,
the exported ones can still be overridden by other libraries which
export the same symbols. Using -fvisibility=protected fixes this. We can
only apply it to the shared library targets because of ld linker issues.

Bug b/110884149

Change-Id: I98222420eabbb9ea0873816f52e1354625b9a3a8
Reviewed-on: https://swiftshader-review.googlesource.com/19688
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c5a017..5a37ce2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -110,6 +110,9 @@
         set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--version-script=${DIR}/${TARGET}.lds")
         set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_DEPENDS "${DIR}/${TARGET}.lds;")
 
+        # Don't allow symbols to be overridden by another module.
+        set_property(TARGET ${TARGET} APPEND_STRING PROPERTY COMPILE_FLAGS " -fvisibility=protected")
+
         # Both hash-style are needed, because we want both gold and
         # GNU ld to be able to read our libraries.
         set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -Wl,--hash-style=both")