Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f014b1b

Browse files
committed
Probe for preadv/pwritev in a more macOS-friendly way.
Apple's mechanism for dealing with functions that are available in only some OS versions confuses AC_CHECK_FUNCS, and therefore AC_REPLACE_FUNCS. We can use AC_CHECK_DECLS instead, so long as we enable -Werror=unguarded-availability-new. This allows people compiling for macOS to control whether or not preadv/pwritev are used by setting MACOSX_DEPLOYMENT_TARGET, rather than supplying a back-rev SDK. (Of course, the latter still works, too.) James Hilliard Discussion: https://postgr.es/m/[email protected]
1 parent f10f0ae commit f014b1b

File tree

5 files changed

+161
-38
lines changed

5 files changed

+161
-38
lines changed

configure

+140-26
Original file line numberDiff line numberDiff line change
@@ -5383,6 +5383,98 @@ if test x"$pgac_cv_prog_CC_cflags__Werror_vla" = x"yes"; then
53835383
fi
53845384

53855385

5386+
# On macOS, complain about usage of symbols newer than the deployment target
5387+
5388+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Werror=unguarded-availability-new, for CFLAGS" >&5
5389+
$as_echo_n "checking whether ${CC} supports -Werror=unguarded-availability-new, for CFLAGS... " >&6; }
5390+
if ${pgac_cv_prog_CC_cflags__Werror_unguarded_availability_new+:} false; then :
5391+
$as_echo_n "(cached) " >&6
5392+
else
5393+
pgac_save_CFLAGS=$CFLAGS
5394+
pgac_save_CC=$CC
5395+
CC=${CC}
5396+
CFLAGS="${CFLAGS} -Werror=unguarded-availability-new"
5397+
ac_save_c_werror_flag=$ac_c_werror_flag
5398+
ac_c_werror_flag=yes
5399+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5400+
/* end confdefs.h. */
5401+
5402+
int
5403+
main ()
5404+
{
5405+
5406+
;
5407+
return 0;
5408+
}
5409+
_ACEOF
5410+
if ac_fn_c_try_compile "$LINENO"; then :
5411+
pgac_cv_prog_CC_cflags__Werror_unguarded_availability_new=yes
5412+
else
5413+
pgac_cv_prog_CC_cflags__Werror_unguarded_availability_new=no
5414+
fi
5415+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5416+
ac_c_werror_flag=$ac_save_c_werror_flag
5417+
CFLAGS="$pgac_save_CFLAGS"
5418+
CC="$pgac_save_CC"
5419+
fi
5420+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CC_cflags__Werror_unguarded_availability_new" >&5
5421+
$as_echo "$pgac_cv_prog_CC_cflags__Werror_unguarded_availability_new" >&6; }
5422+
if test x"$pgac_cv_prog_CC_cflags__Werror_unguarded_availability_new" = x"yes"; then
5423+
CFLAGS="${CFLAGS} -Werror=unguarded-availability-new"
5424+
fi
5425+
5426+
5427+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports -Werror=unguarded-availability-new, for CXXFLAGS" >&5
5428+
$as_echo_n "checking whether ${CXX} supports -Werror=unguarded-availability-new, for CXXFLAGS... " >&6; }
5429+
if ${pgac_cv_prog_CXX_cxxflags__Werror_unguarded_availability_new+:} false; then :
5430+
$as_echo_n "(cached) " >&6
5431+
else
5432+
pgac_save_CXXFLAGS=$CXXFLAGS
5433+
pgac_save_CXX=$CXX
5434+
CXX=${CXX}
5435+
CXXFLAGS="${CXXFLAGS} -Werror=unguarded-availability-new"
5436+
ac_save_cxx_werror_flag=$ac_cxx_werror_flag
5437+
ac_cxx_werror_flag=yes
5438+
ac_ext=cpp
5439+
ac_cpp='$CXXCPP $CPPFLAGS'
5440+
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
5441+
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
5442+
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
5443+
5444+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
5445+
/* end confdefs.h. */
5446+
5447+
int
5448+
main ()
5449+
{
5450+
5451+
;
5452+
return 0;
5453+
}
5454+
_ACEOF
5455+
if ac_fn_cxx_try_compile "$LINENO"; then :
5456+
pgac_cv_prog_CXX_cxxflags__Werror_unguarded_availability_new=yes
5457+
else
5458+
pgac_cv_prog_CXX_cxxflags__Werror_unguarded_availability_new=no
5459+
fi
5460+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
5461+
ac_ext=c
5462+
ac_cpp='$CPP $CPPFLAGS'
5463+
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
5464+
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
5465+
ac_compiler_gnu=$ac_cv_c_compiler_gnu
5466+
5467+
ac_cxx_werror_flag=$ac_save_cxx_werror_flag
5468+
CXXFLAGS="$pgac_save_CXXFLAGS"
5469+
CXX="$pgac_save_CXX"
5470+
fi
5471+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $pgac_cv_prog_CXX_cxxflags__Werror_unguarded_availability_new" >&5
5472+
$as_echo "$pgac_cv_prog_CXX_cxxflags__Werror_unguarded_availability_new" >&6; }
5473+
if test x"$pgac_cv_prog_CXX_cxxflags__Werror_unguarded_availability_new" = x"yes"; then
5474+
CXXFLAGS="${CXXFLAGS} -Werror=unguarded-availability-new"
5475+
fi
5476+
5477+
53865478
# -Wvla is not applicable for C++
53875479

