Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 73275f0

Browse files
committed
Make building with LTO work on macOS
When building with -flto, the backend binary must keep many otherwise unused symbols to make them available to dynamically loaded modules / extensions. This has been done via -Wl,--export-dynamic on many platforms for years. This flag is not supported by the macOS linker, though. Here it's called -Wl,-export_dynamic instead. Thus, make configure pick up on this variant of the flag as well. Meson has the logic upstream as of version 1.5.0. Without this fix, building with -flto fails with errors similar to [1] and [2]. [1]: https://postgr.es/m/1581936537572-0.post%40n3.nabble.com [2]: https://postgr.es/m/21800.1499270547%40sss.pgh.pa.us Author: Wolfgang Walther <walther@technowledgy.de> Discussion: https://www.postgresql.org/message-id/flat/427c7c25-e8e1-4fc5-a1fb-01ceff185e5b@technowledgy.de
1 parent 0dcea33 commit 73275f0

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

configure

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19079,6 +19079,9 @@ fi
1907919079
# For linkers that understand --export-dynamic, add that to the LDFLAGS_EX_BE
1908019080
# (backend specific ldflags). One some platforms this will always fail (e.g.,
1908119081
# windows), but on others it depends on the choice of linker (e.g., solaris).
19082+
# macOS uses -export_dynamic instead. (On macOS, the option is only
19083+
# needed when also using -flto, but we add it anyway since it's
19084+
# harmless.)
1908219085
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wl,--export-dynamic, for LDFLAGS_EX_BE" >&5
1908319086
$as_echo_n "checking whether $CC supports -Wl,--export-dynamic, for LDFLAGS_EX_BE... " >&6; }
1908419087
if ${pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl___export_dynamic+:} false; then :
@@ -19117,6 +19120,46 @@ if test x"$pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl___export_dynamic" = x"yes"; then
1911719120
LDFLAGS_EX_BE="${LDFLAGS_EX_BE} -Wl,--export-dynamic"
1911819121
fi
1911919122

19123+
if test x"$LDFLAGS_EX_BE" = x""; then
19124+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -Wl,-export_dynamic, for LDFLAGS_EX_BE" >&5
19125+
$as_echo_n "checking whether $CC supports -Wl,-export_dynamic, for LDFLAGS_EX_BE... " >&6; }
19126+
if ${pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic+:} false; then :
19127+
$as_echo_n "(cached) " >&6
19128+
else
19129+
pgac_save_LDFLAGS=$LDFLAGS
19130+
LDFLAGS="$pgac_save_LDFLAGS -Wl,-export_dynamic"
19131+
if test "$cross_compiling" = yes; then :
19132+
pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic="assuming no"
19133+
else
19134+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
19135+
/* end confdefs.h. */
19136+
extern void $link_test_func (); void (*fptr) () = $link_test_func;
19137+
int
19138+
main ()
19139+
{
19140+
19141+
;
19142+
return 0;
19143+
}
19144+
_ACEOF
19145+
if ac_fn_c_try_run "$LINENO"; then :
19146+
pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic=yes
19147+
else
19148+
pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic=no
19149+
fi
19150+
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
19151+
conftest.$ac_objext conftest.beam conftest.$ac_ext
19152+
fi
19153+
19154+
LDFLAGS="$pgac_save_LDFLAGS"
19155+
fi
19156+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic" >&5
19157+
$as_echo "$pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic" >&6; }
19158+
if test x"$pgac_cv_prog_cc_LDFLAGS_EX_BE__Wl__export_dynamic" = x"yes"; then
19159+
LDFLAGS_EX_BE="${LDFLAGS_EX_BE} -Wl,-export_dynamic"
19160+
fi
19161+
19162+
fi
1912019163

1912119164

1912219165
# Create compiler version string

configure.ac

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,13 @@ fi
23982398
# For linkers that understand --export-dynamic, add that to the LDFLAGS_EX_BE
23992399
# (backend specific ldflags). One some platforms this will always fail (e.g.,
24002400
# windows), but on others it depends on the choice of linker (e.g., solaris).
2401+
# macOS uses -export_dynamic instead. (On macOS, the option is only
2402+
# needed when also using -flto, but we add it anyway since it's
2403+
# harmless.)
24012404
PGAC_PROG_CC_LD_VARFLAGS_OPT(LDFLAGS_EX_BE, [-Wl,--export-dynamic], $link_test_func)
2405+
if test x"$LDFLAGS_EX_BE" = x""; then
2406+
PGAC_PROG_CC_LD_VARFLAGS_OPT(LDFLAGS_EX_BE, [-Wl,-export_dynamic], $link_test_func)
2407+
fi
24022408
AC_SUBST(LDFLAGS_EX_BE)
24032409

24042410
# Create compiler version string

0 commit comments

Comments
 (0)