Thread: [perfmon2] [PATCH] Limit functions visibility in the libpfm library to ones listed in header files
Status: Beta
Brought to you by:
seranian
|
From: William C. <wc...@re...> - 2016-03-04 16:19:06
|
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 <wc...@re...>
---
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
|
|
From: Stephane E. <er...@go...> - 2016-03-12 16:10:11
|
Hi Will,
I tried your patch on my Ubuntu system.
It is using gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1).
It compiles fine but I see no difference in size using size -t lib/libpfm.a.
It gave me this with or without the patch and with gcc org LLVM:
text data bss dec hex filename
1177904 67804 5760 1251468 13188c(TOTALS) # GCC-4.8
1158994 67056 5768 1231818 12cbca (TOTALS) #CLANG 3.7
So do you need a specific compiler version or the patch is missing
something?
Thanks.
On Fri, Mar 4, 2016 at 5:18 PM, William Cohen <wc...@re...> wrote:
> 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 <wc...@re...>
> ---
> 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
> per...@li...
> https://lists.sourceforge.net/lists/listinfo/perfmon2-devel
>
|
|
From: Andreas B. <an...@de...> - 2016-03-12 22:50:36
|
On 2016-03-12 17:10, Stephane Eranian wrote: > Hi Will, > > I tried your patch on my Ubuntu system. > It is using gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1). > > It compiles fine but I see no difference in size using size -t lib/libpfm.a. > So do you need a specific compiler version or the patch is missing > something? That patch primarily affects the (exported) content of the shared library, not the static library. I gave it a short test on Debian and papi (the only user of the libpfm4 package) continued to work after I installed the new libpfm4 package which exports fewer symbols. (In Debian, papi is built against the separately packaged libpfm4, not the bundled copy. It uses the shared library.) Andreas |
|
From: William C. <wc...@re...> - 2016-03-14 14:06:22
Attachments:
abidiff.log
|
On 03/12/2016 05:50 PM, Andreas Beckmann wrote: > On 2016-03-12 17:10, Stephane Eranian wrote: >> Hi Will, >> >> I tried your patch on my Ubuntu system. >> It is using gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1). >> >> It compiles fine but I see no difference in size using size -t lib/libpfm.a. > >> So do you need a specific compiler version or the patch is missing >> something? > > That patch primarily affects the (exported) content of the shared > library, not the static library. > > I gave it a short test on Debian and papi (the only user of the libpfm4 > package) continued to work after I installed the new libpfm4 package > which exports fewer symbols. (In Debian, papi is built against the > separately packaged libpfm4, not the bundled copy. It uses the shared > library.) > > Andreas Hi Stephane and Andreas, Yes, the change is only going to affect the libpfm.so file. The libpfm.a is going to be the same. the abidiff from libabigail (https://www.sourceware.org/libabigail/) shows that a lot of the internal symbols are no longer exported. Attached is the output of: abidiff libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 > abidiff.log eu-size shows the reduction in size: $ eu-size libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 text data bss dec hex filename 1120871 673600 6208 1800679 1b79e7 libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 1106646 673368 6208 1786222 1b416e libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 "eu-readelf -l" also shows the reductions: $ eu-readelf -l libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 libpfm-4.7.0.orig/lib/libpfm.so.4.7.0: Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x111c4c 0x111c4c R E 0x200000 LOAD 0x112570 0x0000000000312570 0x0000000000312570 0x0a4768 0x0a5fb0 RW 0x200000 DYNAMIC 0x1a5da0 0x00000000003a5da0 0x00000000003a5da0 0x0001d0 0x0001d0 RW 0x8 NOTE 0x0001c8 0x00000000000001c8 0x00000000000001c8 0x000024 0x000024 R 0x4 GNU_EH_FRAME 0x10f614 0x000000000010f614 0x000000000010f614 0x00078c 0x00078c R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 GNU_RELRO 0x112570 0x0000000000312570 0x0000000000312570 0x093a90 0x093a90 R 0x1 Section to Segment mapping: Segment Sections... 00 [RO: .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame] 01 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic .got] .got.plt .data .bss 02 [RELRO: .dynamic] 03 [RO: .note.gnu.build-id] 04 [RO: .eh_frame_hdr] 05 06 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic .got] libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0: Program Headers: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x10e4cc 0x10e4cc R E 0x200000 LOAD 0x10e5c8 0x000000000030e5c8 0x000000000030e5c8 0x0a4670 0x0a5eb8 RW 0x200000 DYNAMIC 0x1a1de0 0x00000000003a1de0 0x00000000003a1de0 0x0001d0 0x0001d0 RW 0x8 NOTE 0x0001c8 0x00000000000001c8 0x00000000000001c8 0x000024 0x000024 R 0x4 GNU_EH_FRAME 0x10be94 0x000000000010be94 0x000000000010be94 0x00078c 0x00078c R 0x4 GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10 GNU_RELRO 0x10e5c8 0x000000000030e5c8 0x000000000030e5c8 0x093a38 0x093a38 R 0x1 Section to Segment mapping: Segment Sections... 00 [RO: .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame] 01 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic .got] .got.plt .data .bss 02 [RELRO: .dynamic] 03 [RO: .note.gnu.build-id] 04 [RO: .eh_frame_hdr] 05 06 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic .got] -Will |
|
From: Stephane E. <er...@go...> - 2016-03-24 06:53:16
|
Hi Will, Indeed seeing a size reduction on the .so on X86 and ARM. Patch applied. Thanks. On Mon, Mar 14, 2016 at 3:06 PM, William Cohen <wc...@re...> wrote: > On 03/12/2016 05:50 PM, Andreas Beckmann wrote: > > On 2016-03-12 17:10, Stephane Eranian wrote: > >> Hi Will, > >> > >> I tried your patch on my Ubuntu system. > >> It is using gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.1). > >> > >> It compiles fine but I see no difference in size using size -t > lib/libpfm.a. > > > >> So do you need a specific compiler version or the patch is missing > >> something? > > > > That patch primarily affects the (exported) content of the shared > > library, not the static library. > > > > I gave it a short test on Debian and papi (the only user of the libpfm4 > > package) continued to work after I installed the new libpfm4 package > > which exports fewer symbols. (In Debian, papi is built against the > > separately packaged libpfm4, not the bundled copy. It uses the shared > > library.) > > > > Andreas > > Hi Stephane and Andreas, > > Yes, the change is only going to affect the libpfm.so file. The libpfm.a > is going to be the same. the abidiff from libabigail ( > https://www.sourceware.org/libabigail/) shows that a lot of the internal > symbols are no longer exported. Attached is the output of: > > > abidiff libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 > libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 > abidiff.log > > > eu-size shows the reduction in size: > > $ eu-size libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 > libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 > text data bss > dec hex filename > 1120871 673600 6208 > 1800679 1b79e7 libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 > 1106646 673368 6208 > 1786222 1b416e libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 > > "eu-readelf -l" also shows the reductions: > > $ eu-readelf -l libpfm-4.7.0.orig/lib/libpfm.so.4.7.0 > libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0 > > libpfm-4.7.0.orig/lib/libpfm.so.4.7.0: > > Program Headers: > Type Offset VirtAddr PhysAddr FileSiz > MemSiz Flg Align > LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x111c4c > 0x111c4c R E 0x200000 > LOAD 0x112570 0x0000000000312570 0x0000000000312570 0x0a4768 > 0x0a5fb0 RW 0x200000 > DYNAMIC 0x1a5da0 0x00000000003a5da0 0x00000000003a5da0 0x0001d0 > 0x0001d0 RW 0x8 > NOTE 0x0001c8 0x00000000000001c8 0x00000000000001c8 0x000024 > 0x000024 R 0x4 > GNU_EH_FRAME 0x10f614 0x000000000010f614 0x000000000010f614 0x00078c > 0x00078c R 0x4 > GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 > 0x000000 RW 0x10 > GNU_RELRO 0x112570 0x0000000000312570 0x0000000000312570 0x093a90 > 0x093a90 R 0x1 > > Section to Segment mapping: > Segment Sections... > 00 [RO: .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version > .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata > .eh_frame_hdr .eh_frame] > 01 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic > .got] .got.plt .data .bss > 02 [RELRO: .dynamic] > 03 [RO: .note.gnu.build-id] > 04 [RO: .eh_frame_hdr] > 05 > 06 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic > .got] > > libpfm-4.7.0.hidden/lib/libpfm.so.4.7.0: > > Program Headers: > Type Offset VirtAddr PhysAddr FileSiz > MemSiz Flg Align > LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x10e4cc > 0x10e4cc R E 0x200000 > LOAD 0x10e5c8 0x000000000030e5c8 0x000000000030e5c8 0x0a4670 > 0x0a5eb8 RW 0x200000 > DYNAMIC 0x1a1de0 0x00000000003a1de0 0x00000000003a1de0 0x0001d0 > 0x0001d0 RW 0x8 > NOTE 0x0001c8 0x00000000000001c8 0x00000000000001c8 0x000024 > 0x000024 R 0x4 > GNU_EH_FRAME 0x10be94 0x000000000010be94 0x000000000010be94 0x00078c > 0x00078c R 0x4 > GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 > 0x000000 RW 0x10 > GNU_RELRO 0x10e5c8 0x000000000030e5c8 0x000000000030e5c8 0x093a38 > 0x093a38 R 0x1 > > Section to Segment mapping: > Segment Sections... > 00 [RO: .note.gnu.build-id .gnu.hash .dynsym .dynstr .gnu.version > .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata > .eh_frame_hdr .eh_frame] > 01 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic > .got] .got.plt .data .bss > 02 [RELRO: .dynamic] > 03 [RO: .note.gnu.build-id] > 04 [RO: .eh_frame_hdr] > 05 > 06 [RELRO: .init_array .fini_array .jcr .data.rel.ro .dynamic > .got] > > > -Will > > > ------------------------------------------------------------------------------ > Transform Data into Opportunity. > Accelerate data analysis in your applications with > Intel Data Analytics Acceleration Library. > Click to learn more. > http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140 > _______________________________________________ > perfmon2-devel mailing list > per...@li... > https://lists.sourceforge.net/lists/listinfo/perfmon2-devel > > |