diff mbox series

libiberty, configure, Darwin: Avoid detecting deprecated sbrk.

Message ID BE7E0198-58D8-46C6-8C58-CBDDFF8DB44B@sandoe.co.uk
State New
Headers show
Series libiberty, configure, Darwin: Avoid detecting deprecated sbrk. | expand

Commit Message

Iain Sandoe Aug. 30, 2021, 7:29 p.m. UTC
Hi,

Darwin provides an implementation of sbrk, which is detected by the
libiberty configuration process.

However, (like most of the BSD-derivatives) sbrk/brk are deprecated on
Darwin which leads to build-time warnings.  It seems that the configure
process does not see the deprecation warnings as reason for excluding
the fn.

Darwin should use the malloc-based implementation.

This patch works around the issue by removing sbrk from the functions
searched (for Darwin only, although it’s likely that other BSD-ish ports
might wish to do the same).

Open to more elegant solutions, of course,
tested on powerpc,i686,x86_64-darwin, x86_64, powerpc64- linux,

OK for master?
thanks Iain

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

libiberty/ChangeLog:

	* configure: Regenerate.
	* configure.ac: Do not search for sbrk on Darwin.
	* xmalloc.c: Do not declare sbrk unless it has been found
	by configure.
---
 libiberty/configure    | 43 ++++++++++++++++++++----------------------
 libiberty/configure.ac | 15 +++++++++++++--
 libiberty/xmalloc.c    |  2 ++
 3 files changed, 35 insertions(+), 25 deletions(-)

Comments

Jeff Law Sept. 1, 2021, 5:45 p.m. UTC | #1
On 8/30/2021 1:29 PM, Iain Sandoe wrote:
> Hi,
>
> Darwin provides an implementation of sbrk, which is detected by the
> libiberty configuration process.
>
> However, (like most of the BSD-derivatives) sbrk/brk are deprecated on
> Darwin which leads to build-time warnings.  It seems that the configure
> process does not see the deprecation warnings as reason for excluding
> the fn.
>
> Darwin should use the malloc-based implementation.
>
> This patch works around the issue by removing sbrk from the functions
> searched (for Darwin only, although it’s likely that other BSD-ish ports
> might wish to do the same).
>
> Open to more elegant solutions, of course,
> tested on powerpc,i686,x86_64-darwin, x86_64, powerpc64- linux,
>
> OK for master?
> thanks Iain
>
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
>
> libiberty/ChangeLog:
>
> 	* configure: Regenerate.
> 	* configure.ac: Do not search for sbrk on Darwin.
> 	* xmalloc.c: Do not declare sbrk unless it has been found
> 	by configure.
OK
jeff
diff mbox series

Patch

diff --git a/libiberty/configure.ac b/libiberty/configure.ac
index a85ff25501a..4b78c1830c7 100644
--- a/libiberty/configure.ac
+++ b/libiberty/configure.ac
@@ -395,9 +395,16 @@  vars="sys_errlist sys_nerr sys_siglist"
 
 checkfuncs="__fsetlocking canonicalize_file_name dup3 getrlimit getrusage \
  getsysinfo gettimeofday on_exit pipe2 psignal pstat_getdynamic pstat_getstatic \
- realpath setrlimit sbrk spawnve spawnvpe strerror strsignal sysconf sysctl \
+ realpath setrlimit spawnve spawnvpe strerror strsignal sysconf sysctl \
  sysmp table times wait3 wait4"
 
+# Darwin has sbrk, but it is deprecated and that produces build-time warnings
+# so do not check for it.
+case "${host}" in
+  *-*-darwin*) ;;
+  *) checkfuncs="$checkfuncs sbrk"
+esac
+
 # These are neither executed nor required, but they help keep
 # autoheader happy without adding a bunch of text to acconfig.h.
 if test "x" = "y"; then
@@ -695,7 +702,11 @@  if test -z "${setobjs}"; then
 
   AC_CHECK_FUNCS($checkfuncs)
   AC_CHECK_DECLS([basename(char *), ffs, asprintf, vasprintf, snprintf, vsnprintf])
-  AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc, sbrk])
+  AC_CHECK_DECLS([calloc, getenv, getopt, malloc, realloc])
+  case "${host}" in
+      *-*-darwin*) ;; # Darwin's sbrk implementation is deprecated.
+      *) AC_CHECK_DECLS([sbrk]);;
+  esac
   AC_CHECK_DECLS([strtol, strtoul, strtoll, strtoull])
   AC_CHECK_DECLS([strverscmp])
   AC_CHECK_DECLS([strnlen])
diff --git a/libiberty/xmalloc.c b/libiberty/xmalloc.c
index 85826c1e10f..b9e23c38643 100644
--- a/libiberty/xmalloc.c
+++ b/libiberty/xmalloc.c
@@ -87,7 +87,9 @@  extern "C" {
 void *malloc (size_t);
 void *realloc (void *, size_t);
 void *calloc (size_t, size_t);
+#ifdef HAVE_SBRK
 void *sbrk (ptrdiff_t);
+#endif
 #    ifdef __cplusplus
 }
 #    endif /* __cplusplus */