]> git.cworth.org Git - apitrace/commitdiff
Use -fvidibility=hidden to restrict dynamic symbols.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 22 Apr 2011 09:40:25 +0000 (10:40 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 22 Apr 2011 09:40:25 +0000 (10:40 +0100)
CMakeLists.txt
glxtrace.py
os.hpp
trace.py

index 6fe8efd86574f7806bc39674fbba1a5f2a3e8999..1960025e471ad946c2d7893a51a1cf77b9917c3c 100755 (executable)
@@ -1,5 +1,7 @@
 cmake_minimum_required (VERSION 2.8)
 
+include (CheckCXXCompilerFlag)
+
 project (apitrace)
 
 set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
@@ -38,6 +40,11 @@ endif (NOT WIN32)
 if (WIN32)
     # MSVC & MinGW only define & use APIENTRY
     add_definitions (-DGLAPIENTRY=__stdcall)
+else (WIN32)
+    CHECK_CXX_COMPILER_FLAG("-fvisibility=hidden" CXX_COMPILER_FLAG_VISIBILITY)
+    if (CXX_COMPILER_FLAG_VISIBILITY)
+        add_definitions ("-fvisibility=hidden")
+    endif (CXX_COMPILER_FLAG_VISIBILITY)
 endif (WIN32)
 
 if (MSVC)
index b7a8f66cd48c3aa65f9408b71c0f9f58bdc88d86..7a3574b38c789239619a9c4c70ccba97573a6317 100644 (file)
@@ -1,5 +1,6 @@
 ##########################################################################
 #
+# Copyright 2011 Jose Fonseca
 # Copyright 2008-2010 VMware, Inc.
 # All Rights Reserved.
 #
@@ -36,6 +37,10 @@ from dispatch import function_pointer_type, function_pointer_value
 
 class GlxTracer(GlTracer):
 
+    def is_public_function(self, function):
+        # The symbols visible in libGL.so can vary, so expose them all
+        return True
+
     def get_function_address(self, function):
         return '__%s' % (function.name,)
 
@@ -114,8 +119,8 @@ static void *__dlopen(const char *filename, int flag)
  * we need to intercept the dlopen() call here, and redirect to our wrapper
  * shared object.
  */
-extern "C" void *
-dlopen(const char *filename, int flag)
+extern "C" PUBLIC
+void * dlopen(const char *filename, int flag)
 {
     void *handle;
 
diff --git a/os.hpp b/os.hpp
index eaf571db0926f0097c5ccbae6f22c450b8be5bb5..0716784ec939e0ef29ba7563b54a9f7166ef9d2c 100644 (file)
--- a/os.hpp
+++ b/os.hpp
@@ -61,6 +61,24 @@ bool GetCurrentDir(char *str, size_t size);
 
 void DebugMessage(const char *format, ...);
 
+#if defined _WIN32 || defined __CYGWIN__
+  /* We always use .def files on windows for now */
+  #if 0
+  #define PUBLIC __declspec(dllexport)
+  #else
+  #define PUBLIC
+  #endif
+  #define PRIVATE
+#else
+  #if __GNUC__ >= 4
+    #define PUBLIC __attribute__ ((visibility("default")))
+    #define PRIVATE __attribute__ ((visibility("hidden")))
+  #else
+    #define PUBLIC
+    #define PRIVATE
+  #endif
+#endif
+
 /**
  * Get the current time in microseconds from an unknown base.
  */
index 7d40cb7c5d9d8ad9cd3f78d34a23c39421bfc28f..1a29a4a84417523611651fc6764b7bc8b7362761 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -313,8 +313,15 @@ class Tracer:
     def get_dispatch_function(self, function):
         return '__' + function.name
 
+    def is_public_function(self, function):
+        return True
+
     def trace_function_impl(self, function):
-        print 'extern "C" ' + function.prototype() + ' {'
+        if self.is_public_function(function):
+            print 'extern "C" PUBLIC'
+        else:
+            print 'extern "C" PRIVATE'
+        print function.prototype() + ' {'
         if function.type is not stdapi.Void:
             print '    %s __result;' % function.type
         self.trace_function_impl_body(function)