[Git][ghc/ghc][wip/rts-configure] 19 commits: Move lib{numa,dw} defines to RTS configure

John Ericson (@Ericson2314) gitlab at gitlab.haskell.org
Fri Sep 22 18:32:56 UTC 2023



John Ericson pushed to branch wip/rts-configure at Glasgow Haskell Compiler / GHC


Commits:
435de9de by John Ericson at 2023-09-22T01:52:05-04:00
Move lib{numa,dw} defines to RTS configure

Clean up the m4 to handle the auto case always and be more consistent.
Also simplify the CPP --- we should always have both headers if we are
using libnuma.

"side effects" (AC_DEFINE, and AC_SUBST) are removed from the macros to
better separate searching from actions taken based on search results.
This might seem overkill now, but will make shuffling logic between
configure scripts easier later.

The macro comments are converted from `dnl` to `#` following the
recomendation in
https://www.gnu.org/software/autoconf/manual/autoconf-2.71/html_node/Macro-Definitions.html

- - - - -
9e3f7f0f by John Ericson at 2023-09-22T13:24:02-04:00
rts configure: Move over `eventfd`, `__thread`, and mem mgmt checks

All of this should boil down to `AC_DEFINE` not `AC_SUBST`, so it
belongs in the RTS configure and should be safe to move without
modification.

- - - - -
545fd3f0 by John Ericson at 2023-09-22T13:29:40-04:00
Split `FP_CHECK_PTHREADS` and move part to RTS configure

`NEED_PTHREAD_LIB` is unused, and so no longer defined.

Progress towards #17191

- - - - -
647cde03 by John Ericson at 2023-09-22T13:32:04-04:00
Move apple compat check to RTS configure

- - - - -
1f951e7e by John Ericson at 2023-09-22T13:39:01-04:00
Move visibility and clock/timer fun checks to RTS configure

Actual library check (which will set the Cabal flag) is left in the
top-level configure for now.

Progress towards #17191

- - - - -
b0336127 by John Ericson at 2023-09-22T13:44:44-04:00
Move leading underscore checks to RTS configure

`CabalLeadingUnderscore` is done via Hadrian already, so we can stop
`AC_SUBST`ing it completely.

- - - - -
b1b2a08f by John Ericson at 2023-09-22T13:51:26-04:00
Move alloca, fork, const, and big endian checks to RTS configure

All of this should boil down to `AC_DEFINE` not `AC_SUBST`, so it
belongs in the RTS configure and should be safe to move without
modification.

- - - - -
6b93a305 by John Ericson at 2023-09-22T13:51:36-04:00
Move libdl check to RTS configure

- - - - -
a154a157 by John Ericson at 2023-09-22T14:02:17-04:00
Adjust `FP_FIND_LIBFFI`

Just set vars, and `AC_SUBST` in top-level configure.

Don't define `HAVE_SYSTEM_LIBFFI` because nothing is using it.

- - - - -
4c243081 by John Ericson at 2023-09-22T14:26:43-04:00
Split BFD support to RTS configure

The flag is still in the top-level configure, but the other checks
(which define various macros --- important) are in the RTS configure.

- - - - -
6dd95610 by John Ericson at 2023-09-22T14:31:23-04:00
Split libm check between top level and RTS

- - - - -
c57c133b by John Ericson at 2023-09-22T14:31:24-04:00
Move mingwex check to RTS configure

- - - - -
2e8f0fd2 by John Ericson at 2023-09-22T14:31:24-04:00
Move function checks to RTS configure

Some of these functions are used in `base` too, but we can copy the
checks over to its configure if that's an issue.

- - - - -
90d46d60 by John Ericson at 2023-09-22T14:31:24-04:00
Move over a number of C-style checks to RTS configure

- - - - -
3b773481 by John Ericson at 2023-09-22T14:31:24-04:00
Move/Copy remaining AC_DEFINE to RTS config

Only exception is the LLVM version macros, which are used for GHC
itself.

- - - - -
f197176f by John Ericson at 2023-09-22T14:31:24-04:00
Generate ghcplatform.h from RTS configure

- - - - -
9a98534c by John Ericson at 2023-09-22T14:31:24-04:00
RTS configure: handle ffi adjustor method

- - - - -
eb924a62 by John Ericson at 2023-09-22T14:31:25-04:00
Handle -lpthread entirely within RTS configure

- - - - -
efc5cfef by John Ericson at 2023-09-22T14:31:25-04:00
RTS makes independent decision on leading-underscore

- - - - -


18 changed files:

- configure.ac
- hadrian/cfg/system.config.in
- hadrian/src/Oracles/Flag.hs
- hadrian/src/Rules/Generate.hs
- hadrian/src/Rules/Lint.hs
- m4/fp_bfd_support.m4
- m4/fp_cc_supports__atomics.m4
- m4/fp_check_pthreads.m4
- m4/fp_find_libdw.m4
- m4/fp_find_libffi.m4
- m4/fp_find_libnuma.m4
- m4/fptools_set_haskell_platform_vars.m4
- rts/configure.ac
- + rts/ghcplatform.h.bottom
- + rts/ghcplatform.h.top.in
- rts/posix/OSMem.c
- rts/rts.buildinfo.in
- rts/rts.cabal.in


Changes:

=====================================
configure.ac
=====================================
@@ -155,27 +155,6 @@ if test "$EnableDistroToolchain" = "YES"; then
   TarballsAutodownload=NO
 fi
 
