summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2021-12-23 11:53:25 -0500
committerBen Gamari <ben@smart-cactus.org>2021-12-23 12:46:05 -0500
commitec8220b3d02c189bee4daf659446b66a594ac139 (patch)
tree9fca0b4e54f886fd62bb416a3f4db34077d2b78c
parentff657a81ae5ebd4ea4628ca8ebc88dce3ecbe0ef (diff)
downloadhaskell-wip/T20861.tar.gz
rts: Only declare environ when necessarywip/T20861
Previously we would unconditionally provide a declaration for `environ`, even if `<unistd.h>` already provided one. This would result in `-Werror` builds failing on some platforms. Also `#include <unistd.h>` to ensure that the declaration is visible. Fixes #20861.
-rw-r--r--configure.ac3
-rw-r--r--m4/fp_check_environ.m414
-rw-r--r--rts/RtsSymbols.c9
3 files changed, 25 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index a66c5c508a..fe1d0756e5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -965,6 +965,9 @@ AC_CHECK_HEADERS([sys/cpuset.h], [], [],
#endif
]])
+dnl ** check whether a declaration for `environ` is provided by libc.
+FP_CHECK_ENVIRON
+
dnl ** check if it is safe to include both <time.h> and <sys/time.h>
AC_HEADER_TIME
diff --git a/m4/fp_check_environ.m4 b/m4/fp_check_environ.m4
new file mode 100644
index 0000000000..88bf0a52de
--- /dev/null
+++ b/m4/fp_check_environ.m4
@@ -0,0 +1,14 @@
+# FP_CHECK_ENVIRON
+# -----------------
+AC_DEFUN([FP_CHECK_ENVIRON],
+[
+ dnl--------------------------------------------------------------------
+ dnl * Check whether the libc headers provide a declaration for the
+ dnl environ symbol. If not then we will provide one in RtsSymbols.c.
+ dnl See #20512, #20577, #20861.
+ dnl--------------------------------------------------------------------
+ AC_CHECK_DECLS([environ], [], [], [
+ #include <unistd.h>
+ ])
+])
+
diff --git a/rts/RtsSymbols.c b/rts/RtsSymbols.c
index 7d7b8422c2..f76573e3ae 100644
--- a/rts/RtsSymbols.c
+++ b/rts/RtsSymbols.c
@@ -34,10 +34,17 @@
#include <elf.h> /* _DYNAMIC */
#endif
+#if defined(HAVE_UNISTD_H)
+#include <unistd.h> /* environ */
+#endif
+
+#if !HAVE_DECL_ENVIRON
/* We must provide a prototype for environ since depending upon the libc
- * version it may or may not be provided by unistd.h. See #20577.
+ * version it may or may not be provided by unistd.h. See #20577 and #20861.
*/
extern char **environ;
+#endif
+
/* -----------------------------------------------------------------------------
* Symbols to be inserted into the RTS symbol table.