unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37483: [PATCH] macOS build error (aligned_alloc)
@ 2019-09-22 17:25 Mattias Engdegård
  2019-09-22 20:14 ` mituharu
  2019-09-23 20:02 ` Paul Eggert
  0 siblings, 2 replies; 7+ messages in thread
From: Mattias Engdegård @ 2019-09-22 17:25 UTC (permalink / raw)
  To: 37483

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

After upgrading the macOS system dev tools, building Emacs fails because aligned_alloc is present in the system headers and can be linked with but isn't actually in the dynamic library (macOS 10.14, Xcode 11).

This means that the configure check for that function needs to be strengthened a bit. Proposed patch attached; please say if it breaks on a different platform. I'm not the greatest fan of autoconf, and am likely to have made mistakes.


[-- Attachment #2: 0001-More-thorough-check-for-aligned_alloc-on-macOS.patch --]
[-- Type: application/octet-stream, Size: 1998 bytes --]

From 491b19f50014cf03a7cc9085568a10bbefed1812 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Sun, 22 Sep 2019 19:01:52 +0200
Subject: [PATCH] More thorough check for aligned_alloc on macOS
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* configure.ac (HAVE_ALIGNED_ALLOC): Use a executing check for
aligned_alloc on macOS, since while that function is only available in
version ≥10.15, it may be present in the system headers and could be
linked with in earlier versions.
---
 configure.ac | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index e822b0b7b0..dfc7bdb883 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4179,8 +4179,27 @@ AC_DEFUN
 cfmakeraw cfsetspeed __executable_start log2 prctl)
 LIBS=$OLD_LIBS
 
+if test "${opsys}" = darwin; then
+  dnl aligned_alloc is available in macOS 10.15 and later, but may be
+  dnl visible (but not functional) before that, and there is no
+  dnl telling without actually running a test.
+  AC_CACHE_CHECK([for aligned_alloc], [ac_cv_func_aligned_alloc],
+    [AC_RUN_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>]],
+                                    [[return !aligned_alloc (1, 1);]])],
+                   [ac_cv_func_aligned_alloc=yes],
+                   [ac_cv_func_aligned_alloc=no], [])])
+  if test $ac_cv_func_aligned_alloc = yes; then
+    AC_DEFINE([HAVE_ALIGNED_ALLOC], 1,
+              [Define to 1 if you have the 'aligned_alloc' function.])
+  fi
+else
+  AC_CHECK_FUNCS([aligned_alloc])
+fi
+
 dnl No need to check for posix_memalign if aligned_alloc works.