-AC_ARG_ENABLE(asserts-all-ways,
-[AS_HELP_STRING([--enable-asserts-all-ways],
-                [Usually ASSERTs are only compiled in the DEBUG way,
-                 this will enable them in all ways.])],
-  [FP_CAPITALIZE_YES_NO(["$enableval"], [EnableAssertsAllWays])],
-  [EnableAssertsAllWays=NO]
-)
-if test "$enable_asserts_all_ways" = "yes" ; then
-   AC_DEFINE([USE_ASSERTS_ALL_WAYS], [1], [Compile-in ASSERTs in all ways.])
-fi
-
-AC_ARG_ENABLE(native-io-manager,
-[AS_HELP_STRING([--enable-native-io-manager],
-                [Enable the native I/O manager by default.])],
-  [FP_CAPITALIZE_YES_NO(["$enableval"], [EnableNativeIOManager])],
-  [EnableNativeIOManager=NO]
-)
-if test "$EnableNativeIOManager" = "YES"; then
-  AC_DEFINE_UNQUOTED([DEFAULT_NATIVE_IO_MANAGER], [1], [Enable Native I/O manager as default.])
-fi
-
 AC_ARG_ENABLE(ghc-toolchain,
 [AS_HELP_STRING([--enable-ghc-toolchain],
                 [Whether to use the newer ghc-toolchain tool to configure ghc targets])],
@@ -336,9 +315,6 @@ dnl ** Do a build with tables next to code?
 dnl --------------------------------------------------------------
 
 GHC_TABLES_NEXT_TO_CODE
-if test x"$TablesNextToCode" = xYES; then
-   AC_DEFINE([TABLES_NEXT_TO_CODE], [1], [Define to 1 if info tables are laid out next to code])
-fi
 AC_SUBST(TablesNextToCode)
 
 # Requires FPTOOLS_SET_PLATFORMS_VARS to be run first.
@@ -626,12 +602,15 @@ dnl    unregisterised, Sparc, and PPC backends. Also determines whether
 dnl    linking to libatomic is required for atomic operations, e.g. on
 dnl    RISCV64 GCC.
 FP_CC_SUPPORTS__ATOMICS
+if test "$need_latomic" = 1; then
+    AC_SUBST([NeedLibatomic],[YES])
+else
+    AC_SUBST([NeedLibatomic],[NO])
+fi
 
 dnl ** look to see if we have a C compiler using an llvm back end.
 dnl
 FP_CC_LLVM_BACKEND
-AS_IF([test x"$CcLlvmBackend" = x"YES"],
-  [AC_DEFINE([CC_LLVM_BACKEND], [1], [Define (to 1) if C compiler has an LLVM back end])])
 AC_SUBST(CcLlvmBackend)
 
 FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
@@ -847,108 +826,26 @@ dnl --------------------------------------------------
 dnl ### program checking section ends here ###
 dnl --------------------------------------------------
 
-dnl --------------------------------------------------
-dnl * Platform header file and syscall feature tests
-dnl ### checking the state of the local header files and syscalls ###
-
-dnl ** Enable large file support.  NB. do this before testing the type of
-dnl    off_t, because it will affect the result of that test.
-AC_SYS_LARGEFILE
-
-dnl ** check for specific header (.h) files that we are interested in
-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])
-
-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 ** 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 for use in settings file
+AC_CHECK_SIZEOF([void *])
 TargetWordSize=$ac_cv_sizeof_void_p
 AC_SUBST(TargetWordSize)
 
 AC_C_BIGENDIAN([TargetWordBigEndian=YES],[TargetWordBigEndian=NO])
 AC_SUBST(TargetWordBigEndian)
 
-FP_CHECK_FUNC([WinExec],
-  [@%:@include <windows.h>], [WinExec("",0)])
-
-FP_CHECK_FUNC([GetModuleFileName],
-  [@%:@include <windows.h>], [GetModuleFileName((HMODULE)0,(LPTSTR)0,0)])
-
-dnl ** check for more functions
-dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
-AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity sched_getaffinity setlocale uselocale])
-
-dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
-dnl ** _POSIX_C_SOURCE is defined
-AC_CHECK_DECLS([ctime_r], , ,
-[#define _POSIX_SOURCE 1
-#define _POSIX_C_SOURCE 199506L
-#include <time.h>])
-
-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 for mingwex library
-AC_CHECK_LIB([mingwex],[closedir])
-
 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, HaveLibM=YES, HaveLibM=NO)
-if test $HaveLibM = YES
-then
-  AC_DEFINE([HAVE_LIBM], [1], [Define to 1 if you need to link with libm])
-  AC_SUBST([UseLibm],[YES])
-else
-  AC_SUBST([UseLibm],[NO])
-fi
-TargetHasLibm=$HaveLibM
+AC_CHECK_LIB(m, atan, UseLibm=YES, UseLibm=NO)
+AC_SUBST([UseLibm])
+TargetHasLibm=$UseLibM
 AC_SUBST(TargetHasLibm)
 
-FP_BFD_SUPPORT
+FP_BFD_FLAG
+AC_SUBST([UseLibbfd])
 
 dnl ################################################################
 dnl Check for libraries
@@ -956,166 +853,20 @@ dnl ################################################################
 
 FP_FIND_LIBFFI
 AC_SUBST(UseSystemLibFFI)
+AC_SUBST(FFILibDir)
+AC_SUBST(FFIIncludeDir)
 
 dnl ** check whether we need -ldl to get dlopen()
-AC_CHECK_LIB([dl], [dlopen])
-AC_CHECK_LIB([dl], [dlopen], HaveLibdl=YES, HaveLibdl=NO)
-AC_SUBST([UseLibdl],[$HaveLibdl])
-dnl ** check whether we have dlinfo
-AC_CHECK_FUNCS([dlinfo])
-
-dnl --------------------------------------------------
-dnl * Miscellaneous feature tests
-dnl --------------------------------------------------
-
-dnl ** can we get alloca?
-AC_FUNC_ALLOCA
-
-dnl ** working vfork?
-AC_FUNC_FORK
-
-dnl ** determine whether or not const works
-AC_C_CONST
-
-dnl ** are we big endian?
-AC_C_BIGENDIAN
-FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
+AC_CHECK_LIB([dl], [dlopen], UseLibdl=YES, UseLibdl=NO)
+AC_SUBST([UseLibdl])
 
 dnl ** check for leading underscores in symbol names
 FP_LEADING_UNDERSCORE
 AC_SUBST([LeadingUnderscore], [`echo $fptools_cv_leading_underscore | sed 'y/yesno/YESNO/'`])
-if test x"$fptools_cv_leading_underscore" = xyes; then
-   AC_SUBST([CabalLeadingUnderscore],[True])
-   AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.])
-else
-   AC_SUBST([CabalLeadingUnderscore],[False])
-fi
-
-FP_VISIBILITY_HIDDEN
-
-FP_MUSTTAIL
 
 dnl ** check for librt
