summaryrefslogtreecommitdiff
path: root/rts/StgCRun.c
Commit message (Collapse)AuthorAgeFilesLines
* Allocate Adjustors and mark them readable in two stepsMoritz Angermann2021-03-291-1/+1
| | | | | | | | | This drops allocateExec for darwin, and replaces it with a alloc, write, mark executable strategy instead. This prevents us from trying to allocate an executable range and then write to it, which X^W will prohibit on darwin. This will *only* work if we can use mmap.
* AArch64/arm64 adjustmentsMoritz Angermann2020-11-151-2/+2
| | | | | | | | This addes the necessary logic to support aarch64 on elf, as well as aarch64 on mach-o, which Apple calls arm64. We change architecture name to AArch64, which is the official arm naming scheme.
* rts: fix race condition in StgCRunTamar Christina2020-10-091-20/+29
| | | | | | | | | | | | | | | | On windows the stack has to be allocated 4k at a time, otherwise we get a segfault. This is done by using a helper ___chkstk_ms that is provided by libgcc. The Haskell side already knows how to handle this but we need to do the same from STG. Previously we would drop the stack in StgRun but would only make it valid whenever the scheduler loop ran. This approach was fundamentally broken in that it falls apart when you take a signal from the OS. We see it less often because you initially get allocated a 1MB stack block which you have to blow past first. Concretely this means we must always keep the stack valid. Fixes #18601.
* RTS: Refactor Haskell-C glue for PPC 64-bitPeter Trommler2020-06-281-97/+40
| | | | | | | | | | | | | | Make sure the stack is 16 byte aligned even when reserved stack bytes are not a multiple of 16 bytes. Avoid saving r2 (TOC). On ELF v1 the function descriptor of StgReturn has the same TOC as StgRun, on ELF v2 the TOC is recomputed in the function prologue. Use the ABI provided functions to save clobbered GPRs and FPRs. Improve comments. Describe what the stack looks like and how it relates to the respective ABIs.
* Clean up file paths for new module hierarchyTakenobu Tani2020-06-011-2/+2
| | | | | | | | | This updates comments only. This patch replaces file references according to new module hierarchy. See also: * https://gitlab.haskell.org/ghc/ghc/-/wikis/Make-GHC-codebase-more-modular * https://gitlab.haskell.org/ghc/ghc/issues/13009
* StgCRun: Enable unwinding only on LinuxBen Gamari2020-04-141-4/+11
| | | | | | It's broken on macOS due and SmartOS due to assembler differences (#15207) so let's be conservative in enabling it. Also, refactor things to make the intent clearer.
* Fix typos, via a Levenshtein-style correctorBrian Wignall2020-01-041-1/+1
|
* Fix typos, using Wikipedia list of common typosBrian Wignall2019-11-281-1/+1
|
* Restore Xmm registers properly in StgCRun.cklebinger.andreas@gmx.at2019-04-041-9/+9
| | | | | This fixes #16514: Xmm6-15 was restored based off rax instead of rsp. The code was introduced in the fix for #14619.
* RTS: Use ELF v1 convention on all powerpc64 systemsPeter Trommler2019-01-171-5/+0
|
* PPC NCG: Remove Darwin supportPeter Trommler2019-01-011-40/+0
| | | | | | | Support for Mac OS X on PowerPC has been dropped by Apple years ago. We follow suit and remove PowerPC support for Darwin. Fixes #16106.
* StgCRun: Disable unwinding on DarwinBen Gamari2018-12-171-2/+12
| | | | See #15207.
* Revert "rts: Use .cfi_{start|end}proc directives"Ben Gamari2018-06-171-18/+1
| | | | This reverts commit 86210b238b86d810874a2315d1715546a4006cea.
* rts: Use .cfi_{start|end}proc directivesBen Gamari2018-06-161-1/+18
| | | | | | | | | | | | | | Test Plan: Validate using LLVM assembler Reviewers: carter, erikd, simonmar Reviewed By: simonmar Subscribers: rwbarton, thomie GHC Trac Issues: #15207 Differential Revision: https://phabricator.haskell.org/D4781
* Fix unwinding of C -> Haskell FFI calls with -threaded (2nd try)Bartosz Nitka2018-05-171-10/+190
| | | | | | | | | | | | | | | | | Summary: See the new note. This should fix cb5c2fe875965b7aedbc189012803fc62e48fb3f enough to unbreak Windows and OS X builds. Test Plan: manual testing with patched gdb Reviewers: bgamari, simonmar, erikd Reviewed By: bgamari Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4694
* Revert "Fix unwinding of C -> Haskell FFI calls with -threaded"Bartosz Nitka2018-05-121-165/+10
| | | | | | This reverts commit cb5c2fe875965b7aedbc189012803fc62e48fb3f. It appears to have broken OSX and Windows builds.
* Fix unwinding of C -> Haskell FFI calls with -threadedBartosz Nitka2018-05-111-10/+165
| | | | | | | | | | | | | See the new note. Test Plan: manual testing with patched gdb Reviewers: bgamari, simonmar, erikd Subscribers: rwbarton, thomie, carter Differential Revision: https://phabricator.haskell.org/D4666
* Mark xmm6 as caller saved in the register allocator for windows.klebinger.andreas@gmx.at2018-01-311-5/+28
| | | | | | | | | | | | | | | | | | This prevents the register being picked up as a scratch register. Otherwise the allocator would be free to use it before a call. This fixes #14619. Test Plan: ci, repro case on #14619 Reviewers: bgamari, Phyx, erikd, simonmar, RyanGlScott, simonpj Reviewed By: Phyx, RyanGlScott, simonpj Subscribers: simonpj, RyanGlScott, Phyx, rwbarton, thomie, carter GHC Trac Issues: #14619 Differential Revision: https://phabricator.haskell.org/D4348
* Fix Windows stack allocations.Tamar Christina2018-01-261-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On Windows we use the function `win32AllocStack` to do stack allocations in 4k blocks and insert a stack check afterwards to ensure the allocation returned a valid block. The problem is this function does something that by C semantics is pointless. The stack allocated value can never escape the function, and the stack isn't used so the compiler just optimizes away the entire function body. After considering a bunch of other possibilities I think the simplest fix is to just disable optimizations for the function. Alternatively inline assembly is an option but the stack check function doesn't have a very portable name as it relies on e.g. `libgcc`. Thanks to Sergey Vinokurov for helping diagnose and test. Test Plan: ./validate Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #14669 Differential Revision: https://phabricator.haskell.org/D4343
* Get rid of some stuttering in comments and docsGabor Greif2017-12-191-1/+1
|
* Prefer #if defined to #ifdefBen Gamari2017-04-281-12/+12
| | | | Our new CPP linter enforces this.
* Fix stop_thread unwinding informationBen Gamari2017-02-081-5/+1
| | | | | | | | | | | | | | | | This corrects the unwind information for `stg_stop_thread`, which allows us to unwind back to the C stack after reaching the end of the STG stack. Test Plan: Validate Reviewers: simonmar, austin, erikd Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2746
* Typos in comments only [ci skip]Gabor Greif2016-11-281-1/+1
|
* Adds x86_64-apple-darwin14 target.Moritz Angermann2016-07-051-2/+2
| | | | | | | | | | | | | | | | | | x86_64-apple-darwin14, is the target for the 64bit simulator. Ideally, we'd have (i386|armv7|arm64|x64_86)-apple-ios, yet, many #ifdefs depend on `darwin`, notably libffi. Hence, this only adds x86_64-apple-darwin14 as a target. This also updates the comment to add the `-S` flag, and dump the output to stdout; and adjusts the `datalayout` and `triple` values, as obtained through the method mentioned in the comment. Reviewers: hvr, erikd, austin, bgamari, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2378
* Add NCG support for AIX/ppc32Herbert Valerio Riedel2016-03-241-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This extends the previous work to revive the unregisterised GHC build for AIX/ppc32. Strictly speaking, AIX runs on POWER4 (and later) hardware, but the PPC32 instructions implemented in the PPC NCG represent a compatible subset of the POWER4 ISA. IBM AIX follows the PowerOpen ABI (and shares many similiarites with the Linux PPC64 ELF V1 NCG backend) but uses the rather limited XCOFF format (compared to ELF). This doesn't support dynamic libraries yet. A major limiting factor is that the AIX assembler does not support the `@ha`/`@l` relocation types nor the ha16()/lo16() functions Darwin's assembler supports. Therefore we need to avoid emitting those. In case of numeric literals we simply compute the functions ourselves, while for labels we have to use local TOCs and hope everything fits into a 16bit offset (for ppc32 this gives us at most 16384 entries per TOC section, which is enough to compile GHC). Another issue is that XCOFF doesn't seem to have a relocation type for label-differences, and therefore the label-differences placed into tables-next-to-code can't be relocated, but the linker may rearrange different sections, so we need to place all read-only sections into the same `.text[PR]` section to workaround this. Finally, the PowerOpen ABI distinguishes between function-descriptors and actualy entry-point addresses. For AIX we need to be specific when emitting assembler code whether we want the address of the function descriptor `printf`) or for the entry-point (`.printf`). So we let the asm pretty-printer prefix a dot to all emitted subroutine calls (i.e. `BL`) on AIX only. For now, STG routines' entry-point labels are not prefixed by a label and don't have any associated function-descriptor. Reviewers: austin, trommler, erikd, bgamari Reviewed By: trommler, erikd, bgamari Differential Revision: https://phabricator.haskell.org/D2019
* StgStartup: Setup unwinding for stg_stop_threadBen Gamari2015-11-011-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a bit ugly as we need to assume the structure of the C stack as left by StgRun. Nevertheless, it allows us to unwind all the way back to `_start` on my machine. ``` Stack trace: set_initial_registers (rts/Libdw.c:272.0) dwfl_thread_getframes dwfl_getthreads dwfl_getthread_frames libdw_get_backtrace (rts/Libdw.c:243.0) base_GHCziExecutionStack_getStackTrace1_info (libraries/base/GHC/ExecutionStack.hs:43.1) base_GHCziExecutionStack_showStackTrace1_info (libraries/base/GHC/ExecutionStack.hs:47.1) base_GHCziBase_bindIO1_info (libraries/base/GHC/Base.hs:1085.1) base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1) base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1) base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1) base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1) base_GHCziBase_thenIO1_info (libraries/base/GHC/Base.hs:1088.1) stg_catch_frame_info (rts/Exception.cmm:370.1) stg_stop_thread_info (rts/StgStartup.cmm:42.1) scheduleWaitThread (rts/Schedule.c:465.0) hs_main (rts/RtsMain.c:65.0) __libc_start_main (/tmp/buildd/glibc-2.19/csu/libc-start.c:321.0) _start ```
* Fix incorrect stack pointer usage in StgRun() on x86_64Ben Gamari2015-08-031-11/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The STG_RETURN code from StgCRun.c is incorrect for x86_64 variants where the ABI doesn't impose a mandatory red zone for the stack, like on Windows or Xen/HaLVM. The current implementation restores the stack pointer first, which effectively marks the area with the saved registers as reusable. Later, the CPU registers are restored from this "free" area. This ordering happens to work by accident on operating systems that strictly adhere to the System V ABI, because any interrupt/signal delivery is guaranteed to leave the first 128 bytes past the stack pointer untouched (red zone). On other systems this might result in corrupted CPU registers if an interruption happens just after restoring the stack pointer. The red zone is usually only used by small leaf functions to avoid updates to the stack pointer and exploiting it doesn't give us any advantage in this case. Reviewers: austin, rwbarton Reviewed By: rwbarton Subscribers: thomie, simonmar Differential Revision: https://phabricator.haskell.org/D1120 GHC Trac Issues: #10155
* Implement PowerPC 64-bit native code backend for LinuxPeter Trommler2015-07-031-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extend the PowerPC 32-bit native code generator for "64-bit PowerPC ELF Application Binary Interface Supplement 1.9" by Ian Lance Taylor and "Power Architecture 64-Bit ELF V2 ABI Specification -- OpenPOWER ABI for Linux Supplement" by IBM. The latter ABI is mainly used on POWER7/7+ and POWER8 Linux systems running in little-endian mode. The code generator supports both static and dynamic linking. PowerPC 64-bit code for ELF ABI 1.9 and 2 is mostly position independent anyway, and thus so is all the code emitted by the code generator. In other words, -fPIC does not make a difference. rts/stg/SMP.h support is implemented. Following the spirit of the introductory comment in PPC/CodeGen.hs, the rest of the code is a straightforward extension of the 32-bit implementation. Limitations: * Code is generated only in the medium code model, which is also gcc's default * Local symbols are not accessed directly, which seems to also be the case for 32-bit * LLVM does not work, but this does not work on 32-bit either * Must use the system runtime linker in GHCi, because the GHC linker for "static" object files (rts/Linker.c) for PPC 64-bit is not implemented. The system runtime (dynamic) linker works. * The handling of the system stack (register 1) is not ELF- compliant so stack traces break. Instead of allocating a new stack frame, spill code should use the "official" spill area in the current stack frame and deallocation code should restore the back chain * DWARF support is missing Fixes #9863 Test Plan: validate (on powerpc, too) Reviewers: simonmar, trofi, erikd, austin Reviewed By: trofi Subscribers: bgamari, arnons1, kgardas, thomie Differential Revision: https://phabricator.haskell.org/D629 GHC Trac Issues: #9863
* rts: Fix typo in commentErik de Castro Lopo2015-05-241-2/+2
|
* RTS : Fix StgRun for aarch64-linux (#9935).Erik de Castro Lopo2015-01-271-8/+10
| | | | | | | | | | | | | | | | | | | | Summary: The GCC assembler doesn't seem to recognise the 'fp' and 'lr' register names which are aliases for 'x29' and 'x30' respectively. Depends on D598. Test Plan: validate Reviewers: lukexi, bgamari, austin Reviewed By: austin Subscribers: carter, thomie Differential Revision: https://phabricator.haskell.org/D599 GHC Trac Issues: #9935
* arm64: 64bit iOS and SMP support (#7942)Luke Iannini2014-11-191-10/+22
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* Revert "rts: add Emacs 'Local Variables' to every .c file"Simon Marlow2014-09-291-8/+0
| | | | This reverts commit 39b5c1cbd8950755de400933cecca7b8deb4ffcd.
* rts: add Emacs 'Local Variables' to every .c fileAustin Seipp2014-07-281-0/+8
| | | | | | | | This will hopefully help ensure some basic consistency in the forward by overriding buffer variables. In particular, it sets the wrap length, the offset to 4, and turns off tabs. Signed-off-by: Austin Seipp <austin@well-typed.com>
* ghc: initial AArch64 patchesColin Watson2014-04-211-0/+66
| | | | Signed-off-by: Austin Seipp <austin@well-typed.com>
* Add support for iOS simulator (issue #8152).Austin Seipp2013-08-241-1/+1
| | | | | | | | The iOS simulator is essentially an iOS target but for an x86 machine instead. It doesn't support the native code generator either, though. Authored-by: Stephen Blackheath <...@blacksapphire.com> Signed-off-by: Austin Seipp <aseipp@pobox.com>
* Fix build on WindowsIan Lynagh2013-04-281-0/+4
|
* Fix mismatched visibility of assembler impls of StgRunIan Lynagh2013-04-271-8/+25
| | | | | | | | | Based on a patch from PHO, in trac #7813. We were previously declaring StgRun as a private symbol (in rts/StgRun.h), but were actually defining it as a public one (in rts/StgCRun.c). This caused a linkage problem with old binutils. See: http://www.haskell.org/pipermail/ghc-devs/2013-April/000932.html
* ios fix from Stephen Blackheath; part of #7707Ian Lynagh2013-03-021-0/+2
| | | | Apparently ios doesn't understand .type %function.
* Use 'r11' rather than 'fp' on Arm; part of #7707Ian Lynagh2013-03-021-3/+3
| | | | | They're both the same register, and Linux seems happy with both, but ios only accepts r11.
* Use .globl rather than .global on arm; part of #7707Ian Lynagh2013-03-021-1/+1
| | | | | Apparently ios only understands .globl, but Linux appears to understand both.
* Fix typosIan Lynagh2012-11-011-1/+1
|
* Fix rsp alignment on Win64Ian Lynagh2012-03-241-1/+1
|
* Fix caller/callee register saving on Win64Ian Lynagh2012-03-231-5/+22
|
* Use win32AllocStack on Win64 tooIan Lynagh2012-03-191-12/+12
|
* Fix the registers used in StgRun on Win64Ian Lynagh2012-03-191-0/+8
|
* Fixes for the threaded RTS on Win64Ian Lynagh2012-03-181-0/+8
|
* fix ARM StgCRun to not save and restore r11/fp register twiceKarel Gardas2012-02-161-2/+2
|
* fix ARM's StgCRun clobbered register list for both ARM and Thumb modesKarel Gardas2012-02-161-1/+15
|
* ARM StgRun: Ensure r11 state is preservedBen Gamari2012-02-071-3/+3
|
* Fix register clobber list in StgRun for ARMBen Gamari2012-01-301-1/+1
| | | | | | | | The ARM implementation of StgRun does not claim that it clobbers r7-r12. As a result, the compiler will sometimes put the returned RegTable in one of these registers, resulting in an invalid RegTable to be returned. Hilarity ensues. Signed-off-by: Ben Gamari <bgamari.foss@gmail.com>