53885480
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports -Wendif-labels, for CFLAGS" >&5
@@ -15931,6 +16023,54 @@ cat >>confdefs.h <<_ACEOF
1593116023
#define HAVE_DECL_STRNLEN $ac_have_decl
1593216024
_ACEOF
1593316025

16026+
16027+
# We can't use AC_REPLACE_FUNCS to replace these functions, because it
16028+
# won't handle deployment target restrictions on macOS
16029+
ac_fn_c_check_decl "$LINENO" "preadv" "ac_cv_have_decl_preadv" "#include <sys/uio.h>
16030+
"
16031+
if test "x$ac_cv_have_decl_preadv" = xyes; then :
16032+
ac_have_decl=1
16033+
else
16034+
ac_have_decl=0
16035+
fi
16036+
16037+
cat >>confdefs.h <<_ACEOF
16038+
#define HAVE_DECL_PREADV $ac_have_decl
16039+
_ACEOF
16040+
if test $ac_have_decl = 1; then :
16041+
16042+
else
16043+
case " $LIBOBJS " in
16044+
*" preadv.$ac_objext "* ) ;;
16045+
*) LIBOBJS="$LIBOBJS preadv.$ac_objext"
16046+
;;
16047+
esac
16048+
16049+
fi
16050+
16051+
ac_fn_c_check_decl "$LINENO" "pwritev" "ac_cv_have_decl_pwritev" "#include <sys/uio.h>
16052+
"
16053+
if test "x$ac_cv_have_decl_pwritev" = xyes; then :
16054+
ac_have_decl=1
16055+
else
16056+
ac_have_decl=0
16057+
fi
16058+
16059+
cat >>confdefs.h <<_ACEOF
16060+
#define HAVE_DECL_PWRITEV $ac_have_decl
16061+
_ACEOF
16062+
if test $ac_have_decl = 1; then :
16063+
16064+
else
16065+
case " $LIBOBJS " in
16066+
*" pwritev.$ac_objext "* ) ;;
16067+
*) LIBOBJS="$LIBOBJS pwritev.$ac_objext"
16068+
;;
16069+
esac
16070+
16071+
fi
16072+
16073+
1593416074
# This is probably only present on macOS, but may as well check always
1593516075
ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>
1593616076
"
@@ -16144,19 +16284,6 @@ esac
1614416284

1614516285
fi
1614616286

16147-
ac_fn_c_check_func "$LINENO" "preadv" "ac_cv_func_preadv"
16148-
if test "x$ac_cv_func_preadv" = xyes; then :
16149-
$as_echo "#define HAVE_PREADV 1" >>confdefs.h
16150-
16151-
else
16152-
case " $LIBOBJS " in
16153-
*" preadv.$ac_objext "* ) ;;
16154-
*) LIBOBJS="$LIBOBJS preadv.$ac_objext"
16155-
;;
16156-
esac
16157-
16158-
fi
16159-
1616016287
ac_fn_c_check_func "$LINENO" "pwrite" "ac_cv_func_pwrite"
1616116288
if test "x$ac_cv_func_pwrite" = xyes; then :
1616216289
$as_echo "#define HAVE_PWRITE 1" >>confdefs.h
@@ -16170,19 +16297,6 @@ esac
1617016297

1617116298
fi
1617216299

16173-
ac_fn_c_check_func "$LINENO" "pwritev" "ac_cv_func_pwritev"
16174-
if test "x$ac_cv_func_pwritev" = xyes; then :
16175-
$as_echo "#define HAVE_PWRITEV 1" >>confdefs.h
16176-
16177-
else
16178-
case " $LIBOBJS " in
16179-
*" pwritev.$ac_objext "* ) ;;
16180-
*) LIBOBJS="$LIBOBJS pwritev.$ac_objext"
16181-
;;
16182-
esac
16183-
16184-
fi
16185-
1618616300
ac_fn_c_check_func "$LINENO" "random" "ac_cv_func_random"
1618716301
if test "x$ac_cv_func_random" = xyes; then :
1618816302
$as_echo "#define HAVE_RANDOM 1" >>confdefs.h

configure.ac

