diff --git a/compiler/GHC/Runtime/Heap/Layout.hs b/compiler/GHC/Runtime/Heap/Layout.hs index 73e2ff9e410a..e0956185a59a 100644 --- a/compiler/GHC/Runtime/Heap/Layout.hs +++ b/compiler/GHC/Runtime/Heap/Layout.hs @@ -438,8 +438,8 @@ cardTableSizeW platform elems = ----------------------------------------------------------------------------- -- deriving the RTS closure type from an SMRep -#include "ClosureTypes.h" -#include "FunTypes.h" +#include "rts/storage/ClosureTypes.h" +#include "rts/storage/FunTypes.h" -- Defines CONSTR, CONSTR_1_0 etc -- | Derives the RTS closure type from an 'SMRep' diff --git a/compiler/GHC/StgToCmm/Layout.hs b/compiler/GHC/StgToCmm/Layout.hs index 2f81200a2891..b93dc1854084 100644 --- a/compiler/GHC/StgToCmm/Layout.hs +++ b/compiler/GHC/StgToCmm/Layout.hs @@ -549,7 +549,7 @@ mkVirtConstrSizes profile field_reps ------------------------------------------------------------------------- -- bring in ARG_P, ARG_N, etc. -#include "FunTypes.h" +#include "rts/storage/FunTypes.h" mkArgDescr :: Platform -> [Id] -> ArgDescr mkArgDescr platform args diff --git a/compiler/GHC/StgToCmm/TagCheck.hs b/compiler/GHC/StgToCmm/TagCheck.hs index 5b3cf2e7e1e8..18fd617c0000 100644 --- a/compiler/GHC/StgToCmm/TagCheck.hs +++ b/compiler/GHC/StgToCmm/TagCheck.hs @@ -12,7 +12,7 @@ module GHC.StgToCmm.TagCheck ( emitTagAssertion, emitArgTagCheck, checkArg, whenCheckTags, checkArgStatic, checkFunctionArgTags,checkConArgsStatic,checkConArgsDyn) where -#include "ClosureTypes.h" +#include "rts/storage/ClosureTypes.h" import GHC.Prelude diff --git a/rts-fs/README b/rts-fs/README new file mode 100644 index 000000000000..446f95e9eceb --- /dev/null +++ b/rts-fs/README @@ -0,0 +1,2 @@ +This "fs" library, used by various ghc utilities is used to share some common +I/O filesystem functions with different packages. diff --git a/rts-fs/fs.c b/rts-fs/fs.c new file mode 100644 index 000000000000..d64094cae158 --- /dev/null +++ b/rts-fs/fs.c @@ -0,0 +1,590 @@ +/* ----------------------------------------------------------------------------- + * + * (c) Tamar Christina 2018-2019 + * + * Windows I/O routines for file opening. + * + * NOTE: Only modify this file in utils/fs/ and rerun configure. Do not edit + * this file in any other directory as it will be overwritten. + * + * ---------------------------------------------------------------------------*/ +#include "fs.h" +#include + +#if defined(_WIN32) + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/* Duplicate a string, but in wide form. The caller is responsible for freeing + the result. */ +static wchar_t* FS(to_wide) (const char *path) { + size_t len = mbstowcs (NULL, path, 0); + wchar_t *w_path = malloc (sizeof (wchar_t) * (len + 1)); + mbstowcs (w_path, path, len); + w_path[len] = L'\0'; + return w_path; +} + +/* This function converts Windows paths between namespaces. More specifically + It converts an explorer style path into a NT or Win32 namespace. + This has several caveats but they are caveats that are native to Windows and + not POSIX. See + https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247.aspx. + Anything else such as raw device paths we leave untouched. The main benefit + of doing any of this is that we can break the MAX_PATH restriction and also + access raw handles that we couldn't before. + + The resulting string is dynamically allocated and so callers are expected to + free this string. */ +wchar_t* FS(create_device_name) (const wchar_t* filename) { + const wchar_t* win32_dev_namespace = L"\\\\.\\"; + const wchar_t* win32_file_namespace = L"\\\\?\\"; + const wchar_t* nt_device_namespace = L"\\Device\\"; + const wchar_t* unc_prefix = L"UNC\\"; + const wchar_t* network_share = L"\\\\"; + + wchar_t* result = _wcsdup (filename); + wchar_t ns[10] = {0}; + + /* If the file is already in a native namespace don't change it. */ + if ( wcsncmp (win32_dev_namespace , filename, 4) == 0 + || wcsncmp (win32_file_namespace, filename, 4) == 0 + || wcsncmp (nt_device_namespace , filename, 8) == 0) + return result; + + /* Since we're using the lower level APIs we must normalize slashes now. The + Win32 API layer will no longer convert '/' into '\\' for us. */ + for (size_t i = 0; i < wcslen (result); i++) + { + if (result[i] == L'/') + result[i] = L'\\'; + } + + /* We need to expand dos short paths as well. */ + DWORD nResult = GetLongPathNameW (result, NULL, 0) + 1; + wchar_t* temp = NULL; + if (nResult > 1) + { + temp = _wcsdup (result); + free (result); + result = malloc (nResult * sizeof (wchar_t)); + if (GetLongPathNameW (temp, result, nResult) == 0) + { + result = memcpy (result, temp, wcslen (temp)); + goto cleanup; + } + free (temp); + } + + /* Now resolve any . and .. in the path or subsequent API calls may fail since + Win32 will no longer resolve them. */ + nResult = GetFullPathNameW (result, 0, NULL, NULL) + 1; + temp = _wcsdup (result); + free (result); + result = malloc (nResult * sizeof (wchar_t)); + if (GetFullPathNameW (temp, nResult, result, NULL) == 0) + { + result = memcpy (result, temp, wcslen (temp)); + goto cleanup; + } + + free (temp); + + int startOffset = 0; + /* When remapping a network share, \\foo needs to become + \\?\UNC\foo and not \\?\\UNC\\foo which is an invalid path. */ + if (wcsncmp (network_share, result, 2) == 0) + { + if (swprintf (ns, 10, L"%ls%ls", win32_file_namespace, unc_prefix) <= 0) + { + goto cleanup; + } + startOffset = 2; + } + else if (swprintf (ns, 10, L"%ls", win32_file_namespace) <= 0) + { + goto cleanup; + } + + /* Create new string. */ + int bLen = wcslen (result) + wcslen (ns) + 1 - startOffset; + temp = _wcsdup (result + startOffset); + free (result); + result = malloc (bLen * sizeof (wchar_t)); + if (swprintf (result, bLen, L"%ls%ls", ns, temp) <= 0) + { + goto cleanup; + } + + free (temp); + + return result; + +cleanup: + free (temp); + free (result); + return NULL; +} + +static int setErrNoFromWin32Error (void); +/* Sets errno to the right error value and returns -1 to indicate the failure. + This function should only be called when the creation of the fd actually + failed and you want to return -1 for the fd. */ +static +int setErrNoFromWin32Error (void) { + switch (GetLastError()) { + case ERROR_SUCCESS: + errno = 0; + break; + case ERROR_ACCESS_DENIED: + case ERROR_FILE_READ_ONLY: + errno = EACCES; + break; + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + errno = ENOENT; + break; + case ERROR_FILE_EXISTS: + errno = EEXIST; + break; + case ERROR_NOT_ENOUGH_MEMORY: + case ERROR_OUTOFMEMORY: + errno = ENOMEM; + break; + case ERROR_INVALID_HANDLE: + errno = EBADF; + break; + case ERROR_INVALID_FUNCTION: + errno = EFAULT; + break; + default: + errno = EINVAL; + break; + } + return -1; +} + + +#define HAS_FLAG(a,b) (((a) & (b)) == (b)) + +int FS(swopen) (const wchar_t* filename, int oflag, int shflag, int pmode) +{ + /* Construct access mode. */ + /* https://docs.microsoft.com/en-us/windows/win32/fileio/file-access-rights-constants */ + DWORD dwDesiredAccess = 0; + if (HAS_FLAG (oflag, _O_RDONLY)) + dwDesiredAccess |= GENERIC_READ; + if (HAS_FLAG (oflag, _O_RDWR)) + dwDesiredAccess |= GENERIC_WRITE | GENERIC_READ; + if (HAS_FLAG (oflag, _O_WRONLY)) + dwDesiredAccess |= GENERIC_WRITE; + if (HAS_FLAG (oflag, _O_APPEND)) + dwDesiredAccess |= FILE_APPEND_DATA; + + /* Construct shared mode. */ + /* https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants */ + DWORD dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; + if (HAS_FLAG (shflag, _SH_DENYRW)) + dwShareMode &= ~(FILE_SHARE_READ | FILE_SHARE_WRITE); + if (HAS_FLAG (shflag, _SH_DENYWR)) + dwShareMode &= ~FILE_SHARE_WRITE; + if (HAS_FLAG (shflag, _SH_DENYRD)) + dwShareMode &= ~FILE_SHARE_READ; + if (HAS_FLAG (pmode, _S_IWRITE)) + dwShareMode |= FILE_SHARE_READ | FILE_SHARE_WRITE; + if (HAS_FLAG (pmode, _S_IREAD)) + dwShareMode |= FILE_SHARE_READ; + + /* Override access mode with pmode if creating file. */ + if (HAS_FLAG (oflag, _O_CREAT)) + { + if (HAS_FLAG (pmode, _S_IWRITE)) + dwDesiredAccess |= FILE_GENERIC_WRITE; + if (HAS_FLAG (pmode, _S_IREAD)) + dwDesiredAccess |= FILE_GENERIC_READ; + } + + /* Create file disposition. */ + /* https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea */ + DWORD dwCreationDisposition = 0; + if (HAS_FLAG (oflag, (_O_CREAT | _O_EXCL))) + dwCreationDisposition |= CREATE_NEW; + else if (HAS_FLAG (oflag, _O_TRUNC | _O_CREAT)) + dwCreationDisposition |= CREATE_ALWAYS; + else if (HAS_FLAG (oflag, _O_TRUNC) && !HAS_FLAG (oflag, O_RDONLY)) + dwCreationDisposition |= TRUNCATE_EXISTING; + else if (HAS_FLAG (oflag, _O_APPEND | _O_CREAT)) + dwCreationDisposition |= OPEN_ALWAYS; + else if (HAS_FLAG (oflag, _O_APPEND)) + dwCreationDisposition |= OPEN_EXISTING; + else if (HAS_FLAG (oflag, _O_CREAT)) + dwCreationDisposition |= OPEN_ALWAYS; + else + dwCreationDisposition |= OPEN_EXISTING; + + /* Set file access attributes. */ + DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; + if (HAS_FLAG (oflag, _O_RDONLY)) + dwFlagsAndAttributes |= 0; /* No special attribute. */ + if (HAS_FLAG (oflag, _O_TEMPORARY)) + { + dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE; + dwShareMode |= FILE_SHARE_DELETE; + } + if (HAS_FLAG (oflag, _O_SHORT_LIVED)) + dwFlagsAndAttributes |= FILE_ATTRIBUTE_TEMPORARY; + if (HAS_FLAG (oflag, _O_RANDOM)) + dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS; + if (HAS_FLAG (oflag, _O_SEQUENTIAL)) + dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN; + /* Flag is only valid on it's own. */ + if (dwFlagsAndAttributes != FILE_ATTRIBUTE_NORMAL) + dwFlagsAndAttributes &= ~FILE_ATTRIBUTE_NORMAL; + + /* Ensure we have shared read for files which are opened read-only. */ + if (HAS_FLAG (dwCreationDisposition, OPEN_EXISTING) + && ((dwDesiredAccess & (GENERIC_WRITE|GENERIC_READ)) == GENERIC_READ)) + dwShareMode |= FILE_SHARE_READ; + + /* Set security attributes. */ + SECURITY_ATTRIBUTES securityAttributes; + ZeroMemory (&securityAttributes, sizeof(SECURITY_ATTRIBUTES)); + securityAttributes.bInheritHandle = !(oflag & _O_NOINHERIT); + securityAttributes.lpSecurityDescriptor = NULL; + securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + + wchar_t* _filename = FS(create_device_name) (filename); + if (!_filename) + return -1; + + HANDLE hResult + = CreateFileW (_filename, dwDesiredAccess, dwShareMode, &securityAttributes, + dwCreationDisposition, dwFlagsAndAttributes, NULL); + + free (_filename); + if (INVALID_HANDLE_VALUE == hResult) + return setErrNoFromWin32Error (); + + /* Now we have a Windows handle, we have to convert it to an FD and apply + the remaining flags. */ + const int flag_mask = _O_APPEND | _O_RDONLY | _O_TEXT | _O_WTEXT; + int fd = _open_osfhandle ((intptr_t)hResult, oflag & flag_mask); + if (-1 == fd) + return setErrNoFromWin32Error (); + + /* Finally we can change the mode to the requested one. */ + const int mode_mask = _O_TEXT | _O_BINARY | _O_U16TEXT | _O_U8TEXT | _O_WTEXT; + if ((oflag & mode_mask) && (-1 == _setmode (fd, oflag & mode_mask))) + return setErrNoFromWin32Error (); + + return fd; +} + +int FS(translate_mode) (const wchar_t* mode) +{ + int oflag = 0; + int len = wcslen (mode); + int i; + #define IS_EXT(X) ((i < (len - 1)) && mode[i+1] == X) + + for (i = 0; i < len; i++) + { + switch (mode[i]) + { + case L'a': + if (IS_EXT (L'+')) + oflag |= _O_RDWR | _O_CREAT | _O_APPEND; + else + oflag |= _O_WRONLY | _O_CREAT | _O_APPEND; + break; + case L'r': + if (IS_EXT (L'+')) + oflag |= _O_RDWR; + else + oflag |= _O_RDONLY; + break; + case L'w': + if (IS_EXT (L'+')) + oflag |= _O_RDWR | _O_CREAT | _O_TRUNC; + else + oflag |= _O_WRONLY | _O_CREAT | _O_TRUNC; + break; + case L'b': + oflag |= _O_BINARY; + break; + case L't': + oflag |= _O_TEXT; + break; + case L'c': + case L'n': + oflag |= 0; + break; + case L'S': + oflag |= _O_SEQUENTIAL; + break; + case L'R': + oflag |= _O_RANDOM; + break; + case L'T': + oflag |= _O_SHORT_LIVED; + break; + case L'D': + oflag |= _O_TEMPORARY; + break; + default: + if (wcsncmp (mode, L"ccs=UNICODE", 11) == 0) + oflag |= _O_WTEXT; + else if (wcsncmp (mode, L"ccs=UTF-8", 9) == 0) + oflag |= _O_U8TEXT; + else if (wcsncmp (mode, L"ccs=UTF-16LE", 12) == 0) + oflag |= _O_U16TEXT; + else continue; + } + } + #undef IS_EXT + + return oflag; +} + +FILE *FS(fwopen) (const wchar_t* filename, const wchar_t* mode) +{ + int shflag = 0; + int pmode = 0; + int oflag = FS(translate_mode) (mode); + + int fd = FS(swopen) (filename, oflag, shflag, pmode); + if (fd < 0) + return NULL; + + FILE* file = _wfdopen (fd, mode); + return file; +} + +FILE *FS(fopen) (const char* filename, const char* mode) +{ + wchar_t * const w_filename = FS(to_wide) (filename); + wchar_t * const w_mode = FS(to_wide) (mode); + + FILE *result = FS(fwopen) (w_filename, w_mode); + free (w_filename); + free (w_mode); + + return result; +} + +int FS(sopen) (const char* filename, int oflag, int shflag, int pmode) +{ + wchar_t * const w_filename = FS(to_wide) (filename); + int result = FS(swopen) (w_filename, oflag, shflag, pmode); + free (w_filename); + + return result; +} + +int FS(_stat) (const char *path, struct _stat *buffer) +{ + wchar_t * const w_path = FS(to_wide) (path); + int result = FS(_wstat) (w_path, buffer); + free (w_path); + + return result; +} + +int FS(_stat64) (const char *path, struct __stat64 *buffer) +{ + wchar_t * const w_path = FS(to_wide) (path); + int result = FS(_wstat64) (w_path, buffer); + free (w_path); + + return result; +} + +static __time64_t ftToPosix(FILETIME ft) +{ + /* takes the last modified date. */ + LARGE_INTEGER date, adjust; + date.HighPart = ft.dwHighDateTime; + date.LowPart = ft.dwLowDateTime; + + /* 100-nanoseconds = milliseconds * 10000. */ + /* A UNIX timestamp contains the number of seconds from Jan 1, 1970, while the + FILETIME documentation says: Contains a 64-bit value representing the + number of 100-nanosecond intervals since January 1, 1601 (UTC). + + Between Jan 1, 1601 and Jan 1, 1970 there are 11644473600 seconds */ + adjust.QuadPart = 11644473600000 * 10000; + + /* removes the diff between 1970 and 1601. */ + date.QuadPart -= adjust.QuadPart; + + /* converts back from 100-nanoseconds to seconds. */ + return (__time64_t)date.QuadPart / 10000000; +} + +int FS(_wstat) (const wchar_t *path, struct _stat *buffer) +{ + ZeroMemory (buffer, sizeof (struct _stat)); + wchar_t* _path = FS(create_device_name) (path); + if (!_path) + return -1; + + /* Construct shared mode. */ + DWORD dwShareMode = FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE; + DWORD dwDesiredAccess = FILE_READ_ATTRIBUTES; + DWORD dwFlagsAndAttributes = FILE_FLAG_BACKUP_SEMANTICS; + DWORD dwCreationDisposition = OPEN_EXISTING; + + SECURITY_ATTRIBUTES securityAttributes; + ZeroMemory (&securityAttributes, sizeof(SECURITY_ATTRIBUTES)); + securityAttributes.bInheritHandle = false; + securityAttributes.lpSecurityDescriptor = NULL; + securityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); + + HANDLE hResult + = CreateFileW (_path, dwDesiredAccess, dwShareMode, &securityAttributes, + dwCreationDisposition, dwFlagsAndAttributes, NULL); + + if (INVALID_HANDLE_VALUE == hResult) + { + free (_path); + return setErrNoFromWin32Error (); + } + + WIN32_FILE_ATTRIBUTE_DATA finfo; + ZeroMemory (&finfo, sizeof (WIN32_FILE_ATTRIBUTE_DATA)); + if(!GetFileAttributesExW (_path, GetFileExInfoStandard, &finfo)) + { + free (_path); + CloseHandle (hResult); + return setErrNoFromWin32Error (); + } + + unsigned short mode = _S_IREAD; + + if (finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + mode |= (_S_IFDIR | _S_IEXEC); + else + { + mode |= _S_IFREG; + DWORD type; + if (GetBinaryTypeW (_path, &type)) + mode |= _S_IEXEC; + } + + if (!(finfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) + mode |= _S_IWRITE; + + buffer->st_mode = mode; + buffer->st_nlink = 1; + buffer->st_size = ((uint64_t)finfo.nFileSizeHigh << 32) + finfo.nFileSizeLow; + buffer->st_atime = ftToPosix (finfo.ftLastAccessTime); + buffer->st_mtime = buffer->st_ctime = ftToPosix (finfo.ftLastWriteTime); + free (_path); + CloseHandle (hResult); + return 0; +} + +int FS(_wstat64) (const wchar_t *path, struct __stat64 *buffer) +{ + struct _stat buf; + ZeroMemory (buffer, sizeof (struct __stat64)); + + int result = FS(_wstat) (path, &buf); + + buffer->st_mode = buf.st_mode; + buffer->st_nlink = 1; + buffer->st_size = buf.st_size; + buffer->st_atime = buf.st_atime; + buffer->st_mtime = buf.st_mtime; + + return result; +} + +int FS(_wrename) (const wchar_t *from, const wchar_t *to) +{ + wchar_t* const _from = FS(create_device_name) (from); + if (!_from) + return -1; + + wchar_t* const _to = FS(create_device_name) (to); + if (!_to) + { + free (_from); + return -1; + } + + if (MoveFileW(_from, _to) == 0) { + free (_from); + free (_to); + return setErrNoFromWin32Error (); + } + + + free (_from); + free (_to); + return 0; +} + +int FS(rename) (const char *from, const char *to) +{ + wchar_t * const w_from = FS(to_wide) (from); + wchar_t * const w_to = FS(to_wide) (to); + int result = FS(_wrename) (w_from, w_to); + free(w_from); + free(w_to); + + return result; +} + +int FS(unlink) (const char *filename) +{ + return FS(_unlink) (filename); +} + +int FS(_unlink) (const char *filename) +{ + wchar_t * const w_filename = FS(to_wide) (filename); + int result = FS(_wunlink) (w_filename); + free(w_filename); + + return result; +} + +int FS(_wunlink) (const wchar_t *filename) +{ + wchar_t* const _filename = FS(create_device_name) (filename); + if (!_filename) + return -1; + + if (DeleteFileW(_filename) == 0) { + free (_filename); + return setErrNoFromWin32Error (); + } + + + free (_filename); + return 0; +} +int FS(remove) (const char *path) +{ + return FS(_unlink) (path); +} +int FS(_wremove) (const wchar_t *path) +{ + return FS(_wunlink) (path); +} +#else +FILE *FS(fopen) (const char* filename, const char* mode) +{ + return fopen (filename, mode); +} +#endif diff --git a/rts-fs/fs.h b/rts-fs/fs.h new file mode 100644 index 000000000000..6c5f56ccdd7a --- /dev/null +++ b/rts-fs/fs.h @@ -0,0 +1,55 @@ +/* ----------------------------------------------------------------------------- + * + * (c) Tamar Christina 2018-2019 + * + * Windows I/O routines for file opening. + * + * NOTE: Only modify this file in utils/fs/ and rerun configure. Do not edit + * this file in any other directory as it will be overwritten. + * + * ---------------------------------------------------------------------------*/ + +#pragma once + +#include + +#if !defined(FS_NAMESPACE) +#define FS_NAMESPACE hs +#endif + +/* Play some dirty tricks to get CPP to expand correctly. */ +#define FS_FULL(ns, name) __##ns##_##name +#define prefix FS_NAMESPACE +#define FS_L(p, n) FS_FULL(p, n) +#define FS(name) FS_L(prefix, name) + +#if defined(_WIN32) +#include +// N.B. defines some macro rewrites to, e.g., turn _wstat into +// _wstat64i32. We must include it here to ensure tat this rewrite applies to +// both the definition and use sites. +#include +#include + +wchar_t* FS(create_device_name) (const wchar_t*); +int FS(translate_mode) (const wchar_t*); +int FS(swopen) (const wchar_t* filename, int oflag, + int shflag, int pmode); +int FS(sopen) (const char* filename, int oflag, + int shflag, int pmode); +FILE *FS(fwopen) (const wchar_t* filename, const wchar_t* mode); +FILE *FS(fopen) (const char* filename, const char* mode); +int FS(_stat) (const char *path, struct _stat *buffer); +int FS(_stat64) (const char *path, struct __stat64 *buffer); +int FS(_wstat) (const wchar_t *path, struct _stat *buffer); +int FS(_wstat64) (const wchar_t *path, struct __stat64 *buffer); +int FS(_wrename) (const wchar_t *from, const wchar_t *to); +int FS(rename) (const char *from, const char *to); +int FS(unlink) (const char *filename); +int FS(_unlink) (const char *filename); +int FS(_wunlink) (const wchar_t *filename); +int FS(remove) (const char *path); +int FS(_wremove) (const wchar_t *path); +#else +FILE *FS(fopen) (const char* filename, const char* mode); +#endif diff --git a/rts-fs/rts-fs.cabal b/rts-fs/rts-fs.cabal new file mode 100644 index 000000000000..f013754d3f40 --- /dev/null +++ b/rts-fs/rts-fs.cabal @@ -0,0 +1,17 @@ +cabal-version: 3.0 +name: rts-fs +version: 1.0.0.0 +license: NONE +author: Andrea Bedini +maintainer: andrea@andreabedini.com +build-type: Simple +extra-doc-files: README +extra-source-files: fs.h + +library + cc-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + cpp-options: -DFS_NAMESPACE=rts -DCOMPILING_RTS + c-sources: fs.c + include-dirs: . + install-includes: fs.h + default-language: Haskell2010 diff --git a/rts/include/rts/Bytecodes.h b/rts-headers/include/rts/Bytecodes.h similarity index 100% rename from rts/include/rts/Bytecodes.h rename to rts-headers/include/rts/Bytecodes.h diff --git a/rts/include/rts/storage/ClosureTypes.h b/rts-headers/include/rts/storage/ClosureTypes.h similarity index 100% rename from rts/include/rts/storage/ClosureTypes.h rename to rts-headers/include/rts/storage/ClosureTypes.h diff --git a/rts/include/rts/storage/FunTypes.h b/rts-headers/include/rts/storage/FunTypes.h similarity index 100% rename from rts/include/rts/storage/FunTypes.h rename to rts-headers/include/rts/storage/FunTypes.h diff --git a/rts/include/stg/MachRegs.h b/rts-headers/include/stg/MachRegs.h similarity index 100% rename from rts/include/stg/MachRegs.h rename to rts-headers/include/stg/MachRegs.h diff --git a/rts/include/stg/MachRegs/arm32.h b/rts-headers/include/stg/MachRegs/arm32.h similarity index 100% rename from rts/include/stg/MachRegs/arm32.h rename to rts-headers/include/stg/MachRegs/arm32.h diff --git a/rts/include/stg/MachRegs/arm64.h b/rts-headers/include/stg/MachRegs/arm64.h similarity index 100% rename from rts/include/stg/MachRegs/arm64.h rename to rts-headers/include/stg/MachRegs/arm64.h diff --git a/rts/include/stg/MachRegs/loongarch64.h b/rts-headers/include/stg/MachRegs/loongarch64.h similarity index 100% rename from rts/include/stg/MachRegs/loongarch64.h rename to rts-headers/include/stg/MachRegs/loongarch64.h diff --git a/rts/include/stg/MachRegs/ppc.h b/rts-headers/include/stg/MachRegs/ppc.h similarity index 100% rename from rts/include/stg/MachRegs/ppc.h rename to rts-headers/include/stg/MachRegs/ppc.h diff --git a/rts/include/stg/MachRegs/riscv64.h b/rts-headers/include/stg/MachRegs/riscv64.h similarity index 100% rename from rts/include/stg/MachRegs/riscv64.h rename to rts-headers/include/stg/MachRegs/riscv64.h diff --git a/rts/include/stg/MachRegs/s390x.h b/rts-headers/include/stg/MachRegs/s390x.h similarity index 100% rename from rts/include/stg/MachRegs/s390x.h rename to rts-headers/include/stg/MachRegs/s390x.h diff --git a/rts/include/stg/MachRegs/wasm32.h b/rts-headers/include/stg/MachRegs/wasm32.h similarity index 100% rename from rts/include/stg/MachRegs/wasm32.h rename to rts-headers/include/stg/MachRegs/wasm32.h diff --git a/rts/include/stg/MachRegs/x86.h b/rts-headers/include/stg/MachRegs/x86.h similarity index 100% rename from rts/include/stg/MachRegs/x86.h rename to rts-headers/include/stg/MachRegs/x86.h diff --git a/rts-headers/rts-headers.cabal b/rts-headers/rts-headers.cabal new file mode 100644 index 000000000000..6d1b89a7ca33 --- /dev/null +++ b/rts-headers/rts-headers.cabal @@ -0,0 +1,31 @@ +cabal-version: 3.4 +name: rts-headers +version: 1.0.3 +synopsis: The GHC runtime system +description: + The GHC runtime system. + + Code produced by GHC links this library to provide missing functionality + that cannot be written in Haskell itself. +license: BSD-3-Clause +maintainer: glasgow-haskell-users@haskell.org +build-type: Simple + + +library + include-dirs: + include + + install-includes: + rts/Bytecodes.h + rts/storage/ClosureTypes.h + rts/storage/FunTypes.h + stg/MachRegs.h + stg/MachRegs/arm32.h + stg/MachRegs/arm64.h + stg/MachRegs/loongarch64.h + stg/MachRegs/ppc.h + stg/MachRegs/riscv64.h + stg/MachRegs/s390x.h + stg/MachRegs/wasm32.h + stg/MachRegs/x86.h diff --git a/rts/.gitignore b/rts/.gitignore index 179d62d55cf7..f1a295e18db0 100644 --- a/rts/.gitignore +++ b/rts/.gitignore @@ -8,7 +8,6 @@ /package.conf.inplace.raw /package.conf.install /package.conf.install.raw -/fs.* /aclocal.m4 /autom4te.cache/ diff --git a/rts/configure.ac b/rts/configure.ac index e9181aaf552a..ae110d76dce7 100644 --- a/rts/configure.ac +++ b/rts/configure.ac @@ -178,10 +178,12 @@ dnl Check for libraries dnl ################################################################ dnl ** check whether we need -ldl to get dlopen() -AC_CHECK_LIB([dl], [dlopen]) +AC_SEARCH_LIBS([dlopen], [dl]) dnl ** check whether we have dlinfo AC_CHECK_FUNCS([dlinfo]) +FP_CHECK_PTHREAD_LIB + dnl -------------------------------------------------- dnl * Miscellaneous feature tests dnl -------------------------------------------------- @@ -520,3 +522,118 @@ cat $srcdir/rts.buildinfo.in \ || exit 1 rm -f external-symbols.flags ] + +AC_SUBST([EXTRA_LIBS],[` printf " %s " "$LIBS" | sed -E 's/ -l([[^ ]]*)/\1 /g' `]) +AS_IF( + [test "`echo $EXTRA_LIBS | sed 's/ //'`" != ""], + [echo "extra-libraries: $EXTRA_LIBS" >> rts.buildinfo]) + +dnl -------------------------------------------------------------- +dnl Generate derived constants +dnl -------------------------------------------------------------- + +AC_ARG_VAR([NM], [Path to the nm program]) +AC_PATH_PROG([NM], nm) +if test -z "$NM"; then + AC_MSG_ERROR([Cannot find nm]) +fi + +AC_ARG_VAR([OBJDUMP], [Path to the objdump program]) +AC_PATH_PROG([OBJDUMP], objdump) +if test -z "$OBJDUMP"; then + AC_MSG_ERROR([Cannot find objdump]) +fi + +AC_ARG_VAR([DERIVE_CONSTANTS], [Path to the deriveConstants program]) +AC_PATH_PROG([DERIVE_CONSTANTS], deriveConstants) +AS_IF([test "x$DERIVE_CONSTANTS" = x], [AC_MSG_ERROR([deriveConstants executable not found. Please install deriveConstants or set DERIVE_CONSTANTS environment variable.])]) + +AC_ARG_VAR([GENAPPLY], [Path to the genapply program]) +AC_PATH_PROG([GENAPPLY], genapply) +AS_IF([test "x$GENAPPLY" = x], [AC_MSG_ERROR([genapply executable not found. Please install genapply or set GENAPPLY environment variable.])]) + +AC_CHECK_PROGS([PYTHON], [python3 python python2]) +AS_IF([test "x$PYTHON" = x], [AC_MSG_ERROR([Python interpreter not found. Please install Python or set PYTHON environment variable.])]) + +AC_MSG_CHECKING([for DerivedConstants.h]) +dnl NOTE: dnl pass `-fcommon` to force symbols into the common section. If they end +dnl up in the ro data section `nm` won't list their size, and thus derivedConstants +dnl will fail. Recent clang (e.g. 16) will by default use `-fno-common`. +dnl +dnl FIXME: using a relative path here is TERRIBLE; Cabal should provide some +dnl env var for _build-dependencies_ headers! +dnl + +if $DERIVE_CONSTANTS \ + --gen-header \ + -o include/DerivedConstants.h \ + --target-os "$HostOS_CPP" \ + --gcc-program "$CC" \ + --nm-program "$NM" \ + --objdump-program "$OBJDUMP" \ + --tmpdir "$(mktemp -d)" \ + --gcc-flag "-fcommon" \ + --gcc-flag "-I$srcdir" \ + --gcc-flag "-I$srcdir/include" \ + --gcc-flag "-Iinclude" \ + --gcc-flag "-I$srcdir/../rts-headers/include" ; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $DERIVE_CONSTANTS --gen-header ...]) +fi + +AC_MSG_CHECKING([for AutoApply.cmm]) +if $GENAPPLY include/DerivedConstants.h > AutoApply.cmm; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $GENAPPLY include/DerivedConstants.h > AutoApply.cmm]) +fi + +AC_MSG_CHECKING([for AutoApply_V16.cmm]) +if $GENAPPLY include/DerivedConstants.h -V16 > AutoApply_V16.cmm; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $GENAPPLY include/DerivedConstants.h -V16 > AutoApply_V16.cmm]) +fi + +AC_MSG_CHECKING([for AutoApply_V32.cmm]) +if $GENAPPLY include/DerivedConstants.h -V32 > AutoApply_V32.cmm; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $GENAPPLY include/DerivedConstants.h -V32 > AutoApply_V32.cmm]) +fi + +AC_MSG_CHECKING([for AutoApply_V64.cmm]) +if $GENAPPLY include/DerivedConstants.h -V64 > AutoApply_V64.cmm; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $GENAPPLY include/DerivedConstants.h -V64 > AutoApply_V64.cmm]) +fi + +AC_MSG_CHECKING([for include/rts/EventLogConstants.h]) +if mkdir -p include/rts && $PYTHON $srcdir/gen_event_types.py --event-types-defines include/rts/EventLogConstants.h; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $PYTHON gen_event_types.py]) +fi + +AC_MSG_CHECKING([for include/rts/EventTypes.h]) +if mkdir -p include/rts && $PYTHON $srcdir/gen_event_types.py --event-types-array include/rts/EventTypes.h; then + AC_MSG_RESULT([created]) +else + AC_MSG_RESULT([failed to create]) + AC_MSG_ERROR([Failed to run $PYTHON gen_event_types.py]) +fi + + +dnl -------------------------------------------------------------- +dnl ** Write config files +dnl -------------------------------------------------------------- + +AC_OUTPUT diff --git a/rts/include/stg/MachRegsForHost.h b/rts/include/stg/MachRegsForHost.h index 7c045c0214bf..cd28215ea0f1 100644 --- a/rts/include/stg/MachRegsForHost.h +++ b/rts/include/stg/MachRegsForHost.h @@ -84,4 +84,4 @@ #endif -#include "MachRegs.h" +#include "stg/MachRegs.h" diff --git a/rts/rts.cabal b/rts/rts.cabal index 20817ef0d63a..5baef6e02a20 100644 --- a/rts/rts.cabal +++ b/rts/rts.cabal @@ -1,4 +1,4 @@ -cabal-version: 3.0 +cabal-version: 3.8 name: rts version: 1.0.3 synopsis: The GHC runtime system @@ -13,9 +13,234 @@ build-type: Configure extra-source-files: configure + config.guess + config.sub + ghcplatform.h.top.in + ghcplatform.h.bottom + ghcautoconf.h.autoconf.in configure.ac external-symbols.list.in rts.buildinfo.in + linker/ELFRelocs/AArch64.def + linker/ELFRelocs/ARM.def + linker/ELFRelocs/i386.def + linker/ELFRelocs/x86_64.def + win32/libHSffi.def + win32/libHSghc-internal.def + win32/libHSghc-prim.def + posix/ticker/Pthread.c + posix/ticker/Setitimer.c + posix/ticker/TimerCreate.c + posix/ticker/TimerFd.c + -- headers files that are not installed by the rts package but only used to + -- build the rts C code + xxhash.h + adjustor/AdjustorPool.h + Adjustor.h + Apply.h + Arena.h + ARMOutlineAtomicsSymbols.h + AutoApply.h + AutoApplyVecs.h + BeginPrivate.h + Capability.h + CheckUnload.h + CheckVectorSupport.h + CloneStack.h + Continuation.h + Disassembler.h + EndPrivate.h + eventlog/EventLog.h + Excn.h + FileLock.h + ForeignExports.h + fs_rts.h + GetEnv.h + GetTime.h + Globals.h + Hash.h + hooks/Hooks.h + include/Cmm.h + include/ghcconfig.h + include/HsFFI.h + include/MachDeps.h + include/rts/Adjustor.h + include/RtsAPI.h + include/rts/BlockSignals.h + include/rts/Config.h + include/rts/Constants.h + include/rts/EventLogFormat.h + include/rts/EventLogWriter.h + include/rts/ExecPage.h + include/rts/FileLock.h + include/rts/Flags.h + include/rts/ForeignExports.h + include/rts/GetTime.h + include/rts/ghc_ffi.h + include/rts/Globals.h + include/Rts.h + include/rts/Hpc.h + include/rts/IOInterface.h + include/rts/IPE.h + include/rts/Libdw.h + include/rts/LibdwPool.h + include/rts/Linker.h + include/rts/Main.h + include/rts/Messages.h + include/rts/NonMoving.h + include/rts/OSThreads.h + include/rts/Parallel.h + include/rts/PosixSource.h + include/rts/PrimFloat.h + include/rts/prof/CCS.h + include/rts/prof/Heap.h + include/rts/Profiling.h + include/rts/prof/LDV.h + include/rts/Signals.h + include/rts/SpinLock.h + include/rts/StableName.h + include/rts/StablePtr.h + include/rts/StaticPtrTable.h + include/rts/storage/Block.h + include/rts/storage/ClosureMacros.h + include/rts/storage/GC.h + include/rts/storage/HeapAlloc.h + include/rts/storage/Heap.h + include/rts/storage/InfoTables.h + include/rts/storage/MBlock.h + include/rts/storage/TSO.h + include/rts/Threads.h + include/rts/Ticky.h + include/rts/Time.h + include/rts/Timer.h + include/rts/TSANUtils.h + include/rts/TTY.h + include/rts/Types.h + include/rts/Utils.h + include/stg/DLL.h + include/Stg.h + include/stg/MachRegsForHost.h + include/stg/MiscClosures.h + include/stg/Prim.h + include/stg/Regs.h + include/stg/SMP.h + include/stg/Ticky.h + include/stg/Types.h + Interpreter.h + IOManager.h + IOManagerInternals.h + IPE.h + Jumps.h + LdvProfile.h + Libdw.h + LibdwPool.h + linker/CacheFlush.h + linker/elf_compat.h + linker/elf_got.h + linker/Elf.h + linker/elf_plt_aarch64.h + linker/elf_plt_arm.h + linker/elf_plt.h + linker/elf_plt_riscv64.h + linker/elf_reloc_aarch64.h + linker/elf_reloc.h + linker/elf_reloc_riscv64.h + linker/ElfTypes.h + linker/elf_util.h + linker/InitFini.h + LinkerInternals.h + linker/LoadNativeObjPosix.h + linker/M32Alloc.h + linker/MachO.h + linker/macho/plt_aarch64.h + linker/macho/plt.h + linker/MachOTypes.h + linker/MMap.h + linker/PEi386.h + linker/PEi386Types.h + linker/SymbolExtras.h + linker/util.h + linker/Wasm32Types.h + Messages.h + PathUtils.h + Pool.h + posix/Clock.h + posix/Select.h + posix/Signals.h + posix/TTY.h + Prelude.h + Printer.h + ProfHeap.h + ProfHeapInternal.h + ProfilerReport.h + ProfilerReportJson.h + Profiling.h + Proftimer.h + RaiseAsync.h + ReportMemoryMap.h + RetainerProfile.h + RetainerSet.h + RtsDllMain.h + RtsFlags.h + RtsSignals.h + RtsSymbolInfo.h + RtsSymbols.h + RtsUtils.h + Schedule.h + sm/BlockAlloc.h + sm/CNF.h + sm/Compact.h + sm/Evac.h + sm/GC.h + sm/GCTDecl.h + sm/GCThread.h + sm/GCUtils.h + sm/HeapUtils.h + sm/MarkStack.h + sm/MarkWeak.h + sm/NonMovingAllocate.h + sm/NonMovingCensus.h + sm/NonMoving.h + sm/NonMovingMark.h + sm/NonMovingScav.h + sm/NonMovingShortcut.h + sm/NonMovingSweep.h + sm/OSMem.h + SMPClosureOps.h + sm/Sanity.h + sm/Scav.h + sm/ShouldCompact.h + sm/Storage.h + sm/Sweep.h + Sparks.h + StableName.h + StablePtr.h + StaticPtrTable.h + Stats.h + StgPrimFloat.h + StgRun.h + STM.h + Task.h + ThreadLabels.h + ThreadPaused.h + Threads.h + Ticker.h + Ticky.h + Timer.h + TopHandler.h + Trace.h + TraverseHeap.h + Updates.h + Weak.h + win32/AsyncMIO.h + win32/AsyncWinIO.h + win32/AwaitEvent.h + win32/ConsoleHandler.h + win32/MIOManager.h + win32/ThrIOManager.h + win32/veh_excn.h + win32/WorkQueue.h + WSDeque.h extra-tmp-files: autom4te.cache @@ -34,18 +259,9 @@ flag libm flag librt default: False manual: True -flag libdl - default: False - manual: True -flag use-system-libffi - default: False - manual: True flag libffi-adjustors default: False manual: True -flag need-pthread - default: False - manual: True flag libbfd default: False manual: True @@ -79,11 +295,11 @@ flag smp flag find-ptr default: False manual: True --- Some cabal flags used to control the flavours we want to produce --- for libHSrts in hadrian. By default, we just produce vanilla and --- threaded. The flags "compose": if you enable debug and profiling, --- you will produce vanilla, _thr, _debug, _p but also _thr_p, --- _thr_debug_p and so on. +-- -- Some cabal flags used to control the flavours we want to produce +-- -- for libHSrts in hadrian. By default, we just produce vanilla and +-- -- threaded. The flags "compose": if you enable debug and profiling, +-- -- you will produce vanilla, _thr, _debug, _p but also _thr_p, +-- -- _thr_debug_p and so on. flag profiling default: False manual: True @@ -104,472 +320,480 @@ flag thread-sanitizer default: False manual: True -library - -- rts is a wired in package and - -- expects the unit-id to be - -- set without version - ghc-options: -this-unit-id rts - - exposed: True - exposed-modules: +common rts-base-config + ghc-options: -ghcversion-file=include/ghcversion.h -optc-DFS_NAMESPACE=rts + cmm-options: - if arch(javascript) + include-dirs: include . + includes: Rts.h + build-depends: + rts-headers, + rts-fs, + rts - include-dirs: include - - js-sources: - js/config.js - js/structs.js - js/arith.js - js/compact.js - js/debug.js - js/enum.js - js/environment.js - js/eventlog.js - js/gc.js - js/goog.js - js/hscore.js - js/md5.js - js/mem.js - js/node-exports.js - js/object.js - js/profiling.js - js/rts.js - js/stableptr.js - js/staticpointer.js - js/stm.js - js/string.js - js/thread.js - js/unicode.js - js/verify.js - js/weak.js - js/globals.js - js/time.js - - install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h - ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h - DerivedConstants.h - stg/MachRegs.h - stg/MachRegs/arm32.h - stg/MachRegs/arm64.h - stg/MachRegs/loongarch64.h - stg/MachRegs/ppc.h - stg/MachRegs/riscv64.h - stg/MachRegs/s390x.h - stg/MachRegs/wasm32.h - stg/MachRegs/x86.h - stg/MachRegsForHost.h - stg/Types.h +common rts-c-sources-base + if !arch(javascript) + cmm-sources: + Apply.cmm + Compact.cmm + ContinuationOps.cmm + Exception.cmm + HeapStackCheck.cmm + Jumps_D.cmm + Jumps_V16.cmm + PrimOps.cmm + StgMiscClosures.cmm + StgStartup.cmm + StgStdThunks.cmm + Updates.cmm + -- Adjustor stuff + if flag(libffi-adjustors) + c-sources: adjustor/LibffiAdjustor.c else - -- If we are using an in-tree libffi then we must declare it as a bundled - -- library to ensure that Cabal installs it. - if !flag(use-system-libffi) - if os(windows) - extra-bundled-libraries: Cffi-6 + 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 - extra-bundled-libraries: Cffi - - install-includes: ffi.h ffitarget.h - -- ^ see Note [Packaging libffi headers] in - -- GHC.Driver.CodeOutput. - - -- Here we declare several flavours to be available when passing the - -- suitable (combination of) flag(s) when configuring the RTS from hadrian, - -- using Cabal. - if flag(threaded) - extra-library-flavours: _thr - if flag(dynamic) - extra-dynamic-library-flavours: _thr - - if flag(profiling) - extra-library-flavours: _p - if flag(threaded) - extra-library-flavours: _thr_p - if flag(debug) - extra-library-flavours: _debug_p - if flag(threaded) - extra-library-flavours: _thr_debug_p - if flag(dynamic) - extra-dynamic-library-flavours: _p - if flag(threaded) - extra-dynamic-library-flavours: _thr_p - if flag(debug) - extra-dynamic-library-flavours: _debug_p - if flag(threaded) - extra-dynamic-library-flavours: _thr_debug_p - - if flag(debug) - extra-library-flavours: _debug - if flag(dynamic) - extra-dynamic-library-flavours: _debug - if flag(threaded) - extra-library-flavours: _thr_debug - if flag(dynamic) - extra-dynamic-library-flavours: _thr_debug - - if flag(thread-sanitizer) - cc-options: -fsanitize=thread - ld-options: -fsanitize=thread - - if os(linux) - -- the RTS depends upon libc. while this dependency is generally - -- implicitly added by `cc`, we must explicitly add it here to ensure - -- that it is ordered correctly with libpthread, since ghc-internal.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) - extra-libraries: - -- for the linker - wsock32 gdi32 winmm - -- for crash dump - dbghelp - -- for process information - psapi - -- TODO: Hadrian will use this cabal file, so drop WINVER from Hadrian's configs. - -- Minimum supported Windows version. - -- These numbers can be found at: - -- https://msdn.microsoft.com/en-us/library/windows/desktop/aa383745(v=vs.85).aspx - -- If we're compiling on windows, enforce that we only support Windows 7+ - -- Adding this here means it doesn't have to be done in individual .c files - -- 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(libdw) - -- for backtraces - extra-libraries: elf dw - if flag(libnuma) - extra-libraries: numa - if flag(libzstd) - if flag(static-libzstd) - if os(darwin) - buildable: False - else - extra-libraries: :libzstd.a - else - extra-libraries: zstd - if !flag(smp) - cpp-options: -DNOSMP - - include-dirs: include - includes: Rts.h - autogen-includes: ghcautoconf.h ghcplatform.h - install-includes: Cmm.h HsFFI.h MachDeps.h Jumps.h Rts.h RtsAPI.h RtsSymbols.h Stg.h - ghcautoconf.h ghcconfig.h ghcplatform.h ghcversion.h - -- ^ from include - DerivedConstants.h - rts/EventLogConstants.h - rts/EventTypes.h - -- ^ generated - rts/ghc_ffi.h - rts/Adjustor.h - rts/ExecPage.h - rts/BlockSignals.h - rts/Bytecodes.h - rts/Config.h - rts/Constants.h - rts/EventLogFormat.h - rts/EventLogWriter.h - rts/FileLock.h - rts/Flags.h - rts/ForeignExports.h - rts/GetTime.h - rts/Globals.h - rts/Hpc.h - rts/IOInterface.h - rts/Libdw.h - rts/LibdwPool.h - rts/Linker.h - rts/Main.h - rts/Messages.h - rts/NonMoving.h - rts/OSThreads.h - rts/Parallel.h - rts/PrimFloat.h - rts/Profiling.h - rts/IPE.h - rts/PosixSource.h - rts/Signals.h - rts/SpinLock.h - rts/StableName.h - rts/StablePtr.h - rts/StaticPtrTable.h - rts/TTY.h - rts/Threads.h - rts/Ticky.h - rts/Time.h - rts/Timer.h - rts/TSANUtils.h - rts/Types.h - rts/Utils.h - rts/prof/CCS.h - rts/prof/Heap.h - rts/prof/LDV.h - rts/storage/Block.h - rts/storage/ClosureMacros.h - rts/storage/ClosureTypes.h - rts/storage/Closures.h - rts/storage/FunTypes.h - rts/storage/Heap.h - rts/storage/HeapAlloc.h - rts/storage/GC.h - rts/storage/InfoTables.h - rts/storage/MBlock.h - rts/storage/TSO.h - stg/DLL.h - stg/MachRegs.h - stg/MachRegs/arm32.h - stg/MachRegs/arm64.h - stg/MachRegs/loongarch64.h - stg/MachRegs/ppc.h - stg/MachRegs/riscv64.h - stg/MachRegs/s390x.h - stg/MachRegs/wasm32.h - stg/MachRegs/x86.h - stg/MachRegsForHost.h - stg/MiscClosures.h - stg/Prim.h - stg/Regs.h - stg/SMP.h - stg/Ticky.h - stg/Types.h - - if os(osx) - ld-options: "-Wl,-search_paths_first" - -- See Note [Undefined symbols in the RTS] - "-Wl,-undefined,dynamic_lookup" - if !arch(x86_64) && !arch(aarch64) - ld-options: -read_only_relocs warning - - cmm-sources: Apply.cmm - Compact.cmm - ContinuationOps.cmm - Exception.cmm - HeapStackCheck.cmm - Jumps_D.cmm - Jumps_V16.cmm - Jumps_V32.cmm - Jumps_V64.cmm - PrimOps.cmm - StgMiscClosures.cmm - StgStartup.cmm - StgStdThunks.cmm - Updates.cmm - -- AutoApply is generated - AutoApply.cmm - AutoApply_V16.cmm - AutoApply_V32.cmm - AutoApply_V64.cmm - - -- Adjustor stuff - if flag(libffi-adjustors) + asm-sources: adjustor/NativeAmd64Asm.S + c-sources: adjustor/NativeAmd64.c + if !arch(x86_64) && !arch(i386) 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 - - -- 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 - - c-sources: Adjustor.c - AllocArray.c - adjustor/AdjustorPool.c - ExecPage.c - Arena.c - Capability.c - CheckUnload.c - CheckVectorSupport.c - CloneStack.c - ClosureFlags.c - ClosureSize.c - Continuation.c - Disassembler.c - FileLock.c - ForeignExports.c - Globals.c - Hash.c - Heap.c - Hpc.c - HsFFI.c - Inlines.c - Interpreter.c - IOManager.c - LdvProfile.c - Libdw.c - LibdwPool.c - Linker.c - ReportMemoryMap.c - Messages.c - OldARMAtomic.c - PathUtils.c - Pool.c - Printer.c - ProfHeap.c - ProfilerReport.c - ProfilerReportJson.c - Profiling.c - IPE.c - Proftimer.c - RaiseAsync.c - RetainerProfile.c - RetainerSet.c - RtsAPI.c - RtsDllMain.c - RtsFlags.c - RtsMain.c - RtsMessages.c - RtsStartup.c - RtsSymbolInfo.c - RtsSymbols.c - RtsUtils.c - STM.c - Schedule.c - Sparks.c - SpinLock.c - StableName.c - StablePtr.c - StaticPtrTable.c - Stats.c - StgCRun.c - StgPrimFloat.c - Task.c - ThreadLabels.c - ThreadPaused.c - Threads.c - Ticky.c - Timer.c - TopHandler.c - Trace.c - TraverseHeap.c - TraverseHeapTest.c - TSANUtils.c - WSDeque.c - Weak.c - ZeroSlop.c - eventlog/EventLog.c - eventlog/EventLogWriter.c - hooks/FlagDefaults.c - hooks/LongGCSync.c - hooks/MallocFail.c - hooks/OnExit.c - hooks/OutOfHeap.c - hooks/StackOverflow.c - linker/CacheFlush.c - linker/Elf.c - linker/InitFini.c - linker/LoadArchive.c - linker/LoadNativeObjPosix.c - linker/M32Alloc.c - linker/MMap.c - linker/MachO.c - linker/macho/plt.c - linker/macho/plt_aarch64.c - linker/ProddableBlocks.c - linker/PEi386.c - linker/SymbolExtras.c - linker/elf_got.c - linker/elf_plt.c - linker/elf_plt_aarch64.c - linker/elf_plt_riscv64.c - linker/elf_plt_arm.c - linker/elf_reloc.c - linker/elf_reloc_aarch64.c - linker/elf_reloc_riscv64.c - linker/elf_tlsgd.c - linker/elf_util.c - sm/BlockAlloc.c - sm/CNF.c - sm/Compact.c - sm/Evac.c - sm/Evac_thr.c - sm/GC.c - sm/GCAux.c - sm/GCUtils.c - sm/MBlock.c - sm/MarkWeak.c - sm/NonMoving.c - sm/NonMovingAllocate.c - sm/NonMovingCensus.c - sm/NonMovingMark.c - sm/NonMovingScav.c - sm/NonMovingShortcut.c - sm/NonMovingSweep.c - sm/Sanity.c - sm/Scav.c - sm/Scav_thr.c - sm/Storage.c - sm/Sweep.c - fs.c + + if arch(ppc) || arch(ppc64) || arch(s390x) || arch(riscv64) || arch(loongarch64) + asm-sources: StgCRunAsm.S + + if arch(wasm32) + cc-options: -fvisibility=default -fvisibility-inlines-hidden + + c-sources: Adjustor.c + AllocArray.c + adjustor/AdjustorPool.c + ExecPage.c + Arena.c + Capability.c + CheckUnload.c + CheckVectorSupport.c + CloneStack.c + ClosureFlags.c + ClosureSize.c + Continuation.c + Disassembler.c + FileLock.c + ForeignExports.c + Globals.c + Hash.c + Heap.c + Hpc.c + HsFFI.c + Inlines.c + Interpreter.c + IOManager.c + LdvProfile.c + Libdw.c + LibdwPool.c + Linker.c + ReportMemoryMap.c + Messages.c + OldARMAtomic.c + PathUtils.c + Pool.c + Printer.c + ProfHeap.c + ProfilerReport.c + ProfilerReportJson.c + Profiling.c + IPE.c + Proftimer.c + RaiseAsync.c + RetainerProfile.c + RetainerSet.c + RtsAPI.c + RtsDllMain.c + RtsFlags.c + RtsMain.c + RtsMessages.c + RtsStartup.c + RtsSymbolInfo.c + RtsSymbols.c + RtsUtils.c + STM.c + Schedule.c + Sparks.c + SpinLock.c + StableName.c + StablePtr.c + StaticPtrTable.c + Stats.c + StgCRun.c + StgPrimFloat.c + Task.c + ThreadLabels.c + ThreadPaused.c + Threads.c + Ticky.c + Timer.c + TopHandler.c + Trace.c + TraverseHeap.c + TraverseHeapTest.c + TSANUtils.c + WSDeque.c + Weak.c + ZeroSlop.c + eventlog/EventLog.c + eventlog/EventLogWriter.c + hooks/FlagDefaults.c + hooks/LongGCSync.c + hooks/MallocFail.c + hooks/OnExit.c + hooks/OutOfHeap.c + hooks/StackOverflow.c + linker/CacheFlush.c + linker/Elf.c + linker/InitFini.c + linker/LoadArchive.c + linker/LoadNativeObjPosix.c + linker/M32Alloc.c + linker/MMap.c + linker/MachO.c + linker/macho/plt.c + linker/macho/plt_aarch64.c + linker/ProddableBlocks.c + linker/PEi386.c + linker/SymbolExtras.c + linker/elf_got.c + linker/elf_plt.c + linker/elf_plt_aarch64.c + linker/elf_plt_riscv64.c + linker/elf_plt_arm.c + linker/elf_reloc.c + linker/elf_reloc_aarch64.c + linker/elf_reloc_riscv64.c + linker/elf_tlsgd.c + linker/elf_util.c + sm/BlockAlloc.c + sm/CNF.c + sm/Compact.c + sm/Evac.c + sm/Evac_thr.c + sm/GC.c + sm/GCAux.c + sm/GCUtils.c + sm/MBlock.c + sm/MarkWeak.c + sm/NonMoving.c + sm/NonMovingAllocate.c + sm/NonMovingCensus.c + sm/NonMovingMark.c + sm/NonMovingScav.c + sm/NonMovingShortcut.c + sm/NonMovingSweep.c + sm/Sanity.c + sm/Scav.c + sm/Scav_thr.c + sm/Storage.c + sm/Sweep.c -- I wish we had wildcards..., this would be: -- *.c hooks/**/*.c sm/**/*.c eventlog/**/*.c linker/**/*.c - if os(windows) - c-sources: win32/AsyncMIO.c - win32/AsyncWinIO.c - win32/AwaitEvent.c - win32/ConsoleHandler.c - win32/GetEnv.c - win32/GetTime.c - win32/MIOManager.c - win32/OSMem.c - win32/OSThreads.c - win32/ThrIOManager.c - win32/Ticker.c - win32/WorkQueue.c - win32/veh_excn.c - -- win32/**/*.c - elif arch(wasm32) - asm-sources: wasm/Wasm.S - c-sources: wasm/StgRun.c - wasm/GetTime.c - wasm/OSMem.c - wasm/OSThreads.c - wasm/JSFFI.c - wasm/JSFFIGlobals.c - posix/Select.c - cmm-sources: wasm/jsval.cmm - wasm/blocker.cmm - wasm/scheduler.cmm + if os(windows) + c-sources: win32/AsyncMIO.c + win32/AsyncWinIO.c + win32/AwaitEvent.c + win32/ConsoleHandler.c + win32/GetEnv.c + win32/GetTime.c + win32/MIOManager.c + win32/OSMem.c + win32/OSThreads.c + win32/ThrIOManager.c + win32/Ticker.c + win32/WorkQueue.c + win32/veh_excn.c + elif arch(wasm32) + asm-sources: wasm/Wasm.S + c-sources: wasm/StgRun.c + wasm/GetTime.c + wasm/OSMem.c + wasm/OSThreads.c + wasm/JSFFI.c + wasm/JSFFIGlobals.c + -- Note: Select.c included for wasm32 + posix/Select.c + cmm-sources: wasm/jsval.cmm + wasm/blocker.cmm + wasm/scheduler.cmm + -- Posix-like + else + c-sources: posix/GetEnv.c + posix/GetTime.c + posix/Ticker.c + posix/OSMem.c + posix/OSThreads.c + posix/Select.c + posix/Signals.c + posix/TTY.c + +common rts-link-options + extra-libraries: ffi + extra-libraries-static: ffi + + if os(linux) + extra-libraries: c + if flag(libm) + extra-libraries: m + if flag(librt) + extra-libraries: rt + if os(windows) + extra-libraries: + wsock32 gdi32 winmm + dbghelp + psapi + cpp-options: -D_WIN32_WINNT=0x06010000 + cc-options: -D_WIN32_WINNT=0x06010000 + if flag(need-atomic) + extra-libraries: atomic + if flag(libbfd) + extra-libraries: bfd iberty + if flag(libdw) + extra-libraries: elf dw + if flag(libnuma) + extra-libraries: numa + if flag(libzstd) + if flag(static-libzstd) + if os(darwin) + buildable: False + else + extra-libraries: :libzstd.a + else + extra-libraries: zstd + + if os(osx) + ld-options: "-Wl,-search_paths_first" + "-Wl,-undefined,dynamic_lookup" + if !arch(x86_64) && !arch(aarch64) + ld-options: -read_only_relocs warning + + "-Wl,-undefined,dynamic_lookup" + if !arch(x86_64) && !arch(aarch64) + ld-options: -read_only_relocs warning + +common rts-global-build-flags + ghc-options: -DCOMPILING_RTS + cpp-options: -DCOMPILING_RTS + if !flag(smp) + ghc-options: -DNOSMP + cpp-options: -DNOSMP + if flag(dynamic) + ghc-options: -DDYNAMIC + cpp-options: -DDYNAMIC + if flag(thread-sanitizer) + cc-options: -fsanitize=thread + ld-options: -fsanitize=thread + +common rts-debug-flags + ghc-options: -optc-DDEBUG + cpp-options: -DDEBUG -fno-omit-frame-pointer -g3 -O0 + +common rts-threaded-flags + ghc-options: -DTHREADED_RTS + cpp-options: -DTHREADED_RTS + +-- the _main_ library needs to deal with all the _configure_ time stuff. +library + ghc-options: -this-unit-id rts -ghcversion-file=include/ghcversion.h -optc-DFS_NAMESPACE=rts + cmm-options: -this-unit-id rts + + autogen-includes: + ghcautoconf.h + ghcplatform.h + DerivedConstants.h + rts/EventLogConstants.h + rts/EventTypes.h + + install-includes: + ghcautoconf.h + ghcplatform.h + DerivedConstants.h + rts/EventLogConstants.h + rts/EventTypes.h + + install-includes: + -- Common headers for non-JS builds + Cmm.h HsFFI.h MachDeps.h Jumps.h Rts.h RtsAPI.h RtsSymbols.h Stg.h + ghcconfig.h ghcversion.h + rts/ghc_ffi.h + rts/Adjustor.h + rts/ExecPage.h + rts/BlockSignals.h + rts/Config.h + rts/Constants.h + rts/EventLogFormat.h + rts/EventLogWriter.h + rts/FileLock.h + rts/Flags.h + rts/ForeignExports.h + rts/GetTime.h + rts/Globals.h + rts/Hpc.h + rts/IOInterface.h + rts/Libdw.h + rts/LibdwPool.h + rts/Linker.h + rts/Main.h + rts/Messages.h + rts/NonMoving.h + rts/OSThreads.h + rts/Parallel.h + rts/PrimFloat.h + rts/Profiling.h + rts/IPE.h + rts/PosixSource.h + rts/Signals.h + rts/SpinLock.h + rts/StableName.h + rts/StablePtr.h + rts/StaticPtrTable.h + rts/TTY.h + rts/Threads.h + rts/Ticky.h + rts/Time.h + rts/Timer.h + rts/TSANUtils.h + rts/Types.h + rts/Utils.h + rts/prof/CCS.h + rts/prof/Heap.h + rts/prof/LDV.h + rts/storage/Block.h + rts/storage/ClosureMacros.h + rts/storage/Closures.h + rts/storage/Heap.h + rts/storage/HeapAlloc.h + rts/storage/GC.h + rts/storage/InfoTables.h + rts/storage/MBlock.h + rts/storage/TSO.h + stg/DLL.h + stg/MiscClosures.h + stg/Prim.h + stg/Regs.h + stg/SMP.h + stg/Ticky.h + stg/MachRegsForHost.h + stg/Types.h + + include-dirs: include . + + build-depends: + rts-headers, + rts-fs + + if !arch(javascript) + -- FIXME: by virtue of being part of the rts main library, these do not get + -- the flags (debug, threaded, ...) as the sub libraries. Thus we are + -- likely missing -DDEBUG, -DTHREADED_RTS, etc. + -- One solution to this would be to turn all of these into `.h` files, and + -- then have the `AutoApply.cmm` in `rts-c-sources-base` include them. This + -- would mean they are included in the sublibraries which will in turn apply + -- the sublibrary specific (c)flags. + autogen-cmm-sources: + AutoApply.cmm + AutoApply_V16.cmm + + if arch(x86_64) + cmm-sources: + Jumps_V32.cmm (-mavx2) + Jumps_V64.cmm (-mavx512f) + autogen-cmm-sources: + AutoApply_V32.cmm (-mavx2) + AutoApply_V64.cmm (-mavx512f) else - c-sources: posix/GetEnv.c - posix/GetTime.c - posix/Ticker.c - posix/OSMem.c - posix/OSThreads.c - posix/Select.c - posix/Signals.c - posix/TTY.c - -- ticker/*.c - -- We don't want to compile posix/ticker/*.c, these will be #included - -- from Ticker.c + cmm-sources: + Jumps_V32.cmm + Jumps_V64.cmm + autogen-cmm-sources: + AutoApply_V32.cmm + AutoApply_V64.cmm + +common ghcjs + import: rts-base-config + + -- Keep original JS specific settings for the main library + include-dirs: include + js-sources: + js/config.js + js/structs.js + js/arith.js + js/compact.js + js/debug.js + js/enum.js + js/environment.js + js/eventlog.js + js/gc.js + js/goog.js + js/hscore.js + js/md5.js + js/mem.js + js/node-exports.js + js/object.js + js/profiling.js + js/rts.js + js/stableptr.js + js/staticpointer.js + js/stm.js + js/string.js + js/thread.js + js/unicode.js + js/verify.js + js/weak.js + js/globals.js + js/time.js + + -- Add JS specific install-includes again + install-includes: HsFFI.h MachDeps.h Rts.h RtsAPI.h Stg.h + ghcconfig.h + ghcversion.h + stg/MachRegsForHost.h + stg/Types.h + +-- this is basiclly the "vanilla" version +library nonthreaded-nodebug + if arch(javascript) + import: ghcjs + else + import: rts-base-config, rts-c-sources-base, rts-link-options, rts-global-build-flags + + visibility: public + + ghc-options: -optc-DRtsWay="v" + + +library threaded-nodebug + import: rts-base-config, rts-c-sources-base, rts-link-options, rts-global-build-flags, rts-threaded-flags + visibility: public + build-depends: rts + if arch(javascript) + buildable: False + +library nonthreaded-debug + import: rts-base-config, rts-c-sources-base, rts-link-options, rts-global-build-flags, rts-debug-flags + visibility: public + build-depends: rts + if arch(javascript) + buildable: False + +library threaded-debug + import: rts-base-config, rts-c-sources-base, rts-link-options, rts-global-build-flags, rts-threaded-flags, rts-debug-flags + visibility: public + build-depends: rts + if arch(javascript) + buildable: False -- Note [Undefined symbols in the RTS] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/utils/iserv/cbits/iservmain.c b/utils/ghc-iserv/cbits/iservmain.c similarity index 100% rename from utils/iserv/cbits/iservmain.c rename to utils/ghc-iserv/cbits/iservmain.c diff --git a/utils/iserv/iserv.cabal.in b/utils/ghc-iserv/ghc-iserv.cabal.in similarity index 85% rename from utils/iserv/iserv.cabal.in rename to utils/ghc-iserv/ghc-iserv.cabal.in index 51286873b819..b0a1e80f0e91 100644 --- a/utils/iserv/iserv.cabal.in +++ b/utils/ghc-iserv/ghc-iserv.cabal.in @@ -1,8 +1,8 @@ --- WARNING: iserv.cabal is automatically generated from iserv.cabal.in by --- ../../configure. Make sure you are editing iserv.cabal.in, not --- iserv.cabal. +-- WARNING: ghc-iserv.cabal is automatically generated from ghc-iserv.cabal.in +-- by ../../configure. Make sure you are editing ghc-iserv.cabal.in, not +-- ghc-iserv.cabal. -Name: iserv +Name: ghc-iserv Version: @ProjectVersion@ Copyright: XXX License: BSD3 @@ -23,7 +23,7 @@ Category: Development build-type: Simple cabal-version: >=1.10 -Executable iserv +Executable ghc-iserv Default-Language: Haskell2010 ghc-options: -no-hs-main Main-Is: Main.hs diff --git a/utils/iserv/src/Main.hs b/utils/ghc-iserv/src/Main.hs similarity index 100% rename from utils/iserv/src/Main.hs rename to utils/ghc-iserv/src/Main.hs