-AC_CHECK_LIB([rt], [clock_gettime])
-AC_CHECK_LIB([rt], [clock_gettime], HaveLibrt=YES, HaveLibrt=NO)
-if test $HaveLibrt = YES
-then
-  AC_SUBST([UseLibrt],[YES])
-else
-  AC_SUBST([UseLibrt],[NO])
-fi
-AC_CHECK_FUNCS(clock_gettime timer_settime)
-FP_CHECK_TIMER_CREATE
-
-dnl ** check for Apple's "interesting" long double compatibility scheme
-AC_MSG_CHECKING(for printf\$LDBLStub)
-AC_LINK_IFELSE([AC_LANG_CALL([], [printf\$LDBLStub])],
-    [
-        AC_MSG_RESULT(yes)
-        AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[1],
-            [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
-    ],
-    [
-        AC_MSG_RESULT(no)
-        AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[0],
-            [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
-    ])
-
-FP_CHECK_PTHREADS
-
-dnl ** check for eventfd which is needed by the I/O manager
-AC_CHECK_HEADERS([sys/eventfd.h])
-AC_CHECK_FUNCS([eventfd])
-
-AC_CHECK_FUNCS([getpid getuid raise])
-
-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 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_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
-
-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])
-
+AC_CHECK_LIB([rt], [clock_gettime], UseLibrt=YES, UseLibrt=NO)
+AC_SUBST([UseLibrt])
 
 GHC_ADJUSTORS_METHOD([Target])
 AC_SUBST([UseLibffiForAdjustors])
@@ -1131,7 +882,14 @@ FP_FIND_LIBZSTD
 dnl ** Other RTS features
 dnl --------------------------------------------------------------
 FP_FIND_LIBDW
+AC_SUBST(UseLibdw)
+AC_SUBST(LibdwLibDir)
+AC_SUBST(LibdwIncludeDir)
+
 FP_FIND_LIBNUMA
+AC_SUBST(UseLibNuma)
+AC_SUBST(LibNumaLibDir)
+AC_SUBST(LibNumaIncludeDir)
 
 dnl ** Documentation
 dnl --------------------------------------------------------------


=====================================
hadrian/cfg/system.config.in
=====================================
@@ -124,5 +124,4 @@ use-lib-m         = @UseLibm@
 use-lib-rt        = @UseLibrt@
 use-lib-dl        = @UseLibdl@
 use-lib-bfd       = @UseLibbfd@
-use-lib-pthread   = @UseLibpthread@
 need-libatomic    = @NeedLibatomic@


=====================================
hadrian/src/Oracles/Flag.hs
=====================================
@@ -36,7 +36,6 @@ data Flag = CrossCompiling
           | UseLibrt
           | UseLibdl
           | UseLibbfd
-          | UseLibpthread
           | NeedLibatomic
           | UseGhcToolchain
 
@@ -60,7 +59,6 @@ flag f = do
             UseLibrt             -> "use-lib-rt"
             UseLibdl             -> "use-lib-dl"
             UseLibbfd            -> "use-lib-bfd"
-            UseLibpthread        -> "use-lib-pthread"
             NeedLibatomic        -> "need-libatomic"
             UseGhcToolchain      -> "use-ghc-toolchain"
     value <- lookupSystemConfig key


=====================================
hadrian/src/Rules/Generate.hs
=====================================
@@ -155,10 +155,10 @@ generatePackageCode context@(Context stage pkg _ _) = do
     when (pkg == rts) $ do
         root -/- "**" -/- dir -/- "cmm/AutoApply.cmm" %> \file ->
             build $ target context GenApply [] [file]
-        let go gen file = generate file (semiEmptyTarget stage) gen
         root -/- "**" -/- dir -/- "include/ghcautoconf.h" %> \_ ->
             need . pure =<< pkgSetupConfigFile context
-        root -/- "**" -/- dir -/- "include/ghcplatform.h" %> go generateGhcPlatformH
+        root -/- "**" -/- dir -/- "include/ghcplatform.h" %> \_ ->
+            need . pure =<< pkgSetupConfigFile context
         root -/- "**" -/- dir -/- "include/DerivedConstants.h" %> genPlatformConstantsHeader context
         root -/- "**" -/- dir -/- "include/rts/EventLogConstants.h" %> genEventTypes "--event-types-defines"
         root -/- "**" -/- dir -/- "include/rts/EventTypes.h" %> genEventTypes "--event-types-array"
@@ -296,7 +296,6 @@ rtsCabalFlags = mconcat
     , flag "CabalHaveLibm" UseLibm
     , flag "CabalHaveLibrt" UseLibrt
     , flag "CabalHaveLibdl" UseLibdl
-    , flag "CabalNeedLibpthread" UseLibpthread
     , flag "CabalHaveLibbfd" UseLibbfd
     , flag "CabalHaveLibNuma" UseLibnuma
     , flag "CabalHaveLibZstd" UseLibzstd
@@ -304,7 +303,6 @@ rtsCabalFlags = mconcat
     , flag "CabalNeedLibatomic" NeedLibatomic
     , flag "CabalUseSystemLibFFI" UseSystemFfi
     , targetFlag "CabalLibffiAdjustors" tgtUseLibffiForAdjustors
