summaryrefslogtreecommitdiff
path: root/rts/m4
diff options
context:
space:
mode:
Diffstat (limited to 'rts/m4')
-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
9 files changed, 478 insertions, 0 deletions
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
+])