-AC_CHECK_FUNCS([aligned_alloc posix_memalign], [break])
+if test "$ac_cv_func_aligned_alloc" != yes; then
+  AC_CHECK_FUNCS([posix_memalign])
+fi
 AC_CHECK_DECLS([aligned_alloc], [], [], [[#include <stdlib.h>]])
 
 # Dump loading
-- 
2.21.0 (Apple Git-122)


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* bug#37483: [PATCH] macOS build error (aligned_alloc)
  2019-09-22 17:25 bug#37483: [PATCH] macOS build error (aligned_alloc) Mattias Engdegård
@ 2019-09-22 20:14 ` mituharu
  2019-09-23  9:14   ` Mattias Engdegård
  2019-09-23 20:02 ` Paul Eggert
  1 sibling, 1 reply; 7+ messages in thread
From: mituharu @ 2019-09-22 20:14 UTC (permalink / raw)
  To: Mattias Engdeg?rd; +Cc: 37483

> After upgrading the macOS system dev tools, building Emacs fails because
> aligned_alloc is present in the system headers and can be linked with but
> isn't actually in the dynamic library (macOS 10.14, Xcode 11).

You would need to install the Command Line Developer Tools with
"xcode-select --install".  In general this is necessary when the
macOS version is older than the newest one Xcode supports.  In
the case of Xcode 11, it is macOS 10.15.

Actually you don't need Xcode for building Emacs, but the Command
Line Developer Tools would be sufficient.

			     YAMAMOTO Mitsuharu
			mituharu@math.s.chiba-u.ac.jp







^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#37483: [PATCH] macOS build error (aligned_alloc)
  2019-09-22 20:14 ` mituharu
@ 2019-09-23  9:14   ` Mattias Engdegård
  2019-09-23 18:37     ` Alan Third
  0 siblings, 1 reply; 7+ messages in thread
From: Mattias Engdegård @ 2019-09-23  9:14 UTC (permalink / raw)
  To: mituharu; +Cc: 37483

22 sep. 2019 kl. 22.14 skrev mituharu@math.s.chiba-u.ac.jp:
> 
> You would need to install the Command Line Developer Tools with
> "xcode-select --install".  In general this is necessary when the
> macOS version is older than the newest one Xcode supports.  In
> the case of Xcode 11, it is macOS 10.15.
> 
> Actually you don't need Xcode for building Emacs, but the Command
> Line Developer Tools would be sufficient.

Thank you, this is useful to know.

Even so, doesn't it make sense to make the configure script work with tools that support newer OS versions? After all, we are not talking about cross-tools or tools that can only generate code for newer versions. If I want to use the most recent toolchain for my OS, these (Xcode 11) tools are the ones to use.

I first tried some other workarounds: configuring with -Werror=unguarded-availability-new in CFLAGS will prevent HAVE_DECL_ALIGNED_ALLOC from being defined, but HAVE_ALIGNED_ALLOC is not affected because its config check doesn't include the standard header (by design).






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#37483: [PATCH] macOS build error (aligned_alloc)
  2019-09-23  9:14   ` Mattias Engdegård
@ 2019-09-23 18:37     ` Alan Third
  2019-09-23 19:53       ` Mattias Engdegård
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Third @ 2019-09-23 18:37 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 37483

On Mon, Sep 23, 2019 at 11:14:55AM +0200, Mattias Engdegård wrote:
> 22 sep. 2019 kl. 22.14 skrev mituharu@math.s.chiba-u.ac.jp:
> > 
> > You would need to install the Command Line Developer Tools with
> > "xcode-select --install".  In general this is necessary when the
> > macOS version is older than the newest one Xcode supports.  In
> > the case of Xcode 11, it is macOS 10.15.
> > 
> > Actually you don't need Xcode for building Emacs, but the Command
> > Line Developer Tools would be sufficient.
> 
> Thank you, this is useful to know.
> 
> Even so, doesn't it make sense to make the configure script work
> with tools that support newer OS versions? After all, we are not
> talking about cross-tools or tools that can only generate code for
> newer versions. If I want to use the most recent toolchain for my
> OS, these (Xcode 11) tools are the ones to use.

The command line tools are closely related to XCode, they’re not old
or obsolete.

-- 
Alan Third





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#37483: [PATCH] macOS build error (aligned_alloc)
  2019-09-23 18:37     ` Alan Third
@ 2019-09-23 19:53       ` Mattias Engdegård
  0 siblings, 0 replies; 7+ messages in thread
From: Mattias Engdegård @ 2019-09-23 19:53 UTC (permalink / raw)
  To: Alan Third; +Cc: 37483

23 sep. 2019 kl. 20.37 skrev Alan Third <alan@idiocy.org>:
> 
> The command line tools are closely related to XCode, they’re not old
> or obsolete.

I didn't mean to imply they were. Yet a newer compiler version is likely to produce better code than an older. It should be possible to build Emacs with the latest set of command line tools, shouldn't it?






^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#37483: [PATCH] macOS build error (aligned_alloc)
  2019-09-22 17:25 bug#37483: [PATCH] macOS build error (aligned_alloc) Mattias Engdegård
  2019-09-22 20:14 ` mituharu
@ 2019-09-23 20:02 ` Paul Eggert
  2019-09-24 11:08   ` Mattias Engdegård
  1 sibling, 1 reply; 7+ messages in thread
From: Paul Eggert @ 2019-09-23 20:02 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 37483

I'm not seeing why this patch is needed. If you build with tools that 
expect a macOS version N library, Emacs can't be expected to run on a 
system that has older libraries.

Put it another way: if we install this patch, for consistency shouldn't 
we install a similar patch for every other function that 'configure' 
checks for, and have 'configure' do a run-time test instead of just a 
link-time test for the function?





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#37483: [PATCH] macOS build error (aligned_alloc)
  2019-09-23 20:02 ` Paul Eggert
@ 2019-09-24 11:08   ` Mattias Engdegård
  0 siblings, 0 replies; 7+ messages in thread
From: Mattias Engdegård @ 2019-09-24 11:08 UTC (permalink / raw)
  To: Paul Eggert; +Cc: 37483, Alan Third

tags 37483 notabug
close 37483
stop

23 sep. 2019 kl. 22.02 skrev Paul Eggert <eggert@cs.ucla.edu>:
> 
> I'm not seeing why this patch is needed. If you build with tools that expect a macOS version N library, Emacs can't be expected to run on a system that has older libraries.

I don't think it's accurate to say that the tools expect a macOS 10.15 library; they are perfectly able to build code for 10.14, and that is the default when running on such a system. Since aligned_alloc will be available in 10.15, the header file contains an annotated prototype of that function, so that the compiler can warn on attempts to use it when building for 10.14:

conftest.c:151:9: warning: 'aligned_alloc' is only available on macOS 10.15 or newer [-Wunguarded-availability-new]
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/malloc/_malloc.h:50:10: note: 'aligned_alloc' has been marked as being introduced in macOS 10.15 here, but the deployment target is macOS 10.14.0

AC_CHECK_FUNCS supplies a made-up prototype for aligned_alloc instead of including <stdlib.h>, and then compilation and linking will proceed without diagnostics. The run-time linker will complain and abort.

However, I followed Alan's advice and used 'xcode-select --install' to install SDKs specifically for 10.14, and now clang uses a different header file tree that does not include aligned_alloc at all. I'm happy, because the compiler and associated tools are still of version 11. I must admit I'm not entirely sure how about the exact mechanics behind it all; 'xcode-select -p' still returns the same path, but the compiler now uses headers from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk.

At any rate, it's good enough to withdraw the patch for now. Thank you for your patience.

> Put it another way: if we install this patch, for consistency shouldn't we install a similar patch for every other function that 'configure' checks for, and have 'configure' do a run-time test instead of just a link-time test for the function?

That's a legitimate question. AC_CHECK_FUNCS & friends make Unix-centric assumptions that aren't correct in all build environments, but not running a test binary is slightly faster and makes cross-builds easier.

(Should you ever consider replacing autoconf for Emacs with something faster, you will find in me a fervent supporter.)






^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2019-09-24 11:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-09-22 17:25 bug#37483: [PATCH] macOS build error (aligned_alloc) Mattias Engdegård
2019-09-22 20:14 ` mituharu
2019-09-23  9:14   ` Mattias Engdegård
2019-09-23 18:37     ` Alan Third
2019-09-23 19:53       ` Mattias Engdegård
2019-09-23 20:02 ` Paul Eggert
2019-09-24 11:08   ` Mattias Engdegård

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).