Skip to content

Commit ec15e1c

Browse files
committed
meson: prereq: Can we get away with not export-all'ing libraries?
By using explicit export annotations in shared libraries we avoid the need to generate export files on windows. And it reduces the number of exported symbols, which is good too. See also https://www.postgresql.org/message-id/20220111025328.iq5g6uck53j5qtin%40alap3.anarazel.de currently stuck on https://www.postgresql.org/message-id/20220111025328.iq5g6uck53j5qtin%40alap3.anarazel.de
1 parent 877d418 commit ec15e1c

File tree

18 files changed

+144
-52
lines changed

18 files changed

+144
-52
lines changed

configure

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ CPP
741741
CFLAGS_SL
742742
BITCODE_CXXFLAGS
743743
BITCODE_CFLAGS
744+
CFLAGS_SL_MOD
744745
CFLAGS_VECTORIZE
745746
CFLAGS_UNROLL_LOOPS
746747
PERMIT_DECLARATION_AFTER_STATEMENT
@@ -6485,6 +6486,54 @@ fi
64856486
if test -n "$NOT_THE_CFLAGS"; then
64866487
CFLAGS="$CFLAGS -Wno-stringop-truncation"
64876488
fi
6489+
6490+
# If the compiler knows how to hide symbols, use that. But only for shared libraries,
6491+
# for postgres itself that'd be too verbose for now.
6492+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MOD" >&5
6493+
$as_echo_n "checking whether ${CC} supports -fvisibility=hidden, for CFLAGS_SL_MOD... " >&6; }
6494+
if ${pgac_cv_prog_CC_cflags__fvisibility_hidden+:} false; then :
6495+
$as_echo_n "(cached) " >&6
6496+
else
6497+
pgac_save_CFLAGS=$CFLAGS
6498+
pgac_save_CC=$CC
6499+
CC=${CC}
6500+
CFLAGS="${CFLAGS_SL_MOD} -fvisibility=hidden"
6501+
ac_save_c_werror_flag=$ac_c_werror_flag
6502+
ac_c_werror_flag=yes
6503+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
6504+
/* end confdefs.h. */
6505+
6506+
int
6507+
main ()
6508+
{
6509+
6510+
;
6511+
return 0;
6512+
}
6513+
_ACEOF
6514+
if ac_fn_c_try_compile "$LINENO"; then :
6515+
pgac_cv_prog_CC_cflags__fvisibility_hidden=yes
6516+
else
6517+
pgac_cv_prog_CC_cflags__fvisibility_hidden=no
6518+
fi
6519+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
6520+
ac_c_werror_flag=$ac_save_c_werror_flag
6521+
CFLAGS="$pgac_save_CFLAGS"
6522+
CC="$pgac_save_CC"
6523+
fi
6524+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__fvisibility_hidden" >&5
6525+
$as_echo "$pgac_cv_prog_CC_cflags__fvisibility_hidden" >&6; }
6526+
if test x"$pgac_cv_prog_CC_cflags__fvisibility_hidden" = x"yes"; then
6527+
CFLAGS_SL_MOD="${CFLAGS_SL_MOD} -fvisibility=hidden"
6528+
fi
6529+
6530+
6531+
if test "$pgac_cv_prog_CC_cflags__fvisibility_hidden" = yes; then
6532+
6533+
$as_echo "#define HAVE_VISIBILITY_ATTRIBUTE 1" >>confdefs.h
6534+
6535+
fi
6536+
64886537
elif test "$ICC" = yes; then
64896538
# Intel's compiler has a bug/misoptimization in checking for
64906539
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.

