summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViktor Dukhovni <ietf-dane@dukhovni.org>2021-04-26 16:20:37 -0400
committerViktor Dukhovni <ietf-dane@dukhovni.org>2021-04-27 04:43:35 -0400
commit3c8b1f3eb4beda49548b048d2ca142f1a9d9e5c6 (patch)
tree0954370cefe93f955070cc5e65165c68aab3ad99
parent5b65d9fbe686d0cd8460a80a7c0d78e6520432e4 (diff)
downloadhaskell-3c8b1f3eb4beda49548b048d2ca142f1a9d9e5c6.tar.gz
Fix pthread_setname_np in itimer for Darwin
_POSIX_SOURCE is too strict, we need _DARWIN_C_SOURCE, otherwise <pthread.h> does not expose pthread_setname_np(3).
-rw-r--r--includes/Rts.h6
-rw-r--r--rts/posix/Itimer.c21
-rw-r--r--rts/posix/OSThreads.c17
3 files changed, 34 insertions, 10 deletions
diff --git a/includes/Rts.h b/includes/Rts.h
index 568a7e6108..1db3ea0df8 100644
--- a/includes/Rts.h
+++ b/includes/Rts.h
@@ -29,12 +29,6 @@ extern "C" {
#include <windows.h>
#endif
-#if defined(ios_HOST_OS) || defined(darwin_HOST_OS)
-/* Inclusion of system headers usually requires _DARWIN_C_SOURCE on Mac OS X
- * because of some specific defines like MMAP_ANON, MMAP_ANONYMOUS. */
-#define _DARWIN_C_SOURCE 1
-#endif
-
#if !defined(IN_STG_CODE)
#define IN_STG_CODE 0
#endif
diff --git a/rts/posix/Itimer.c b/rts/posix/Itimer.c
index 80925df703..98b23f623e 100644
--- a/rts/posix/Itimer.c
+++ b/rts/posix/Itimer.c
@@ -18,6 +18,27 @@
*/
#include "PosixSource.h"
+
+/* We've defined _POSIX_SOURCE via "PosixSource.h", and yet still use
+ some non-POSIX features. With _POSIX_SOURCE defined, visibility of
+ non-POSIX extension prototypes requires _DARWIN_C_SOURCE on Mac OS X and
+ __BSD_VISIBLE on FreeBSD and DragonflyBSD. Otherwise, for example, code
+ using pthread_setname_np(3) and variants will not compile. We must
+ therefore define the additional macros that expose non-POSIX APIs early,
+ before any of the relevant system headers are included via "Rts.h".
+
+ An alternative approach could be to write portable wrappers or stubs for all
+ the non-posix functions in a C-module that does not include "PosixSource.h",
+ and then use only POSIX features and the portable wrapper functions in all
+ other C-modules. */
+#include "ghcconfig.h"
+#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)
+#define __BSD_VISIBLE 1
+#endif
+#if defined(darwin_HOST_OS)
+#define _DARWIN_C_SOURCE 1
+#endif
+
#include "Rts.h"
/*
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 481b0f8c17..cacb829921 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -9,14 +9,23 @@
#include "PosixSource.h"
+/* We've defined _POSIX_SOURCE via "PosixSource.h", and yet still use
+ some non-POSIX features. With _POSIX_SOURCE defined, visibility of
+ non-POSIX extension prototypes requires _DARWIN_C_SOURCE on Mac OS X and
+ __BSD_VISIBLE on FreeBSD and DragonflyBSD. Otherwise, for example, code
+ using pthread_setname_np(3) and variants will not compile. We must
+ therefore define the additional macros that expose non-POSIX APIs early,
+ before any of the relevant system headers are included via "Rts.h".
+
+ An alternative approach could be to write portable wrappers or stubs for all
+ the non-posix functions in a C-module that does not include "PosixSource.h",
+ and then use only POSIX features and the portable wrapper functions in all
+ other C-modules. */
+#include "ghcconfig.h"
#if defined(freebsd_HOST_OS) || defined(dragonfly_HOST_OS)
-/* Inclusion of system headers usually requires __BSD_VISIBLE on FreeBSD and
- * DragonflyBSD, because of some specific types, like u_char, u_int, etc. */
#define __BSD_VISIBLE 1
#endif
#if defined(darwin_HOST_OS)
-/* Inclusion of system headers usually requires _DARWIN_C_SOURCE on Mac OS X
- * because of some specific types like u_char, u_int, etc. */
#define _DARWIN_C_SOURCE 1
#endif