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)
Test Trac #8963

(cherry picked from commit cc3ccf9f47c7f4684cdd2b08d0e2acf50b69bc18)

Conflicts:
	testsuite/tests/deriving/should_compile/all.T
Fix annotation reification for home package modules

The reifyAnnotation method of the Q monad correctly gathered annotations
from TCG and EPS.  Unfortunately it didn't look into the Home Package
Table.  This resulted in annotations not being found if they are in the
same package as the splice that is reifying and ghc --make is used for
compilation management.  Fix this by using the already existing
prepareAnnotations method from HscTypes.lhs that correctly searches
in HPT and EPS both.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 48e475e45f517896c6618d38a09b8d223f3d7585)
Add a comprehensive test for using Annotations from TH

The provided tests test both annotation generation and reification
from Template Haskell.  Both --make and compilation via separate
units (ghc -c) are tested.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit 5f5e326c3c310c4bceb2b0bce291d3a0a3fc30d6)
rts: Fix leak of file archive handle

Issue discovered by Coverity Scan, CID 43171.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit e597f5feb065c075c86715e24bf0ebd341fa8b9e)
rts: Fix memory leak when loading ELF objects

Issue discovered by Coverity Scan, CID 43168.

Signed-off-by: Austin Seipp <austin@well-typed.com>
(cherry picked from commit b7278d3d7bbe384eee7538b1e50bb741e99fb01d)
Merge latest upstream changes into ghc-7.8