summaryrefslogtreecommitdiff
path: root/rts
diff options
context:
space:
mode:
Diffstat (limited to 'rts')
-rw-r--r--rts/configure.ac138
-rw-r--r--rts/include/rts/PosixSource.h2
-rw-r--r--rts/linker/Elf.c2
-rw-r--r--rts/linker/elf_got.c1
-rw-r--r--rts/m4/fp_bfd_support.m449
-rw-r--r--rts/m4/fp_cc_supports__atomics.m467
-rw-r--r--rts/m4/fp_check_pthreads.m4117
-rw-r--r--rts/m4/fp_find_libdw.m456
-rw-r--r--rts/m4/fp_find_libnuma.m451
-rw-r--r--rts/m4/fp_large_address_space.m457
-rw-r--r--rts/m4/fp_musttail.m416
-rw-r--r--rts/m4/fp_visibility_hidden.m416
-rw-r--r--rts/m4/ghc_adjustors_method.m449
-rw-r--r--rts/posix/OSThreads.c3
-rw-r--r--rts/posix/ticker/Pthread.c3
-rw-r--r--rts/rts.buildinfo.in60
-rw-r--r--rts/rts.cabal.in73
17 files changed, 683 insertions, 77 deletions
diff --git a/rts/configure.ac b/rts/configure.ac
index 81c702d3c4..a9d08b179d 100644
--- a/rts/configure.ac
+++ b/rts/configure.ac
@@ -8,7 +8,7 @@
AC_INIT([GHC run-time system], [1.0.2], [libraries@haskell.org], [rts])
-AC_CONFIG_MACRO_DIRS([../m4])
+AC_CONFIG_MACRO_DIRS([m4 ../m4])
# Safety check: Ensure that we are in the correct source directory.
AC_CONFIG_SRCDIR([include/rts/Constants.h])
@@ -29,19 +29,143 @@ AC_CONFIG_HEADERS([ghcautoconf.h.autoconf])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
+GHC_CONVERT_PLATFORM_PARTS([build], [Build])
GHC_CONVERT_PLATFORM_PARTS([host], [Host])
+FPTOOLS_SET_PLATFORM_VARS([build], [Build])
FPTOOLS_SET_PLATFORM_VARS([host], [Host])
FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
+AC_CHECK_HEADERS([ctype.h dirent.h dlfcn.h errno.h fcntl.h grp.h limits.h locale.h nlist.h pthread.h pwd.h signal.h sys/param.h sys/mman.h sys/resource.h sys/select.h sys/time.h sys/timeb.h sys/timerfd.h sys/timers.h sys/times.h sys/utsname.h sys/wait.h termios.h utime.h windows.h winsock.h sched.h])
+
+AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity sched_getaffinity setlocale uselocale])
+
+dnl sys/cpuset.h needs sys/param.h to be included first on FreeBSD 9.1; #7708
+AC_CHECK_HEADERS([sys/cpuset.h], [], [],
+[[#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+]])
+
+dnl ** check whether a declaration for `environ` is provided by libc.
+FP_CHECK_ENVIRON
+
dnl ** Other RTS features
dnl --------------------------------------------------------------
-AC_DEFINE_UNQUOTED([USE_LIBDW], [$CABAL_FLAG_libdw], [Set to 1 to use libdw])
-AC_DEFINE_UNQUOTED([HAVE_LIBNUMA], [$CABAL_FLAG_libnuma], [Define to 1 if you have libnuma])
+FP_FIND_LIBDW
+
+FP_FIND_LIBNUMA
-dnl ** Write config files
+FP_LEADING_UNDERSCORE
+FP_MUSTTAIL
+
+dnl ** Check for __thread support in the compiler
+AC_MSG_CHECKING(for __thread support)
+AC_COMPILE_IFELSE(
+ [ AC_LANG_SOURCE([[__thread int tester = 0;]]) ],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([CC_SUPPORTS_TLS],[1],[Define to 1 if __thread is supported])
+ ],
+ [
+ AC_MSG_RESULT(no)
+ AC_DEFINE([CC_SUPPORTS_TLS],[0],[Define to 1 if __thread is supported])
+ ])
+
+dnl ** Use MMAP in the runtime linker?
dnl --------------------------------------------------------------
+case ${TargetOS} in
+ linux|linux-android|freebsd|dragonfly|netbsd|openbsd|kfreebsdgnu|gnu|solaris2)
+ RtsLinkerUseMmap=1
+ ;;
+ darwin|ios|watchos|tvos)
+ RtsLinkerUseMmap=1
+ ;;
+ *)
+ # Windows (which doesn't have mmap) and everything else.
+ RtsLinkerUseMmap=0
+ ;;
+ esac
+
+AC_DEFINE_UNQUOTED([RTS_LINKER_USE_MMAP], [$RtsLinkerUseMmap],
+ [Use mmap in the runtime linker])
+
+
+GHC_ADJUSTORS_METHOD([Target])
+AC_SUBST([UseLibffiForAdjustors])
+AS_IF(
+ [test x"${UseLibffiForAdjustors}" = x"YES"],
+ [AC_DEFINE([GHC_LIBFFI_ADJUSTORS],[1],[Should libffi be used for adjustors?])],
+ [AC_DEFINE([GHC_LIBFFI_ADJUSTORS],[0],[Should libffi be used for adjustors?])]
+)
+
+dnl ** do we have long longs?
+AC_CHECK_TYPES([long long])
+
+dnl ** what are the sizes of various types
+FP_CHECK_SIZEOF_AND_ALIGNMENT(char)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(double)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(float)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(int)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(long)
+if test "$ac_cv_type_long_long" = yes; then
+FP_CHECK_SIZEOF_AND_ALIGNMENT(long long)
+fi
+FP_CHECK_SIZEOF_AND_ALIGNMENT(short)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned char)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned int)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned long)
+if test "$ac_cv_type_long_long" = yes; then
+FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned long long)
+fi
+FP_CHECK_SIZEOF_AND_ALIGNMENT(unsigned short)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(void *)
+
+FP_CHECK_SIZEOF_AND_ALIGNMENT(int8_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(uint8_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(int16_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(uint16_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(int32_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(uint32_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(int64_t)
+FP_CHECK_SIZEOF_AND_ALIGNMENT(uint64_t)
+
+dnl ** check for pthreads
+FP_CHECK_PTHREADS
+
+dnl ** check for math library
+dnl Keep that check as early as possible.
+dnl as we need to know whether we need libm
+dnl for math functions or not
+dnl (see https://gitlab.haskell.org/ghc/ghc/issues/3730)
+AC_CHECK_LIB([m], [atan], [need_libm=1], [need_libm=0])
+AC_DEFINE_UNQUOTED([GHC_NEED_LIBM], [$need_libm], [Define to 1 if you need to link with libm])
+
+dnl ** check for librt
+AC_CHECK_LIB([rt], [clock_gettime], [need_librt=1], [need_librt=1])
+AC_DEFINE_UNQUOTED([GHC_NEED_LIBRT], [$need_librt], [Define to 1 if you need to link with librt])
+AC_CHECK_FUNCS(clock_gettime timer_settime)
+FP_CHECK_TIMER_CREATE
+
+dnl ** check whether we need -ldl to get dlopen()
+AC_CHECK_LIB([dl], [dlopen], [need_libdl=1], [need_libdl=0])
+AC_DEFINE_UNQUOTED([GHC_NEED_LIBDL], [$need_libdl], [Define to 1 if you need to link with libdl to get dlopen])
+dnl ** check whether we have dlinfo
+AC_CHECK_FUNCS([dlinfo])
+
+dnl ** On Linux we should have program_invocation_short_name
+AC_CHECK_DECLS([program_invocation_short_name], , ,
+[#define _GNU_SOURCE 1
+#include <errno.h>])
+
+dnl ** check whether we should use the two-step allocator
+FP_LARGE_ADDRESS_SPACE
+
+FP_BFD_SUPPORT
+
+AC_CONFIG_FILES([rts.buildinfo])
+
AC_OUTPUT
dnl ######################################################################
@@ -55,9 +179,9 @@ touch include/ghcautoconf.h
echo "#if !defined(__GHCAUTOCONF_H__)" >> include/ghcautoconf.h
echo "#define __GHCAUTOCONF_H__" >> include/ghcautoconf.h
-# Copy the contents of $srcdir/../mk/config.h, turning '#define PACKAGE_FOO
+# Copy the contents of ghcautoconf.h.autoconf, turning '#define PACKAGE_FOO
# "blah"' into '/* #undef PACKAGE_FOO */' to avoid clashes.
-cat $srcdir/../mk/config.h ghcautoconf.h.autoconf | sed \
+sed ghcautoconf.h.autoconf \
-e 's,^\([ ]*\)#[ ]*define[ ][ ]*\(PACKAGE_[A-Z]*\)[ ][ ]*".*".*$,\1/* #undef \2 */,' \
-e '/__GLASGOW_HASKELL/d' \
-e '/REMOVE ME/d' \
@@ -92,4 +216,6 @@ cat $srcdir/rts.buildinfo.in | \
"$CC" -E -P -traditional - -o - \
> rts.buildinfo
echo "" >> rts.buildinfo
+echo "cc-options: ${CFLAGS}" >> rts.buildinfo
+echo "ld-options: ${LDFLAGS}" >> rts.buildinfo
rm -f external-symbols.list
diff --git a/rts/include/rts/PosixSource.h b/rts/include/rts/PosixSource.h
index be6c8ecca1..bc1be83d87 100644
--- a/rts/include/rts/PosixSource.h
+++ b/rts/include/rts/PosixSource.h
@@ -37,6 +37,8 @@
#define _XOPEN_SOURCE 700
#endif
+#define _GNU_SOURCE 1
+
#if defined(mingw32_HOST_OS)
# if defined(__USE_MINGW_ANSI_STDIO)
# if __USE_MINGW_ANSI_STDIO != 1
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index 3595a4c3d4..ff242e835a 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -28,10 +28,10 @@
#include "linker/util.h"
#include "linker/elf_util.h"
-#include <link.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
+#include <link.h>
#if defined(HAVE_DLFCN_H)
#include <dlfcn.h>
#endif
diff --git a/rts/linker/elf_got.c b/rts/linker/elf_got.c
index 4d0c97871e..9c9f07e7fa 100644
--- a/rts/linker/elf_got.c
+++ b/rts/linker/elf_got.c
@@ -1,6 +1,7 @@
#include "Rts.h"
#include "elf_got.h"
#include "linker/MMap.h"
+#include "sys/mman.h"
#include <string.h>
diff --git a/rts/m4/fp_bfd_support.m4 b/rts/m4/fp_bfd_support.m4
new file mode 100644
index 0000000000..2f357820f7
--- /dev/null
+++ b/rts/m4/fp_bfd_support.m4
@@ -0,0 +1,49 @@
+# FP_BFD_SUPPORT()
+# ----------------------
+# whether to use libbfd for debugging RTS
+AC_DEFUN([FP_BFD_SUPPORT], [
+ HaveLibbfd=NO
+ AC_ARG_ENABLE(bfd-debug,
+ [AS_HELP_STRING([--enable-bfd-debug],
+ [Enable symbol resolution for -debug rts ('+RTS -Di') via binutils' libbfd [default=no]])],
+ [
+ # don't pollute general LIBS environment
+ save_LIBS="$LIBS"
+ AC_CHECK_HEADERS([bfd.h])
+ dnl ** check whether this machine has BFD and libiberty installed (used for debugging)
+ dnl the order of these tests matters: bfd needs libiberty
+ AC_CHECK_LIB(iberty, xmalloc)
+ dnl 'bfd_init' is a rare non-macro in libbfd
+ AC_CHECK_LIB(bfd, bfd_init)
+
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <bfd.h>]],
+ [[
+ /* mimic our rts/Printer.c */
+ bfd* abfd;
+ const char * name;
+ char **matching;
+
+ name = "some.executable";
+ bfd_init();
+ abfd = bfd_openr(name, "default");
+ bfd_check_format_matches (abfd, bfd_object, &matching);
+ {
+ long storage_needed;
+ storage_needed = bfd_get_symtab_upper_bound (abfd);
+ }
+ {
+ asymbol **symbol_table;
+ long number_of_symbols;
+ symbol_info info;
+
+ number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+ bfd_get_symbol_info(abfd,symbol_table[0],&info);
+ }
+ ]])],
+ HaveLibbfd=YES,dnl bfd seems to work
+ [AC_MSG_ERROR([can't use 'bfd' library])])
+ LIBS="$save_LIBS"
+ ]
+ )
+ AC_SUBST([UseLibbfd],[$HaveLibbfd])
+])
diff --git a/rts/m4/fp_cc_supports__atomics.m4 b/rts/m4/fp_cc_supports__atomics.m4
new file mode 100644
index 0000000000..9c15ef6a1f
--- /dev/null
+++ b/rts/m4/fp_cc_supports__atomics.m4
@@ -0,0 +1,67 @@
+dnl FP_CC_SUPPORTS__ATOMICS
+dnl ------------------------
+dnl Does C compiler support the __atomic_* family of builtins?
+AC_DEFUN([FP_CC_SUPPORTS__ATOMICS],
+[
+ AC_REQUIRE([AC_PROG_CC])
+ AC_MSG_CHECKING([whether C compiler supports __atomic_ builtins])
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[int x, y;]], [[__atomic_load(&x, &y, __ATOMIC_SEQ_CST); return y]])],
+ [
+ AC_MSG_RESULT(yes)
+
+ need_latomic=0
+ AC_MSG_CHECKING(whether -latomic is needed for sub-word-sized atomic operations)
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned char a;]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
+ [
+ AC_MSG_RESULT(no)
+ ],
+ [
+ _save_LIBS="$LIBS"
+ LIBS="-latomic"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[unsigned char a;]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
+ [
+ AC_MSG_RESULT(yes)
+ need_latomic=1
+ ],
+ [
+ AC_MSG_RESULT(failed)
+ AC_MSG_ERROR([sub-word-sized atomic operations are not available.])
+ ])
+ LIBS="$_save_LIBS"
+ ])
+ AC_MSG_CHECKING(whether -latomic is needed for 64-bit atomic operations)
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(
+ [[
+ #include <inttypes.h>
+ uint64_t a;
+ ]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
+ [
+ AC_MSG_RESULT(no)
+ ],
+ [
+ _save_LIBS="$LIBS"
+ LIBS="-latomic"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(
+ [[
+ #include <inttypes.h>
+ uint64_t a;
+ ]], [[__atomic_fetch_or(&a, 1, __ATOMIC_RELAXED);]])],
+ [
+ AC_MSG_RESULT(yes)
+ need_latomic=1
+ ],
+ [
+ AC_MSG_RESULT(failed)
+ AC_MSG_ERROR([64-bit atomic operations are not available.])
+ ])
+ LIBS="$_save_LIBS"
+ ])
+ ],
+ [
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([C compiler needs to support __atomic primitives.])
+ ])
+ AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does C compiler support __atomic primitives?])
+ AC_DEFINE_UNQUOTED([GHC_NEED_LIBATOMIC], [$need_latomic],
+ [Define to 1 if we need -latomic.])
+])
diff --git a/rts/m4/fp_check_pthreads.m4 b/rts/m4/fp_check_pthreads.m4
new file mode 100644
index 0000000000..5c63cac2a5
--- /dev/null
+++ b/rts/m4/fp_check_pthreads.m4
@@ -0,0 +1,117 @@
+dnl FP_CHECK_PTHREADS
+dnl ----------------------------------
+dnl Check various aspects of the platform's pthreads support
+AC_DEFUN([FP_CHECK_PTHREADS],
+[
+ dnl Some platforms (e.g. Android's Bionic) have pthreads support available
+ dnl without linking against libpthread. Check whether -lpthread is necessary
+ dnl to use pthreads.
+ dnl
+ dnl Note that it is important that this happens before we AC_CHECK_LIB(thread)
+ AC_MSG_CHECKING(whether -lpthread is needed for pthreads)
+ AC_CHECK_FUNC(pthread_create,
+ [
+ AC_MSG_RESULT(no)
+ need_lpthread=0
+ ],
+ [
+ AC_CHECK_LIB(pthread, pthread_create,
+ [
+ AC_MSG_RESULT(yes)
+ need_lpthread=1
+ ],
+ [
+ AC_MSG_RESULT([no pthreads support found.])
+ need_lpthread=0
+ ])
+ ])
+ AC_DEFINE_UNQUOTED([GHC_NEED_LIBPTHREAD], [$need_lpthread],
+ [Define 1 if we need to link code using pthreads with -lpthread])
+
+ dnl Setting thread names
+ dnl ~~~~~~~~~~~~~~~~~~~~
+ dnl The portability situation here is complicated:
+ dnl
+ dnl * FreeBSD supports pthread_set_name_np in <pthread_np.h>
+ dnl and (if not _POSIX_SOURCE) pthread_setname_np() in <pthread.h>
+ dnl because of the conditional visibility, we prefer the former.
+ dnl * glibc supports pthread_setname_np
+ dnl * Darwin supports pthread_setname_np but does not take a
+ dnl pthread_t argument.
+ dnl
+ AC_CHECK_HEADERS([pthread_np.h])
+
+ dnl ** pthread_setname_np is a recent addition to glibc, and OS X has
+ dnl a different single-argument version.
+ AC_CHECK_LIB(pthread, pthread_setname_np)
+
+ AC_MSG_CHECKING([for pthread_setname_np (Darwin)])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #include <pthread.h>
+ ]],
+ [[pthread_setname_np("name");]]
+ )],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_DARWIN], [1],
+ [Define to 1 if you have the Darwin version of pthread_setname_np])
+ ],
+ AC_MSG_RESULT(no)
+ )
+
+ dnl glibc
+ AC_MSG_CHECKING([for pthread_setname_np (glibc)])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #define _GNU_SOURCE
+ #include <pthread.h>
+ ]],
+ [[pthread_setname_np(pthread_self(), "name");]]
+ )],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1],
+ [Define to 1 if you have the glibc version of pthread_setname_np])
+ ],
+ AC_MSG_RESULT(no)
+ )
+
+ dnl NetBSD
+ AC_MSG_CHECKING([for pthread_setname_np (NetBSD)])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #include <pthread.h>
+ ]],
+ [[pthread_setname_np(pthread_self(), "%s", "name");]]
+ )],
+ [
+ AC_MSG_RESULT([yes])
+ AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_NETBSD], [1],
+ [Define to 1 if you have the NetBSD version of pthread_setname_np])
+ ],
+ AC_MSG_RESULT([no])
+ )
+
+ dnl FreeBSD
+ AC_MSG_CHECKING([for pthread_set_name_np])
+ AC_LINK_IFELSE([
+ AC_LANG_PROGRAM(
+ [[
+ #include <pthread_np.h>
+ ]],
+ [[pthread_set_name_np(pthread_self(), "name");]]
+ )],
+ [
+ AC_MSG_RESULT(yes)
+ AC_DEFINE([HAVE_PTHREAD_SET_NAME_NP], [1],
+ [Define to 1 if you have pthread_set_name_np])
+ ],
+ AC_MSG_RESULT(no)
+ )
+
+ AC_CHECK_FUNCS_ONCE([pthread_condattr_setclock])
+])
diff --git a/rts/m4/fp_find_libdw.m4 b/rts/m4/fp_find_libdw.m4
new file mode 100644
index 0000000000..70305c78fe
--- /dev/null
+++ b/rts/m4/fp_find_libdw.m4
@@ -0,0 +1,56 @@
+dnl ** Have libdw?
+dnl --------------------------------------------------------------
+dnl Sets UseLibdw.
+AC_DEFUN([FP_FIND_LIBDW],
+[
+ AC_ARG_WITH([libdw-libraries],
+ [AS_HELP_STRING([--with-libdw-libraries=ARG],
+ [Find libraries for libdw in ARG [default=system default]])
+ ],
+ [
+ LibdwLibDir="$withval"
+ LIBDW_LDFLAGS="-L$withval"
+ ])
+
+ AC_ARG_WITH([libdw-includes],
+ [AS_HELP_STRING([--with-libdw-includes=ARG],
+ [Find includes for libdw in ARG [default=system default]])
+ ],
+ [
+ LibdwIncludeDir="$withval"
+ LIBDW_CFLAGS="-I$withval"
+ ])
+
+ AC_ARG_ENABLE(dwarf-unwind,
+ [AS_HELP_STRING([--enable-dwarf-unwind],
+ [Enable DWARF unwinding support in the runtime system via elfutils' libdw [default=no]])],
+ [],
+ [enable_dwarf_unwind=no])
+
+ UseLibdw=NO
+ if test "$enable_dwarf_unwind" != "no" ; then
+ CFLAGS2="$CFLAGS"
+ CFLAGS="$LIBDW_CFLAGS $CFLAGS"
+ LDFLAGS2="$LDFLAGS"
+ LDFLAGS="$LIBDW_LDFLAGS $LDFLAGS"
+
+ AC_CHECK_HEADER([elfutils/libdwfl.h],
+ [AC_CHECK_LIB(dw, dwfl_attach_state,
+ [UseLibdw=YES])])
+
+ if test "x:$enable_dwarf_unwind:$UseLibdw" = "x:yes:NO" ; then
+ AC_MSG_ERROR([Cannot find system libdw (required by --enable-dwarf-unwind)])
+ fi
+
+ CFLAGS="$CFLAGS2"
+ LDFLAGS="$LDFLAGS2"
+ fi
+
+ AC_SUBST(UseLibdw)
+ USE_LIBDW=0
+ if test $UseLibdw = "YES" ; then
+ USE_LIBDW=1
+ fi
+ AC_DEFINE_UNQUOTED([USE_LIBDW], [$USE_LIBDW], [Set to 1 to use libdw]
+])
+
diff --git a/rts/m4/fp_find_libnuma.m4 b/rts/m4/fp_find_libnuma.m4
new file mode 100644
index 0000000000..eadd7d86fd
--- /dev/null
+++ b/rts/m4/fp_find_libnuma.m4
@@ -0,0 +1,51 @@
+AC_DEFUN([FP_FIND_LIBNUMA],
+[
+ dnl ** Have libnuma?
+ dnl --------------------------------------------------------------
+ AC_ARG_WITH([libnuma-libraries],
+ [AS_HELP_STRING([--with-libnuma-libraries=ARG],
+ [Find libraries for libnuma in ARG [default=system default]])
+ ],
+ [
+ LibNumaLibDir="$withval"
+ LIBNUMA_LDFLAGS="-L$withval"
+ ])
+
+ AC_ARG_WITH([libnuma-includes],
+ [AS_HELP_STRING([--with-libnuma-includes=ARG],
+ [Find includes for libnuma in ARG [default=system default]])
+ ],
+ [
+ LibNumaIncludeDir="$withval"
+ LIBNUMA_CFLAGS="-I$withval"
+ ])
+
+ AC_ARG_ENABLE(numa,
+ [AS_HELP_STRING([--enable-numa],
+ [Enable NUMA memory policy and thread affinity support in the
+ runtime system via numactl's libnuma [default=auto]])],
+ [],
+ [enable_numa=auto])
+
+ HaveLibNuma=0
+ if test "$enable_numa" != "no" ; then
+ CFLAGS2="$CFLAGS"
+ CFLAGS="$LIBNUMA_CFLAGS $CFLAGS"
+ LDFLAGS2="$LDFLAGS"
+ LDFLAGS="$LIBNUMA_LDFLAGS $LDFLAGS"
+
+ AC_CHECK_HEADERS([numa.h numaif.h])
+
+ if test "x:$ac_cv_header_numa_h:$ac_cv_header_numaif_h" = "x:yes:yes" ; then
+ AC_CHECK_LIB([numa], [numa_available], [HaveLibNuma=1])
+ fi
+ if test "x:$enable_numa:$HaveLibNuma" = "x:yes:0" ; then
+ AC_MSG_ERROR([Cannot find system libnuma (required by --enable-numa)])
+ fi
+
+ CFLAGS="$CFLAGS2"
+ LDFLAGS="$LDFLAGS2"
+ fi
+
+ AC_DEFINE_UNQUOTED([HAVE_LIBNUMA], [$HaveLibNuma], [Define to 1 if you have libnuma])
+])
diff --git a/rts/m4/fp_large_address_space.m4 b/rts/m4/fp_large_address_space.m4
new file mode 100644
index 0000000000..fd8a352a57
--- /dev/null
+++ b/rts/m4/fp_large_address_space.m4
@@ -0,0 +1,57 @@
+dnl large address space support (see rts/include/rts/storage/MBlock.h)
+dnl
+dnl Darwin has vm_allocate/vm_protect
+dnl Linux has mmap(MAP_NORESERVE)/madv(MADV_DONTNEED)
+dnl FreeBSD, Solaris and maybe other have MAP_NORESERVE/MADV_FREE
+dnl (They also have MADV_DONTNEED, but it means something else!)
+dnl
+dnl Windows has VirtualAlloc MEM_RESERVE/MEM_COMMIT, however
+dnl it counts page-table space as committed memory, and so quickly
+dnl runs out of paging file when we have multiple processes reserving
+dnl 1TB of address space, we get the following error:
+dnl VirtualAlloc MEM_RESERVE 1099512676352 bytes failed: The paging file is too small for this operation to complete.
+dnl
+
+AC_DEFUN([FP_LARGE_ADDRESS_SPACE],
+[
+ AC_ARG_ENABLE(large-address-space,
+ [AS_HELP_STRING([--enable-large-address-space],
+ [Use a single large address space on 64 bit systems (enabled by default on 64 bit platforms)])],
+ EnableLargeAddressSpace=$enableval,
+ EnableLargeAddressSpace=yes
+ )
+
+ use_large_address_space=no
+ if test "$ac_cv_sizeof_void_p" -eq 8 ; then
+ if test "x$EnableLargeAddressSpace" = "xyes" ; then
+ if test "$ghc_host_os" = "darwin" ; then
+ use_large_address_space=yes
+ elif test "$ghc_host_os" = "openbsd" ; then
+ # as of OpenBSD 5.8 (2015), OpenBSD does not support mmap with MAP_NORESERVE.
+ # The flag MAP_NORESERVE is supported for source compatibility reasons,
+ # but is completely ignored by OS mmap
+ use_large_address_space=no
+ elif test "$ghc_host_os" = "mingw32" ; then
+ # as of Windows 8.1/Server 2012 windows does no longer allocate the page
+ # tabe for reserved memory eagerly. So we are now free to use LAS there too.
+ use_large_address_space=yes
+ else
+ AC_CHECK_DECLS([MAP_NORESERVE, MADV_FREE, MADV_DONTNEED],[],[],
+ [
+ #include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/mman.h>
+ #include <fcntl.h>
+ ])
+ if test "$ac_cv_have_decl_MAP_NORESERVE" = "yes" &&
+ test "$ac_cv_have_decl_MADV_FREE" = "yes" ||
+ test "$ac_cv_have_decl_MADV_DONTNEED" = "yes" ; then
+ use_large_address_space=yes
+ fi
+ fi
+ fi
+ fi
+ if test "$use_large_address_space" = "yes" ; then
+ AC_DEFINE([USE_LARGE_ADDRESS_SPACE], [1], [Enable single heap address space support])
+ fi
+])
diff --git a/rts/m4/fp_musttail.m4 b/rts/m4/fp_musttail.m4
new file mode 100644
index 0000000000..0c61c2ad4c
--- /dev/null
+++ b/rts/m4/fp_musttail.m4
@@ -0,0 +1,16 @@
+# FP_MUSTTAIL
+# ----------------------------------
+# Is the musttail attribute supported?
+AC_DEFUN([FP_MUSTTAIL],
+[
+ AC_MSG_CHECKING([whether __attribute__((musttail)) is supported])
+ echo 'extern int foo(void); int bar(void) { __attribute__((musttail)) return foo(); }' > conftest.c
+ if $CC -c conftest.c -o conftest.o > /dev/null 2>&1
+ then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE(HAS_MUSTTAIL, 1, [Has musttail])
+ else
+ AC_MSG_RESULT([no])
+ fi
+ rm -f conftest.c conftest.o
+])
diff --git a/rts/m4/fp_visibility_hidden.m4 b/rts/m4/fp_visibility_hidden.m4
new file mode 100644
index 0000000000..5f5cebeeec
--- /dev/null
+++ b/rts/m4/fp_visibility_hidden.m4
@@ -0,0 +1,16 @@
+# FP_VISIBILITY_HIDDEN
+# ----------------------------------
+# Is the visibility hidden attribute supported?
+AC_DEFUN([FP_VISIBILITY_HIDDEN],
+[
+ AC_MSG_CHECKING([whether __attribute__((visibility("hidden"))) is supported])
+ echo '__attribute__((visibility("hidden"))) void foo(void) {}' > conftest.c
+ if $CC -Wall -Werror -c conftest.c > /dev/null 2>&1
+ then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE(HAS_VISIBILITY_HIDDEN, 1, [Has visibility hidden])
+ else
+ AC_MSG_RESULT([no])
+ fi
+ rm -f conftest.c conftest.o
+])
diff --git a/rts/m4/ghc_adjustors_method.m4 b/rts/m4/ghc_adjustors_method.m4
new file mode 100644
index 0000000000..cae941a20e
--- /dev/null
+++ b/rts/m4/ghc_adjustors_method.m4
@@ -0,0 +1,49 @@
+dnl GHC_ADJUSTORS_METHOD(Platform)
+dnl --------------------------------------------------------------
+dnl Use libffi for adjustors?
+AC_DEFUN([GHC_ADJUSTORS_METHOD],
+[
+ case [$]{$1[Arch]} in
+ i386|x86_64)
+ # We have native adjustor support on these platforms
+ HaveNativeAdjustor=yes
+ ;;
+ *)
+ HaveNativeAdjustor=no
+ ;;
+ esac
+
+ AC_ARG_ENABLE(libffi-adjustors,
+ [AS_HELP_STRING(
+ [--enable-libffi-adjustors],
+ [Force use of libffi for adjustors, even on platforms which have support for more efficient, native adjustors.])],
+ UseLibffiForAdjustors=$enableval,
+ dnl do nothing
+ )
+
+ AC_MSG_CHECKING([whether to use libffi for adjustors])
+ if test "$UseLibffiForAdjustors" = "yes" ; then
+ # Use libffi is the user explicitly requested it
+ AdjustorType="libffi"
+ elif test "$HaveNativeAdjustor" = "yes"; then
+ # Otherwise if we have a native adjustor implementation use that
+ AdjustorType="native"
+ else
+ # If we don't have a native adjustor implementation then default to libffi
+ AdjustorType="libffi"
+ fi
+
+ case "$AdjustorType" in
+ libffi)
+ UseLibffiForAdjustors=YES
+ AC_MSG_RESULT([yes])
+ ;;
+ native)
+ UseLibffiForAdjustors=NO
+ AC_MSG_RESULT([no])
+ ;;
+ *)
+ AC_MSG_ERROR([Internal error: Invalid AdjustorType])
+ exit 1
+ esac
+])
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 44cda2626d..5b5b736703 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -32,6 +32,9 @@
#if defined(netbsd_HOST_OS)
#define _NETBSD_SOURCE 1
#endif
+#if defined(linux_HOST_OS)
+#define _GNU_SOURCE 1
+#endif
#include "Rts.h"
diff --git a/rts/posix/ticker/Pthread.c b/rts/posix/ticker/Pthread.c
index a4c7af588f..9200ff8318 100644
--- a/rts/posix/ticker/Pthread.c
+++ b/rts/posix/ticker/Pthread.c
@@ -55,6 +55,9 @@
#include <string.h>
+#if defined(linux_HOST_OS)
+#define _GNU_SOURCE 1
+#endif
#include <pthread.h>
#if defined(HAVE_PTHREAD_NP_H)
#include <pthread_np.h>
diff --git a/rts/rts.buildinfo.in b/rts/rts.buildinfo.in
index 07540357c8..ac68fdc861 100644
--- a/rts/rts.buildinfo.in
+++ b/rts/rts.buildinfo.in
@@ -1,3 +1,63 @@
-- External symbols referenced by the RTS
ld-options:
#include "external-symbols.list"
+
+#if GHC_LIBFFI_ADJUSTORS
+ -- Adjustors via libffi
+ c-sources: adjustor/LibffiAdjustor.c
+#else
+ -- Use GHC's native adjustors
+# if defined(i386_HOST_ARCH)
+ asm-sources: adjustor/Nativei386Asm.S
+ c-sources: adjustor/Nativei386.c
+# elif defined(x86_64_HOST_ARCH)
+# if defined(mingw32_HOST_OS)
+ asm-sources: adjustor/NativeAmd64MingwAsm.S
+ c-sources: adjustor/NativeAmd64Mingw.c
+# else
+ asm-sources: adjustor/NativeAmd64Asm.S
+ c-sources: adjustor/NativeAmd64.c
+# endif
+# elif defined(powerpc_HOST_ARCH) || defined(powerpc64_HOST_ARCH)
+ asm-sources: AdjustorAsm.S
+ c-sources: adjustor/NativePowerPC.c
+# elif defined(ia64_HOST_ARCH)
+ c-sources: adjustor/NativeIA64.c
+# endif
+#endif
+
+#if GHC_NEED_LIBRT
+ extra-libraries: rt
+#endif
+
+#if GHC_NEED_LIBM
+ extra-libraries: m
+#endif
+
+#if GHC_NEED_LIBDL
+ extra-libraries: dl
+#endif
+
+#if GHC_NEED_LIBATOMIC
+ -- for sub-word-sized atomic operations (#19119)
+ extra-libraries: atomic
+#endif
+
+#if GHC_NEED_LIBPTHREAD
+ -- for pthread_getthreadid_np, pthread_create, ...
+ extra-libraries: pthread
+#endif
+
+#if USE_LIBBFD
+ -- for debugging
+ extra-libraries: bfd iberty
+#endif
+
+#if USE_LIBDW
+ -- for backtraces
+ extra-libraries: elf dw
+#endif
+
+#if USE_LIBNUMA
+ extra-libraries: numa
+#endif
diff --git a/rts/rts.cabal.in b/rts/rts.cabal.in
index 98ca808917..52b8311027 100644
--- a/rts/rts.cabal.in
+++ b/rts/rts.cabal.in
@@ -28,32 +28,9 @@ source-repository head
location: https://gitlab.haskell.org/ghc/ghc.git
subdir: rts
-flag libm
- default: @CabalHaveLibm@
-flag librt
- default: @CabalHaveLibrt@
-flag libdl
- default: @CabalHaveLibdl@
+-- Configuration
flag use-system-libffi
- default: @CabalUseSystemLibFFI@
-flag libffi-adjustors
- default: @CabalLibffiAdjustors@
-flag need-pthread
- default: @CabalNeedLibpthread@
-flag libbfd
- default: @CabalHaveLibbfd@
-flag mingwex
- default: @CabalMingwex@
-flag need-atomic
- default: @CabalNeedLibatomic@
-flag libdw
- default: @CabalHaveLibdw@
-flag libnuma
- default: @CabalHaveLibNuma@
-flag 64bit
- default: @Cabal64bit@
-flag leading-underscore
- default: @CabalLeadingUnderscore@
+ description: Use the system's libffi library rather than GHC's internally built library.
flag smp
default: True
flag find-ptr
@@ -177,13 +154,6 @@ library
-- that it is ordered correctly with libpthread, since ghc-prim.cabal
-- also explicitly lists libc. See #19029.
extra-libraries: c
- if flag(libm)
- -- for ldexp()
- extra-libraries: m
- if flag(librt)
- extra-libraries: rt
- if flag(libdl)
- extra-libraries: dl
if flag(use-system-libffi)
extra-libraries: ffi
if os(windows)
@@ -203,22 +173,8 @@ library
-- and also centralizes the versioning.
cpp-options: -D_WIN32_WINNT=0x06010000
cc-options: -D_WIN32_WINNT=0x06010000
- if flag(need-pthread)
- -- for pthread_getthreadid_np, pthread_create, ...
- extra-libraries: pthread
- if flag(need-atomic)
- -- for sub-word-sized atomic operations (#19119)
- extra-libraries: atomic
- if flag(libbfd)
- -- for debugging
- extra-libraries: bfd iberty
- if flag(mingwex)
+ if os(windows)
extra-libraries: mingwex
- if flag(libdw)
- -- for backtraces
- extra-libraries: elf dw
- if flag(libnuma)
- extra-libraries: numa
if !flag(smp)
cpp-options: -DNOSMP
@@ -297,8 +253,6 @@ library
if os(osx)
ld-options: "-Wl,-search_paths_first"
- -- See Note [fd_set_overflow]
- "-Wl,-U,___darwin_check_fd_set_overflow"
if !arch(x86_64) && !arch(aarch64)
ld-options: -read_only_relocs warning
@@ -315,27 +269,6 @@ library
-- AutoApply is generated
AutoApply.cmm
- -- Adjustor stuff
- if flag(libffi-adjustors)
- c-sources: adjustor/LibffiAdjustor.c
- else
- -- Use GHC's native adjustors
- if arch(i386)
- asm-sources: adjustor/Nativei386Asm.S
- c-sources: adjustor/Nativei386.c
- if arch(x86_64)
- if os(mingw32)
- asm-sources: adjustor/NativeAmd64MingwAsm.S
- c-sources: adjustor/NativeAmd64Mingw.c
- else
- asm-sources: adjustor/NativeAmd64Asm.S
- c-sources: adjustor/NativeAmd64.c
- if arch(ppc) || arch(ppc64)
- asm-sources: AdjustorAsm.S
- c-sources: adjustor/NativePowerPC.c
- if arch(ia64)
- c-sources: adjustor/NativeIA64.c
-
-- Use assembler STG entrypoint on architectures where it is used
if arch(ppc) || arch(ppc64) || arch(s390x) || arch(riscv64) || arch(loongarch64)
asm-sources: StgCRunAsm.S