-    , targetFlag "CabalLeadingUnderscore" tgtSymbolsHaveLeadingUnderscore
     ]
   where
     flag = interpolateCabalFlag
@@ -369,62 +367,6 @@ ghcWrapper stage  = do
                                      else [])
                                ++ [ "$@" ]
 
--- | Given a 'String' replace characters '.' and '-' by underscores ('_') so that
--- the resulting 'String' is a valid C preprocessor identifier.
-cppify :: String -> String
-cppify = replaceEq '-' '_' . replaceEq '.' '_'
-
--- | Generate @ghcplatform.h@ header.
--- ROMES:TODO: For the runtime-retargetable GHC, these will eventually have to
--- be determined at runtime, and no longer hardcoded to a file (passed as -D
--- flags to the preprocessor, probably)
-generateGhcPlatformH :: Expr String
-generateGhcPlatformH = do
-    trackGenerateHs
-    stage    <- getStage
-    let chooseSetting x y = case stage of { Stage0 {} -> x; _ -> y }
-    buildPlatform  <- chooseSetting (queryBuild targetPlatformTriple) (queryHost targetPlatformTriple)
-    buildArch      <- chooseSetting (queryBuild queryArch)   (queryHost queryArch)
-    buildOs        <- chooseSetting (queryBuild queryOS)     (queryHost queryOS)
-    buildVendor    <- chooseSetting (queryBuild queryVendor) (queryHost queryVendor)
-    hostPlatform   <- chooseSetting (queryHost targetPlatformTriple) (queryTarget targetPlatformTriple)
-    hostArch       <- chooseSetting (queryHost queryArch)    (queryTarget queryArch)
-    hostOs         <- chooseSetting (queryHost queryOS)      (queryTarget queryOS)
-    hostVendor     <- chooseSetting (queryHost queryVendor)  (queryTarget queryVendor)
-    ghcUnreg       <- queryTarget tgtUnregisterised
-    return . unlines $
-        [ "#if !defined(__GHCPLATFORM_H__)"
-        , "#define __GHCPLATFORM_H__"
-        , ""
-        , "#define BuildPlatform_TYPE  " ++ cppify buildPlatform
-        , "#define HostPlatform_TYPE   " ++ cppify hostPlatform
-        , ""
-        , "#define " ++ cppify buildPlatform   ++ "_BUILD 1"
-        , "#define " ++ cppify hostPlatform ++ "_HOST 1"
-        , ""
-        , "#define " ++ buildArch   ++ "_BUILD_ARCH 1"
-        , "#define " ++ hostArch ++ "_HOST_ARCH 1"
-        , "#define BUILD_ARCH " ++ show buildArch
-        , "#define HOST_ARCH "  ++ show hostArch
-        , ""
-        , "#define " ++ buildOs   ++ "_BUILD_OS 1"
-        , "#define " ++ hostOs ++ "_HOST_OS 1"
-        , "#define BUILD_OS " ++ show buildOs
-        , "#define HOST_OS "  ++ show hostOs
-        , ""
-        , "#define " ++ buildVendor   ++ "_BUILD_VENDOR 1"
-        , "#define " ++ hostVendor ++ "_HOST_VENDOR 1"
-        , "#define BUILD_VENDOR " ++ show buildVendor
-        , "#define HOST_VENDOR "  ++ show hostVendor
-        , ""
-        ]
-        ++
-        [ "#define UnregisterisedCompiler 1" | ghcUnreg ]
-        ++
-        [ ""
-        , "#endif /* __GHCPLATFORM_H__ */"
-        ]
-
 generateSettings :: Expr String
 generateSettings = do
     ctx <- getContext


=====================================
hadrian/src/Rules/Lint.hs
=====================================
@@ -22,6 +22,8 @@ lintRules = do
       cmd_ (Cwd "libraries/base") "./configure"
   "rts" -/- "include" -/- "ghcautoconf.h" %> \_ ->
       cmd_ (Cwd "rts") "./configure"
+  "rts" -/- "include" -/- "ghcplatform.h" %> \_ ->
+      cmd_ (Cwd "rts") "./configure"
 
 lint :: Action () -> Action ()
 lint lintAction = do
@@ -68,7 +70,6 @@ base = do
   let includeDirs =
         [ "rts/include"
         , "libraries/base/include"
-        , stage1RtsInc
         ]
   runHLint includeDirs [] "libraries/base"
 


=====================================
m4/fp_bfd_support.m4
=====================================
@@ -1,49 +1,59 @@
 # 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)
+# Whether to use libbfd for debugging RTS
+#
+# Sets:
+#   UseLibbfd: [YES|NO]
+AC_DEFUN([FP_BFD_FLAG], [
+  UseLibbfd=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]])],
+    [UseLibbfd=YES],
+    [UseLibbfd=NO])
+])
+
+# FP_WHEN_ENABLED_BFD
+# ----------------------
+# Checks for libraries in the default way, which will define various
+# `HAVE_*` macros.
+AC_DEFUN([FP_WHEN_ENABLED_BFD], [
+  # 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;
+  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;
+        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])
+            number_of_symbols = bfd_canonicalize_symtab (abfd, symbol_table);
+            bfd_get_symbol_info(abfd,symbol_table[0],&info);
+        }
+      ]])],
+    [], dnl bfd seems to work
+    [AC_MSG_ERROR([can't use 'bfd' library])])
+  LIBS="$save_LIBS"
 ])


=====================================
m4/fp_cc_supports__atomics.m4
=====================================
@@ -61,12 +61,4 @@ AC_DEFUN([FP_CC_SUPPORTS__ATOMICS],
         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?])
