mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
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
This commit is contained in:
152
configure
vendored
Executable file → Normal file
152
configure
vendored
Executable file → Normal file
@ -741,6 +741,8 @@ CPP
|
||||
CFLAGS_SL
|
||||
BITCODE_CXXFLAGS
|
||||
BITCODE_CFLAGS
|
||||
CXXFLAGS_SL_MODULE
|
||||
CFLAGS_SL_MODULE
|
||||
CFLAGS_VECTORIZE
|
||||
CFLAGS_UNROLL_LOOPS
|
||||
PERMIT_DECLARATION_AFTER_STATEMENT
|
||||
@ -6302,6 +6304,154 @@ if test x"$pgac_cv_prog_CC_cflags__ftree_vectorize" = x"yes"; then
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# If the compiler knows how to hide symbols add the switch needed for that
|
||||
# to CFLAGS_SL_MODULE and define HAVE_VISIBILITY_ATTRIBUTE.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MODULE" >&5
|
||||
$as_echo_n "checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MODULE... " >&6; }
|
||||
if ${pgac_cv_prog_CC_cflags__fvisibility_hidden+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
pgac_save_CFLAGS=$CFLAGS
|
||||
pgac_save_CC=$CC
|
||||
CC=${CC}
|
||||
CFLAGS="${CFLAGS_SL_MODULE} -fvisibility=hidden"
|
||||
ac_save_c_werror_flag=$ac_c_werror_flag
|
||||
ac_c_werror_flag=yes
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
pgac_cv_prog_CC_cflags__fvisibility_hidden=yes
|
||||
else
|
||||
pgac_cv_prog_CC_cflags__fvisibility_hidden=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
ac_c_werror_flag=$ac_save_c_werror_flag
|
||||
CFLAGS="$pgac_save_CFLAGS"
|
||||
CC="$pgac_save_CC"
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__fvisibility_hidden" >&5
|
||||
$as_echo "$pgac_cv_prog_CC_cflags__fvisibility_hidden" >&6; }
|
||||
if test x"$pgac_cv_prog_CC_cflags__fvisibility_hidden" = x"yes"; then
|
||||
CFLAGS_SL_MODULE="${CFLAGS_SL_MODULE} -fvisibility=hidden"
|
||||
fi
|
||||
|
||||
|
||||
if test "$pgac_cv_prog_CC_cflags__fvisibility_hidden" = yes; then
|
||||
|
||||
$as_echo "#define HAVE_VISIBILITY_ATTRIBUTE 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
# For C++ we additionally want -fvisibility-inlines-hidden
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE" >&5
|
||||
$as_echo_n "checking whether ${CXX} supports -fvisibility=hidden, for CXXFLAGS_SL_MODULE... " >&6; }
|
||||
if ${pgac_cv_prog_CXX_cxxflags__fvisibility_hidden+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
pgac_save_CXXFLAGS=$CXXFLAGS
|
||||
pgac_save_CXX=$CXX
|
||||
CXX=${CXX}
|
||||
CXXFLAGS="${CXXFLAGS_SL_MODULE} -fvisibility=hidden"
|
||||
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
|
||||
ac_cxx_werror_flag=yes
|
||||
ac_ext=cpp
|
||||
ac_cpp='$CXXCPP $CPPFLAGS'
|
||||
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
||||
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_cxx_try_compile "$LINENO"; then :
|
||||
pgac_cv_prog_CXX_cxxflags__fvisibility_hidden=yes
|
||||
else
|
||||
pgac_cv_prog_CXX_cxxflags__fvisibility_hidden=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
|
||||
CXXFLAGS="$pgac_save_CXXFLAGS"
|
||||
CXX="$pgac_save_CXX"
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" >&5
|
||||
$as_echo "$pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" >&6; }
|
||||
if test x"$pgac_cv_prog_CXX_cxxflags__fvisibility_hidden" = x"yes"; then
|
||||
CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -fvisibility=hidden"
|
||||
fi
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE" >&5
|
||||
$as_echo_n "checking whether ${CXX} supports -fvisibility-inlines-hidden, for CXXFLAGS_SL_MODULE... " >&6; }
|
||||
if ${pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
pgac_save_CXXFLAGS=$CXXFLAGS
|
||||
pgac_save_CXX=$CXX
|
||||
CXX=${CXX}
|
||||
CXXFLAGS="${CXXFLAGS_SL_MODULE} -fvisibility-inlines-hidden"
|
||||
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
|
||||
ac_cxx_werror_flag=yes
|
||||
ac_ext=cpp
|
||||
ac_cpp='$CXXCPP $CPPFLAGS'
|
||||
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
|
||||
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_cxx_try_compile "$LINENO"; then :
|
||||
pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden=yes
|
||||
else
|
||||
pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
ac_ext=c
|
||||
ac_cpp='$CPP $CPPFLAGS'
|
||||
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
|
||||
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
|
||||
ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
|
||||
CXXFLAGS="$pgac_save_CXXFLAGS"
|
||||
CXX="$pgac_save_CXX"
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" >&5
|
||||
$as_echo "$pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" >&6; }
|
||||
if test x"$pgac_cv_prog_CXX_cxxflags__fvisibility_inlines_hidden" = x"yes"; then
|
||||
CXXFLAGS_SL_MODULE="${CXXFLAGS_SL_MODULE} -fvisibility-inlines-hidden"
|
||||
fi
|
||||
|
||||
#
|
||||
# The following tests want to suppress various unhelpful warnings by adding
|
||||
# -Wno-foo switches. But gcc won't complain about unrecognized -Wno-foo
|
||||
@ -6860,6 +7010,8 @@ fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Determine flags used to emit bitcode for JIT inlining.
|
||||
# 1. We must duplicate any behaviour-changing compiler flags used above,
|
||||
# to keep compatibility with the compiler used for normal Postgres code.
|
||||
|
Reference in New Issue
Block a user