configure.ac

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,15 @@ if test "$GCC" = yes -a "$ICC" = no; then
555555
if test -n "$NOT_THE_CFLAGS"; then
556556
CFLAGS="$CFLAGS -Wno-stringop-truncation"
557557
fi
558+
559+
# If the compiler knows how to hide symbols, use that. But only for shared libraries,
560+
# for postgres itself that'd be too verbose for now.
561+
PGAC_PROG_CC_VAR_OPT(CFLAGS_SL_MOD, [-fvisibility=hidden])
562+
if test "$pgac_cv_prog_CC_cflags__fvisibility_hidden" = yes; then
563+
AC_DEFINE(HAVE_VISIBILITY_ATTRIBUTE, 1,
564+
[Define to 1 if your compiler knows the visibility("hidden") attribute.])
565+
fi
566+
558567
elif test "$ICC" = yes; then
559568
# Intel's compiler has a bug/misoptimization in checking for
560569
# division by NAN (NaN == 0), -mp1 fixes it, so add it to the CFLAGS.
@@ -573,6 +582,7 @@ fi
573582

574583
AC_SUBST(CFLAGS_UNROLL_LOOPS)
575584
AC_SUBST(CFLAGS_VECTORIZE)
585+
AC_SUBST(CFLAGS_SL_MOD)
576586

577587
# Determine flags used to emit bitcode for JIT inlining.
578588
# 1. We must duplicate any behaviour-changing compiler flags used above,

contrib/basic_archive/basic_archive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
PG_MODULE_MAGIC;
4242

43-
void _PG_init(void);
44-
void _PG_archive_module_init(ArchiveModuleCallbacks *cb);
43+
PGDLLEXPORT void _PG_init(void);
44+
PGDLLEXPORT void _PG_archive_module_init(ArchiveModuleCallbacks *cb);
4545

4646
static char *archive_directory = NULL;
4747
static MemoryContext basic_archive_context;

contrib/hstore/hstore.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ typedef struct
147147
} while (0)
148148

149149
/* DatumGetHStoreP includes support for reading old-format hstore values */
150-
extern HStore *hstoreUpgrade(Datum orig);
150+
extern PGDLLEXPORT HStore *hstoreUpgrade(Datum orig);
151151

152152
#define DatumGetHStoreP(d) hstoreUpgrade(d)
153153

@@ -168,14 +168,14 @@ typedef struct
168168
bool needfree; /* need to pfree the value? */
169169
} Pairs;
170170

171-
extern int hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen);
172-
extern HStore *hstorePairs(Pairs *pairs, int32 pcount, int32 buflen);
171+
extern PGDLLEXPORT int hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen);
172+
extern PGDLLEXPORT HStore *hstorePairs(Pairs *pairs, int32 pcount, int32 buflen);
173173

174-
extern size_t hstoreCheckKeyLen(size_t len);
175-
extern size_t hstoreCheckValLen(size_t len);
174+
extern PGDLLEXPORT size_t hstoreCheckKeyLen(size_t len);
175+
extern PGDLLEXPORT size_t hstoreCheckValLen(size_t len);
176176

177-
extern int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen);
178-
extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs);
177+
extern PGDLLEXPORT int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen);
178+
extern PGDLLEXPORT Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs);
179179

180180
#define HStoreContainsStrategyNumber 7
181181
#define HStoreExistsStrategyNumber 9
@@ -194,7 +194,7 @@ extern Pairs *hstoreArrayToPairs(ArrayType *a, int *npairs);
194194
#if HSTORE_POLLUTE_NAMESPACE
195195
#define HSTORE_POLLUTE(newname_,oldname_) \
196196
PG_FUNCTION_INFO_V1(oldname_); \
197-
Datum newname_(PG_FUNCTION_ARGS); \
197+
extern PGDLLEXPORT Datum newname_(PG_FUNCTION_ARGS); \
198198
Datum oldname_(PG_FUNCTION_ARGS) { return newname_(fcinfo); } \
199199
extern int no_such_variable
200200
#else

contrib/ltree/ltree.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -176,30 +176,30 @@ typedef struct
176176

177177

