summaryrefslogtreecommitdiff
path: root/rts/Linker.c
Commit message (Collapse)AuthorAgeFilesLines
* Add relocation type R_X86_64_REX_GOTPCRELXTamar Christina2016-06-051-1/+7
| | | | | | | | | | | | | | | | | | | | | | Summary: Adding support for the `R_X86_64_REX_GOTPCRELX` relocation type. This relocation is treated by the linker the same as the `R_X86_64_GOTPCRELX` type `G + GOT + A - P` to generate relative offsets to the GOT. The `REX` prefix has no influence in this stage. This is based on https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r252.pdf Test Plan: ./validate Reviewers: erikd, austin, bgamari, simonmar Reviewed By: erikd Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2303 GHC Trac Issues: #12147
* Refactor the SymbolName and SymbolAddr types to be pointersTamar Christina2016-06-041-45/+45
| | | | | | | | | | | | | | | | | | | | | | | Take the pointer notation out of the typedef such that it preserves the fact that these are pointers at the use site. Test Plan: ./validate on all platforms that use the runtime linker. For unix platforms please ensure `DYNAMIC_GHC_PROGRAMS=NO` is added to your validate file. Continuation of D2250 Reviewers: austin, bgamari, simonmar, erikd Reviewed By: erikd Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2302 GHC Trac Issues: #11816
* Use useful names for Symbol Addr and Names in Linker.cTamar Christina2016-06-031-52/+52
| | | | | | | | | | | | | | | | | | | | | | | | Replace `char*` and `void*` with `SymbolName` and `SymbolAddr` in `Linker.c`. Gives some useful information about what the variables are used for and also normalizes the types used in Mac, Linux and Windows Test Plan: ./validate on all platforms that use the runtime linker. For unix platforms please ensure `DYNAMIC_GHC_PROGRAMS=NO` is added to your validate file. This is a continuation from D2184 Reviewers: austin, erikd, simonmar, bgamari Reviewed By: bgamari Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2250 GHC Trac Issues: #11816
* Refactored SymbolInfo to lower memory usage in RTSTamar Christina2016-06-031-35/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously as part of #11223 a new struct `SymbolInfo` was introduced to keep track it the weak symbol status of a symbol. This structure also kept a copy of the calculated address of the symbol which turns out was useful in ignoring non-weak zero-valued symbols. The information was kept in an array so it means for every symbol two extra bytes were kept even though the vast majority of symbols are non-weak and non-zero valued. This changes the array into a sparse map keeping this information only for the symbols that are weak or zero-valued. This allows for a reduction in the amount of information needed to be kept while giving up a small (negligable) hit in performance as this information now has to be looked up in hashmaps. Test Plan: ./validate on all platforms that use the runtime linker. For unix platforms please ensure `DYNAMIC_GHC_PROGRAMS=NO` is added to your validate file. Reviewers: simonmar, austin, erikd, bgamari Reviewed By: simonmar, bgamari Subscribers: thomie, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D2184 GHC Trac Issues: #11816
* Runtime linker: Break m32 allocator out into its own fileErik de Castro Lopo2016-05-251-307/+14
| | | | | | | | | | | | | | | | | | | | This makes the code a little more modular and allows the removal of some CPP hackery. By providing dummy implementations of of the `m32_*` functions (which simply call `errorBelch`) it means that the call sites for these functions are syntax checked even when `RTS_LINKER_USE_MMAP` is `0`. Also changes some size parameter types from `unsigned int` to `size_t`. Test Plan: Validate on Linux, OS X and Windows Reviewers: Phyx, hsyl20, bgamari, simonmar, austin Reviewed By: simonmar, austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2237
* rts/Linker.c: Fix compile error on ArmErik de Castro Lopo2016-05-221-0/+3
| | | | | | | | | | | | | | | Commit da3c1ebb8a left Arm with a compile error. This is a short term fixup pending a much more through fix of removing as much CPP hackery as possible. Test Plan: Validate on arm and x86_64 Reviewers: simonmar, austin, hsyl20, bgamari, Phyx Reviewed By: Phyx Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2254
* Enable checkProddableBlock on x86_64Simon Marlow2016-05-211-2/+2
| | | | | | | | | | | | | | | | | | We've been seeing some memory corruption after using the linker, and I want to enable this to see if it catches anything. Test Plan: * validate * modified the linker_unload test to remove the performGC calls to use as a benchmark, saw no significant difference after this change. Reviewers: bgamari, erikd, austin Reviewed By: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2245
* Set `USE_MMAP` at configure timeErik de Castro Lopo2016-05-171-35/+19
| | | | | | | | | | | | | | | Summary: The `USE_MMAP` macro is used in the run time linker and was being set with some really ugly CPP hackery. Setting in the configure script is much neater. Reviewers: rwbarton, hvr, austin, simonmar, bgamari Reviewed By: hvr, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2223
* rts: Fix C compiler warnings on WindowsErik de Castro Lopo2016-05-111-3/+6
| | | | | | | | | | | | | | | | Summary: Specifcally we want the MinGW compiler to use ISO print format specfifiers. Test Plan: Validate on Linux, OS X and Windows Reviewers: Phyx, austin, bgamari, simonmar Reviewed By: bgamari, simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2192
* rts: Replace `nat` with `uint32_t`Erik de Castro Lopo2016-05-051-5/+5
| | | | | | | | | | | | The `nat` type was an alias for `unsigned int` with a comment saying it was at least 32 bits. We keep the typedef in case client code is using it but mark it as deprecated. Test Plan: Validated on Linux, OS X and Windows Reviewers: simonmar, austin, thomie, hvr, bgamari, hsyl20 Differential Revision: https://phabricator.haskell.org/D2166
* Linker: Fix implicit function declaration warning on OS XErik de Castro Lopo2016-04-291-4/+1
| | | | | | | | | | | | Introduced in commit 177aec697b3. Test Plan: Validate on OSX and Linux. Reviewers: austin, bgamari, hvr Subscribers: goldfire, thomie Differential Revision: https://phabricator.haskell.org/D2140
* Linker: Clean up #if USE_MMAP usageErik de Castro Lopo2016-04-171-58/+52
| | | | | | | | | | | | | | | Test Plan: - Run tests on x86_64/linux, x86_64/darwin and powerpc/linux - Cross compile rts/Linker.c with the i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc Linux to Windows cross-compilers. Reviewers: hvr, austin, thomie, bgamari, simonmar, Phyx Reviewed By: Phyx Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1437
* Add Windows import library support to the Runtime LinkerTamar Christina2016-04-171-136/+249
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Import libraries are files ending in `.dll.a` and `.lib` depending on which compiler creates them (GCC, vs MSVC). Import Libraries are standard `archive` files that contain object files. These object files can have two different formats: 1) The normal COFF Object format for object files (contains all ascii data and very little program code, so do not try to execute.) 2) "short import" format which just contains a symbol name and the dll in which the symbol can be found. Import Libraries are useful for two things: 1) Allowing applications that don't support dynamic linking to link against the import lib (non-short format) which then makes calls into the DLL by loading it at runtime. 2) Allow linking of mutually recursive dlls. if `A.DLL` requires `B.DLL` and vice versa, import libs can be used to break the cycle as they can be created from the expected exports of the DLLs. A side effect of having these two capabilities is that Import libs are often used to hide specific versions of DLLs behind a non-versioned import lib. e.g. GCC_S.a (non-conventional import lib) will point to the correct `libGCC` DLL. With this support Windows Haskell files can now just link to `-lGCC_S` and not have to worry about what the actual name of libGCC is. Also third party libraries such as `icuuc` use import libs to forward to versioned DLLs. e.g. `icuuc.lib` points to `icuuc51.dll` etc. Test Plan: ./validate Two new tests added T11072gcc T11072msvc Two binary files have been added to the test folder because the "short" import library format doesn't seem to be creatable via `dlltool` and requires Microsoft's `lib.exe`. Reviewers: bgamari, RyanGlScott, erikd, goldfire, austin, hvr Reviewed By: RyanGlScott, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1696 GHC Trac Issues: #11072
* Linker: Fix signedness mismatchBen Gamari2016-04-151-2/+2
| | | | | | | | | | | | | | Test Plan: Validate on OS X Reviewers: erikd, austin, Phyx Reviewed By: austin, Phyx Subscribers: Phyx, thomie Differential Revision: https://phabricator.haskell.org/D2110 GHC Trac Issues: #11828
* Add linker notesTamar Christina2016-04-111-0/+13
| | | | | | | | | | | | Summary: Add linker notes following #11223 and D1805 Reviewers: austin, bgamari, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2102 GHC Trac Issues: #11223
* Change runtime linker to perform lazy loading of symbols/sectionsTamar Christina2016-04-111-92/+353
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The Runtime Linker is currently eagerly loading all object files on all platforms which do not use the system linker for `GHCi`. The problem with this approach is that it requires all symbols to be found. Even those of functions never used/called. This makes the number of libraries required to link things like `mingwex` quite high. To work around this the `rts` was relying on a trick. It itself was compiled with `MingW64-w`'s `GCC`. So it was already linked against `mingwex`. As such, it re-exported the symbols from itself. While this worked it made it impossible to link against `mingwex` in user libraries. And with this means no `C99` code could ever run in `GHCi` on Windows without having the required symbols re-exported from the rts. Consequently this rules out a large number of packages on Windows. SDL2, HMatrix etc. After talking with @rwbarton I have taken the approach of loading entire object files when a symbol is needed instead of doing the dependency tracking on a per symbol basis. This is a lot less fragile and a lot less complicated to implement. The changes come down to the following steps: 1) modify the linker to and introduce a new state for ObjectCode: `Needed`. A Needed object is one that is required for the linking to succeed. The initial set consists of all Object files passed as arguments to the link. 2) Change `ObjectCode`'s to be indexed but not initialized or resolved. This means we know where we would load the symbols, but haven't actually done so. 3) Mark any `ObjectCode` belonging to `.o` passed as argument as required: ObjectState `NEEDED`. 4) During `Resolve` object calls, mark all `ObjectCode` containing the required symbols as `NEEDED` 5) During `lookupSymbol` lookups, (which is called from `linkExpr` and `linkDecl` in `GHCI.hs`) is the symbol is in a not-yet-loaded `ObjectCode` then load the `ObjectCode` on demand and return the address of the symbol. Otherwise produce an unresolved symbols error as expected. 6) On `unloadObj` we then change the state of the object and remove it's symbols from the `reqSymHash` table so it can be reloaded. This change affects all platforms and OSes which use the runtime linker. It seems there are no real perf tests for `GHCi`, but performance shouldn't be impacted much. We gain a lot of time not loading all `obj` files, and we lose some time in `lookupSymbol` when we're finding sections that have to be loaded. The actual finding itself is O(1) (Assuming the hashtnl is perfect) It also consumes slighly more memory as instead of storing just the address of a symbol I also store some other information, like if the symbol is weak or not. This change will break any packages relying on renamed POSIX functions that were re-named and re-exported by the rts. Any packages following the proper naming for functions as found on MSDN will work fine. Test Plan: ./validate on all platforms which use the Runtime linker. Reviewers: thomie, rwbarton, simonmar, erikd, bgamari, austin, hvr Reviewed By: erikd Subscribers: kgardas, gridaphobe, RyanGlScott, simonmar, rwbarton, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D1805 GHC Trac Issues: #11223
* Reduce fragmentation from m32_allocatorBartosz Nitka2016-03-071-4/+24
| | | | | | | | | | | | | | | | | | | | This patch brings in two improvements: a) m32_allocator will now reuse the pages that are no longer used by anyone else. b) m32_allocator will preallocate the "filling" area, so that the pages it allocates end up as a big chunk instead of being allocated on demand in random places, fragmenting the precious lower 2G address space. Test Plan: testsuite - 3 tests failing with substTy asserts Reviewers: ezyang, austin, bgamari, erikd, hsyl20, simonmar Reviewed By: hsyl20, simonmar Subscribers: hvr, thomie Differential Revision: https://phabricator.haskell.org/D1976
* Fix Windows build after D1874Tamar Christina2016-02-021-2/+24
| | | | | | | | | | | | | | Windows uses wchar_t* for paths. The code committed won't compile for Windows as the types are incorrect and the types in the branches of the ternary operator aren't consistent. Test Plan: ./validate --fast Reviewers: austin, rwbarton, erikd, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1878
* Fix runtime linker error message when old symbol had no ownerReid Barton2016-02-011-0/+1
| | | | | | | | | | | | Test Plan: Actually run validate. This fixes test linker_error3. Reviewers: austin, erikd, bgamari Reviewed By: erikd, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1874
* When encountering a duplicate symbol, show source of the first symbolReid Barton2016-01-311-1/+5
| | | | | | | | | | | | Test Plan: Used this to track down an issue I was having. Reviewers: simonmar, austin, erikd, bgamari Reviewed By: erikd, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1863
* Show error message for unknown symbol on Elf_Rel platformsReid Barton2016-01-251-1/+0
| | | | | | | | | | | | Summary: This is already the behavior on Elf_Rela platforms, and is helpful. Reviewers: simonmar, austin, bgamari, erikd Reviewed By: erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1841
* Remove lookup of sections by name instead use the index numbers as offsetsTamar Christina2016-01-141-63/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch comes from @awson {{{ Playing with `-fsplit-sections` on Windows I've found a pile of ancient (it was borrowed from Hugs interpreter code and I don't even know when was it created), absolutely redundant and plain wrong code in RTS linker. Technically it is a bug, but it doesn't break things when used with current Windows binutils with no special linker scripts involved. OTOH, it slows down runtime linker on Windows noticeably and thus can be considered as a performance bug. The nice side-effect for existing users is that GHCi now loads compiled object code much faster on Windows. }}} More specifically, sections were being looked up by name by doing a loop over all sections until the section with the given name is found. The new approach uses the section index and finds the section in O(1) time based on information gathered when we originally processed the section Test Plan: ./validate (was run on GHC x86) Reviewers: austin, awson, erikd, thomie, bgamari Reviewed By: thomie, bgamari Subscribers: awson, #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D1773 GHC Trac Issues: #11388
* Linker: Define ELF_64BIT for aarch64_HOST_ARCHErik de Castro Lopo2016-01-111-0/+2
| | | | | | | | | | | | Test Plan: Build on x86_64 and AArch64 Reviewers: hvr, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1759
* Linker: Move helpers to #ifdefBen Gamari2016-01-041-11/+15
| | | | Otherwise Clang seems to complain about unused static definitions.
* Linker: ARM: Don't change to BLX if jump needed veneerBen Gamari2016-01-041-2/+5
| | | | Since we produce ARM veneer.
* Linker: Use contiguous mmapping on ARMBen Gamari2016-01-031-3/+11
| | | | | | | | | ARM has a 24-bit relative jump offset just like PowerPC. Ensure that symbols don't get too far from their symbol extras. See #11340. Differential Revision: https://phabricator.haskell.org/D1728
* Linker: Make debugging output a bit more readableBen Gamari2016-01-031-1/+1
| | | | Differential Revision: https://phabricator.haskell.org/D1728
* Linker: ARM: Refactor relocation handlingBen Gamari2016-01-031-39/+54
| | | | | | | | | | | | | | | | This refactors handling of R_ARM_CALL, R_ARM_JUMP24, R_ARM_MOVW_NC, and R_ARM_MOVT relocations to follow the LLVM LLD implementation. The "ELF for ARM" specification is (like most documents of this type, sadly) a bit vague in some areas, so it seems safest to follow the behavior of a trusted implementation like LLD, which is remarkable in its clarity.. Moreover, we now throw a proper error message when a jump to a symbol extra is out of range. This is great improvement over the previous behavior, which ended in a segfault. See #11340. Differential Revision: https://phabricator.haskell.org/D1728
* Linker: ARM: Ensure that cache flush covers all symbol extrasBen Gamari2016-01-031-1/+3
| | | | | | Previously part of the last symbol extra wasn't covered. Differential Revision: https://phabricator.haskell.org/D1728
* rts/Linker.c: mark ia64 as 64-bit ELF, drop unused branchesSergei Trofimovich2015-12-301-4/+6
| | | | Signed-off-by: Sergei Trofimovich <siarheit@google.com>
* rts/Linker(ARM): Ensure all code sections are flushed from cacheBen Gamari2015-12-281-1/+9
| | | | | | | | | | | | Test Plan: Validate with T12299 Reviewers: hsyl20, austin, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1708 GHC Trac Issues: #11299
* RTS: Detect powerpc64le as ELF 64-bit systemPeter Trommler2015-12-271-1/+1
| | | | | | | | | | | | | | Test Plan: validate Reviewers: simonmar, erikd, austin, bgamari Reviewed By: austin, bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1672 GHC Trac Issues: #11269
* Linker(ELF): Fix addProddableBlocks usageBen Gamari2015-12-271-1/+1
| | | | | | | | | | | | | | | The range marked as proddable didn't actually match the range that we mapped. This fixed `ghc-api/T8628` et al on ARM. Test Plan: Validate Reviewers: austin, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1700 GHC Trac Issues: #11289
* Linker: Reenable Thumb supportBen Gamari2015-12-271-4/+24
| | | | | I believe this ought to be okay now since we only produce ARM-encoded objects. Added a Note describing the state of things.
* Linker: Fix cut-and-paste error in debug outputBen Gamari2015-12-271-1/+1
|
* Fix GHCi segfault in Windows 32bitTamar Christina2015-12-221-6/+2
| | | | | | | | | | | | | | | | | | Summary: Add missing calling convention to function pointer, incorrect `cdecl` calling convention which should be `stdcall` on x86 was causing the stack to be corrupted. When it tried to return from the function the return pointer would be invalid. Test Plan: ./validate Reviewers: austin, erikd, bgamari, thomie Reviewed By: bgamari, thomie Differential Revision: https://phabricator.haskell.org/D1683 GHC Trac Issues: #11234
* rts: Remove space before argument list in ASSERTsBen Gamari2015-12-071-1/+1
| | | | | | | | | | Test Plan: Validate Reviewers: austin, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1569
* Use Autoconf's AC_USE_SYSTEM_EXTENSIONSHerbert Valerio Riedel2015-12-041-7/+0
| | | | | | | | | | | | | | | | | | | | | | This takes care of setting feature test macros (i.e. let Autoconf decide when those can be set safely) to allow subsequent Autoconf tests to better detect available OS features. This also includes a submodule update of unix which enables the use of `AC_USE_SYSTEM_EXTENSIONS` in there as well. Specifically, this takes care of setting `_GNU_SOURCE` (which allows to remove two occurences where it's set manually) and `_ALL_SOURCE` (which fixes issues on AIX). See also https://www.gnu.org/software/autoconf/manual/autoconf-2.69/html_node/Posix-Variants.html for details. At some point we may want to reconsider the purpose of "rts/PosixSource.h" and rely more on Autoconf instead.
* Fix archive loading on Windows by the runtime loaderTamar Christina2015-11-171-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The runtime loader is unable to find archive files `.a` shipping with the inplace `GCC`. It seems the issue is caused by `findArchive` being unable to find any archives that are shipped using the in-place `GCC`. - It works on Linux because `findArchive` would search the standard Linux include path. - It works during compilation because `GCC` can find it's own libraries (we explicitly tell it where to look for libraries using the `gcc` wrapper around `realgcc`) So fixing the issue means using `searchForLibUsingGcc` in `findArchive` as well, which will then find the correct file. The reason for the error as it is, is because if we can't locate the library using any of the methods we have, we assume it is a system dll, or something on the system search path. e.g. if trying to load `kernel32.dll`. There is a slight issue in that the `GHCi` code (incorrectly) favors `static archives` over `dynamic` ones ``` findDll `orElse` findArchive `orElse` tryGcc `orElse` tryGccPrefixed `orElse` assumeDll ``` This has the unwanted effect of when `kernel32` is specified as a lib, it will try to load `kernel32.a` instead of `kernel32.dll`. To solve this I have added another search function that is able to search the Windows search paths using `SearchPath` in order to find if it is a dll on the system search path. The new search order is: ``` findDll `orElse` findSysDll `orElse` tryGcc `orElse` findArchive `orElse` assumeDll ``` (`tryGccPrefixed` was rolled into `tryGcc` so it is no longer needed at top level) Test Plan: ./validate added new windows tests T3242 Reviewers: thomie, erikd, hvr, austin, bgamari Reviewed By: thomie, erikd, bgamari Differential Revision: https://phabricator.haskell.org/D1455 GHC Trac Issues: #3242
* fix RTS Linker on platforms without SHN_XINDEX supportKarel Gardas2015-11-111-6/+30
| | | | | | | | | | | | | | | Summary: This patch fixes RTS Linker compilation issues on platforms where SHN_XINDEX is not defined. Tested on OpenBSD. When SHN_XINDEX is not defined, the code reverts to the old behavior, that means behavior of the Linker before D1357 which added SHN_XINDEX based functionality. Reviewers: bgamari, austin, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1446
* Allow the GHCi Linker to resolve related dependencies when loading DLLsTamar Christina2015-11-071-17/+182
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: GHCi does not correctly tell the Windows Loader how to handle dependencies to DLL's that are not on the standard Windows load path: 1. The directory from which the application loaded. 2. The current directory. 3. The system directory. Use the GetSystemDirectory function to get the path of this directory. 4. The 16-bit system directory. There is no function that obtains the path of this directory, but it is searched. 5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory. 6. The directories that are listed in the PATH environment variable. Note that this does not include the per-application path specified by the AppPaths registry key. The App Paths key is not used when computing the DLL search path. So what this means is given two DLLs `A` and `B` and `B` depending on `A`. If we put both DLLs into a new folder bin and then call GHC with: `ghc -L$(PWD)/bin -lB` the loading will fail as the Windows loader will try to load the dependency of `B` and fail since it cannot find `A`. *IMPORTANT* this patch drops XP Support. The APIs being used were natively added to Windows 8+ and backported to Windows 7 and Vista via a mandatory security patch (in 2011). This means that there is a chance that KB2533623 has not been installed on certain machines. For those machines I display a warning and temporarily expand the `PATH` to allow it to load. This patch will make sure that paths provided by the user with `-L` *and* the folder in which a DLL is found are added to the search path. It does so using one of two methods depending upon how new of a Windows version we are running on: - If the APIs are available it will use `addDllDirectory` and `removeDllDirectory`. The order of which these directories are searched is nondeterministic. - If the APIs are not available it means that we're running on a pretty old unpatched machine. But if it's being used in an environment with no internet access it may be the case. So if the APIs are not available we temporarily extend the `PATH` with the directories. A warning is also displayed to the user informing them that the linking may fail, and if it does, install the needed patch. The `PATH` variable has limitations. Test Plan: ./validate Added two new test T10955 and T10955dyn Reviewers: erikd, bgamari, thomie, hvr, austin Reviewed By: erikd, thomie Subscribers: #ghc_windows_task_force Differential Revision: https://phabricator.haskell.org/D1340 GHC Trac Issues: #10955
* Make GHCi & TH work when the compiler is built with -profSimon Marlow2015-11-071-3/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Amazingly, there were zero changes to the byte code generator and very few changes to the interpreter - mainly because we've used good abstractions that hide the differences between profiling and non-profiling. So that bit was pleasantly straightforward, but there were a pile of other wibbles to get the whole test suite through. Note that a compiler built with -prof is now like one built with -dynamic, in that to use TH you have to build the code the same way. For dynamic, we automatically enable -dynamic-too when TH is required, but we don't have anything equivalent for profiling, so you have to explicitly use -prof when building code that uses TH with a profiled compiler. For this reason Cabal won't work with TH. We don't expect to ship a profiled compiler, so I think that's OK. Test Plan: validate with GhcProfiled=YES in validate.mk Reviewers: goldfire, bgamari, rwbarton, austin, hvr, erikd, ezyang Reviewed By: ezyang Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1407 GHC Trac Issues: #4837, #545
* Linker: #ifdef cleanupErik de Castro Lopo2015-11-041-40/+11
| | | | | | | | | | | | | Test Plan: - Run tests on x86_64/linux and powerpc/linux - Cross compile rts/Linker.c with the i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc Linux to Windows cross-compilers. Reviewers: bgamari, austin, hvr, Phyx Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1429
* get rid of Elf32/Elf64_Section as this is a non-portable Linux-ism.Karel Gardas2015-11-021-3/+1
| | | | | | | | | | | | | | | | Summary: D1357 introduces usage of Elf32_Section/Elf64_Section in RTS linker code. Unfortunately this is a non-portable Linux-ism and such types are not defined anywhere except the Linux-land probably. I've checked Solaris 11.2, Solaris 11.3, FreeBSD 10.1, NetBSD 6.1.5 and OpenBSD current. The fix is easy to use `unsigned short' as this is also an underlying type of those Elf*_Section defines in Linux. Reviewers: olsner, austin, bgamari, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1419
* Linker: More uint64_t to uintptr_t fixesErik de Castro Lopo2015-11-011-2/+2
| | | | | | | | | | | | | | | Need to use `uintptr_t` on PowerPC and possibly other 32 bit architectures. Test Plan: Validate on x86_64 and powerpc Linux Reviewers: austin, hvr, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1412
* Add rts/Linker support for more than 64k sectionsSimon Brenner2015-11-011-39/+141
| | | | | | | | | | | | | | | | | | | Since some ELF fields ran out of range to represent that many sections, they've been extended with magic numbers that indicate that the full value is stored in another field. This will be necessary for GHCi with -split-sections on ELF platforms that don't use GNU ld. Reviewers: austin, bgamari, simonmar, erikd Reviewed By: bgamari, simonmar, erikd Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1357 GHC Trac Issues: #8405
* Linker: Clean up USE_MMAP usageErik de Castro Lopo2015-10-301-33/+31
| | | | | | | | | | | | Test Plan: Validate on powerpc/linux, x86_64/linux and x86_64/darwin Reviewers: austin, bgamari, thomie Reviewed By: thomie Subscribers: Phyx, thomie Differential Revision: https://phabricator.haskell.org/D1398
* Linker: Fix type in m32_free_internalErik de Castro Lopo2015-10-301-1/+1
| | | | | | | | | | | | | | | | | | | | | The code: uint64_t c = __sync_sub_and_fetch((uint64_t*)addr, 1); was causing GCC to emit atomic instructions for 64 bit values which are not available on PowerPC. However, since PowerPC only has a 32 bit address space, use of a 64 bit value is superflous. Switching the type from `uint64_t` to `uintptr_t` should simply do the correct thing on all 32 and 64 bit architectures. Reviewers: austin, bgamari, simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1399 GHC Trac Issues: #11036
* rts/Linker.c: Drop support for legacy OS X dyn loadingErik de Castro Lopo2015-10-291-15/+1
| | | | | | | | | | | | | Drop support for old OS X (OS X 10.2 and earlier) dynamic linking. 10.3 was released in 2003. Test Plan: Validate on OS X and Linux. Reviewers: bgamari, thomie, austin Reviewed By: thomie, austin Differential Revision: https://phabricator.haskell.org/D1393
* Remove cygwin32_HOST_OS #ifdefsErik de Castro Lopo2015-10-261-17/+1
| | | | | | | | | | | | | | | | | Build system support for Cygwin was removed in b6be81b841. Test Plan: - Validate on x86_64/linux - Cross-compile rts/RtsSymbols.c and rts/Linker.c to Windows using the i686-w64-mingw32-gcc and x86_64-w64-mingw32-gcc cross compilers. Reviewers: hvr, austin, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D1371