-    if test "$need_latomic" = 1; then
-        AC_SUBST([NeedLibatomic],[YES])
-    else
-        AC_SUBST([NeedLibatomic],[NO])
-    fi
-    AC_DEFINE_UNQUOTED([NEED_ATOMIC_LIB], [$need_latomic],
-        [Define to 1 if we need -latomic.])
 ])


=====================================
m4/fp_check_pthreads.m4
=====================================
@@ -1,7 +1,10 @@
-dnl FP_CHECK_PTHREADS
-dnl ----------------------------------
-dnl Check various aspects of the platform's pthreads support
-AC_DEFUN([FP_CHECK_PTHREADS],
+# FP_CHECK_PTHREAD_LIB
+# ----------------------------------
+# Check whether -lpthread is needed for pthread.
+#
+# Sets variables:
+#   - UseLibpthread: [YES|NO]
+AC_DEFUN([FP_CHECK_PTHREAD_LIB],
 [
   dnl Some platforms (e.g. Android's Bionic) have pthreads support available
   dnl without linking against libpthread. Check whether -lpthread is necessary
@@ -12,25 +15,28 @@ AC_DEFUN([FP_CHECK_PTHREADS],
   AC_CHECK_FUNC(pthread_create,
       [
           AC_MSG_RESULT(no)
-          AC_SUBST([UseLibpthread],[NO])
-          need_lpthread=0
+          UseLibpthread=NO
       ],
       [
           AC_CHECK_LIB(pthread, pthread_create,
               [
                   AC_MSG_RESULT(yes)
-                  AC_SUBST([UseLibpthread],[YES])
-                  need_lpthread=1
+                  UseLibpthread=YES
               ],
               [
-                  AC_SUBST([UseLibpthread],[NO])
                   AC_MSG_RESULT([no pthreads support found.])
-                  need_lpthread=0
+                  UseLibpthread=NO
               ])
       ])
-  AC_DEFINE_UNQUOTED([NEED_PTHREAD_LIB], [$need_lpthread],
-      [Define 1 if we need to link code using pthreads with -lpthread])
+])
 
+# FP_CHECK_PTHREAD_FUNCS
+# ----------------------------------
+# Check various aspects of the platform's pthreads support
+#
+# `AC_DEFINE`s various C `HAVE_*` macros.
+AC_DEFUN([FP_CHECK_PTHREAD_FUNCS],
+[
   dnl Setting thread names
   dnl ~~~~~~~~~~~~~~~~~~~~
   dnl The portability situation here is complicated:


=====================================
m4/fp_find_libdw.m4
=====================================
@@ -1,6 +1,11 @@
-dnl ** Have libdw?
-dnl --------------------------------------------------------------
-dnl Sets UseLibdw.
+# FP_FIND_LIBDW
+# --------------------------------------------------------------
+# Should we used libdw? (yes, no, or auto.)
+#
+# Sets variables:
+#   - UseLibdw: [YES|NO]
+#   - LibdwLibDir: optional path
+#   - LibdwIncludeDir: optional path
 AC_DEFUN([FP_FIND_LIBDW],
 [
   AC_ARG_WITH([libdw-libraries],
@@ -12,8 +17,6 @@ AC_DEFUN([FP_FIND_LIBDW],
       LIBDW_LDFLAGS="-L$withval"
     ])
 
-  AC_SUBST(LibdwLibDir)
-
   AC_ARG_WITH([libdw-includes],
     [AS_HELP_STRING([--with-libdw-includes=ARG],
       [Find includes for libdw in ARG [default=system default]])
@@ -23,32 +26,28 @@ AC_DEFUN([FP_FIND_LIBDW],
       LIBDW_CFLAGS="-I$withval"
     ])
 
-  AC_SUBST(LibdwIncludeDir)
+  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
-  USE_LIBDW=0
-  AC_ARG_ENABLE(dwarf-unwind,
-      [AS_HELP_STRING([--enable-dwarf-unwind],
-          [Enable DWARF unwinding support in the runtime system via elfutils' libdw [default=no]])])
-  if test "$enable_dwarf_unwind" = "yes" ; then
+  if test "$enable_dwarf_unwind" != "no" ; then
     CFLAGS2="$CFLAGS"
     CFLAGS="$LIBDW_CFLAGS $CFLAGS"
     LDFLAGS2="$LDFLAGS"
     LDFLAGS="$LIBDW_LDFLAGS $LDFLAGS"
 
-    AC_CHECK_LIB(dw, dwfl_attach_state,
-        [AC_CHECK_HEADERS([elfutils/libdw.h], [break], [])
-         UseLibdw=YES],
-        [AC_MSG_ERROR([Cannot find system libdw (required by --enable-dwarf-unwind)])])
+    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)
-  if test $UseLibdw = "YES" ; then
-    USE_LIBDW=1
-  fi
-  AC_DEFINE_UNQUOTED([USE_LIBDW], [$USE_LIBDW], [Set to 1 to use libdw])
 ])
-


=====================================
m4/fp_find_libffi.m4
=====================================
@@ -1,6 +1,11 @@
-dnl ** Have libffi?
-dnl --------------------------------------------------------------
-dnl Sets UseSystemLibFFI.
+# FP_FIND_LIBFFI
+# --------------------------------------------------------------
+# Should we used libffi? (yes or no)
+#
+# Sets variables:
+#   - UseSystemLibFFI: [YES|NO]
+#   - FFILibDir: optional path
+#   - FFIIncludeDir: optional path
 AC_DEFUN([FP_FIND_LIBFFI],
 [
   # system libffi
@@ -28,8 +33,6 @@ AC_DEFUN([FP_FIND_LIBFFI],
    fi
   ])
 
-  AC_SUBST(FFIIncludeDir)
-
   AC_ARG_WITH([ffi-libraries],
   [AS_HELP_STRING([--with-ffi-libraries=ARG],
     [Find libffi in ARG [default=system default]])
@@ -42,8 +45,6 @@ AC_DEFUN([FP_FIND_LIBFFI],
    fi
   ])
 
-  AC_SUBST(FFILibDir)
-
   AS_IF([test "$UseSystemLibFFI" = "YES"], [
    CFLAGS2="$CFLAGS"
    CFLAGS="$LIBFFI_CFLAGS $CFLAGS"
@@ -63,7 +64,7 @@ AC_DEFUN([FP_FIND_LIBFFI],
    AC_CHECK_LIB(ffi, ffi_call,
     [AC_CHECK_HEADERS(
       [ffi.h],
-      [AC_DEFINE([HAVE_SYSTEM_LIBFFI], [1], [Define to 1 if you have libffi.])],
+      [],
       [AC_MSG_ERROR([Cannot find ffi.h for system libffi])]
      )],
     [AC_MSG_ERROR([Cannot find system libffi])]


=====================================
m4/fp_find_libnuma.m4
=====================================
@@ -1,7 +1,13 @@
+# FP_FIND_LIBNUMA
+# --------------------------------------------------------------
+# Should we used libnuma? (yes, no, or auto.)
+#
+# Sets variables:
+#   - UseLibNuma: [YES|NO]
+#   - LibNumaLibDir: optional path
+#   - LibNumaIncludeDir: optional path
 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]])
@@ -11,8 +17,6 @@ AC_DEFUN([FP_FIND_LIBNUMA],
       LIBNUMA_LDFLAGS="-L$withval"
     ])
 
-  AC_SUBST(LibNumaLibDir)
-
   AC_ARG_WITH([libnuma-includes],
     [AS_HELP_STRING([--with-libnuma-includes=ARG],
       [Find includes for libnuma in ARG [default=system default]])
@@ -22,14 +26,14 @@ AC_DEFUN([FP_FIND_LIBNUMA],
       LIBNUMA_CFLAGS="-I$withval"
     ])
 
-  AC_SUBST(LibNumaIncludeDir)
-
-  HaveLibNuma=0
   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]])])
+    [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])
 
+  UseLibNuma=NO
   if test "$enable_numa" != "no" ; then
     CFLAGS2="$CFLAGS"
     CFLAGS="$LIBNUMA_CFLAGS $CFLAGS"
@@ -38,23 +42,14 @@ AC_DEFUN([FP_FIND_LIBNUMA],
 
     AC_CHECK_HEADERS([numa.h numaif.h])
 
-    if test "$ac_cv_header_numa_h$ac_cv_header_numaif_h" = "yesyes" ; then
-      AC_CHECK_LIB(numa, numa_available,HaveLibNuma=1)
+    if test "$ac_cv_header_numa_h:$ac_cv_header_numaif_h" = "yes:yes" ; then
+      AC_CHECK_LIB([numa], [numa_available], [UseLibNuma=YES])
     fi
-    if test "$enable_numa:$HaveLibNuma" = "yes:0" ; then
-        AC_MSG_ERROR([Cannot find system libnuma (required by --enable-numa)])
+    if test "$enable_numa:$UseLibNuma" = "yes:NO" ; 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])
-  if test $HaveLibNuma = "1" ; then
-    AC_SUBST([UseLibNuma],[YES])
-    AC_SUBST([CabalHaveLibNuma],[True])
-  else
-    AC_SUBST([UseLibNuma],[NO])
-    AC_SUBST([CabalHaveLibNuma],[False])
-  fi
 ])


=====================================
m4/fptools_set_haskell_platform_vars.m4
=====================================
@@ -162,8 +162,6 @@ AC_DEFUN([GHC_SUBSECTIONS_VIA_SYMBOLS],
             TargetHasSubsectionsViaSymbols=NO
          else
             TargetHasSubsectionsViaSymbols=YES
-            AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1],
-                   [Define to 1 if Apple-style dead-stripping is supported.])
          fi
         ],
         [TargetHasSubsectionsViaSymbols=NO


=====================================
rts/configure.ac
=====================================
@@ -22,25 +22,363 @@ dnl     #define SIZEOF_CHAR 0
 dnl   recently.
 AC_PREREQ([2.69])
 
+AC_CONFIG_FILES([ghcplatform.h.top])
+
 AC_CONFIG_HEADERS([ghcautoconf.h.autoconf])
 
+AC_ARG_ENABLE(asserts-all-ways,
+[AS_HELP_STRING([--enable-asserts-all-ways],
+                [Usually ASSERTs are only compiled in the DEBUG way,
+                 this will enable them in all ways.])],
+  [FP_CAPITALIZE_YES_NO(["$enableval"], [EnableAssertsAllWays])],
+  [EnableAssertsAllWays=NO]
+)
+if test "$enable_asserts_all_ways" = "yes" ; then
+   AC_DEFINE([USE_ASSERTS_ALL_WAYS], [1], [Compile-in ASSERTs in all ways.])
+fi
+
+AC_ARG_ENABLE(native-io-manager,
+[AS_HELP_STRING([--enable-native-io-manager],
+                [Enable the native I/O manager by default.])],
+  [FP_CAPITALIZE_YES_NO(["$enableval"], [EnableNativeIOManager])],
+  [EnableNativeIOManager=NO]
+)
+if test "$EnableNativeIOManager" = "YES"; then
+  AC_DEFINE_UNQUOTED([DEFAULT_NATIVE_IO_MANAGER], [1], [Enable Native I/O manager as default.])
+fi
+
 # We have to run these unconditionally, but we may discard their
 # results in the following code
 AC_CANONICAL_BUILD
 AC_CANONICAL_HOST
 
+dnl ** Do an unregisterised build?
+dnl --------------------------------------------------------------
+
+GHC_UNREGISTERISED
+
+dnl ** Do a build with tables next to code?
+dnl --------------------------------------------------------------
+
+GHC_TABLES_NEXT_TO_CODE
+if test x"$TablesNextToCode" = xYES; then
+   AC_DEFINE([TABLES_NEXT_TO_CODE], [1], [Define to 1 if info tables are laid out next to code])
+fi
+
+dnl detect compiler (prefer gcc over clang) and set $CC (unless CC already set),
+dnl later CC is copied to CC_STAGE{1,2,3}
+AC_PROG_CC([cc gcc clang])
+
+dnl make extensions visible to allow feature-tests to detect them lateron
+AC_USE_SYSTEM_EXTENSIONS
+
+dnl ** Used to determine how to compile ghc-prim's atomics.c, used by
+dnl    unregisterised, Sparc, and PPC backends. Also determines whether
+dnl    linking to libatomic is required for atomic operations, e.g. on
+dnl    RISCV64 GCC.
+FP_CC_SUPPORTS__ATOMICS
+AC_DEFINE([HAVE_C11_ATOMICS], [1], [Does C compiler support __atomic primitives?])
+AC_DEFINE_UNQUOTED([NEED_ATOMIC_LIB], [$need_latomic],
+    [Define to 1 if we need -latomic for sub-word atomic operations.])
+
+dnl ** look to see if we have a C compiler using an llvm back end.
+dnl
+FP_CC_LLVM_BACKEND
+AS_IF([test x"$CcLlvmBackend" = x"YES"],
+  [AC_DEFINE([CC_LLVM_BACKEND], [1], [Define (to 1) if C compiler has an LLVM back end])])
+
+GHC_CONVERT_PLATFORM_PARTS([build], [Build])
+FPTOOLS_SET_PLATFORM_VARS([build],[Build])
+FPTOOLS_SET_HASKELL_PLATFORM_VARS([Build])
+
 GHC_CONVERT_PLATFORM_PARTS([host], [Host])
 FPTOOLS_SET_PLATFORM_VARS([host], [Host])
 FPTOOLS_SET_HASKELL_PLATFORM_VARS([Host])
 
+GHC_SUBSECTIONS_VIA_SYMBOLS
+AS_IF([test x"${TargetHasSubsectionsViaSymbols}" = x"YES"],
+  [AC_DEFINE([HAVE_SUBSECTIONS_VIA_SYMBOLS],[1],
+    [Define to 1 if Apple-style dead-stripping is supported.])])
+
+dnl --------------------------------------------------
+dnl * Platform header file and syscall feature tests
+dnl ### checking the state of the local header files and syscalls ###
+
+dnl ** Enable large file support.  NB. do this before testing the type of
+dnl    off_t, because it will affect the result of that test.
+AC_SYS_LARGEFILE
+
+dnl ** check for specific header (.h) files that we are interested in
+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])
+
+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 ** 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)
+
+
+FP_CHECK_FUNC([WinExec],
+  [@%:@include <windows.h>], [WinExec("",0)])
+
+FP_CHECK_FUNC([GetModuleFileName],
+  [@%:@include <windows.h>], [GetModuleFileName((HMODULE)0,(LPTSTR)0,0)])
+
+dnl ** check for more functions
+dnl ** The following have been verified to be used in ghc/, but might be used somewhere else, too.
+AC_CHECK_FUNCS([getclock getrusage gettimeofday setitimer siginterrupt sysconf times ctime_r sched_setaffinity sched_getaffinity setlocale uselocale])
+
+dnl ** On OS X 10.4 (at least), time.h doesn't declare ctime_r if
+dnl ** _POSIX_C_SOURCE is defined
+AC_CHECK_DECLS([ctime_r], , ,
+[#define _POSIX_SOURCE 1
+#define _POSIX_C_SOURCE 199506L
+#include <time.h>])
+
+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 for mingwex library
+AC_CHECK_LIB([mingwex],[closedir])
+
+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)
+AS_IF(
+  [test "$CABAL_FLAG_libm" = 1],
+  [AC_DEFINE([HAVE_LIBM], [1], [Define to 1 if you need to link with libm])])
+
+AS_IF([test "$CABAL_FLAG_libbfd" = 1], [FP_WHEN_ENABLED_BFD])
+
+dnl ################################################################
+dnl Check for libraries
+dnl ################################################################
+
+dnl ** check whether we need -ldl to get dlopen()
+AC_CHECK_LIB([dl], [dlopen])
+dnl ** check whether we have dlinfo
+AC_CHECK_FUNCS([dlinfo])
+
+dnl --------------------------------------------------
+dnl * Miscellaneous feature tests
+dnl --------------------------------------------------
+
+dnl ** can we get alloca?
+AC_FUNC_ALLOCA
+
+dnl ** working vfork?
+AC_FUNC_FORK
+
+dnl ** determine whether or not const works
+AC_C_CONST
+
+dnl ** are we big endian?
+AC_C_BIGENDIAN
+FPTOOLS_FLOAT_WORD_ORDER_BIGENDIAN
+
+dnl ** check for leading underscores in symbol names
+FP_LEADING_UNDERSCORE
+if test x"$fptools_cv_leading_underscore" = xyes; then
+   AC_DEFINE([LEADING_UNDERSCORE], [1], [Define to 1 if C symbols have a leading underscore added by the compiler.])
+fi
+
+FP_VISIBILITY_HIDDEN
+
+FP_MUSTTAIL
+
+dnl ** check for librt
+AC_CHECK_FUNCS(clock_gettime timer_settime)
+FP_CHECK_TIMER_CREATE
+
+dnl ** check for Apple's "interesting" long double compatibility scheme
+AC_MSG_CHECKING(for printf\$LDBLStub)
+AC_LINK_IFELSE([AC_LANG_CALL([], [printf\$LDBLStub])],
+    [
+        AC_MSG_RESULT(yes)
+        AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[1],
+            [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
+    ],
+    [
+        AC_MSG_RESULT(no)
+        AC_DEFINE([HAVE_PRINTF_LDBLSTUB],[0],
+            [Define to 1 if we have printf$LDBLStub (Apple Mac OS >= 10.4, PPC).])
+    ])
+
+dnl ** for pthread_getthreadid_np, pthread_create, ...
+FP_CHECK_PTHREAD_LIB
+AS_IF([test "$UseLibpthread" "YES"],
+    [buildinfoExtraDefs+=' -DNEED_PTHREAD_LIB'])
+FP_CHECK_PTHREAD_FUNCS
+
+dnl ** check for eventfd which is needed by the I/O manager
+AC_CHECK_HEADERS([sys/eventfd.h])
+AC_CHECK_FUNCS([eventfd])
+
+AC_CHECK_FUNCS([getpid getuid raise])
+
+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 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_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
+
+dnl ** Use MMAP in the runtime linker?
+dnl --------------------------------------------------------------
+
+case ${HostOS} 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([Host])
+AC_SUBST([UseLibffiForAdjustors])
+
+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])
+
+dnl ** Write config files
+dnl --------------------------------------------------------------
+
 AC_OUTPUT
 
 dnl ######################################################################
