summaryrefslogtreecommitdiff
path: root/rts/LinkerInternals.h
Commit message (Collapse)AuthorAgeFilesLines
* linker: Fix BFD import librariesTamar Christina2023-02-031-4/+9
| | | | | | | | | | This commit fixes the BFD style import library support in the runtime linker. This was accidentally broken during the refactoring to clang and went unnoticed because clang itself is unable to generate the BFD style import libraries. With this change we can not link against both GCC or Clang produced libraries again and intermix code produced by both compilers.
* rts: wasm32 placeholder linkerCheng Shao2022-11-111-0/+4
| | | | | | 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/linker: Ensure that __cxa_finalize is called on code unloadBen Gamari2022-07-161-0/+7
|
* rts/linker: Clean up section kindsBen Gamari2022-07-161-2/+5
|
* rts/linker/PEi386: Rename finit field to finiBen Gamari2022-07-161-1/+1
| | | | fini is short for "finalizer", which does not contain a "t".
* rts/linker/Elf: Introduce support for invoking finalizers on unloadBen Gamari2022-07-161-1/+4
| | | | Addresses #20494.
*-. Merge branches 'wip/windows-high-codegen', 'wip/windows-high-linker', ↵Ben Gamari2022-04-071-6/+42
|\ \ | | | | | | | | | 'wip/windows-clang-2' and 'wip/lint-rts-includes' into wip/windows-clang-join
| | * rts: Fix various #include issuesBen Gamari2022-04-061-2/+2
| |/ |/| | | | | This fixes various violations of the newly-added RTS includes linter.
| * rts/linker: More descriptive debug outputBen Gamari2022-04-061-0/+6
| |
| * rts/PEi386: Rework linkerBen Gamari2022-04-061-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a significant rework of the PEi386 linker, making the linker compatible with high image base addresses. Specifically, we now use the m32 allocator instead of `HeapAllocate`. In addition I found a number of latent bugs in our handling of import libraries and relocations. I've added quite a few comments describing what I've learned about Windows import libraries while fixing these. Thanks to Tamar Christina (@Phyx) for providing the address space search logic, countless hours of help while debugging, and his boundless Windows knowledge. Co-Authored-By: Tamar Christina <tamar@zhox.com>
| * rts/PEi386: Fix relocation overflow behaviorBen Gamari2022-04-061-0/+1
| | | | | | | | | | | | | | | | This fixes handling of overflowed relocations on PEi386 targets: * Refuse to create jump islands for relocations of data symbols * Correctly handle the `__imp___acrt_iob_func` symbol, which is an new type of symbol: `SYM_TYPE_INDIRECT_DATA`
| * rts/linker: Preserve information about symbol typesBen Gamari2022-04-061-3/+20
|/ | | | | | | | | | | | | As noted in #20978, the linker would previously handle overflowed relocations by creating a jump island. While this is fine in the case of code symbols, it's very much not okay in the case of data symbols. To fix this we must keep track of whether each symbol is code or data and relocate them appropriately. This patch takes the first step in this direction, adding a symbol type field to the linker's symbol table. It doesn't yet change relocation behavior to take advantage of this knowledge. Fixes #20978.
* rts/linker: Catch archives masquerading as object filesBen Gamari2022-04-061-0/+4
| | | | | | | Check the file's header to catch static archive bearing the `.o` extension, as may happen on Windows after the Clang refactoring. See #21068
* linker: Initial Windows C++ exception unwinding supportTamar Christina2022-03-171-0/+4
|
* rts/linker: Drop dead IA64 codeBen Gamari2022-02-091-6/+0
|
* rts: Move mmapForLinker and friends to linker/MMap.cBen Gamari2022-02-091-88/+0
| | | | They are not particularly related to linking.
* rts: Generalize mmapForLinkerMarkExecutableGHC GitLab CI2022-02-061-1/+9
| | | | | Renamed to mprotectForLinker and allowed setting of arbitrary protection modes.
* rts/m32: Accept any address within 4GB of program textBen Gamari2022-02-061-0/+60
| | | | | | | | | | | Previously m32 would assume that the program image was located near the start of the address space and therefore assume that it wanted pages in the bottom 4GB of address space. Instead we now check whether they are within 4GB of whereever the program is loaded. This is necessary on Windows, which now tends to place the image in high memory. The eventual goal is to use m32 to allocate memory for linker sections on Windows.
* Fix a few Note inconsistenciesBen Gamari2022-02-011-0/+1
|
* rts/linker: Introduce a notion of strong symbolsBen Gamari2021-10-121-2/+8
|
* Tighten scope of non-POSIX visibility macrosViktor Dukhovni2021-04-301-5/+0
| | | | | | | The __BSD_VISIBLE and _DARWIN_C_SOURCE macros expose non-POSIX prototypes in system header files. We should scope these to just the ".c" modules that actually need them, and avoid defining them in header files used in other C modules.
* Add background note in elf_tlsgd.c.Viktor Dukhovni2021-04-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | Also some code cleanup, and a fix for an (extant unrelated) missing <pthread_np.h> include that should hopefully resolve a failure in the FreeBSD CI build, since it is best to make sure that this MR actually builds on FreeBSD systems other than mine. Some unexpected metric changes on FreeBSD (perhaps because CI had been failing for a while???): Metric Decrease: T3064 T5321Fun T5642 T9020 T12227 T13253-spj T15164 T18282 WWRec Metric Increase: haddock.compiler
* Support R_X86_64_TLSGD relocation on FreeBSDViktor Dukhovni2021-04-221-1/+5
| | | | | | | | | | | | | | | The FreeBSD C <ctype.h> header supports per-thread locales by exporting a static inline function that references the `_ThreadRuneLocale` thread-local variable. This means that object files that use e.g. isdigit(3) end up with TLSGD(19) relocations, and would not load into ghci or the language server. Here we add support for this type of relocation, for now just on FreeBSD, and only for external references to thread-specifics defined in already loaded dynamic modules (primarily libc.so). This is sufficient to resolve the <ctype.h> issues. Runtime linking of ".o" files which *define* new thread-specific variables would be noticeably more difficult, as this would likely require new rtld APIs.
* [armv7] arm32 needs symbols!Moritz Angermann2021-03-291-1/+1
|
* Allocate Adjustors and mark them readable in two stepsMoritz Angermann2021-03-291-0/+5
| | | | | | | | | 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.
* rts: Make markLiveObject thread-safeBen Gamari2021-03-041-1/+1
| | | | | | | | markLiveObject is called by GC worker threads and therefore must be thread-safe. This was a rather egregious oversight which the testsuite missed. (cherry picked from commit fe28a062e47bd914a6879f2d01ff268983c075ad)
* rts/linker: Don't assume existence of dlinfoBen Gamari2021-01-171-3/+0
| | | | | | | | | The native-code codepath uses dlinfo to identify memory regions owned by a loaded dynamic object, facilitating safe unload. Unfortunately, this interface is not always available. Add an autoconf check for it and introduce a safe fallback behavior. Fixes #19159.
* rts/linker: Use m32 to allocate symbol extras in PEi386Ben Gamari2020-12-011-1/+1
|
* rts/m32: Introduce NEEDS_M32 macroBen Gamari2020-12-011-1/+9
| | | | Instead of relying on RTS_LINKER_USE_MMAP
* rts/linker: Introduce munmapForLinkerBen Gamari2020-12-011-0/+1
| | | | Consolidates munmap calls to ensure consistent error handling.
* rts: Introduce mmapAnonForLinkerBen Gamari2020-12-011-0/+1
| | | | | | | | Previously most of the uses of mmapForLinker were mapping anonymous memory, resulting in a great deal of unnecessary repetition. Factor this out into a new helper. Also fixes a few places where error checking was missing or suboptimal.
* rts/linker: Move shared library loading logic into Elf.cBen Gamari2020-11-301-40/+51
|
* CmmToLlvm: Declare signature for memcmpwip/angerman/arm64Ben Gamari2020-11-241-1/+1
| | | | | | Otherwise `opt` fails with: error: use of undefined value '@memcmp$def'
* Add loadNativeObj and unloadNativeObjRay Shih2020-11-111-2/+31
| | | | | | | | | | | | | | | | | | | (This change is originally written by niteria) This adds two functions: * `loadNativeObj` * `unloadNativeObj` and implements them for Linux. They are useful if you want to load a shared object with Haskell code using the system linker and have GHC call dlclose() after the code is no longer referenced from the heap. Using the system linker allows you to load the shared object above outside the low-mem region. It also loads the DWARF sections in a way that `perf` understands. `dl_iterate_phdr` is what makes this implementation Linux specific.
* Fix and enable object unloading in GHCiÖmer Sinan Ağacan2020-11-111-11/+34
| | | | | | | Fixes #16525 by tracking dependencies between object file symbols and marking symbol liveness during garbage collection See Note [Object unloading] in CheckUnload.c for details.
* [AArch64] Aarch64 Always PICMoritz Angermann2020-11-061-1/+0
|
* rts: Refactor unloading of foreign export StablePtrsBen Gamari2020-09-181-12/+2
| | | | | | Previously we would allocate a linked list cell for each foreign export. Now we can avoid this by taking advantage of the fact that they are already broken into groups.
* [linker] Fix out of range relocations.Moritz Angermann2020-07-231-1/+2
| | | | | | | | | | | | mmap may return address all over the place. mmap_next will ensure we get the next free page after the requested address. This is especially important for linking on aarch64, where the memory model with PIC admits relocations in the +-4GB range, and as such we can't work with arbitrary object locations in memory. Of note: we map the rts into process space, so any mapped objects must not be ouside of the 4GB from the processes address space.
* Fix duplicated words and typos in comments and user guideJan Hrček2020-06-281-1/+1
|
* fix windows bootstrap due to linker changesTamar Christina2020-06-181-2/+2
|
* [linker] Adds void printLoadedObjects(void);wip/angerman/print-loaded-objectsMoritz Angermann2020-06-041-0/+2
| | | | | | This allows us to dump in-memory object code locations for debugging. Fixup printLoadedObjects prototype
* Remove unused SEGMENT_PROT_RWXGreg Steuck2020-05-081-2/+0
| | | | | It's been unused for a year and is problematic on any OS which requires W^X for security.
* rts: Specialize hashing at call site rather than in struct.Crazycolorz52019-12-111-4/+4
| | | | | | | | | | | | | | | | Separate word and string hash tables on the type level, and do not store the hashing function. Thus when a different hash function is desire it is provided upon accessing the table. This is worst case the same as before the change, and in the majority of cases is better. Also mark the functions for aggressive inlining to improve performance. {F1686506} Reviewers: bgamari, erikd, simonmar Subscribers: rwbarton, thomie, carter GHC Trac Issues: #13165 Differential Revision: https://phabricator.haskell.org/D4889
* Fix typos, using Wikipedia list of common typosBrian Wignall2019-11-281-1/+1
|
* rts/linker: Ensure that code isn't writableBen Gamari2019-11-041-4/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | For many years the linker would simply map all of its memory with PROT_READ|PROT_WRITE|PROT_EXEC. However operating systems have been becoming increasingly reluctant to accept this practice (e.g. #17353 and #12657) and for good reason: writable code is ripe for exploitation. Consequently mmapForLinker now maps its memory with PROT_READ|PROT_WRITE. After the linker has finished filling/relocating the mapping it must then call mmapForLinkerMarkExecutable on the sections of the mapping which contain executable code. Moreover, to make all of this possible it was necessary to redesign the m32 allocator. First, we gave (in an earlier commit) each ObjectCode its own m32_allocator. This was necessary since code loading and symbol resolution/relocation are currently interleaved, meaning that it is not possible to enforce W^X when symbols from different objects reside in the same page. We then redesigned the m32 allocator to take advantage of the fact that all of the pages allocated with the allocator die at the same time (namely, when the owning ObjectCode is unloaded). This makes a number of things simpler (e.g. no more page reference counting; the interface provided by the allocator for freeing is simpler). See Note [M32 Allocator] for details.
* rts: Make m32 allocator per-ObjectCodeBen Gamari2019-11-011-0/+6
| | | | | | | | | | | | | | | | | MacOS Catalina is finally going to force our hand in forbidden writable exeutable mappings. Unfortunately, this is quite incompatible with the current global m32 allocator, which mixes symbols from various objects in a single page. The problem here is that some of these symbols may not yet be resolved (e.g. had relocations performed) as this happens lazily (and therefore we can't yet make the section read-only and therefore executable). The easiest way around this is to simply create one m32 allocator per ObjectCode. This may slightly increase fragmentation for short-running programs but I suspect will actually improve fragmentation for programs doing lots of loading/unloading since we can always free all of the pages allocated to an object when it is unloaded (although this ability will only be implemented in a later patch).
* Expunge #ifdef and #ifndef from the codebaseJohn Ericson2019-07-141-1/+1
| | | | | | | | These are unexploded minds as far as the linter is concerned. I don't want to hit in my MRs by mistake! I did this with `sed`, and then rolled back some changes in the docs, config.guess, and the linter itself.
* Add missing levels to SegmentProt enumArtem Pyanykh2019-03-201-1/+16
|
* Address some todos and fixmesArtem Pyanykh2019-03-201-6/+1
|
* Use segments for section layoutArtem Pyanykh2019-03-201-0/+25
|