OSDN Git Service

Fix protecting exported symbols from overrides.
authorNicolas Capens <capn@google.com>
Fri, 29 Jun 2018 17:30:57 +0000 (13:30 -0400)
committerNicolas Capens <nicolascapens@google.com>
Wed, 4 Jul 2018 13:36:45 +0000 (13:36 +0000)
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>
CMakeLists.txt

index 9c5a017..5a37ce2 100644 (file)
@@ -110,6 +110,9 @@ macro(set_shared_library_export_map TARGET DIR)
         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")