178178
/* use in array iterator */
179-
Datum ltree_isparent(PG_FUNCTION_ARGS);
180-
Datum ltree_risparent(PG_FUNCTION_ARGS);
181-
Datum ltq_regex(PG_FUNCTION_ARGS);
182-
Datum ltq_rregex(PG_FUNCTION_ARGS);
183-
Datum lt_q_regex(PG_FUNCTION_ARGS);
184-
Datum lt_q_rregex(PG_FUNCTION_ARGS);
185-
Datum ltxtq_exec(PG_FUNCTION_ARGS);
186-
Datum ltxtq_rexec(PG_FUNCTION_ARGS);
187-
Datum _ltq_regex(PG_FUNCTION_ARGS);
188-
Datum _ltq_rregex(PG_FUNCTION_ARGS);
189-
Datum _lt_q_regex(PG_FUNCTION_ARGS);
190-
Datum _lt_q_rregex(PG_FUNCTION_ARGS);
191-
Datum _ltxtq_exec(PG_FUNCTION_ARGS);
192-
Datum _ltxtq_rexec(PG_FUNCTION_ARGS);
193-
Datum _ltree_isparent(PG_FUNCTION_ARGS);
194-
Datum _ltree_risparent(PG_FUNCTION_ARGS);
179+
PGDLLEXPORT Datum ltree_isparent(PG_FUNCTION_ARGS);
180+
PGDLLEXPORT Datum ltree_risparent(PG_FUNCTION_ARGS);
181+
PGDLLEXPORT Datum ltq_regex(PG_FUNCTION_ARGS);
182+
PGDLLEXPORT Datum ltq_rregex(PG_FUNCTION_ARGS);
183+
PGDLLEXPORT Datum lt_q_regex(PG_FUNCTION_ARGS);
184+
PGDLLEXPORT Datum lt_q_rregex(PG_FUNCTION_ARGS);
185+
PGDLLEXPORT Datum ltxtq_exec(PG_FUNCTION_ARGS);
186+
PGDLLEXPORT Datum ltxtq_rexec(PG_FUNCTION_ARGS);
187+
PGDLLEXPORT Datum _ltq_regex(PG_FUNCTION_ARGS);
188+
PGDLLEXPORT Datum _ltq_rregex(PG_FUNCTION_ARGS);
189+
PGDLLEXPORT Datum _lt_q_regex(PG_FUNCTION_ARGS);
190+
PGDLLEXPORT Datum _lt_q_rregex(PG_FUNCTION_ARGS);
191+
PGDLLEXPORT Datum _ltxtq_exec(PG_FUNCTION_ARGS);
192+
PGDLLEXPORT Datum _ltxtq_rexec(PG_FUNCTION_ARGS);
193+
PGDLLEXPORT Datum _ltree_isparent(PG_FUNCTION_ARGS);
194+
PGDLLEXPORT Datum _ltree_risparent(PG_FUNCTION_ARGS);
195195

196196
/* Concatenation functions */
197-
Datum ltree_addltree(PG_FUNCTION_ARGS);
198-
Datum ltree_addtext(PG_FUNCTION_ARGS);
199-
Datum ltree_textadd(PG_FUNCTION_ARGS);
197+
PGDLLEXPORT Datum ltree_addltree(PG_FUNCTION_ARGS);
198+
PGDLLEXPORT Datum ltree_addtext(PG_FUNCTION_ARGS);
199+
PGDLLEXPORT Datum ltree_textadd(PG_FUNCTION_ARGS);
200200

201201
/* Util function */
202-
Datum ltree_in(PG_FUNCTION_ARGS);
202+
PGDLLEXPORT Datum ltree_in(PG_FUNCTION_ARGS);
203203

204204
bool ltree_execute(ITEM *curitem, void *checkval,
205205
bool calcnot, bool (*chkcond) (void *checkval, ITEM *val));

