Limiting functions and data structures visibility in a shared library
so they are hidden from other other code linked with library can allow
the compiler to generate better quality code and reduce linking
overhead on startup.  Hiding the internal functions and data
structures also allow more flexibility in changing internal
implementation while keeping compatibility with previous versions of
the library.

This patch limits libpfm to making visible the function listed in the
header files it provides.  The llvm clang compiler honor the gcc
visibility option and pragmas.  According to the libabigail tool
abidiff 59 functions and 154 variables were hidden as a result of this
change. The patch reduces the size of the shared library by about 14KB
(0.8%) on x86_64.

Signed-off-by: William Cohen <wco...@redhat.com>
---
 include/perfmon/perf_event.h        | 4 ++++
 include/perfmon/pfmlib.h            | 4 ++++
 include/perfmon/pfmlib_perf_event.h | 4 ++++
 lib/Makefile                        | 2 +-
 4 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/perfmon/perf_event.h b/include/perfmon/perf_event.h
index cadcec7..a11a8cd 100644
--- a/include/perfmon/perf_event.h
+++ b/include/perfmon/perf_event.h
@@ -22,6 +22,8 @@
 #ifndef __PERFMON_PERF_EVENT_H__
 #define __PERFMON_PERF_EVENT_H__
 
+#pragma GCC visibility push(default)
+
 #include <sys/types.h>
 #include <unistd.h>            /* for syscall numbers */
 #include <inttypes.h>
@@ -588,4 +590,6 @@ union perf_mem_data_src {
 }
 #endif
 
+#pragma GCC visibility pop
+
 #endif /* __PERFMON_PERF_EVENT_H__ */
diff --git a/include/perfmon/pfmlib.h b/include/perfmon/pfmlib.h
index a548be2..b05754b 100644
--- a/include/perfmon/pfmlib.h
+++ b/include/perfmon/pfmlib.h
@@ -26,6 +26,8 @@
 #ifndef __PFMLIB_H__
 #define __PFMLIB_H__
 
+#pragma GCC visibility push(default)
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -534,4 +536,6 @@ extern pfm_err_t pfm_get_event_encoding(const char *str, 
int dfl_plm, char **fst
 }
 #endif
 
+#pragma GCC visibility pop
+
 #endif /* __PFMLIB_H__ */
diff --git a/include/perfmon/pfmlib_perf_event.h 
b/include/perfmon/pfmlib_perf_event.h
index 8b3dae2..0516277 100644
--- a/include/perfmon/pfmlib_perf_event.h
+++ b/include/perfmon/pfmlib_perf_event.h
@@ -25,6 +25,8 @@
 #include <perfmon/pfmlib.h>
 #include <perfmon/perf_event.h>
 
+#pragma GCC visibility push(default)
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -61,4 +63,6 @@ extern pfm_err_t pfm_get_perf_event_encoding(const char *str,
 }
 #endif
 
+#pragma GCC visibility pop
+
 #endif /* __PFMLIB_PERF_EVENT_H__ */
diff --git a/lib/Makefile b/lib/Makefile
index a2c5818..f035307 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -33,7 +33,7 @@ ifeq ($(SYS),Linux)
 SRCS += pfmlib_perf_event_pmu.c pfmlib_perf_event.c pfmlib_perf_event_raw.c
 endif
 
-CFLAGS+=-D_REENTRANT -I.
+CFLAGS+=-D_REENTRANT -I. -fvisibility=hidden
 
 #
 # list all library support modules
-- 
2.5.0


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
perfmon2-devel mailing list
perfmon2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perfmon2-devel

Reply via email to