+9-2
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ if test "$GCC" = yes -a "$ICC" = no; then
494494
AC_SUBST(PERMIT_DECLARATION_AFTER_STATEMENT)
495495
# Really don't want VLAs to be used in our dialect of C
496496
PGAC_PROG_CC_CFLAGS_OPT([-Werror=vla])
497+
# On macOS, complain about usage of symbols newer than the deployment target
498+
PGAC_PROG_CC_CFLAGS_OPT([-Werror=unguarded-availability-new])
499+
PGAC_PROG_CXX_CFLAGS_OPT([-Werror=unguarded-availability-new])
497500
# -Wvla is not applicable for C++
498501
PGAC_PROG_CC_CFLAGS_OPT([-Wendif-labels])
499502
PGAC_PROG_CXX_CFLAGS_OPT([-Wendif-labels])
@@ -1749,6 +1752,12 @@ AC_CHECK_DECLS(posix_fadvise, [], [], [#include <fcntl.h>])
17491752

17501753
AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
17511754
AC_CHECK_DECLS([strlcat, strlcpy, strnlen])
1755+
1756+
# We can't use AC_REPLACE_FUNCS to replace these functions, because it
1757+
# won't handle deployment target restrictions on macOS
1758+
AC_CHECK_DECLS([preadv], [], [AC_LIBOBJ(preadv)], [#include <sys/uio.h>])
1759+
AC_CHECK_DECLS([pwritev], [], [AC_LIBOBJ(pwritev)], [#include <sys/uio.h>])
1760+
17521761
# This is probably only present on macOS, but may as well check always
17531762
AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
17541763

@@ -1784,9 +1793,7 @@ AC_REPLACE_FUNCS(m4_normalize([
17841793
link
17851794
mkdtemp
17861795
pread
1787-
preadv
17881796
pwrite
1789-
pwritev
17901797
random
17911798
srandom
17921799
strlcat

src/include/pg_config.h.in

+8-6
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@
142142
don't. */
143143
#undef HAVE_DECL_POSIX_FADVISE
144144

145+
/* Define to 1 if you have the declaration of `preadv', and to 0 if you don't.
146+
*/
147+
#undef HAVE_DECL_PREADV
148+
149+
/* Define to 1 if you have the declaration of `pwritev', and to 0 if you
150+
don't. */
151+
#undef HAVE_DECL_PWRITEV
152+
145153
/* Define to 1 if you have the declaration of `RTLD_GLOBAL', and to 0 if you
146154
don't. */
147155
#undef HAVE_DECL_RTLD_GLOBAL
@@ -421,9 +429,6 @@
421429
/* Define to 1 if you have the `pread' function. */
422430
#undef HAVE_PREAD
423431

424-
/* Define to 1 if you have the `preadv' function. */
425-
#undef HAVE_PREADV
426-
427432
/* Define to 1 if you have the `pstat' function. */
428433
#undef HAVE_PSTAT
429434

@@ -445,9 +450,6 @@
445450
/* Define to 1 if you have the `pwrite' function. */
446451
#undef HAVE_PWRITE
447452

448-
/* Define to 1 if you have the `pwritev' function. */
449-
#undef HAVE_PWRITEV
450-
451453
/* Define to 1 if you have the `random' function. */
452454
#undef HAVE_RANDOM
453455

src/include/port/pg_iovec.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ struct iovec
3939
/* Define a reasonable maximum that is safe to use on the stack. */
4040
#define PG_IOV_MAX Min(IOV_MAX, 32)
4141

42-
#ifdef HAVE_PREADV
42+
#if HAVE_DECL_PREADV
4343
#define pg_preadv preadv
4444
#else
4545
extern ssize_t pg_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset);
4646
#endif
4747

48-
#ifdef HAVE_PWRITEV
48+
#if HAVE_DECL_PWRITEV
4949
#define pg_pwritev pwritev
5050
#else
5151
extern ssize_t pg_pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset);

src/tools/msvc/Solution.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ sub GenerateFiles
245245
HAVE_DECL_LLVMGETHOSTCPUFEATURES => 0,
246246
HAVE_DECL_LLVMORCGETSYMBOLADDRESSIN => 0,
247247
HAVE_DECL_POSIX_FADVISE => undef,
248+
HAVE_DECL_PREADV => 0,
249+
HAVE_DECL_PWRITEV => 0,
248250
HAVE_DECL_RTLD_GLOBAL => 0,
249251
HAVE_DECL_RTLD_NOW => 0,
250252
HAVE_DECL_STRLCAT => undef,
@@ -335,15 +337,13 @@ sub GenerateFiles
335337
HAVE_PPC_LWARX_MUTEX_HINT => undef,
336338
HAVE_PPOLL => undef,
337339
HAVE_PREAD => undef,
338-
HAVE_PREADV => undef,
339340
HAVE_PSTAT => undef,
340341
HAVE_PS_STRINGS => undef,
341342
HAVE_PTHREAD => undef,
342343
HAVE_PTHREAD_BARRIER_WAIT => undef,
343344
HAVE_PTHREAD_IS_THREADED_NP => undef,
344345
HAVE_PTHREAD_PRIO_INHERIT => undef,
345346
HAVE_PWRITE => undef,
346-
HAVE_PWRITEV => undef,
347347
HAVE_RANDOM => undef,
348348
HAVE_READLINE_H => undef,
349349
HAVE_READLINE_HISTORY_H => undef,

0 commit comments

Comments
 (0)