From 23691291a81667795d209f3f2a812a99781412c4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Fri, 22 Apr 2011 10:40:25 +0100 Subject: [PATCH] Use -fvidibility=hidden to restrict dynamic symbols. --- CMakeLists.txt | 7 +++++++ glxtrace.py | 9 +++++++-- os.hpp | 18 ++++++++++++++++++ trace.py | 9 ++++++++- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fe8efd..1960025 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/glxtrace.py b/glxtrace.py index b7a8f66..7a3574b 100644 --- a/glxtrace.py +++ b/glxtrace.py @@ -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 eaf571d..0716784 100644 --- 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. */ diff --git a/trace.py b/trace.py index 7d40cb7..1a29a4a 100644 --- 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) -- 2.7.4