summaryrefslogtreecommitdiff
path: root/rts/linker
Commit message (Collapse)AuthorAgeFilesLines
* [aarch64-macho] Fix off-by-one error in the linkerMoritz Angermann2021-06-241-1/+11
| | | | | | We need to be careful about the sign bit for BR26 relocation otherwise we end up encoding a large positive number and reading back a large negative number.
* Adds AArch64 Native Code GeneratorMoritz Angermann2021-06-051-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In which we add a new code generator to the Glasgow Haskell Compiler. This codegen supports ELF and Mach-O targets, thus covering Linux, macOS, and BSDs in principle. It was tested only on macOS and Linux. The NCG follows a similar structure as the other native code generators we already have, and should therfore be realtively easy to follow. It supports most of the features required for a proper native code generator, but does not claim to be perfect or fully optimised. There are still opportunities for optimisations. Metric Decrease: ManyAlternatives ManyConstructors MultiLayerModules PmSeriesG PmSeriesS PmSeriesT PmSeriesV T10421 T10421a T10858 T11195 T11276 T11303b T11374 T11822 T12227 T12545 T12707 T13035 T13253 T13253-spj T13379 T13701 T13719 T14683 T14697 T15164 T15630 T16577 T17096 T17516 T17836 T17836b T17977 T17977b T18140 T18282 T18304 T18478 T18698a T18698b T18923 T1969 T3064 T5030 T5321FD T5321Fun T5631 T5642 T5837 T783 T9198 T9233 T9630 T9872d T9961 WWRec Metric Increase: T4801
* rts/m32: Fix bounds checkBen Gamari2021-04-261-2/+3
| | | | | | | | Previously we would check only that the *start* of the mapping was in the bottom 32-bits of address space. However, we need the *entire* mapping to be in low memory. Fix this. Noticed by @Phyx.
* Add background note in elf_tlsgd.c.Viktor Dukhovni2021-04-223-21/+155
| | | | | | | | | | | | | | | | | | | | | | | | 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-223-3/+164
| | | | | | | | | | | | | | | 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-2/+4
|
* [aarch64-darwin] be very careful of warnings.Moritz Angermann2021-03-291-0/+1
| | | | | | | So we did *not* have the stgCallocBytes prototype, and subsequently the C compiler defaulted to `int` as a return value. Thus generating sxtw instructions for the return value of stgCalloBytes to produce the expected void *.
* [rts] cast return value to struct.Moritz Angermann2021-03-291-1/+1
|
* [linker] no munmap if either agument is invalid.Moritz Angermann2021-03-291-1/+4
|
* [linker/aarch64-elf] support section symbols for GOT relocationMoritz Angermann2021-03-291-1/+7
|
* [linker] align prototype with implementation signature.Moritz Angermann2021-03-291-2/+2
|
* [linker] SymbolExtras are only used on PPC and X86Moritz Angermann2021-03-292-5/+4
|
* [linker] Additional FALLTHROUGH decorations.Moritz Angermann2021-03-291-0/+2
|
* [macho] improved linker with proper plt supportMoritz Angermann2021-03-296-91/+304
| | | | This is a pre-requisite for making aarch64-darwin work.
* [elf/aarch64] Fall Through decorationMoritz Angermann2021-03-211-4/+4
|
* Implement riscv64 LLVM backendAndreas Schwab2021-03-051-0/+6
| | | | This enables a registerised build for the riscv64 architecture.
* Move absentError into ghc-prim.Andreas Klebinger2021-02-261-1/+1
| | | | | | | | | | | | When using -fdicts-strict we generate references to absentError while compiling ghc-prim. However we always load ghc-prim before base so this caused linker errors. We simply solve this by moving absentError into ghc-prim. This does mean it's now a panic instead of an exception which can no longer be caught. But given that it should only be thrown if there is a compiler error that seems acceptable, and in fact we already do this for absentSumFieldError which has similar constraints.
* linker: Fix atexit handlers on PETamar Christina2021-02-221-0/+5
|
* rts/linker: Don't assume existence of dlinfoBen Gamari2021-01-171-8/+20
| | | | | | | | | 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/PEi386: Fix reentrant lock usageBen Gamari2021-01-091-1/+1
| | | | | | | | | | | | Previously lookupSymbol_PEi386 would call lookupSymbol while holding linker_mutex. Fix this by rather calling `lookupDependentSymbol`. This is safe because lookupSymbol_PEi386 unconditionally holds linker_mutex. Happily, this un-breaks `T12771`, `T13082_good`, and `T14611`, which were previously marked as broken due to #18718. Closes #19155.
* Rts/elf-linker: Upcast to 64bit to satisfy format string.Andreas Klebinger2020-12-181-2/+2
| | | | | The elf size is 32bit on 32bit builds and 64 otherwise. We just upcast to 64bits before printing now.
* rts/linker/Elf.c: add missing <dlfcn.h> include (musl support)Sergei Trofimovich2020-12-101-0/+3
| | | | | | | | | | | | | | The change fixes build failure on musl: ``` rts/linker/Elf.c:2031:3: error: warning: implicit declaration of function 'dlclose'; did you mean 'close'? [-Wimplicit-function-declaration] 2031 | dlclose(nc->dlopen_handle); | ^~~~~~~ | close ``` Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* rts/linker: Use m32 to allocate symbol extras in PEi386Ben Gamari2020-12-012-30/+16
|
* rts/m32: Introduce NEEDS_M32 macroBen Gamari2020-12-013-22/+17
| | | | Instead of relying on RTS_LINKER_USE_MMAP
* rts/linker: Introduce munmapForLinkerBen Gamari2020-12-015-26/+7
| | | | Consolidates munmap calls to ensure consistent error handling.
* rts: Introduce mmapAnonForLinkerBen Gamari2020-12-016-25/+29
| | | | | | | | 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: Don't declare dynamic objects with image_mappedGHC GitLab CI2020-11-301-1/+1
| | | | This previously resulted in warnings due to spurious unmap failures.
* rts/linker: Move shared library loading logic into Elf.cBen Gamari2020-11-303-4/+144
|
* rts/linker: Replace some ASSERTs with CHECKBen Gamari2020-11-304-33/+32
| | | | | | | | In the past some people have confused ASSERT, which is for checking internal invariants, which CHECK, which should be used when checking things that might fail due to bad input (and therefore should be enabled even in the release compiler). Change some of these cases in the linker to use CHECK.
* rts: Use CHECK instead of assertBen Gamari2020-11-301-28/+27
| | | | Use the GHC wrappers instead of <assert.h>.
* rts/m32: Refactor handling of allocator seedingBen Gamari2020-11-301-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | Previously, in an attempt to reduce fragmentation, each new allocator would map a region of M32_MAX_PAGES fresh pages to seed itself. However, this ends up being extremely wasteful since it turns out that we often use fewer than this. Consequently, these pages end up getting freed which, ends up fragmenting our address space more than than we would have if we had naively allocated pages on-demand. Here we refactor m32 to avoid this waste while achieving the fragmentation mitigation previously desired. In particular, we move all page allocation into the global m32_alloc_page, which will pull a page from the free page pool. If the free page pool is empty we then refill it by allocating a region of M32_MAP_PAGES and adding them to the pool. Furthermore, we do away with the initial seeding entirely. That is, the allocator starts with no active pages: pages are rather allocated on an as-needed basis. On the whole this ends up being a pleasingly simple change, simultaneously making m32 more efficient, more robust, and simpler. Fixes #18980.
* CmmToLlvm: Declare signature for memcmpwip/angerman/arm64Ben Gamari2020-11-242-3/+11
| | | | | | Otherwise `opt` fails with: error: use of undefined value '@memcmp$def'
* rts/linker: Align bssSize to page size when mapping symbol extrasBen Gamari2020-11-201-1/+3
| | | | | | | We place symbol_extras right after bss. We also need to ensure that symbol_extras can be mprotect'd independently from the rest of the image. To ensure this we round up the size of bss to a page boundary, thus ensuring that symbol_extras is also page-aligned.
* AArch64/arm64 adjustmentsMoritz Angermann2020-11-152-3/+3
| | | | | | | | 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.
* Add loadNativeObj and unloadNativeObjRay Shih2020-11-111-1/+1
| | | | | | | | | | | | | | | | | | | (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-115-17/+19
| | | | | | | 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.
* rts/linker: Fix relocation overflow in PE linkerBen Gamari2020-11-101-4/+6
| | | | | | | | | | | | | | | | | | | | | | | Previously the overflow check for the IMAGE_REL_AMD64_ADDR32NB relocation failed to account for the signed nature of the value. Specifically, the overflow check was: uint64_t v; v = S + A; if (v >> 32) { ... } However, `v` ultimately needs to fit into 32-bits as a signed value. Consequently, values `v > 2^31` in fact overflow yet this is not caught by the existing overflow check. Here we rewrite the overflow check to rather ensure that `INT32_MIN <= v <= INT32_MAX`. There is now quite a bit of repetition between the `IMAGE_REL_AMD64_REL32` and `IMAGE_REL_AMD64_ADDR32` cases but I am leaving fixing this for future work. This bug was first noticed by @awson. Fixes #15808.
* rts: Consistently use stgMallocBytes instead of mallocGHC GitLab CI2020-09-051-10/+10
| | | | | This can help in debugging RTS memory leaks since all allocations go through the same interface.
* [fixup 3433] move debugBelch into IF_DEBUG(linker)Moritz Angermann2020-08-311-2/+3
| | | | | | | | The commit in dff1cb3d9c111808fec60190747272b973547c52 incorrectly left the `debugBelch` function without a comment or IF_DEBUG(linker,) decoration. This rectifies it. Needs at least a 8.10 backport, as it was backported in 6471cc6aff80d5deebbdb1bf7b677b31ed2af3d5
* [linker] Fix out of range relocations.Moritz Angermann2020-07-236-19/+43
| | | | | | | | | | | | 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.
* winio: Small linker comment and ifdef cleanupsTamar Christina2020-07-151-2/+0
|
* Fix invalid printf formatSylvain Henry2020-06-231-1/+1
|
* fix windows bootstrap due to linker changesTamar Christina2020-06-182-9/+8
|
* Load .lo as well.Moritz Angermann2020-06-151-0/+1
| | | | | | | | Some archives contain so called linker objects, with the affectionate .lo suffic. For example the musl libc.a will come in that form. We still want to load those objects, hence we should not discard them and look for .lo as well. Ultimately we might want to fix this proerly by looking at the file magic.
* Range is actually +/-2^32, not +/-2^31Moritz Angermann2020-06-071-5/+7
| | | | See also: https://static.docs.arm.com/ihi0056/g/aaelf64.pdf
* rts: Make non-existent linker search path merely a warningBen Gamari2020-05-091-2/+2
| | | | | | | | As noted in #18105, previously this resulted in a rather intrusive error message. This is in contrast to the general expectation that search paths are merely places to look, not places that must exist. Fixes #18105.
* ELF linker: increment curSymbol after filling in fields of current entryÖmer Sinan Ağacan2020-05-061-1/+2
| | | | | | | | | The bug was introduced in a8b7cef4d45 which added a field to the `symbols` array elements and then updated this code incorrectly: - oc->symbols[curSymbol++] = nm; + oc->symbols[curSymbol++].name = nm; + oc->symbols[curSymbol].addr = symbol->addr;
* Fix build warning; add more informative information to the linker; fix ↵Moritz Angermann2020-04-221-4/+15
| | | | linker for empty sections
* rts/M32Alloc: Don't attempt to unmap non-existent pagesBen Gamari2020-02-011-1/+3
| | | | | | The m32 allocator's `pages` list may contain NULLs in the case that the page was flushed. Some `munmap` implementations (e.g. FreeBSD's) don't like it if we pass them NULL. Don't do that.
* Fix more typos, via an improved Levenshtein-style correctorBrian Wignall2020-01-122-4/+4
|