diff options
| author | Andres Freund <andres@anarazel.de> | 2022-07-17 17:49:51 -0700 |
|---|---|---|
| committer | Andres Freund <andres@anarazel.de> | 2022-07-17 17:49:51 -0700 |
| commit | 089480c077056fc20fa8d8f5a3032a9dcf5ed812 (patch) | |
| tree | e5b2ad0c9a66073ea08306e5539e0f3b4df159ba /configure.ac | |
| parent | fd4bad1655391582f639527c325fc4a99680cc64 (diff) | |
Default to hidden visibility for extension libraries where possible
Until now postgres built extension libraries with global visibility, i.e.
exporting all symbols. On the one platform where that behavior is not
natively available, namely windows, we emulate it by analyzing the input files
to the shared library and exporting all the symbols therein.
Not exporting all symbols is actually desirable, as it can improve loading
speed, reduces the likelihood of symbol conflicts and can improve intra
extension library function call performance. It also makes the non-windows
builds more similar to windows builds.
Additionally, with meson implementing the export-all-symbols behavior for
windows, turns out to be more verbose than desirable.
This patch adds support for hiding symbols by default and, to counteract that,
explicit symbol visibility annotation for compilers that support
__attribute__((visibility("default"))) and -fvisibility=hidden. That is
expected to be most, if not all, compilers except msvc (for which we already
support explicit symbol export annotations).
Now that extension library symbols are explicitly exported, we don't need to
export all symbols on windows anymore, hence remove that behavior from
src/tools/msvc. The supporting code can't be removed, as we still need to
export all symbols from the main postgres binary.
Author: Andres Freund <andres@anarazel.de>
Author: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/20211101020311.av6hphdl6xbjbuif@alap3.anarazel.de
Diffstat (limited to 'configure.ac')
| -rw-r--r-- | configure.ac | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index 71191f14ad7..5bd29a4d2f2 100644 --- a/configure.ac +++ b/configure.ac @@ -525,6 +525,17 @@ if test "$GCC" = yes -a "$ICC" = no; then # Optimization flags for specific files that benefit from vectorization PGAC_PROG_CC_VAR_OPT(CFLAGS_VECTORIZE, [-ftree-vectorize]) # + # If the compiler knows how to hide symbols add the switch needed for that + # to CFLAGS_SL_MODULE and define HAVE_VISIBILITY_ATTRIBUTE. + PGAC_PROG_CC_VAR_OPT(CFLAGS_SL_MODULE, [-fvisibility=hidden]) + if test "$pgac_cv_prog_CC_cflags__fvisibility_hidden" = yes; then + AC_DEFINE([HAVE_VISIBILITY_ATTRIBUTE], 1, + [Define to 1 if your compiler knows the visibility("hidden") attribute.]) + fi + # For C++ we additionally want -fvisibility-inlines-hidden + PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-fvisibility=hidden]) + PGAC_PROG_VARCXX_VARFLAGS_OPT(CXX, CXXFLAGS_SL_MODULE, [-fvisibility-inlines-hidden]) + # # The following tests want to suppress various unhelpful warnings by adding # -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo # switches, so we have to test for the positive form and if that works, @@ -573,6 +584,8 @@ fi AC_SUBST(CFLAGS_UNROLL_LOOPS) AC_SUBST(CFLAGS_VECTORIZE) +AC_SUBST(CFLAGS_SL_MODULE) +AC_SUBST(CXXFLAGS_SL_MODULE) # Determine flags used to emit bitcode for JIT inlining. # 1. We must duplicate any behaviour-changing compiler flags used above, |
