Fix #8641, creating directories when we have stubs.

Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
(cherry picked from commit c7498bbdaa74dadd976c75c4e303c2050aa78277)
Small issue with signatures in a TH splice (fixes Trac #8932)

(cherry picked from commit d8d798b1b33ab0593ed03f193360b8725ba2c2ba)

Conflicts:
	testsuite/tests/th/all.T
Be less untruthful about the prototypes of external functions

GHC's generated C code uses dummy prototypes for foreign imports.  At the
moment these all claim to be (void), i.e. functions of zero arguments.  On
most platforms this doesn't matter very much: calls to these functions put
the parameters in the usual places anyway, and (with the exception of
varargs) things just work.

However, the ELFv2 ABI on ppc64 optimises stack allocation
(http://gcc.gnu.org/ml/gcc-patches/2013-11/msg01149.html): a call to a
function that has a prototype, is not varargs, and receives all parameters
in registers rather than on the stack does not require the caller to
allocate an argument save area.  The incorrect prototypes cause GCC to
believe that all functions declared this way can be called without an
argument save area, but if the callee has sufficiently many arguments then
it will expect that area to be present, and will thus corrupt the caller's
stack.  This happens in particular with calls to runInteractiveProcess in
libraries/process/cbits/runProcess.c.

The simplest fix appears to be to declare these external functions with an
unspecified argument list rather than a void argument list.  This is no
worse for platforms that don't care either way, and allows a successful
bootstrap of GHC 7.8 on little-endian Linux ppc64 (which uses the ELFv2
ABI).

Fixes #8965

Signed-off-by: Colin Watson <cjwatson@debian.org>
Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 5a31f231eebfb8140f9b519b166094d9d4fc2d79)
Add the powerpc64le architecture

This is ArchUnknown for now, as it requires some porting work over and
above powerpc64 due to such things as the different function calling
sequence in the ELFv2 ABI.  For now, an unregisterised port is better
than nothing.

Signed-off-by: Colin Watson <cjwatson@debian.org>
Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 8586f600613a6a99fee8fe707b00adab1a340641)
ghc: Do not add a space in '-U __PIC__'

GHC previously introduced a space here. However, this can in some cases
be interpreted as "-U __PIC__" - note that in shell, the -U would still
be recognized with an argument, but the argument would be " __PIC__",
with a space in front, as opposed to the single string '__PIC__'.

In practice most tools seem to handle this OK. But the Coverity Scan
analysis tool does not: it errors on the fact that ' __PIC__' is an
invalid CPP name to undefine.

With this, it seems the Coverity analysis tool can easily analyze the
entire GHC build.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 574ef4293b867609f2d28d85747e01f3ac0d052d)
Kill whitespace after cpp's `-I` flag

This clean-up is in a similiar spirit as 574ef4293b8676.

Signed-off-by: Herbert Valerio Riedel <hvr@gnu.org>
(cherry picked from commit 4ab8fc55eb6119dbba2f487c5a01d30a7c6ae113)
Zonk the existential type variables in tcPatSynDecl

This was just an omission, which showed up as Trac #8966

(cherry picked from commit 4dc9f9869bfc82fdb8bd61864859007873ebcc27)
Simplify and tidy up the handling of tuple names

This fixes Trac #8954.

There were actually three places where tuple occ-names
were parsed:
  - IfaceEnv.lookupOrigNameCache
  - Convert.isBuiltInOcc
  - OccName.isTupleOcc_maybe

I combined all three into TysWiredIn.isBuiltInOcc_maybe
Much nicer.

(cherry picked from commit 750271e61bdbaad50c19176406512e79abe404a8)

Conflicts:
	testsuite/tests/th/all.T
Honour the untouchability of kind variables

Trac #8985 showed up a major shortcoming in the kind unifier: it was
ignoring untoucability.  This has unpredictably-bad consequences;
notably, the skolem-escape check can fail.

There were two things wrong
 * TcRnMonad.isTouchableTcM was returning a constant value for kind variables
   (wrong), and even worse the constant was back-to-front (it was always False).

 * We weren't even calling isTouchableTcM in TcType.unifyKindX.

I'm not sure how this ever worked.

Merge to 7.8.3 in due course.

(cherry picked from commit e7f0ae7ff4f2199abe42f20bac825a7802bff466)
Test Trac #8985

(cherry picked from commit ff9f9a7f2e227fcda7b8a2f52ec8be66de2e76cd)
rts: Fix potential memory leak in ProfHeap.c

Discovered by Coverity. CID 43166.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 95da409719bab6f92229dc1a632c471e248d2fdd)
rts: Fix possible int overflow in resize_nursery

n_capabilities is declared as unsigned int (32bit), and so multiplication
is 32-bit before being stored in a 64bit integer (StgWord).

Instead, cast n_capabilities to StgWord before multiplying.

Discovered by Coverity. CID 43164.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 111b8454cc1b64da5b9816b89d79f44a8ae24355)
Check return value of sigaction

Issue discovered by Coverity scan, CID 43142.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit f2595fd9d03803874df792072292d792a2c03bce)
Fix potential out-of-bound memory access

Issue discovered by Coverity scan, CID 43165.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit fa0cbd297ba12e02273efcaa5f52fe76e10b7126)
Check correct variable for NULL

Issue discovered by Coverity scan, CID 43163. This should fix CID 43172 as a
side-effect as well.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 6ed7123dcc24c343a1ece85c7aa72ac1c34e6aff)
Fix memleak in hp2ps

Issue discovered by Coverity scan, CID 43167.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit f17dcf09a5797bbefe22aef7d4c508d1672484df)
Start 7.8.3 release notes

There are already quite a few bugfixes, I'll fill them out shortly.

Signed-off-by: Austin Seipp <austin@well-typed.com>
Mention TH pattern splices in 7.8.1 release notes
Fix scavenge_stack crash (#9045)

The new stg_gc_prim_p_ll stack frame was missing an info table.  This
is a regression since 7.6, because this stuff was part of a cleanup
that happened in 7.7.

(cherry picked from commit ab8bb4893be1896303f30d0f1adff8ea9c2470f6)
Allow a longer demand signature than arity

See Note [Demand analysis for trivial right-hand sides] in DmdAnal.
This allows a function with arity 2 to have a DmdSig with 3 args;
which in turn had a knock-on effect, which showed up in the test for
Trac #8963.

In fact it seems entirely reasonable, so this patch removes the
WARN and CoreLint checks that were complaining.

(cherry picked from commit 848f595266268f578480ceb4ab1ce4938611c97e)