summaryrefslogtreecommitdiff
path: root/rts
Commit message (Collapse)AuthorAgeFilesLines
* wipwip/stack-overflow-sizeBen Gamari2022-11-216-11/+27
|
* base: make Foreign.Marshal.Pool use RTS internal arena for allocationCheng Shao2022-11-161-3/+3
| | | | | | | | | | | | | | | | | | `Foreign.Marshal.Pool` used to call `malloc` once for each allocation request. Each `Pool` maintained a list of allocated pointers, and traverses the list to `free` each one of those pointers. The extra O(n) overhead is apparently bad for a `Pool` that serves a lot of small allocation requests. This patch uses the RTS internal arena to implement `Pool`, with these benefits: - Gets rid of the extra O(n) overhead. - The RTS arena is simply a bump allocator backed by the block allocator, each allocation request is likely faster than a libc `malloc` call. Closes #14762 #18338.
* eventlog: Ensure that IPE output contains actual info table pointersBen Gamari2022-11-142-1/+5
| | | | | | | | | The refactoring in 866c736e introduced a rather subtle change in the semantics of the IPE eventlog output, changing the eventlog field from encoding info table pointers to "TNTC pointers" (which point to entry code when tables-next-to-code is enabled). Fix this. Fixes #22452.
* rts: Check for program_invocation_short_name via autoconfBen Gamari2022-11-111-1/+1
| | | | Instead of assuming support on all Linuxes.
* rts: wasm32 specific logicCheng Shao2022-11-117-0/+214
| | | | This patch adds the rest of wasm32 specific logic in rts.
* Add register mapping for wasm32Cheng Shao2022-11-113-0/+218
| | | | | This patch adds register mapping logic for wasm32. See Note [Register mapping on WebAssembly] in wasm32 NCG for more description.
* rts: OSThreads.h: stub types for wasm32Cheng Shao2022-11-111-0/+16
| | | | | | | This patch defines stub Condition/Mutex/OSThreadId/ThreadLocalKey types for wasm32, just enough to unblock compiling RTS. Any threading-related functionality has been patched to be disabled on wasm32.
* rts: RtsStartup: don't call resetTerminalSettings, freeThreadingResources on ↵Cheng Shao2022-11-111-1/+3
| | | | | | | | wasm32 This patch prevents resetTerminalSettings and freeThreadingResources to be called on wasm32, since there is no TTY or threading on wasm32 at all.
* rts: make flushExec a no-op on wasm32Cheng Shao2022-11-111-0/+1
| | | | | This patch makes flushExec a no-op on wasm32, since there's no such thing as executable memory on wasm32 in the first place.
* rts: don't return memory to OS on wasm32Cheng Shao2022-11-112-0/+8
| | | | | | This patch makes the storage manager not return any memory on wasm32. The detailed reason is described in Note [Megablock allocator on wasm].
* rts: LibffiAdjustor: adapt to ffi_alloc_prep_closure interface for wasm32Cheng Shao2022-11-111-10/+24
| | | | | | | libffi-wasm32 only supports non-standard libffi closure api via ffi_alloc_prep_closure(). This patch implements ffi_alloc_prep_closure() via standard libffi closure api on other targets, and uses it to implement adjustor functionality.
* rts: Schedule: no FORKPROCESS_PRIMOP_SUPPORTED on wasm32Cheng Shao2022-11-111-1/+1
| | | | | On wasm32 there isn't a process model at all, so no FORKPROCESS_PRIMOP_SUPPORTED.
* rts: RtsSymbols: empty RTS_POSIX_ONLY_SYMBOLS for wasm32Cheng Shao2022-11-111-1/+5
| | | | The default RTS_POSIX_ONLY_SYMBOLS doesn't make sense on wasm32.
* rts: no timer for wasm32Cheng Shao2022-11-112-0/+25
| | | | | | | Due to the lack of threads, on wasm32 there can't be a background timer that periodically resets the context switch flag. This patch disables timer for wasm32, and also makes the scheduler default to -C0 on wasm32 to avoid starving threads.
* rts: RtsStartup: chdir to PWD on wasm32Cheng Shao2022-11-111-0/+11
| | | | | | | | | | | | This patch adds a wasm32-specific behavior to RtsStartup logic. When the PWD environment variable is present, we chdir() to it first. The point is to workaround an issue in wasi-libc: it's currently not possible to specify the initial working directory, it always defaults to / (in the virtual filesystem mapped from some host directory). For some use cases this is sufficient, but there are some other cases (e.g. in the testsuite) where the program needs to access files outside.
* rts: wasm32 placeholder linkerCheng Shao2022-11-113-0/+15
| | | | | | This patch adds minimal placeholder linker logic for wasm32, just enough to unblock compiling rts on wasm32. RTS linker functionality is not properly implemented yet for wasm32.
* rts: checkSuid: don't do it when not HAVE_GETUIDCheng Shao2022-11-111-1/+1
| | | | | When getuid() is not present, don't do checkSuid since it doesn't make sense anyway on that target.
* rts: genericRaise: use exit() instead when not HAVE_RAISECheng Shao2022-11-111-1/+3
| | | | | We check existence of raise() in autoconf, and here, if not HAVE_RAISE, we should use exit() instead in genericRaise.
* rts: IPE.c: don't do mutex stuff when THREADED_RTS is not definedCheng Shao2022-11-111-0/+10
| | | | | This patch adds the missing THREADED_RTS CPP guard to mutex logic in IPE.c.
* rts: use HAVE_GETPID to guard subprocess related logicCheng Shao2022-11-113-2/+20
| | | | | | | We've previously added detection of getpid() in autoconf. This patch uses HAVE_GETPID to guard some subprocess related logic in the RTS. This is required for certain targets like wasm32-wasi, where there isn't a process model at all.
* rts: don't define RTS_USER_SIGNALS when signal.h is not presentCheng Shao2022-11-117-7/+32
| | | | | | | | In the rts, we have a RTS_USER_SIGNALS macro, and most signal-related logic is guarded with RTS_USER_SIGNALS. This patch extends the range of code guarded with RTS_USER_SIGNALS, and define RTS_USER_SIGNALS iff signal.h is actually detected by autoconf. This is required for wasm32-wasi to work, which lacks signals.
* rts: prefer ffi_type_void over FFI_TYPE_VOIDCheng Shao2022-11-111-1/+1
| | | | | | | | This patch uses ffi_type_void instead of FFI_TYPE_VOID in the interpreter code, since the FFI_TYPE_* macros are not available in libffi-wasm32 yet. The libffi public documentation also only mentions the lower-case ffi_type_* symbols, so we should prefer the lower-case API here.
* rts: workaround cmm's improper variadic ccall breaking wasm32 typecheckingCheng Shao2022-11-115-7/+11
| | | | | | | | | | | | | | | | Unlike other targets, wasm requires the function signature of the call site and callee to strictly match. So in Cmm, when we call a C function that actually returns a value, we need to add an _unused local variable to receive it, otherwise type error awaits. An even bigger problem is calling variadic functions like barf() and such. Cmm doesn't support CAPI calling convention yet, so calls to variadic functions just happen to work in some cases with some target's ABI. But again, it doesn't work with wasm. Fortunately, the wasm C ABI lowers varargs to a stack pointer argument, and it can be passed NULL when no other arguments are expected to be passed. So we also add the additional unused NULL arguments to those functions, so to fix wasm, while not affecting behavior on other targets.
* Fix Cmm symbol kindCheng Shao2022-11-1111-11/+205
|
* rts: tag `stgStrndup` as `STG_MALLOC`Nicolas Trangez2022-11-021-1/+2
| | | | See: https://gitlab.haskell.org/ghc/ghc/-/issues/22381
* rts: add and use `STG_RETURNS_NONNULL`Nicolas Trangez2022-11-022-2/+19
| | | | | See: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-returns_005fnonnull-function-attribute See: https://gitlab.haskell.org/ghc/ghc/-/issues/22381
* rts: use `alloc_size` attributeNicolas Trangez2022-11-022-3/+17
| | | | | | | | This patch adds the `STG_ALLOC_SIZE1` and `STG_ALLOC_SIZE2` macros which allow to set the `alloc_size` attribute on functions, when available. See: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-alloc_005fsize-function-attribute See: https://gitlab.haskell.org/ghc/ghc/-/issues/22381
* rts: specify deallocator of allocating functionsNicolas Trangez2022-11-023-6/+50
| | | | | | | | | | | | | This patch adds a new `STG_MALLOC1` macro (and its counterpart `STG_MALLOC2` for completeness) which allows to specify the deallocation function to be used with allocations of allocating functions, and applies it to `stg*allocBytes`. It also fixes a case where `free` was used to free up an `stgMallocBytes` allocation, found by the above change. See: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute See: https://gitlab.haskell.org/ghc/ghc/-/issues/22381
* rts: use `STG_UNUSED`Nicolas Trangez2022-11-022-3/+3
|
* rts: introduce (and use) `STG_MALLOC`Nicolas Trangez2022-11-022-2/+4
| | | | | Instead of using `GNUC3_ATTRIBUTE(__malloc__)`, provide a `STG_MALLOC` macro definition and use it instead.
* rts: introduce (and use) `STG_USED`Nicolas Trangez2022-11-022-4/+5
| | | | | Similar to `STG_UNUSED`, have a specific macro for `__attribute__(used)`.
* rts: consistently use `STG_UNUSED`Nicolas Trangez2022-11-022-2/+2
|
* rts: introduce (and use) `STG_NORETURN`Nicolas Trangez2022-11-0217-24/+26
| | | | | | | Instead of sprinkling the codebase with `GNU(C3)_ATTRIBUTE(__noreturn__)`, add a `STG_NORETURN` macro (for, basically, the same thing) similar to `STG_UNUSED` and others, and update the code to use this macro where applicable.
* rts: fix OS thread naming in tickerNicolas Trangez2022-11-013-26/+20
| | | | | | | | | | | | | | | Since ee0deb805, the use of `pthread_setname_np` on Darwin was fixed when invoking `createOSThread`. However, the 'ticker' has some thread-creation code which doesn't rely on `createOSThread`, yet also uses `pthread_setname_np`. This patch enforces all thread creation to go through a single function, which uses the (correct) thread-naming code introduced in ee0deb805. See: https://gitlab.haskell.org/ghc/ghc/-/commit/ee0deb8054da2a597fc5624469b4c44fd769ada2 See: https://gitlab.haskell.org/ghc/ghc/-/issues/22206 See: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9066
* rts: fix lifetime of `start_thread`s `name` valueNicolas Trangez2022-11-011-8/+14
| | | | | | | | | | Since, unlike the code in ee0deb8054da2^, usage of the `name` value passed to `createOSThread` now outlives said function's lifetime, and could hence be released by the caller by the time the new thread runs `start_thread`, it needs to be copied. See: https://gitlab.haskell.org/ghc/ghc/-/commit/ee0deb8054da2a597fc5624469b4c44fd769ada2#note_460080 See: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/9066
* rts: `name` argument of `createOSThread` can be `const`Nicolas Trangez2022-11-013-3/+3
| | | | | | | | | | Since we don't intend to ever change the incoming string, declare this to be true. Also, in the POSIX implementation, the argument is no longer `STG_UNUSED` (since ee0deb8054da2a597fc5624469b4c44fd769ada2) in any code path. See: https://gitlab.haskell.org/ghc/ghc/-/commit/ee0deb8054da2a597fc5624469b4c44fd769ada2#note_460080
* Numeric exceptions: replace FFI calls with primopsSylvain Henry2022-10-252-9/+6
| | | | | | | | | | | | | ghc-bignum needs a way to raise numerical exceptions defined in base package. At the time we used FFI calls into primops defined in the RTS. These FFI calls had to be wrapped into hacky bottoming functions because "foreign import prim" syntax doesn't support giving a bottoming demand to the foreign call (cf #16929). These hacky wrapper functions trip up the JavaScript backend (#21078) because they are polymorphic in their return type. This commit replaces them with primops very similar to raise# but raising predefined exceptions.
* Introduce a standard thunk for allocating stringsÖmer Sinan Ağacan2022-10-224-1/+110
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently for a top-level closure in the form hey = unpackCString# x we generate code like this: Main.hey_entry() // [R1] { info_tbls: [(c2T4, label: Main.hey_info rep: HeapRep static { Thunk } srt: Nothing)] stack_info: arg_space: 8 updfr_space: Just 8 } {offset c2T4: // global _rqm::P64 = R1; if ((Sp + 8) - 24 < SpLim) (likely: False) goto c2T5; else goto c2T6; c2T5: // global R1 = _rqm::P64; call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8; c2T6: // global (_c2T1::I64) = call "ccall" arg hints: [PtrHint, PtrHint] result hints: [PtrHint] newCAF(BaseReg, _rqm::P64); if (_c2T1::I64 == 0) goto c2T3; else goto c2T2; c2T3: // global call (I64[_rqm::P64])() args: 8, res: 0, upd: 8; c2T2: // global I64[Sp - 16] = stg_bh_upd_frame_info; I64[Sp - 8] = _c2T1::I64; R2 = hey1_r2Gg_bytes; Sp = Sp - 16; call GHC.CString.unpackCString#_info(R2) args: 24, res: 0, upd: 24; } } This code is generated for every string literal. Only difference between top-level closures like this is the argument for the bytes of the string (hey1_r2Gg_bytes in the code above). With this patch we introduce a standard thunk in the RTS, called stg_MK_STRING_info, that does what `unpackCString# x` does, except it gets the bytes address from the payload. Using this, for the closure above, we generate this: Main.hey_closure" { Main.hey_closure: const stg_MK_STRING_info; const 0; // padding for indirectee const 0; // static link const 0; // saved info const hey1_r1Gg_bytes; // the payload } This is much smaller in code. Metric Decrease: T10421 T11195 T12150 T12425 T16577 T18282 T18698a T18698b Co-Authored By: Ben Gamari <ben@well-typed.com>
* rts: remove use of `TIME_WITH_SYS_TIME`Nicolas Trangez2022-10-212-22/+8
| | | | | | | | | | | | | | | | | | | | | | | `autoreconf` will insert an `m4_warning` when the obsolescent `AC_HEADER_TIME` macro is used: > Update your code to rely only on HAVE_SYS_TIME_H, > then remove this warning and the obsolete code below it. > All current systems provide time.h; it need not be checked for. > Not all systems provide sys/time.h, but those that do, all allow > you to include it and time.h simultaneously. Presence of `sys/time.h` was already checked in an earlier `AC_CHECK_HEADERS` invocation, so `AC_HEADER_TIME` can be dropped and guards relying on `TIME_WITH_SYS_TIME` can be reworked to (unconditionally) include `time.h` and include `sys/time.h` based on `HAVE_SYS_TIME_H`. Note the documentation of `AC_HEADER_TIME` in (at least) Autoconf 2.67 says > This macro is obsolescent, as current systems can include both files > when they exist. New programs need not use this macro.
* build: get rid of `HAVE_TIME_H`Nicolas Trangez2022-10-213-8/+2
| | | | | | | | | | | | As advertized by `autoreconf`: > All current systems provide time.h; it need not be checked for. Hence, remove the check for it in `configure.ac` and remove conditional inclusion of the header in `HAVE_TIME_H` blocks where applicable. The `time.h` header was being included in various source files without a `HAVE_TIME_H` guard already anyway.
* rts: trigger a major collection if megablock usage exceeds maxHeapSizeTeo Camarasu2022-10-151-1/+5
| | | | | | | | | | | When the heap is suffering from block fragmentation, live bytes might be low while megablock usage is high. If megablock usage exceeds maxHeapSize, we want to trigger a major GC to try to recover some memory otherwise we will die from a heapOverflow at the end of the GC. Fixes #21927
* rts: ensure we are below maxHeapSize after returning megablocksTeo Camarasu2022-10-151-0/+7
| | | | | | | | | When the heap is heavily block fragmented the live byte size might be low while the memory usage is high. We want to ensure that heap overflow triggers in these cases. We do so by checking that we can return enough megablocks to under maxHeapSize at the end of GC.
* rts: Use pthread_setname_np correctly on DarwinBen Gamari2022-10-141-10/+36
| | | | | | As noted in #22206, pthread_setname_np on Darwin only supports setting the name of the calling thread. Consequently we must introduce a trampoline which first sets the thread name before entering the thread entrypoint.
* rts/linker: Add support for .fini sectionsBen Gamari2022-10-133-0/+9
|
* rts/linker: Consolidate initializer/finalizer handlingBen Gamari2022-10-137-251/+316
| | | | | | | | | Here we extend our treatment of initializer/finalizer priorities to include ELF and in so doing refactor things to share the implementation with PEi386. As well, I fix a subtle misconception of the ordering behavior for `.ctors`. Fixes #21847.
* rts: Don't hint inlining of appendToRunQueueBen Gamari2022-10-122-54/+58
| | | | | | | | | These hints have resulted in compile-time warnings due to failed inlinings for quite some time. Moreover, it's quite unlikely that inlining them is all that beneficial given that they are rather sizeable functions. Resolves #22280.
* Separate IPE source file from spanBen Gamari2022-10-114-10/+23
| | | | | | The source file name can very often be shared across many IPE entries whereas the source coordinates are generally unique. Separate the two to exploit sharing of the former.
* Refactor IPE initializationBen Gamari2022-10-118-108/+149
| | | | | | | | | | | | | | | Here we refactor the representation of info table provenance information in object code to significantly reduce its size and link-time impact. Specifically, we deduplicate strings and represent them as 32-bit offsets into a common string table. In addition, we rework the registration logic to eliminate allocation from the registration path, which is run from a static initializer where things like allocation are technically undefined behavior (although it did previously seem to work). For similar reasons we eliminate lock usage from registration path, instead relying on atomic CAS. Closes #22077.
* rts: Refactor IPE tracing supportBen Gamari2022-10-116-66/+34
|
* rts: Add missing declaration of stg_noDuplicateBen Gamari2022-10-111-0/+1
|