src/Makefile.global.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ SUN_STUDIO_CC = @SUN_STUDIO_CC@
258258
CXX = @CXX@
259259
CFLAGS = @CFLAGS@
260260
CFLAGS_SL = @CFLAGS_SL@
261+
CFLAGS_SL_MOD = @CFLAGS_SL_MOD@
261262
CFLAGS_UNROLL_LOOPS = @CFLAGS_UNROLL_LOOPS@
262263
CFLAGS_VECTORIZE = @CFLAGS_VECTORIZE@
263264
CFLAGS_SSE42 = @CFLAGS_SSE42@

src/Makefile.shlib

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ ifeq ($(PORTNAME), win32)
218218
endif
219219

220220

221+
# If the shared library doesn't have an export file, mark all symbols not
222+
# explicitly exported using PGDLLEXPORT as hidden. We can't pass these flags
223+
# when building a library with explicit exports, as the symbols would be
224+
# hidden before the linker script / exported symbol list takes effect.
225+
#
226+
# XXX: This probably isn't the best location, but not clear instead?
227+
ifeq ($(SHLIB_EXPORTS),)
228+
LDFLAGS += $(CFLAGS_SL_MOD)
229+
override CFLAGS += $(CFLAGS_SL_MOD)
230+
override CXXFLAGS += $(CFLAGS_SL_MOD)
231+
endif
232+
221233

222234
##
223235
## BUILD

src/include/c.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,8 +1339,18 @@ extern unsigned long long strtoull(const char *str, char **endptr, int base);
13391339
/*
13401340
* Use "extern PGDLLIMPORT ..." to declare variables that are defined
13411341
* in the core backend and need to be accessible by loadable modules.
1342-
* No special marking is required on most ports.
13431342
*/
1343+
1344+
/*
1345+
* If the platform knows __attribute__((visibility("*"))), i.e. gcc like
1346+
* compilers, we use that.
1347+
*/
1348+
#if !defined(PGDLLIMPORT) && defined(HAVE_VISIBILITY_ATTRIBUTE)
1349+
#define PGDLLIMPORT __attribute__((visibility("default")))
1350+
#define PGDLLEXPORT __attribute__((visibility("default")))
1351+
#endif
1352+
1353+
/* No special marking is required on most ports. */
13441354
#ifndef PGDLLIMPORT
13451355
#define PGDLLIMPORT
13461356
#endif

src/include/fmgr.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ typedef const Pg_finfo_record *(*PGFInfoFunction) (void);
413413
* info function, since authors shouldn't need to be explicitly aware of it.
414414
*/
415415
#define PG_FUNCTION_INFO_V1(funcname) \
416-
extern Datum funcname(PG_FUNCTION_ARGS); \
416+
extern PGDLLEXPORT Datum funcname(PG_FUNCTION_ARGS); \
417417
extern PGDLLEXPORT const Pg_finfo_record * CppConcat(pg_finfo_,funcname)(void); \
418418
const Pg_finfo_record * \
419419
CppConcat(pg_finfo_,funcname) (void) \
@@ -424,6 +424,10 @@ CppConcat(pg_finfo_,funcname) (void) \
424424
extern int no_such_variable
425425

426426

427+
extern PGDLLEXPORT void _PG_init(void);
428+
extern PGDLLEXPORT void _PG_fini(void);
429+
430+
427431
/*-------------------------------------------------------------------------
428432
* Support for verifying backend compatibility of loaded modules
429433
*

src/include/jit/jit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct JitContext
6363

6464
typedef struct JitProviderCallbacks JitProviderCallbacks;
6565

66-
extern void _PG_jit_provider_init(JitProviderCallbacks *cb);
66+
extern PGDLLEXPORT void _PG_jit_provider_init(JitProviderCallbacks *cb);
6767
typedef void (*JitProviderInit) (JitProviderCallbacks *cb);
6868
typedef void (*JitProviderResetAfterErrorCB) (void);
6969
typedef void (*JitProviderReleaseContextCB) (JitContext *context);

0 commit comments

Comments
 (0)