1. 05 Feb, 2020 1 commit
    • Tamar Christina's avatar
      SysTools: Use "process job" when spawning processes on Windows · 463b9b86
      Tamar Christina authored and Ben Gamari's avatar Ben Gamari committed
      GHC should make calls using process jobs when calling out to GCC and LD.
      The reason is these use the exec () family of posix functions.  Window's
      process model doesn't allow replacement of processes so this is emulated
      by creating a new process and immediately exiting the old one.  Because
      of this when using normal Windows wait functions you would return even
      without the child process having finished.  In this case if you are
      depending on data from the child you will enter a race condition.
      
      The usual fix for this is to use process jobs and wait for the
      termination of all children that have ever been spawn by the process you
      called. But also waiting for the freeing of all resources.
      463b9b86
  2. 31 Jan, 2020 1 commit
    • Sylvain Henry's avatar
      Refactor package related code · 29c701c1
      Sylvain Henry authored and  Marge Bot's avatar Marge Bot committed
      The package terminology is a bit of a mess. Cabal packages contain
      components. Instances of these components when built with some
      flags/options/dependencies are called units. Units are registered into
      package databases and their metadata are called PackageConfig.
      
      GHC only knows about package databases containing units. It is a sad
      mismatch not fixed by this patch (we would have to rename parameters
      such as `package-id <unit-id>` which would affect users).
      
      This patch however fixes the following internal names:
      
      - Renames PackageConfig into UnitInfo.
      - Rename systemPackageConfig into globalPackageDatabase[Path]
      - Rename PkgConfXX into PkgDbXX
      - Rename pkgIdMap into unitIdMap
      - Rename ModuleToPkgDbAll into ModuleNameProvidersMap
      - Rename lookupPackage into lookupUnit
      - Add comments on DynFlags package related fields
      
      It also introduces a new `PackageDatabase` datatype instead of
      explicitly passing the following tuple: `(FilePath,[PackageConfig])`.
      
      The `pkgDatabase` field in `DynFlags` now contains the unit info for
      each unit of each package database exactly as they have been read from
      disk. Previously the command-line flag `-distrust-all-packages` would
      modify these unit info. Now this flag only affects the "dynamic"
      consolidated package state found in `pkgState` field. It makes sense
      because `initPackages` could be called first with this
      `distrust-all-packages` flag set and then again (using ghc-api) without
      and it should work (package databases are not read again from disk when
      `initPackages` is called the second time).
      
      Bump haddock submodule
      29c701c1
  3. 27 Dec, 2019 1 commit
  4. 24 Nov, 2019 1 commit
  5. 23 Nov, 2019 1 commit
    • Ryan Scott's avatar
      Prevent -optc arguments from being duplicated in reverse order (#17471) · 15f1dc33
      Ryan Scott authored and  Marge Bot's avatar Marge Bot committed
      This reverts a part of commit
      7bc5d6c6 that causes all arguments
      to `-optc` (and `-optcxx`) to be passed twice to the C/C++ compiler,
      once in reverse order and then again in the correct order. While
      passing duplicate arguments is usually harmless it can cause breakage
      in this pattern, which is employed by Hackage libraries in the wild:
      
      ```
      ghc Foo.hs foo.c -optc-D -optcFOO
      ```
      
      As `FOO -D -D FOO` will cause compilers to error.
      
      Fixes #17471.
      15f1dc33
  6. 04 Nov, 2019 1 commit
  7. 23 Oct, 2019 1 commit
    • Andreas Klebinger's avatar
      Make dynflag argument for withTiming pure. · 6beea836
      Andreas Klebinger authored and  Marge Bot's avatar Marge Bot committed
      19 times out of 20 we already have dynflags in scope.
      
      We could just always use `return dflags`. But this is in fact not free.
      When looking at some STG code I noticed that we always allocate a
      closure for this expression in the heap. Clearly a waste in these cases.
      
      For the other cases we can either just modify the callsite to
      get dynflags or use the _D variants of withTiming I added which
      will use getDynFlags under the hood.
      6beea836
  8. 05 Oct, 2019 3 commits
  9. 11 Sep, 2019 1 commit
    • Niklas Hambüchen's avatar
      linker: Move -optl flags to end of linker invocation. · 60c26403
      Niklas Hambüchen authored and  Marge Bot's avatar Marge Bot committed
      Until now, giving `-optl` linker flags to `ghc` on the command line placed
      them in the wrong place in the `ld` command line:
      
      They were given before all the Haskell libararies, when they should appear after.
      
      Background:
      Most linkers like `ld.bfd` and `ld.gold`, but not the newer LLVM `lld`, work in
      a way where the order of `-l` flags given matters; earlier `-lmylib1` flags are
      supposed to create "holes" for linker symbols that are to be filled with later
      `lmylib2` flags that "fill the holes" for these symbols.
      
      As discovered in
      https://github.com/haskell/cabal/pull/5451#issuecomment-518001240,
      the `-optl` flags appeared before e.g. the
      
          -lHStext-1.2.3.1
          -lHSbinary-0.8.6.0
          -lHScontainers-0.6.0.1
      
      flags that GHC added at the very end.
      
      Haskell libraries typically depend on C libraries, so `-lHS*` flags will create
      holes for the C libraries to fill in, but that only works when those libraries'
      `-l` flags are given **after** the `-lHS*` flags; until now they were given
      before, which was wrong.
      
      This meant that Cabal's `--ld-options` flag and `ld-options` `.cabal` file field
      were pretty ineffective, unless you used the `--ld-option=--start-group` hack as
      (https://github.com/haskell/cabal/pull/5451#issuecomment-406761676) that
      convinces the classical linkers to not be dependent on the order of linker flags
      given.
      
      This commit fixes the problem by simply flipping the order, putting `-optl`
      flags at the end, after Haskell libraries.
      
      The code change is effectively only `args1 ++ args` -> `args ++ args1`
      but the commit also renames the variables for improved clarity.
      
      Simple way to test it:
      
          ghc --make Main.hs -fforce-recomp -v -optl-s
      
      on a `Main.hs` like:
      
          import qualified Data.Set as Set
          main = print $ Set.fromList "hello"
      60c26403
  10. 09 Sep, 2019 1 commit
    • Ryan Scott's avatar
      Replace queryCygwinTerminal with Win32's isMinTTYHandle · 270fbe85
      Ryan Scott authored and  Marge Bot's avatar Marge Bot committed
      `SysTools.Terminal.queryCygwinTerminal` now exists in the `Win32`
      library under the name `isMinTTYHandle` since `Win32-2.5.0.0`.
      (GHC 8.4.4 ships with `Win32-2.6.1.0`, so this is well within GHC's
      support window.) We can therefore get replace `queryCygwinTerminal`
      with `isMinTTYHandle` and delete quite a bit of code from
      `SysTools.Terminal` in the process.
      
      Along the way I needed to replace some uses of `#if defined x` with
      `#if defined(x)` to please the CI linters.
      270fbe85
  11. 29 Aug, 2019 1 commit
    • Ömer Sinan Ağacan's avatar
      Fix LLVM version check yet again · bf9dfe1c
      Ömer Sinan Ağacan authored and  Marge Bot's avatar Marge Bot committed
      There were two problems with LLVM version checking:
      
      - The parser would only parse x and x.y formatted versions. E.g. 1.2.3
        would be rejected.
      
      - The version check was too strict and would reject x.y formatted
        versions. E.g. when we support version 7 it'd reject 7.0 ("LLVM
        version 7.0") and only accept 7 ("LLVM version 7").
      
      We now parse versions with arbitrarily deep minor numbering (x.y.z.t...)
      and accept versions as long as the major version matches the supported
      version (e.g. 7.1, 7.1.2, 7.1.2.3 ...).
      bf9dfe1c
  12. 13 Jul, 2019 1 commit
    • Alp Mestanogullari's avatar
      compiler: trace SysTools commands to emit start/stop eventlog markers · 688a1b89
      Alp Mestanogullari authored and  Marge Bot's avatar Marge Bot committed
      This patch was motivated by some performance characterization work done
      for #16822, where we suspected that GHC was spending a lot of time waiting
      on the linker to be done. (That turned out to be true.)
      
      The tracing is taken care of by ErrUtils.withTiming, so this patch just defines
      and uses a little wrapper around that function in all the helpers for
      calling the various systools (C compiler, linker, unlit, ...).
      
      With this patch, assuming a GHC executable linked against an eventlog-capable
      RTS (RTS ways that contain the debug, profiling or eventlog way units), we can
      measure how much time is spent in each of the SysTools when building hello.hs
      by simply doing:
      
        ghc hello.hs -ddump-timings +RTS -l
      
      The event names are "systool:{cc, linker, as, unlit, ...}".
      688a1b89
  13. 24 Jun, 2019 1 commit
    • Erik de Castro Lopo's avatar
      Fixes for LLVM 7 · 71aca77c
      Erik de Castro Lopo authored and  Marge Bot's avatar Marge Bot committed
      LLVM version numberinf changed recently. Previously, releases were numbered
      4.0, 5.0 and 6.0 but with version 7, they dropped the redundant ".0".
      
      Fix requires for Llvm detection and some code.
      71aca77c
  14. 20 Jun, 2019 2 commits
  15. 14 Jun, 2019 1 commit
    • Ben Gamari's avatar
      Maintain separate flags for C++ compiler invocations · 7bc5d6c6
      Ben Gamari authored and  Marge Bot's avatar Marge Bot committed
      Previously we would pass flags intended for the C compiler to the C++
      compiler (see #16738). This would cause, for instance, `-std=gnu99` to
      be passed to the C++ compiler, causing spurious test failures. Fix this
      by maintaining a separate set of flags for C++ compilation invocations.
      7bc5d6c6
  16. 07 Jun, 2019 1 commit
    • John Ericson's avatar
      Factor out 'getLibDir' / 'getBaseDir' into a new GHC.BaseDir ghc-boot module · 387050d0
      John Ericson authored and  Marge Bot's avatar Marge Bot committed
      ghc-pkg and ghc already both needed this. I figure it is better to
      deduplicate, especially seeing that changes to one (FreeBSD CPP) didn't
      make it to the other.
      
      Additionally in !1090 I make ghc-pkg look up the settings file, which
      makes it use the top dir a bit more widely. If that lands, any
      difference in the way they find the top dir would be more noticable.
      
      That change also means sharing more code between ghc and ghc-package
      (namely the settings file parsing code), so I'd think it better to get
      off the slipperly slope of duplicating code now.
      387050d0
  17. 08 Apr, 2019 1 commit
  18. 15 Mar, 2019 1 commit
  19. 06 Mar, 2019 1 commit
    • Ben Gamari's avatar
      Rip out object splitting · 37f257af
      Ben Gamari authored and  Marge Bot's avatar Marge Bot committed
      The splitter is an evil Perl script that processes assembler code.
      Its job can be done better by the linker's --gc-sections flag. GHC
      passes this flag to the linker whenever -split-sections is passed on
      the command line.
      
      This is based on @DemiMarie's D2768.
      
      Fixes Trac #11315
      Fixes Trac #9832
      Fixes Trac #8964
      Fixes Trac #8685
      Fixes Trac #8629
      37f257af
  20. 08 Dec, 2018 1 commit
  21. 22 Nov, 2018 1 commit
  22. 17 Nov, 2018 1 commit
  23. 03 Oct, 2018 1 commit
    • Ryan Scott's avatar
      Drop GHC 8.2 compatibility · a838ae37
      Ryan Scott authored
      Summary:
      GHC 8.6.1 is out, so now GHC's support window only extends
      back to GHC 8.4. This means we can delete gobs of code that were
      only used for GHC 8.2 support. Hooray!
      
      Test Plan: ./validate
      
      Reviewers: bgamari, Phyx, erikd
      
      Reviewed By: bgamari, Phyx
      
      Subscribers: rwbarton, erikd, carter
      
      Differential Revision: https://phabricator.haskell.org/D5192
      a838ae37
  24. 28 Sep, 2018 1 commit
    • Simon Marlow's avatar
      Add -fkeep-cafs · df67f95b
      Simon Marlow authored and Krzysztof Gogolewski's avatar Krzysztof Gogolewski committed
      Summary:
      I noticed while playing around with
      https://github.com/fbsamples/ghc-hotswap/ that the main binary needs to
      have a custom main function to set `config.keep_cafs = true` when
      initialising the runtime. This is pretty annoying, it means an extra
      C file with some cryptic incantations in it, and a `-no-hs-main` flag.
      
      So I've replaced this with a link-time flag to GHC, `-fkeep-cafs` that
      does the same thing.
      
      Test Plan:
      New unit test that tests for the RTS's GC'd CAFs assertion, and also
      the -keep-cafs flag.
      
      Reviewers: bgamari, osa1, erikd, noamz
      
      Reviewed By: osa1
      
      Subscribers: rwbarton, carter
      
      Differential Revision: https://phabricator.haskell.org/D5183
      df67f95b
  25. 25 Aug, 2018 1 commit
    • Tamar Christina's avatar
      ghc, ghc-pkg: use getExecutablePath on Windows when base >= 4.11.0 · c523525b
      Tamar Christina authored
      Summary:
      This completes the work started in D4227 by using just 'getExecutablePath'
      in ghc and ghc-pkg when building with base >= 4.11.0.
      
      On the long term, we will be able to simply kill the existing code that
      follows (or not) symlinks and just get this behaviour for free from
      getExecutable. For now we however have to require base >= 4.11.0 to be able
      to just use getExecutablePath under Windows, and use the current code when
      building with an older base.
      
      Original code by @alpmestan commandeering since patch has been stale
      and bug remains open.
      
      Test Plan: Validate
      
      Reviewers: angerman, bgamari, erikd, alpmestan
      
      Reviewed By: bgamari
      
      Subscribers: carter, rwbarton, thomie
      
      GHC Trac Issues: #14483
      
      Differential Revision: https://phabricator.haskell.org/D4229
      c523525b
  26. 27 Jul, 2018 1 commit
    • Michael Sloan's avatar
      Modifications to support loading GHC into GHCi · 60ecf43a
      Michael Sloan authored and Ben Gamari's avatar Ben Gamari committed
      This change was previously part of
      [D4904](https://phabricator.haskell.org/D4904), but is being split off
      to aid in getting this reviewed and merged.
      
      * The compiler code is built with `NoImplicitPrelude`, but GHCi's
        modules are incompatible with it. So, this adds the pragma to all GHCi
        modules that didn't have it, and adds imports of Prelude.
      
      * In order to run GHC within itself, a `call of 'initGCStatistics`
        needed to be skipped. This uses CPP to skip it when
        `-DGHC_LOADED_INTO_GHCI` is set.
      
      * There is an environment variable workaround suggested by Ben Gamari
        [1], where `_GHC_TOP_DIR` can be used to specify GHC's top dir if `-B`
        isn't provided.  This can be used to solve a problem where the GHC being
        run within GHCi attempts to look in `inplace/lib/lib/` instead of
        `inplace/lib/`.
      
      [1]: https://phabricator.haskell.org/D4904#135438
      
      Reviewers: goldfire, bgamari, erikd, alpmestan
      
      Reviewed By: alpmestan
      
      Subscribers: alpmestan, lelf, rwbarto...
      60ecf43a
  27. 20 Jun, 2018 1 commit
  28. 17 Apr, 2018 1 commit
    • Alp Mestanogullari's avatar
      Introduce a $tooldir variable for nicer toolchain detection on Windows · 5d768464
      Alp Mestanogullari authored and Tamar Christina's avatar Tamar Christina committed
      Summary:
      This patch affects several files that affect how we detect mingw and perl
      on Windows. The initial motivation is:
      
          https://github.com/snowleopard/hadrian/issues/564
      
      where, with Hadrian building relocatable (non-inplace) GHCs, the current
      detection mechanism falls short by e.g only trying $topdir/../mingw. But
      in Hadrian, for reasons given in that issue, we would need to store e.g mingw
      under $topdir/../../mingw except for binary distributions, where we want
      to follow the existing structure, in which case $topdir/../mingw is correct. So
      we need to support both, which is what this patch hopefully implements.
      
      Test Plan: ./validate
      
      Reviewers: Phyx, hvr, bgamari, erikd
      
      Reviewed By: Phyx
      
      Subscribers: snowleopard, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4598
      5d768464
  29. 26 Mar, 2018 1 commit
  30. 13 Mar, 2018 1 commit
    • Ryan Scott's avatar
      Drop GHC 8.0 compatibility · 152055a1
      Ryan Scott authored and David Feuer's avatar David Feuer committed
      GHC 8.4.1 is out, so now GHC's support window only extends
      back to GHC 8.2. This means we can delete gobs of code that were
      only used for GHC 8.0 support. Hooray!
      
      Test Plan: ./validate
      
      Reviewers: bgamari, erikd, dfeuer
      
      Reviewed By: bgamari, dfeuer
      
      Subscribers: alexbiehl, dfeuer, rwbarton, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D4492
      152055a1
  31. 21 Jan, 2018 1 commit
    • Ben Gamari's avatar
      SysTools: Add detection support for LLD linker · 6c0db98b
      Ben Gamari authored
      I noticed while trying to test against LLVM 5.0 that GHC would throw "Couldn't
      figure out linker information" warnings due to LLD being chosen by configure.
      Adding detection support to silence these is simple enough, let's just do it.
      6c0db98b
  32. 15 Jan, 2018 1 commit
  33. 23 Nov, 2017 1 commit
  34. 10 Oct, 2017 1 commit
    • Tamar Christina's avatar
      Split SysTools up some · e51e565d
      Tamar Christina authored
      Summary:
      SysTools and DriverTools have an annoying mutual dependency.
      They also each contain pieces of the linker. In order for
      changes to be shared between the library and the exe linking
      code this dependency needs to be broken in order to avoid
      using hs-boot files.
      
      Reviewers: austin, bgamari, erikd
      
      Reviewed By: bgamari
      
      Subscribers: rwbarton, thomie
      
      Differential Revision: https://phabricator.haskell.org/D4071
      e51e565d
  35. 19 Sep, 2017 2 commits
  36. 17 Dec, 2016 1 commit
    • Rufflewind's avatar
      Windows: Improve terminal detection mechanism · 3dbd2b09
      Rufflewind authored and Ben Gamari's avatar Ben Gamari committed
      The previous detection mechanism allowed environment variables (ANSICON,
      ConEmuANSI, TERM) to supersede the fact that the stderr is not a
      terminal, which is probably what led to color codes appearing in the
      stderr of the tests (see: 847d2293).
      
      This commit changes the detection mechanism to detect Cygwin/MSYS2
      terminals in a more reliable manner, avoiding the use of environment
      variables entirely.
      
      Test Plan: validate
      
      Reviewers: Phyx, austin, erikd, bgamari
      
      Reviewed By: Phyx, bgamari
      
      Subscribers: RyanGlScott, thomie
      
      Differential Revision: https://phabricator.haskell.org/D2809
      3dbd2b09