-dnl Generate ghcautoconf.h
+dnl Generate ghcplatform.h
 dnl ######################################################################
 
 [
 mkdir -p include
+
+touch include/ghcplatform.h
+> include/ghcplatform.h
+
+cat ghcplatform.h.top                          >> include/ghcplatform.h
+]
+AS_IF([test x"${Unregisterised}" = x"YES"],
+  [echo "#define UnregisterisedCompiler 1"     >> include/ghcplatform.h])
+[
+cat $srcdir/ghcplatform.h.bottom               >> include/ghcplatform.h
+]
+
+dnl ######################################################################
+dnl Generate ghcautoconf.h
+dnl ######################################################################
+
+[
 touch include/ghcautoconf.h
 > include/ghcautoconf.h
 
@@ -90,7 +428,7 @@ dnl ######################################################################
 
 [
 cat $srcdir/rts.buildinfo.in \
-    | "$CC" -E -P -traditional - -o - \
+    | "$CC" $buildinfoExtraDeps -E -P -traditional - -o - \
     | sed -e '/^ *$/d' \
     > rts.buildinfo \
     || exit 1


=====================================
rts/ghcplatform.h.bottom
=====================================
@@ -0,0 +1,2 @@
+
+#endif /* __GHCPLATFORM_H__ */


=====================================
rts/ghcplatform.h.top.in
=====================================
@@ -0,0 +1,23 @@
+#if !defined(__GHCPLATFORM_H__)
+#define __GHCPLATFORM_H__
+
+#define BuildPlatform_TYPE  @BuildPlatform_CPP@
+#define HostPlatform_TYPE   @HostPlatform_CPP@
+
+#define @BuildPlatform_CPP at _BUILD  1
+#define @HostPlatform_CPP at _HOST  1
+
+#define @BuildArch_CPP at _BUILD_ARCH  1
+#define @HostArch_CPP at _HOST_ARCH  1
+#define BUILD_ARCH  "@BuildArch_CPP@"
+#define HOST_ARCH  "@HostArch_CPP@"
+
+#define @BuildOS_CPP at _BUILD_OS  1
+#define @HostOS_CPP at _HOST_OS  1
+#define BUILD_OS  "@BuildOS_CPP@"
+#define HOST_OS  "@HostOS_CPP@"
+
+#define @BuildVendor_CPP at _BUILD_VENDOR  1
+#define @HostVendor_CPP at _HOST_VENDOR  1
+#define BUILD_VENDOR  "@BuildVendor_CPP@"
+#define HOST_VENDOR  "@HostVendor_CPP@"


=====================================
rts/posix/OSMem.c
=====================================
@@ -30,10 +30,8 @@
 #if defined(HAVE_FCNTL_H)
 #include <fcntl.h>
 #endif
-#if defined(HAVE_NUMA_H)
+#if HAVE_LIBNUMA
 #include <numa.h>
-#endif
-#if defined(HAVE_NUMAIF_H)
 #include <numaif.h>
 #endif
 #if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_SYS_TIME_H)


=====================================
rts/rts.buildinfo.in
=====================================
@@ -1,3 +1,6 @@
 -- External symbols referenced by the RTS
+#ifdef NEED_PTHREAD_LIB
+extra-libraries: pthread
+#endif
 ld-options:
 #include "external-symbols.flags"


=====================================
rts/rts.cabal.in
=====================================
@@ -38,8 +38,6 @@ flag use-system-libffi
   default: @CabalUseSystemLibFFI@
 flag libffi-adjustors
   default: @CabalLibffiAdjustors@
-flag need-pthread
-  default: @CabalNeedLibpthread@
 flag libbfd
   default: @CabalHaveLibbfd@
 flag need-atomic
@@ -52,8 +50,6 @@ flag libzstd
   default: @CabalHaveLibZstd@
 flag static-libzstd
   default: @CabalStaticLibZstd@
-flag leading-underscore
-  default: @CabalLeadingUnderscore@
 flag smp
   default: True
 flag find-ptr
@@ -205,9 +201,6 @@ 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
@@ -232,7 +225,7 @@ library
 
       include-dirs: include
       includes: Rts.h
-      autogen-includes: ghcautoconf.h
+      autogen-includes: ghcautoconf.h ghcplatform.h
       install-includes: Cmm.h HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h
                         ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h
                         -- ^ from include



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/86d3c8a089c29fa9d7b2db85201d78fd1f8941a4...efc5cfefd59ba6a9a62c564bb8b6351961146334

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/86d3c8a089c29fa9d7b2db85201d78fd1f8941a4...efc5cfefd59ba6a9a62c564bb8b6351961146334
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230922/ae06f0d2/attachment-0001.html>


More information about the ghc-commits mailing list