Version bump.
authorSergei Trofimovich <slyfox@gentoo.org>
Tue, 23 Dec 2014 22:46:14 +0000 (22:46 +0000)
committerSergei Trofimovich <slyfox@gentoo.org>
Tue, 23 Dec 2014 22:46:14 +0000 (22:46 +0000)
Package-Manager: portage-2.2.14/cvs/Linux x86_64
Manifest-Sign-Key: 0x611FF3AA

dev-lang/ghc/ChangeLog
dev-lang/ghc/Manifest
dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch [new file with mode: 0644]
dev-lang/ghc/ghc-7.8.4.ebuild [new file with mode: 0644]

index d15ebba5cb531134b68652522c023faa21139ef7..ed5906d186704cffd84c89216bd9728daa524fd3 100644 (file)
@@ -1,6 +1,12 @@
 # ChangeLog for dev-lang/ghc
 # Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-lang/ghc/ChangeLog,v 1.269 2014/09/07 06:29:23 slyfox Exp $
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/ghc/ChangeLog,v 1.270 2014/12/23 22:46:09 slyfox Exp $
+
+*ghc-7.8.4 (23 Dec 2014)
+
+  23 Dec 2014; Sergei Trofimovich <slyfox@gentoo.org>
+  +files/ghc-7.8.3-ppc32-fPIC.patch, +ghc-7.8.4.ebuild:
+  Version bump.
 
   07 Sep 2014; Sergei Trofimovich <slyfox@gentoo.org> ghc-6.12.3-r2.ebuild,
   ghc-7.0.4.ebuild:
index d89f498289995fedcaef71ecac16a17f7d9249a9..1e49d1828ddb8ed535626c990cc5aec8824be4d5 100644 (file)
@@ -48,6 +48,7 @@ AUX ghc-7.8.3-ia64-prim.patch 2528 SHA256 9e154f87cd89cbf524b4143b4f4ba0362060a9
 AUX ghc-7.8.3-linker-warn.patch 1317 SHA256 0beacf4d6a43784fc77b95c5b8d0dd752261ba442501e72177b59e1a628242eb SHA512 3b0ece4a6536ef43f15e97e723d036401dcf41d47c15e29dd8fe30c9f1563894102922617982db7b6c7cf3ed8aea64458b540ef92ffe690ff72994b1246834c9 WHIRLPOOL 0e17c8d0d675b330f4bdea3ab60d6b17ac68eb4421fb8cd919d5924c269be3761335c2712270800e84c1d1d43918e9a53b49233c67a7f7fd85d3962c2f429667
 AUX ghc-7.8.3-pic-asm.patch 4227 SHA256 ca59c8ecab4196b37410e12550d4781cee9744bd7450d2bf1ee4396d064f21bd SHA512 9bcfd043b0a194eec86f700c315799581920e37a9789a7f02e5ef5a8d13f1ec6509e194d89afaf410357abb77893e14f8c09c13bc6fd878eeb81d249818c4625 WHIRLPOOL 7c2605300fafe83c28e5f807135ab693ce78423bb83de6f3052cd5fcf754cd4cca18ce983a585c4b64d4a6eb67a033ef1bd45666cd86fdddcef2b58d48e4f6ca
 AUX ghc-7.8.3-pic-sparc.patch 1007 SHA256 71a77d9d43c76a5bb712bbd4bc00892058f51944157684b00758219e379cb2e7 SHA512 d3d81142a1e606c85c22127e2fbb26ceaeb2116435bf0bbc3743273577f04991e28c38a375a78b3f633a9b0e25f10951146d1f322e0ad7972089c1e5d977d16b WHIRLPOOL aebaa832e59ff50bbfb5447f89b9df0394167228bdab3da15399f9604cdfef5252bbc647c001af0b8b5753b34e5b554304e21f5cab7e65a30e8891e00045c000
+AUX ghc-7.8.3-ppc32-fPIC.patch 14549 SHA256 413638aeec8e7cf35495f163e584d459870ea001e74360c546419e801eb36b57 SHA512 aa6f13e04a52e7f25db456c02031b63c01b71adf41262361b36ca97aec18965f618ebba73494b4283ad3c0224f15d5c80dbd43076553e604d86a07baf7fa86db WHIRLPOOL 98b008bf28280b878446f3aab83176334c4dc27c759d408eff2a6a52e84d8d7f002f3cb15be8022e6c8ebdb3d364067db0738a9ca96c4159c213eaa925ea63e6
 AUX ghc-7.8.3-prim-lm.patch 444 SHA256 c147880c5c9f784cd731749589009a777317bd32b80b63f508730854025fcb7e SHA512 6979e002589a54c870c70eee8357dad4feb55b4e5102350cc09a466145677dacaa1bab5ebe4818cf0d3cd8ab50ee0ec2ab642ab0fb3fd34f4a266e5e90f9f389 WHIRLPOOL e33b43f42fa5e408d7879822c5081c89688cb924fadea32bb3c7ba426661c6b345e2051aac29e5f73ec2c7eafd63ae87413b4d52228e7e345308f5f816e1117a
 AUX ghc-7.8.3-unreg-lit.patch 3248 SHA256 dd7dc819e0211f936c8bc450adb90c433ca7e37596898c97698c93dae7c4011a SHA512 c16361d3bf04839106221e18f9b1d861cf52da8091276fd4e6347f24e0707093b94e4d384bd452e1d7ef772392b8ce0103e42d68d91ec583f26250bb9af2be9e WHIRLPOOL 94194d10dd6b5ca9d624071bc455a1d76b4323f2cbc229bcb4cc9f41089903d7405cfa2e1000bb24b5828bcd5bdf1a44defe5c95a26e8d470c899906f2be0784
 AUX ghc-apply-gmp-hack 2585 SHA256 0d3c9e52be232734c916e9765fae770225ad6fb04c0948780867450401ff1eed SHA512 54d4a7ccb4a652e36b012bfa37696895755495a698449f77e854822f0be10d33803a7d049101c8835c8bcb587af3b5ab735e578e820feaa6a90bba0e21ad0a63 WHIRLPOOL 76d2d62886a1dcdb1da1ada62e48846f20b91dcdc2d1d7882107fc7662dd127a821f275eb909b93e4a3e0733c70afb70e41ae405da2eb39f57246f3dec01a914
@@ -67,6 +68,7 @@ DIST ghc-7.4.2-src.tar.bz2 25836446 SHA256 f2ee1289a33cc70539287129841acc7eaf161
 DIST ghc-7.6.2-src.tar.bz2 110778081 SHA256 d5f45184abeacf7e9c6b4f63c7101a5c1d7b4fe9007901159e2287ecf38de533 SHA512 2e6e54f509e564f3713ea15dfefb16a84a467f8044c692ad2647c05b641e1ccb4125b9b63bbf711be1054d7ef56612186d2b9cd88ba4127fe01eec225152e4cf WHIRLPOOL 78724187c0f7579c3f39f257620d3046711f20fe07c540b6b70cf1b0b87bb8476d2382835895b5770865faaac291de05be88e2708fd0c1956ad7bc132d558b9c
 DIST ghc-7.6.3-src.tar.bz2 110763823 SHA256 bd43823d31f6b5d0b2ca7b74151a8f98336ab0800be85f45bb591c9c26aac998 SHA512 ac86f18b4feeb0bdc9e867261600b210caf62740d73ae657259bbe8149b8c2c4f5a73d09d74d944d4e50f85cc87503485365f0a0ae65befe8d2b6844e5e1253a WHIRLPOOL 0fe1f5f2987699067494559e6a679d28f027eee8fb2a00c683161dbce5443b1faeebfb51572209b75231cee24c7f0c929cabbc82a93f70e16d05e351fdfe2eaf
 DIST ghc-7.8.3-src.tar.xz 9160092 SHA256 b0cd96a549ba3b5e512847a4a8cd1a3174e4b2b75dadfc41c568fb812887b958 SHA512 2cc8c2aa6f18ba565c1e2aa637045e246f1214c2a77e95c2a97dfb97203b8983e4ad3cc13178b4b51aff70c58d59a1f68f94cd813d043745cb02411bad04bb00 WHIRLPOOL 3a2e8eea0db7a150e4732efed488a3a5eb56da00a9a90a3379afcb4090323925a2a7485fec6676e784139f112d7c825e8d18a576c34c760af4a7f3adb22c021a
+DIST ghc-7.8.4-src.tar.bz2 10600755 SHA256 59e3bd514a1820cc1c03e1808282205c0b8518369acae12645ceaf839e6f114b SHA512 079a53891d8ebd8d9b88da96170e60981608a619f8282e4b7948f35244e99bd87277649ac7fcebc227a61a4d21960db8d5e5b9e92f2c69c82d8d68d7fd0a41d3 WHIRLPOOL a9be7641adbd237ed6e0f644c312e655e98be9566097aee5e2c0022e8756d5b2236e42dd86d76c638a001b5ca3f67307e89ec0cd003a92cd112a5d6d3e3d8467
 DIST ghc-bin-6.12.3-alpha-haddock.tbz2 106307940 SHA256 22951ccbaa2e77f811c634fa95492451f28f8b79e5cfe0297890ce1dd9d525ab SHA512 47b124cb2b745ffa6471dd75b9b922170cd275d837093f320116a842cc2ed4e6f215128fe7269bbe5f85b34239fe46bac697d7210c2f5df97b67c5629ea30c94 WHIRLPOOL 2f26c8c046e779ed63f86fdfcf2cb4815f5f0ea08b0c6c98668909a7a3bcca3c6fa2dac390d3bd066e197093227086cbe4bd5c35044a23d344e591b5d5a1cfc1
 DIST ghc-bin-6.12.3-amd64.tbz2 82390661 SHA256 6a1c9978c4ad19bb98f70b900afa799f16cfd3e159bb6d51437c264e35f4d6cc SHA512 ae883f94621fcf0ffe8b57954e403db6812769bbeee92e031be49fc9cc2087c7700bb6a36c6fdd170936c2fea9024d2400db04db94c530841ab6662be34227e8 WHIRLPOOL ffbb50018216af9cc84d2cc04a39646dd47f70e1451bbaf700495864edddbbf729c61c3a020dde472e27236b19151b3373fd1b1735da5d3d9f68c63d9e3ea4ed
 DIST ghc-bin-6.12.3-ia64-haddock.tbz2 113756002 SHA256 135c60f870badec5e10add87061d0d9c85276e182ae448ab52c6f9f7ebe6eb2e SHA512 0e789ff5af719106e9eac030c477109a928f04facfd9b7da0c55a25465cd5c92c409d08838f75206939943df6c028e302854da368eefe17fd704c88bc5e83fe4 WHIRLPOOL 7e6ad1b44f28724c4cbf8c618aa04202e61dddaf2f50a71de42161d32b78573fc530aeffb1cb4b550e2141690515487fd99e8c5e01d5c79775ffb771ee5cefe9
@@ -109,6 +111,8 @@ DIST ghc-bin-7.6.3-r1-sparc.tbz2 121641337 SHA256 0fb31b9584c1c6caafb44a51158bfd
 DIST ghc-bin-7.6.3-x86.tbz2 93718672 SHA256 a55024f66a048437fcd6ef0f33cdb994a43628998a2f0fe4d094cc9ba83d1615 SHA512 624f2a3238dee15853018d45632d1363e42d34099a77e5e9ce5c8da976cb4c33578144f7c39dbf25ee68c17d8d42910db2347186849eeeda6bc20053ce2be990 WHIRLPOOL bc646fc19906b59416358fb7558b6e2c3f7ad069c2fcf443be36b621894cfcecb0844acf5b5f9c383e034dfff3e24d312a7da0d7a629836134ec5dc1ecd6f139
 DIST ghc-bin-7.8.3-amd64.tbz2 100786052 SHA256 af49f547336a4f9f13cd625155d5a6a998e52ae7da8bbbddc856f88b00b6aff4 SHA512 b1826095b67fa2028678057f70909bff4e082b82f3b70f1aedbc91073efad54334fa1864bc8248c9249eec6edab3671dc38ac1650be86f1245e2fecf92528952 WHIRLPOOL 5b44fff77a0d79c6f7c5c8ca792eb6b36987d1de58d5ebc0a9b05da9c19a2c312eca6b9d40e7e63437742b7f9c28c925feb3bea7f9803dda95fac7acaa7a3132
 DIST ghc-bin-7.8.3-x86.tbz2 102583755 SHA256 c67f0d2471e594b4fdfc5b219bb6b61e57e6ba75132aa3f63d171550af8cbe3c SHA512 badabbba2f46b5ab3a2601e53997ce6533162afeec7dc36eeb877a62680a9f599aeb05dd3682f45d3e273d71d28b8bd01eee37dcad3c7354e8f83b7be4e58536 WHIRLPOOL 7b99b6bbeb4ad6d203f270d8446285825ad0857a8ab058d8c126155b49e8819e0efc2f6c42b5ff775dc0ece5488e97fcc7ae2459fe87fdceef43d63a75443430
+DIST ghc-bin-7.8.4-amd64.tbz2 100573133 SHA256 bd9d144c08caa0ff345ada8d7eed7592531b8f8b9ef2f94d0b9a42fd747440aa SHA512 e4416d6dae3c644f74bafb3aecf1a123f985427aba32d0e0c43143a137d64a9220fc5947cd9bde8a3bc44555ae71184fc06a3f7df7976aadd065ad5681b90954 WHIRLPOOL ab0bd6219d68e08cb473cf2f3f15538d65940f28e84f026361032c3a6bc09f7820faf67629e915f27c2afda7de41fa9c6010a1b5cd487df0936d968c7e58a3a4
+DIST ghc-bin-7.8.4-x86.tbz2 102312459 SHA256 4c53148836e5a1ba55b8db5bb7c3eb915103e0955fb503b2facdc5a72f12a974 SHA512 cabc5bd6d8760ce4120e7053f6c1dffca7d161ba454b6201087760096c037c932e3ff8c82e53346c8278855bf0cff1c2f5fb8046242ca4d8307355b060a9556e WHIRLPOOL 0171d67dc1b63381a491e1577a783eb0e8f53cb579ba96a9b4fdf6685d494d78eb2be780f77ff33422d3b7c320ed102d9b48f6e954f8fee5532982575001a4a5
 EBUILD ghc-6.12.3-r2.ebuild 20796 SHA256 527f54ef419549e18778e2b3be5ecbe3026fcd7a91c6e52e373c7214ac1a826a SHA512 028a823d9e1da226580c28405e8d8d555dcac4a605731de1066ff695428fe2b26efe7d0345a32b037952bc48b35968e2a427f89000ebbb89e5ec32d7dba0c60a WHIRLPOOL c32681c78b7f78b93c42fd161c057ce414ce397a893cb2301ee14e0871326923dfc18b9b81e1a6444dca5a5432a34514e373137d4f6fffd680e17e0686a74c26
 EBUILD ghc-7.0.4.ebuild 20256 SHA256 d9525a3cec1a9f0ba46eb8ac0fb4fe4e136bef03f6c7dfd6bfe82c82e2ff6552 SHA512 35989124a714ac7297af8043653fd34844effe545c7775b37a1b98a7f4d58d7478de1300bd85cce9a0a34ed24cc27f7ffa1a250f167e6632c6ca75e499b43a02 WHIRLPOOL d7e349c59deaa0ef7a1293e4742d667cd4e537633725f6a611c6ea03f2a6b0e3960fb82ceca2bb0e301cff41940c883f2b08679b25cb53d330abfa2c9b5a52e8
 EBUILD ghc-7.4.1-r1.ebuild 21359 SHA256 58c914920bddc3dc9ef84509fd58ec2d3cb86ca8f61f316b85aac75cc8985206 SHA512 8aeeded46d1ab2baeb14837d7b58a7cac4b2c3b8960bd85b9885dae616e44594b831dd336469f2f2f168393fce76215809640d1d1ed84c44c5ceb321ca67b14d WHIRLPOOL 102d072ffb5bfbfbc1e70fa8b6b94c8308587d9669edf56b47505b62039aa2ef02e1c6f6c8d859d3189f2a983b420e0410cfd6303ef6950684810760a1c3711b
@@ -118,12 +122,13 @@ EBUILD ghc-7.6.2.ebuild 25352 SHA256 1986bda9cf2dcc52b90b3dd18d8241bb9d93b5f7b7e
 EBUILD ghc-7.6.3-r1.ebuild 29017 SHA256 898e3fe4d3561f75a46d65a3e3bb978895e63c0ae2b77075e899fdaebd6328ad SHA512 1b5e5bc934059bc6c761477ed3746ff2eac15f5d71be3b786d84c8f900a23fa1064938dfa72b411dc60ff4185b3c4d18b0bf4f0a3a392cdcb1df1081552ebb55 WHIRLPOOL 03ea67ec40a951dd4e5dc6dafe56c147ab0f16605bc32c6f9ca55c3e9ed74adeb14c8a2c952a3160453bcb827d175ce93cc3514aa607bf76e77660d21eb387d6
 EBUILD ghc-7.6.3.ebuild 26240 SHA256 517f567d0241deee7c473edcc999c7255f7a8cb14e6cc36f13850021e7802310 SHA512 26c8aa9894e1bcc194b2f62dd1741d03e90ea0b8607e760027117c391ab0ff036e66fe76ce8b07d5cc1acf372e3ed4316d9b866d818e5299285cfbfcb13c19eb WHIRLPOOL 429c9f83b45b153145a999655c6a9f17518f70e48ecbfe91cb8d682eacc3ea9d7818b0de23a7507aa454b3885dbcff3a8393f5f4eb734402f1dd0688535500bc
 EBUILD ghc-7.8.3.ebuild 20718 SHA256 36f3de9ed9f5f72e742a0109e02b3c305d4a7e7fa40790990f66bec2e37ef9d0 SHA512 09caadef7b208ad4c89bbf70c1897f01a0cb5f3a15c4005c606651c1424d0c920a8dce7a45a3abaa77a2516c55a71ea2745175f248dd90d8044fc2df5763ef7f WHIRLPOOL 40815fd6c952826a4b299dc26ce1dd3431026e8a7075f495273f66fc57f841bad8f0fc20a4f3b21eb1b08adc036edff75330e2810d68a23dfe4f03f02abf6605
-MISC ChangeLog 49123 SHA256 13532ce7a9c8ac48e7dc16c1e54ea73fae46fc68267a19f4949c56b6cf5bc553 SHA512 b256bbbc884c1c05d5d041e135e19da1cead2a961912a1b1a0f94efb1bebfb501f0a71bd78e1e7e965ae672dc7550365e0cdfd0a57df5766a9d5871384327105 WHIRLPOOL 8f69b9d49d139a972b93c5f221ff547b86a482ce94db8be27d75450878dea2586ea4e800dd499b5b41f89d0aabaed7ed829783d041dfefd7bfc8077068836571
+EBUILD ghc-7.8.4.ebuild 20525 SHA256 77e064882901a414f156d0142c51a4cebdd2d7bb9fd35c161f85c38d734073d2 SHA512 45e407f6d45eb820d746d8db6c595b5d1b4f3c8686daef70d390a6968c53bd966d3edc42760cc65508888ec40864ce48391bc3f28756948440d74367f466974a WHIRLPOOL 31048840d35133b9651420de2dfd80a02dc3137ef96d74c135b8e466b5cf5726facff94b9923616e65c0712c485121d12e3c3a662f1e87d94b1fdfce0bacf482
+MISC ChangeLog 49276 SHA256 08b230ecd3df05d26a3e8920bd78877e8ad82da1aa948c45e339219cde22c0cc SHA512 ffda2d21db192a326933172b2b6a994f40f264ab1ade2eacd8f4e6c9b4cfcef1780b26c7e7847636744d5d0f8149282b4efab9559f1be9d0e40a1f53be37478e WHIRLPOOL 24320f481e1971743ff5858177be68a3c3713ff9bfac2fe05f328ffd1e1469e4b045e6984bbb991c9c9189f7c62b5fe82527f88e8e5dba15f78db6c03600a0a0
 MISC metadata.xml 561 SHA256 f964cd5b31b8a5e1979c03ced645f9e28b61528b456340e36cacef4b25104735 SHA512 50ef5db553f7ae99de80ef2f45d2c6c9c3b85bc4ef70ef7f79797a3c47f33a8ca9c9caf14752f38b81f0abd17df594820bc2161a10c7d177c126fcb101b24c31 WHIRLPOOL 1d4e744e284d0053a8cff1547dd25c4f0f2dcb8da35dee4523dbadcc9e29a92beb6ce7e63044c09995ffb255d39c5f02d901b330c481763b608ba4ed6e243faf
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
-iEYEAREIAAYFAlQL+0gACgkQcaHudmEf86oaKACfZs1vWyEZqz5/xTqDXV6LUVFZ
-bKoAoIUNX5pFnIe4Xk2PYgCmDXWYOyrh
-=zWlP
+iEYEAREIAAYFAlSZ8LUACgkQcaHudmEf86r1NgCeIL/m3gdxYxd6D6CUH5/7kWsU
+E1QAmgMi7J12gcpoJCoGWcDfu6fGUs47
+=zYhI
 -----END PGP SIGNATURE-----
diff --git a/dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch b/dev-lang/ghc/files/ghc-7.8.3-ppc32-fPIC.patch
new file mode 100644 (file)
index 0000000..434be8b
--- /dev/null
@@ -0,0 +1,351 @@
+commit fa31e8f4a0f853848d96549a429083941877bf8d
+Author: Sergei Trofimovich <siarheit@google.com>
+Date:   Sun Dec 14 14:30:12 2014 +0000
+
+    powerpc: fix and enable shared libraries by default on linux
+    
+    Summary:
+    And fix things all the way down to it. Namely:
+        - remove 'r30' from free registers, it's an .LCTOC1 register
+          for gcc. generated .plt stubs expect it to be initialised.
+        - fix PicBase computation, which originally forgot to use 'tmp'
+          reg in 'initializePicBase_ppc.fetchPC'
+        - mark 'ForeighTarget's as implicitly using 'PicBase' register
+          (see comment for details)
+        - add 64-bit MO_Sub and test on alloclimit3/4 regtests
+        - fix dynamic label offsets to match with .LCTOC1 offset
+    
+    Signed-off-by: Sergei Trofimovich <siarheit@google.com>
+    
+    Test Plan: validate passes equal amount of vanilla/dyn tests
+    
+    Reviewers: simonmar, erikd, austin
+    
+    Reviewed By: erikd, austin
+    
+    Subscribers: carter, thomie
+    
+    Differential Revision: https://phabricator.haskell.org/D560
+    
+    GHC Trac Issues: #8024, #9831
+
+diff --git a/compiler/cmm/CLabel.hs b/compiler/cmm/CLabel.hs
+index 0f2c0ae..37b8ada 100644
+--- a/compiler/cmm/CLabel.hs
++++ b/compiler/cmm/CLabel.hs
+@@ -1170,7 +1170,8 @@ pprDynamicLinkerAsmLabel platform dllInfo lbl
+    else if osElfTarget (platformOS platform)
+         then if platformArch platform == ArchPPC
+              then case dllInfo of
+-                  CodeStub  -> ppr lbl <> text "@plt"
++                  CodeStub  -> -- See Note [.LCTOC1 in PPC PIC code]
++                               ppr lbl <> text "+32768@plt"
+                   SymbolPtr -> text ".LC_" <> ppr lbl
+                   _         -> panic "pprDynamicLinkerAsmLabel"
+              else if platformArch platform == ArchX86_64
+diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs
+index 9b5c080..6326a8b 100644
+--- a/compiler/nativeGen/PIC.hs
++++ b/compiler/nativeGen/PIC.hs
+@@ -54,7 +54,6 @@ import qualified X86.Instr      as X86
+ 
+ import Platform
+ import Instruction
+-import Size
+ import Reg
+ import NCGMonad
+ 
+@@ -468,11 +467,8 @@ pprGotDeclaration dflags ArchX86 OSDarwin
+ pprGotDeclaration _ _ OSDarwin
+         = empty
+ 
+--- pprGotDeclaration
++-- Emit GOT declaration
+ -- Output whatever needs to be output once per .s file.
+--- The .LCTOC1 label is defined to point 32768 bytes into the table,
+--- to make the most of the PPC's 16-bit displacements.
+--- Only needed for PIC.
+ pprGotDeclaration dflags arch os
+         | osElfTarget os
+         , arch  /= ArchPPC_64
+@@ -482,6 +478,7 @@ pprGotDeclaration dflags arch os
+         | osElfTarget os
+         , arch  /= ArchPPC_64
+         = vcat [
++                -- See Note [.LCTOC1 in PPC PIC code]
+                 ptext (sLit ".section \".got2\",\"aw\""),
+                 ptext (sLit ".LCTOC1 = .+32768") ]
+ 
+@@ -688,12 +685,7 @@ pprImportedSymbol _ _ _
+ 
+ 
+ -- Get a pointer to our own fake GOT, which is defined on a per-module basis.
+--- This is exactly how GCC does it, and it's quite horrible:
+--- We first fetch the address of a local label (mkPicBaseLabel).
+--- Then we add a 16-bit offset to that to get the address of a .long that we
+--- define in .text space right next to the proc. This .long literal contains
+--- the (32-bit) offset from our local label to our global offset table
+--- (.LCTOC1 aka gotOffLabel).
++-- This is exactly how GCC does it in linux.
+ 
+ initializePicBase_ppc
+         :: Arch -> OS -> Reg
+@@ -704,18 +696,9 @@ initializePicBase_ppc ArchPPC os picReg
+     (CmmProc info lab live (ListGraph blocks) : statics)
+     | osElfTarget os
+     = do
+-        dflags <- getDynFlags
+-        gotOffLabel <- getNewLabelNat
+-        tmp <- getNewRegNat $ intSize (wordWidth dflags)
+         let
+-            gotOffset = CmmData Text $ Statics gotOffLabel [
+-                            CmmStaticLit (CmmLabelDiffOff gotLabel
+-                                                          mkPicBaseLabel
+-                                                          0)
+-                        ]
+-            offsetToOffset
+-                        = PPC.ImmConstantDiff
+-                                (PPC.ImmCLbl gotOffLabel)
++            gotOffset = PPC.ImmConstantDiff
++                                (PPC.ImmCLbl gotLabel)
+                                 (PPC.ImmCLbl mkPicBaseLabel)
+ 
+             blocks' = case blocks of
+@@ -726,15 +709,23 @@ initializePicBase_ppc ArchPPC os picReg
+               | bID `mapMember` info = fetchPC b
+               | otherwise            = b
+ 
++            -- GCC does PIC prologs thusly:
++            --     bcl 20,31,.L1
++            -- .L1:
++            --     mflr 30
++            --     addis 30,30,.LCTOC1-.L1@ha
++            --     addi 30,30,.LCTOC1-.L1@l
++            -- TODO: below we use it over temporary register,
++            -- it can and should be optimised by picking
++            -- correct PIC reg.
+             fetchPC (BasicBlock bID insns) =
+               BasicBlock bID (PPC.FETCHPC picReg
+-                              : PPC.ADDIS tmp picReg (PPC.HI offsetToOffset)
+-                              : PPC.LD PPC.archWordSize tmp
+-                                   (PPC.AddrRegImm tmp (PPC.LO offsetToOffset))
+-                              : PPC.ADD picReg picReg (PPC.RIReg picReg)
++                              : PPC.ADDIS picReg picReg (PPC.HA gotOffset)
++                              : PPC.ADDI picReg picReg (PPC.LO gotOffset)
++                              : PPC.MR PPC.r30 picReg
+                               : insns)
+ 
+-        return (CmmProc info lab live (ListGraph blocks') : gotOffset : statics)
++        return (CmmProc info lab live (ListGraph blocks') : statics)
+ 
+ 
+ initializePicBase_ppc ArchPPC OSDarwin picReg
+diff --git a/compiler/nativeGen/PPC/CodeGen.hs b/compiler/nativeGen/PPC/CodeGen.hs
+index ddf483a..c1c4a74 100644
+--- a/compiler/nativeGen/PPC/CodeGen.hs
++++ b/compiler/nativeGen/PPC/CodeGen.hs
+@@ -54,7 +54,7 @@ import Outputable
+ import Unique
+ import DynFlags
+ 
+-import Control.Monad    ( mapAndUnzipM )
++import Control.Monad    ( mapAndUnzipM, when )
+ import Data.Bits
+ import Data.Word
+ 
+@@ -355,6 +355,19 @@ iselExpr64 (CmmMachOp (MO_Add _) [e1,e2]) = do
+                        ADDE rhi r1hi r2hi ]
+    return (ChildCode64 code rlo)
+ 
++iselExpr64 (CmmMachOp (MO_Sub _) [e1,e2]) = do
++   ChildCode64 code1 r1lo <- iselExpr64 e1
++   ChildCode64 code2 r2lo <- iselExpr64 e2
++   (rlo,rhi) <- getNewRegPairNat II32
++   let
++        r1hi = getHiVRegFromLo r1lo
++        r2hi = getHiVRegFromLo r2lo
++        code =  code1 `appOL`
++                code2 `appOL`
++                toOL [ SUBFC rlo r2lo r1lo,
++                       SUBFE rhi r2hi r1hi ]
++   return (ChildCode64 code rlo)
++
+ iselExpr64 (CmmMachOp (MO_UU_Conv W32 W64) [expr]) = do
+     (expr_reg,expr_code) <- getSomeReg expr
+     (rlo, rhi) <- getNewRegPairNat II32
+@@ -918,8 +931,12 @@ genCCall' dflags gcp target dest_regs args0
+                                                         (toOL []) []
+ 
+         (labelOrExpr, reduceToFF32) <- case target of
+-            ForeignTarget (CmmLit (CmmLabel lbl)) _ -> return (Left lbl, False)
+-            ForeignTarget expr _ -> return  (Right expr, False)
++            ForeignTarget (CmmLit (CmmLabel lbl)) _ -> do
++                uses_pic_base_implicitly
++                return (Left lbl, False)
++            ForeignTarget expr _ -> do
++                uses_pic_base_implicitly
++                return (Right expr, False)
+             PrimTarget mop -> outOfLineMachOp mop
+ 
+         let codeBefore = move_sp_down finalStack `appOL` passArgumentsCode
+@@ -940,6 +957,13 @@ genCCall' dflags gcp target dest_regs args0
+     where
+         platform = targetPlatform dflags
+ 
++        uses_pic_base_implicitly = do
++            -- See Note [implicit register in PPC PIC code]
++            -- on why we claim to use PIC register here
++            when (gopt Opt_PIC dflags) $ do
++                _ <- getPicBaseNat archWordSize
++                return ()
++
+         initialStackOffset = case gcp of
+                              GCPDarwin -> 24
+                              GCPLinux  -> 8
+@@ -1431,3 +1455,21 @@ coerceFP2Int _ toRep x = do
+                 -- read low word of value (high word is undefined)
+             LD II32 dst (spRel dflags 3)]
+     return (Any (intSize toRep) code')
++
++-- Note [.LCTOC1 in PPC PIC code]
++-- The .LCTOC1 label is defined to point 32768 bytes into the GOT table
++-- to make the most of the PPC's 16-bit displacements.
++-- As 16-bit signed offset is used (usually via addi/lwz instructions)
++-- first element will have '-32768' offset against .LCTOC1.
++
++-- Note [implicit register in PPC PIC code]
++-- PPC generates calls by labels in assembly
++-- in form of:
++--     bl puts+32768@plt
++-- in this form it's not seen directly (by GHC NCG)
++-- that r30 (PicBaseReg) is used,
++-- but r30 is a required part of PLT code setup:
++--   puts+32768@plt:
++--       lwz     r11,-30484(r30) ; offset in .LCTOC1
++--       mtctr   r11
++--       bctr
+diff --git a/compiler/nativeGen/PPC/Instr.hs b/compiler/nativeGen/PPC/Instr.hs
+index f5b9506..b7081f9 100644
+--- a/compiler/nativeGen/PPC/Instr.hs
++++ b/compiler/nativeGen/PPC/Instr.hs
+@@ -205,8 +205,11 @@ data Instr
+     | ADD     Reg Reg RI            -- dst, src1, src2
+     | ADDC    Reg Reg Reg           -- (carrying) dst, src1, src2
+     | ADDE    Reg Reg Reg           -- (extend) dst, src1, src2
++    | ADDI    Reg Reg Imm           -- Add Immediate dst, src1, src2
+     | ADDIS   Reg Reg Imm           -- Add Immediate Shifted dst, src1, src2
+     | SUBF    Reg Reg Reg           -- dst, src1, src2 ; dst = src2 - src1
++    | SUBFC   Reg Reg Reg           -- (carrying) dst, src1, src2 ; dst = src2 - src1
++    | SUBFE   Reg Reg Reg           -- (extend) dst, src1, src2 ; dst = src2 - src1
+     | MULLW   Reg Reg RI
+     | DIVW    Reg Reg Reg
+     | DIVWU   Reg Reg Reg
+@@ -284,8 +287,11 @@ ppc_regUsageOfInstr platform instr
+     ADD     reg1 reg2 ri     -> usage (reg2 : regRI ri, [reg1])
+     ADDC    reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
+     ADDE    reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
++    ADDI    reg1 reg2 _      -> usage ([reg2], [reg1])
+     ADDIS   reg1 reg2 _      -> usage ([reg2], [reg1])
+     SUBF    reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
++    SUBFC   reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
++    SUBFE   reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
+     MULLW   reg1 reg2 ri     -> usage (reg2 : regRI ri, [reg1])
+     DIVW    reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
+     DIVWU   reg1 reg2 reg3   -> usage ([reg2,reg3], [reg1])
+@@ -358,8 +364,11 @@ ppc_patchRegsOfInstr instr env
+     ADD     reg1 reg2 ri    -> ADD (env reg1) (env reg2) (fixRI ri)
+     ADDC    reg1 reg2 reg3  -> ADDC (env reg1) (env reg2) (env reg3)
+     ADDE    reg1 reg2 reg3  -> ADDE (env reg1) (env reg2) (env reg3)
++    ADDI    reg1 reg2 imm   -> ADDI (env reg1) (env reg2) imm
+     ADDIS   reg1 reg2 imm   -> ADDIS (env reg1) (env reg2) imm
+     SUBF    reg1 reg2 reg3  -> SUBF (env reg1) (env reg2) (env reg3)
++    SUBFC   reg1 reg2 reg3  -> SUBFC (env reg1) (env reg2) (env reg3)
++    SUBFE   reg1 reg2 reg3  -> SUBFE (env reg1) (env reg2) (env reg3)
+     MULLW   reg1 reg2 ri    -> MULLW (env reg1) (env reg2) (fixRI ri)
+     DIVW    reg1 reg2 reg3  -> DIVW (env reg1) (env reg2) (env reg3)
+     DIVWU   reg1 reg2 reg3  -> DIVWU (env reg1) (env reg2) (env reg3)
+diff --git a/compiler/nativeGen/PPC/Ppr.hs b/compiler/nativeGen/PPC/Ppr.hs
+index 6851769..f59d51f 100644
+--- a/compiler/nativeGen/PPC/Ppr.hs
++++ b/compiler/nativeGen/PPC/Ppr.hs
+@@ -525,6 +525,16 @@ pprInstr (BCTRL _) = hcat [
+         ptext (sLit "bctrl")
+     ]
+ pprInstr (ADD reg1 reg2 ri) = pprLogic (sLit "add") reg1 reg2 ri
++pprInstr (ADDI reg1 reg2 imm) = hcat [
++        char '\t',
++        ptext (sLit "addi"),
++        char '\t',
++        pprReg reg1,
++        ptext (sLit ", "),
++        pprReg reg2,
++        ptext (sLit ", "),
++        pprImm imm
++    ]
+ pprInstr (ADDIS reg1 reg2 imm) = hcat [
+         char '\t',
+         ptext (sLit "addis"),
+@@ -539,6 +549,8 @@ pprInstr (ADDIS reg1 reg2 imm) = hcat [
+ pprInstr (ADDC reg1 reg2 reg3) = pprLogic (sLit "addc") reg1 reg2 (RIReg reg3)
+ pprInstr (ADDE reg1 reg2 reg3) = pprLogic (sLit "adde") reg1 reg2 (RIReg reg3)
+ pprInstr (SUBF reg1 reg2 reg3) = pprLogic (sLit "subf") reg1 reg2 (RIReg reg3)
++pprInstr (SUBFC reg1 reg2 reg3) = pprLogic (sLit "subfc") reg1 reg2 (RIReg reg3)
++pprInstr (SUBFE reg1 reg2 reg3) = pprLogic (sLit "subfe") reg1 reg2 (RIReg reg3)
+ pprInstr (MULLW reg1 reg2 ri@(RIReg _)) = pprLogic (sLit "mullw") reg1 reg2 ri
+ pprInstr (MULLW reg1 reg2 ri@(RIImm _)) = pprLogic (sLit "mull") reg1 reg2 ri
+ pprInstr (DIVW reg1 reg2 reg3) = pprLogic (sLit "divw") reg1 reg2 (RIReg reg3)
+diff --git a/compiler/nativeGen/PPC/Regs.hs b/compiler/nativeGen/PPC/Regs.hs
+index 0f636bf..69e69c0 100644
+--- a/compiler/nativeGen/PPC/Regs.hs
++++ b/compiler/nativeGen/PPC/Regs.hs
+@@ -37,7 +37,8 @@ module PPC.Regs (
+         fits16Bits,
+         makeImmediate,
+         fReg,
+-        sp, r3, r4, r27, r28, f1, f20, f21,
++        sp, r3, r4, r27, r28, r30,
++        f1, f20, f21,
+ 
+         allocatableRegs
+ 
+@@ -295,12 +296,13 @@ point registers.
+ fReg :: Int -> RegNo
+ fReg x = (32 + x)
+ 
+-sp, r3, r4, r27, r28, f1, f20, f21 :: Reg
++sp, r3, r4, r27, r28, r30, f1, f20, f21 :: Reg
+ sp      = regSingle 1
+ r3      = regSingle 3
+ r4      = regSingle 4
+ r27     = regSingle 27
+ r28     = regSingle 28
++r30     = regSingle 30
+ f1      = regSingle $ fReg 1
+ f20     = regSingle $ fReg 20
+ f21     = regSingle $ fReg 21
+diff --git a/includes/CodeGen.Platform.hs b/includes/CodeGen.Platform.hs
+index 9916e0e..1d46a01 100644
+--- a/includes/CodeGen.Platform.hs
++++ b/includes/CodeGen.Platform.hs
+@@ -881,6 +881,8 @@ freeReg 1 = fastBool False -- The Stack Pointer
+ # if !MACHREGS_darwin
+ -- most non-darwin powerpc OSes use r2 as a TOC pointer or something like that
+ freeReg 2 = fastBool False
++-- at least linux in -fPIC relies on r30 in PLT stubs
++freeReg 30 = fastBool False
+ # endif
+ # ifdef REG_Base
+ freeReg REG_Base = fastBool False
+diff --git a/mk/config.mk.in b/mk/config.mk.in
+index 0f5820f..8f134bc 100644
+--- a/mk/config.mk.in
++++ b/mk/config.mk.in
+@@ -95,7 +95,7 @@ TargetElf = YES
+ endif
+ 
+ # Some platforms don't support shared libraries
+-NoSharedLibsPlatformList = powerpc-unknown-linux \
++NoSharedLibsPlatformList = \
+       x86_64-unknown-mingw32 \
+       i386-unknown-mingw32
+ 
diff --git a/dev-lang/ghc/ghc-7.8.4.ebuild b/dev-lang/ghc/ghc-7.8.4.ebuild
new file mode 100644 (file)
index 0000000..14660b5
--- /dev/null
@@ -0,0 +1,608 @@
+# Copyright 1999-2014 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-lang/ghc/ghc-7.8.4.ebuild,v 1.1 2014/12/23 22:46:09 slyfox Exp $
+
+EAPI=5
+
+# to make make a crosscompiler use crossdev and symlink ghc tree into
+# cross overlay. result would look like 'cross-sparc-unknown-linux-gnu/ghc'
+#
+# 'CTARGET' definition and 'is_crosscompile' are taken from 'toolchain.eclass'
+export CTARGET=${CTARGET:-${CHOST}}
+if [[ ${CTARGET} = ${CHOST} ]] ; then
+       if [[ ${CATEGORY/cross-} != ${CATEGORY} ]] ; then
+               export CTARGET=${CATEGORY/cross-}
+       fi
+fi
+
+inherit autotools bash-completion-r1 eutils flag-o-matic ghc-package
+inherit multilib pax-utils toolchain-funcs versionator
+
+DESCRIPTION="The Glasgow Haskell Compiler"
+HOMEPAGE="http://www.haskell.org/ghc/"
+
+# we don't have any binaries yet
+arch_binaries=""
+
+# sorted!
+#arch_binaries="$arch_binaries alpha? ( http://code.haskell.org/~slyfox/ghc-alpha/ghc-bin-${PV}-alpha.tbz2 )"
+#arch_binaries="$arch_binaries arm? ( http://code.haskell.org/~slyfox/ghc-arm/ghc-bin-${PV}-arm.tbz2 )"
+arch_binaries="$arch_binaries amd64? ( http://code.haskell.org/~slyfox/ghc-amd64/ghc-bin-${PV}-amd64.tbz2 )"
+#arch_binaries="$arch_binaries ia64?  ( http://code.haskell.org/~slyfox/ghc-ia64/ghc-bin-${PV}-ia64-fixed-fiw.tbz2 )"
+#arch_binaries="$arch_binaries ppc? ( http://code.haskell.org/~slyfox/ghc-ppc/ghc-bin-${PV}-ppc.tbz2 )"
+#arch_binaries="$arch_binaries ppc64? ( http://code.haskell.org/~slyfox/ghc-ppc64/ghc-bin-${PV}-ppc64.tbz2 )"
+#arch_binaries="$arch_binaries sparc? ( http://code.haskell.org/~slyfox/ghc-sparc/ghc-bin-${PV}-sparc.tbz2 )"
+arch_binaries="$arch_binaries x86? ( http://code.haskell.org/~slyfox/ghc-x86/ghc-bin-${PV}-x86.tbz2 )"
+
+# various ports:
+#arch_binaries="$arch_binaries x86-fbsd? ( http://code.haskell.org/~slyfox/ghc-x86-fbsd/ghc-bin-${PV}-x86-fbsd.tbz2 )"
+
+# 0 - yet
+yet_binary() {
+       case "${ARCH}" in
+               #alpha) return 0 ;;
+               #arm)
+               #       ewarn "ARM binary is built on armv5tel-eabi toolchain. Use with caution."
+               #       return 0
+               #;;
+               amd64) return 0 ;;
+               #ia64) return 0 ;;
+               #ppc) return 0 ;;
+               #ppc64) return 0 ;;
+               #sparc) return 0 ;;
+               x86) return 0 ;;
+               *) return 1 ;;
+       esac
+}
+
+GHC_PV=${PV}
+#GHC_PV=7.8.3.20141119 # uncomment only for -rc ebuilds
+GHC_P=${PN}-${GHC_PV} # using ${P} is almost never correct
+
+SRC_URI="!binary? ( http://downloads.haskell.org/~ghc/${PV/_rc/-rc}/${GHC_P}-src.tar.bz2 )"
+S="${WORKDIR}"/${GHC_P}
+
+[[ -n $arch_binaries ]] && SRC_URI+=" !ghcbootstrap? ( $arch_binaries )"
+LICENSE="BSD"
+SLOT="0/${PV}"
+KEYWORDS="~amd64 ~x86 ~amd64-linux ~x86-linux"
+IUSE="doc ghcbootstrap ghcmakebinary +gmp"
+IUSE+=" binary"
+IUSE+=" elibc_glibc" # system stuff
+
+RDEPEND="
+       >=dev-lang/perl-5.6.1
+       >=dev-libs/gmp-5:=
+       sys-libs/ncurses:=[unicode]
+       !ghcmakebinary? ( virtual/libffi:= )
+       !kernel_Darwin? ( >=sys-devel/gcc-2.95.3 )
+       kernel_linux? ( >=sys-devel/binutils-2.17 )
+       kernel_SunOS? ( >=sys-devel/binutils-2.17 )
+"
+
+# force dependency on >=gmp-5, even if >=gmp-4.1 would be enough. this is due to
+# that we want the binaries to use the latest versioun available, and not to be
+# built against gmp-4
+
+# similar for glibc. we have bootstrapped binaries against glibc-2.17
+DEPEND="${RDEPEND}
+       ghcbootstrap? ( >=dev-haskell/alex-2.3
+               >=dev-haskell/happy-1.18
+               doc? ( app-text/docbook-xml-dtd:4.2
+                       app-text/docbook-xml-dtd:4.5
+                       app-text/docbook-xsl-stylesheets
+                       >=dev-libs/libxslt-1.1.2 ) )
+       !ghcbootstrap? ( !prefix? ( elibc_glibc? ( >=sys-libs/glibc-2.17 ) ) )"
+
+PDEPEND="!ghcbootstrap? ( =app-admin/haskell-updater-1.2* )"
+
+REQUIRED_USE="?? ( ghcbootstrap binary )"
+
+# yeah, top-level 'use' sucks. I'd like to have it in 'src_install()'
+use binary && QA_PREBUILT="*"
+
+# haskell libraries built with cabal in configure mode, #515354
+QA_CONFIGURE_OPTIONS+=" --with-compiler --with-gcc"
+
+is_crosscompile() {
+       [[ ${CHOST} != ${CTARGET} ]]
+}
+
+append-ghc-cflags() {
+       local persistent compile assemble link
+       local flag ghcflag
+
+       for flag in $*; do
+               case ${flag} in
+                       persistent)     persistent="yes";;
+                       compile)        compile="yes";;
+                       assemble)       assemble="yes";;
+                       link)           link="yes";;
+                       *)
+                               [[ ${compile}  ]] && ghcflag="-optc${flag}"  CFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
+                                       [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
+                               [[ ${assemble} ]] && ghcflag="-opta${flag}"  CFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
+                                       [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
+                               [[ ${link}     ]] && ghcflag="-optl${flag}" LDFLAGS+=" ${flag}" && GHC_FLAGS+=" ${ghcflag}" &&
+                                       [[ ${persistent} ]] && GHC_PERSISTENT_FLAGS+=" ${ghcflag}"
+                               ;;
+               esac
+       done
+}
+
+ghc_setup_cflags() {
+       if is_crosscompile; then
+               export CFLAGS=${GHC_CFLAGS-"-O2 -pipe"}
+               export LDFLAGS=${GHC_LDFLAGS-"-Wl,-O1"}
+               einfo "Crosscompiling mode:"
+               einfo "   CHOST:   ${CHOST}"
+               einfo "   CTARGET: ${CTARGET}"
+               einfo "   CFLAGS:  ${CFLAGS}"
+               einfo "   LDFLAGS: ${LDFLAGS}"
+               return
+       fi
+       # We need to be very careful with the CFLAGS we ask ghc to pass through to
+       # gcc. There are plenty of flags which will make gcc produce output that
+       # breaks ghc in various ways. The main ones we want to pass through are
+       # -mcpu / -march flags. These are important for arches like alpha & sparc.
+       # We also use these CFLAGS for building the C parts of ghc, ie the rts.
+       strip-flags
+       strip-unsupported-flags
+
+       # Cmm can't parse line numbers #482086
+       replace-flags -ggdb[3-9] -ggdb2
+
+       GHC_FLAGS=""
+       GHC_PERSISTENT_FLAGS=""
+       for flag in ${CFLAGS}; do
+               case ${flag} in
+
+                       # Ignore extra optimisation (ghc passes -O to gcc anyway)
+                       # -O2 and above break on too many systems
+                       -O*) ;;
+
+                       # Arch and ABI flags are what we're really after
+                       -m*) append-ghc-cflags compile assemble ${flag};;
+
+                       # Sometimes it's handy to see backtrace of RTS
+                       # to get an idea what happens there
+                       -g*) append-ghc-cflags compile ${flag};;
+
+                       # Ignore all other flags, including all -f* flags
+               esac
+       done
+
+       for flag in ${LDFLAGS}; do
+               append-ghc-cflags link ${flag}
+       done
+
+       # hardened-gcc needs to be disabled, because the mangler doesn't accept
+       # its output.
+       gcc-specs-pie && append-ghc-cflags persistent compile link -nopie
+       gcc-specs-ssp && append-ghc-cflags persistent compile      -fno-stack-protector
+
+       # prevent from failind building unregisterised ghc:
+       # http://www.mail-archive.com/debian-bugs-dist@lists.debian.org/msg171602.html
+       use ppc64 && append-ghc-cflags persistent compile -mminimal-toc
+       # fix the similar issue as ppc64 TOC on ia64. ia64 has limited size of small data
+       # currently ghc fails to build haddock
+       # http://osdir.com/ml/gnu.binutils.bugs/2004-10/msg00050.html
+       use ia64 && append-ghc-cflags persistent compile -G0 -Os
+}
+
+# substitutes string $1 to $2 in files $3 $4 ...
+relocate_path() {
+       local from=$1
+       local   to=$2
+       shift 2
+       local file=
+       for file in "$@"
+       do
+               sed -i -e "s|$from|$to|g" \
+                       "$file" || die "path relocation failed for '$file'"
+       done
+}
+
+# changes hardcoded ghc paths and updates package index
+# $1 - new absolute root path
+relocate_ghc() {
+       local to=$1
+
+       # libdir for prebuilt binary and for current system may mismatch
+       # It does for prefix installation for example: bug #476998
+       local bin_ghc_prefix=${WORKDIR}/usr
+       local bin_libpath=$(echo "${bin_ghc_prefix}"/lib*)
+       local bin_libdir=${bin_libpath#${bin_ghc_prefix}/}
+
+       # backup original script to use it later after relocation
+       local gp_back="${T}/ghc-pkg-${GHC_PV}-orig"
+       cp "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" "$gp_back" || die "unable to backup ghc-pkg wrapper"
+
+       if [[ ${bin_libdir} != $(get_libdir) ]]; then
+               einfo "Relocating '${bin_libdir}' to '$(get_libdir)' (bug #476998)"
+               # moving the dir itself is not strictly needed
+               # but then USE=binary would result in installing
+               # in '${bin_libdir}'
+               mv "${bin_ghc_prefix}/${bin_libdir}" "${bin_ghc_prefix}/$(get_libdir)" || die
+
+               relocate_path "/usr/${bin_libdir}" "/usr/$(get_libdir)" \
+                       "${WORKDIR}/usr/bin/ghc-${GHC_PV}" \
+                       "${WORKDIR}/usr/bin/ghci-${GHC_PV}" \
+                       "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" \
+                       "${WORKDIR}/usr/bin/hsc2hs" \
+                       "${WORKDIR}/usr/bin/runghc-${GHC_PV}" \
+                       "$gp_back" \
+                       "${WORKDIR}/usr/$(get_libdir)/${GHC_P}/package.conf.d/"*
+       fi
+
+       # Relocate from /usr to ${EPREFIX}/usr
+       relocate_path "/usr" "${to}/usr" \
+               "${WORKDIR}/usr/bin/ghc-${GHC_PV}" \
+               "${WORKDIR}/usr/bin/ghci-${GHC_PV}" \
+               "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" \
+               "${WORKDIR}/usr/bin/hsc2hs" \
+               "${WORKDIR}/usr/bin/runghc-${GHC_PV}" \
+               "${WORKDIR}/usr/$(get_libdir)/${GHC_P}/package.conf.d/"*
+
+       # this one we will use to regenerate cache
+       # so it should point to current tree location
+       relocate_path "/usr" "${WORKDIR}/usr" "$gp_back"
+
+       if use prefix; then
+               # and insert LD_LIBRARY_PATH entry to EPREFIX dir tree
+               # TODO: add the same for darwin's CHOST and it's DYLD_
+               local new_ldpath='LD_LIBRARY_PATH="'${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir)'${LD_LIBRARY_PATH:+:}${LD_LIBRARY_PATH}"\nexport LD_LIBRARY_PATH'
+               sed -i -e '2i'"$new_ldpath" \
+                       "${WORKDIR}/usr/bin/ghc-${GHC_PV}" \
+                       "${WORKDIR}/usr/bin/ghci-${GHC_PV}" \
+                       "${WORKDIR}/usr/bin/ghc-pkg-${GHC_PV}" \
+                       "${WORKDIR}/usr/bin/hsc2hs" \
+                       "${WORKDIR}/usr/bin/runghc-${GHC_PV}" \
+                       "$gp_back" \
+                       "${WORKDIR}/usr/bin/hsc2hs" \
+                       || die "Adding LD_LIBRARY_PATH for wrappers failed"
+       fi
+
+       # regenerate the binary package cache
+       "$gp_back" recache || die "failed to update cache after relocation"
+       rm "$gp_back"
+}
+
+pkg_setup() {
+       if use ghcbootstrap; then
+               ewarn "You requested ghc bootstrapping, this is usually only used"
+               ewarn "by Gentoo developers to make binary .tbz2 packages."
+
+               [[ -z $(type -P ghc) ]] && \
+                       die "Could not find a ghc to bootstrap with."
+       else
+               if ! yet_binary; then
+                       eerror "Please try emerging with USE=ghcbootstrap and report build"
+                       eerror "sucess or failure to the haskell team (haskell@gentoo.org)"
+                       die "No binary available for '${ARCH}' arch yet, USE=ghcbootstrap"
+               fi
+       fi
+}
+
+src_unpack() {
+       # Create the ${S} dir if we're using the binary version
+       use binary && mkdir "${S}"
+
+       # the Solaris and Darwin binaries from ghc (maeder) need to be
+       # unpacked separately, so prevent them from being unpacked
+       local ONLYA=${A}
+       case ${CHOST} in
+               *-darwin* | *-solaris*)  ONLYA=${GHC_P}-src.tar.bz2  ;;
+       esac
+       unpack ${ONLYA}
+
+       if [[ -d "${S}"/libraries/dph ]]; then
+               # Sometimes dph libs get accidentally shipped with ghc
+               # but they are not installed unless user requests it.
+               # We never install them.
+               elog "Removing 'libraries/dph'"
+               rm -rf "${S}"/libraries/dph
+       fi
+}
+
+src_prepare() {
+       ghc_setup_cflags
+
+       if ! use ghcbootstrap && [[ ${CHOST} != *-darwin* && ${CHOST} != *-solaris* ]]; then
+               # Modify the wrapper script from the binary tarball to use GHC_PERSISTENT_FLAGS.
+               # See bug #313635.
+               sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_PERSISTENT_FLAGS}|" \
+                       "${WORKDIR}/usr/bin/ghc-${GHC_PV}"
+
+               # allow hardened users use vanilla binary to bootstrap ghc
+               # ghci uses mmap with rwx protection at it implements dynamic
+               # linking on it's own (bug #299709)
+               pax-mark -m "${WORKDIR}/usr/$(get_libdir)/${GHC_P}/bin/ghc"
+       fi
+
+       if use binary; then
+               if use prefix; then
+                       relocate_ghc "${EPREFIX}"
+               fi
+
+               # Move unpacked files to the expected place
+               mv "${WORKDIR}/usr" "${S}"
+       else
+               if ! use ghcbootstrap; then
+                       case ${CHOST} in
+                               *-darwin* | *-solaris*)
+                               # UPDATE ME for ghc-7
+                               mkdir "${WORKDIR}"/ghc-bin-installer || die
+                               pushd "${WORKDIR}"/ghc-bin-installer > /dev/null || die
+                               use sparc-solaris && unpack ghc-6.10.4-sparc-sun-solaris2.tar.bz2
+                               use x86-solaris && unpack ghc-7.0.3-i386-unknown-solaris2.tar.bz2
+                               use x86-macos && unpack ghc-7.4.1-i386-apple-darwin.tar.bz2
+                               use x64-macos && unpack ghc-7.4.1-x86_64-apple-darwin.tar.bz2
+                               popd > /dev/null
+
+                               pushd "${WORKDIR}"/ghc-bin-installer/ghc-[67].?*.? > /dev/null || die
+                               # fix the binaries so they run, on Solaris we need an
+                               # LD_LIBRARY_PATH which has our prefix libdirs, on
+                               # Darwin we need to replace the frameworks with our libs
+                               # from the prefix fix before installation, because some
+                               # of the tools are actually used during configure/make
+                               if [[ ${CHOST} == *-solaris* ]] ; then
+                                       export LD_LIBRARY_PATH="${EPREFIX}/$(get_libdir):${EPREFIX}/usr/$(get_libdir):${LD_LIBRARY_PATH}"
+                               elif [[ ${CHOST} == *-darwin* ]] ; then
+                                       local readline_framework=GNUreadline.framework/GNUreadline
+                                       local gmp_framework=/opt/local/lib/libgmp.10.dylib
+                                       local ncurses_file=/opt/local/lib/libncurses.5.dylib
+                                       for binary in $(scanmacho -BRE MH_EXECUTE -F '%F' .) ; do
+                                               install_name_tool -change \
+                                                       ${readline_framework} \
+                                                       "${EPREFIX}"/lib/libreadline.dylib \
+                                                       ${binary} || die
+                                               install_name_tool -change \
+                                                       ${gmp_framework} \
+                                                       "${EPREFIX}"/usr/lib/libgmp.dylib \
+                                                       ${binary} || die
+                                               install_name_tool -change \
+                                                       ${ncurses_file} \
+                                                       "${EPREFIX}"/usr/lib/libncurses.dylib \
+                                                       ${binary} || die
+                                       done
+                                       # we don't do frameworks!
+                                       sed -i \
+                                               -e 's/\(frameworks = \)\["GMP"\]/\1[]/g' \
+                                               -e 's/\(extraLibraries = \)\["m"\]/\1["m","gmp"]/g' \
+                                               rts/package.conf.in || die
+                               fi
+
+                               # it is autoconf, but we really don't want to give it too
+                               # much arguments, in fact we do the make in-place anyway
+                               ./configure --prefix="${WORKDIR}"/usr || die
+                               make install || die
+                               popd > /dev/null
+                               ;;
+                               *)
+                               relocate_ghc "${WORKDIR}"
+                               ;;
+                       esac
+               fi
+
+               sed -i -e "s|\"\$topdir\"|\"\$topdir\" ${GHC_PERSISTENT_FLAGS}|" \
+                       "${S}/ghc/ghc.wrapper"
+
+               cd "${S}" # otherwise epatch will break
+
+               epatch "${FILESDIR}/ghc-7.0.4-CHOST-prefix.patch"
+
+               epatch "${FILESDIR}"/${PN}-7.8.1_rc1-libbfd.patch
+
+               epatch "${FILESDIR}"/${PN}-7.8.2-cgen-constify.patch
+               epatch "${FILESDIR}"/${PN}-7.8.3-prim-lm.patch
+               # bug 518734
+               epatch "${FILESDIR}"/${PN}-7.6.3-preserve-inplace-xattr.patch
+
+               # upstream backports
+               epatch "${FILESDIR}"/${PN}-7.8.3-linker-warn.patch
+               epatch "${FILESDIR}"/${PN}-7.8.3-pic-sparc.patch
+               epatch "${FILESDIR}"/${PN}-7.8.3-ppc32-fPIC.patch
+
+               if use prefix; then
+                       # Make configure find docbook-xsl-stylesheets from Prefix
+                       sed -e '/^FP_DIR_DOCBOOK_XSL/s:\[.*\]:['"${EPREFIX}"'/usr/share/sgml/docbook/xsl-stylesheets/]:' \
+                               -i utils/haddock/doc/configure.ac || die
+               fi
+
+               # as we have changed the build system
+               eautoreconf
+       fi
+}
+
+src_configure() {
+       if ! use binary; then
+               # initialize build.mk
+               echo '# Gentoo changes' > mk/build.mk
+
+               # Put docs into the right place, ie /usr/share/doc/ghc-${GHC_PV}
+               echo "docdir = ${EPREFIX}/usr/share/doc/${P}" >> mk/build.mk
+               echo "htmldir = ${EPREFIX}/usr/share/doc/${P}" >> mk/build.mk
+
+               # We also need to use the GHC_FLAGS flags when building ghc itself
+               echo "SRC_HC_OPTS+=${GHC_FLAGS}" >> mk/build.mk
+               echo "SRC_CC_OPTS+=${CFLAGS}" >> mk/build.mk
+               echo "SRC_LD_OPTS+=${LDFLAGS}" >> mk/build.mk
+
+               # We can't depend on haddock except when bootstrapping when we
+               # must build docs and include them into the binary .tbz2 package
+               # app-text/dblatex is not in portage, can not build PDF or PS
+               if use ghcbootstrap && use doc; then
+                       echo "BUILD_DOCBOOK_PDF  = NO"  >> mk/build.mk
+                       echo "BUILD_DOCBOOK_PS   = NO"  >> mk/build.mk
+                       echo "BUILD_DOCBOOK_HTML = YES" >> mk/build.mk
+                       echo "HADDOCK_DOCS       = YES" >> mk/build.mk
+               else
+                       echo "BUILD_DOCBOOK_PDF  = NO" >> mk/build.mk
+                       echo "BUILD_DOCBOOK_PS   = NO" >> mk/build.mk
+                       echo "BUILD_DOCBOOK_HTML = NO" >> mk/build.mk
+                       echo "HADDOCK_DOCS       = NO" >> mk/build.mk
+               fi
+
+               # allows overriding build flavours for libraries:
+               # v   - vanilla (static libs)
+               # p   - profiled
+               # dyn - shared libraries
+               # example: GHC_LIBRARY_WAYS="v dyn"
+               if [[ -n ${GHC_LIBRARY_WAYS} ]]; then
+                       echo "GhcLibWays=${GHC_LIBRARY_WAYS}" >> mk/build.mk
+               fi
+
+               # Get ghc from the unpacked binary .tbz2
+               # except when bootstrapping we just pick ghc up off the path
+               if ! use ghcbootstrap; then
+                       export PATH="${WORKDIR}/usr/bin:${PATH}"
+               fi
+
+               if use gmp; then
+                       echo "INTEGER_LIBRARY=integer-gmp" >> mk/build.mk
+               else
+                       echo "INTEGER_LIBRARY=integer-simple" >> mk/build.mk
+               fi
+
+               # don't strip anything. Very useful when stage2 SIGSEGVs on you
+               echo "STRIP_CMD = :" >> mk/build.mk
+
+               local econf_args=()
+
+               # GHC embeds 'gcc' it was built by and uses it later.
+               # Don't allow things like ccache or versioned binary slip.
+               # We use stable thing across gcc upgrades.
+               is_crosscompile || econf_args+=(--with-gcc=${CHOST}-gcc)
+
+               if ! use ghcmakebinary; then
+                       econf_args+=(--with-system-libffi)
+                       econf_args+=(--with-ffi-includes=$(pkg-config libffi --cflags-only-I | sed -e 's@^-I@@'))
+               fi
+
+               econf ${econf_args[@]} --enable-bootstrap-with-devel-snapshot
+
+               if [[ ${PV} == *9999* ]]; then
+                       GHC_PV="$(grep 'S\[\"PACKAGE_VERSION\"\]' config.status | sed -e 's@^.*=\"\(.*\)\"@\1@')"
+                       GHC_P=${PN}-${GHC_PV}
+               fi
+               GHC_TPF="$(grep 'S\[\"TargetPlatformFull\"\]' config.status | sed -e 's@^.*=\"\(.*\)\"@\1@')"
+       fi # ! use binary
+}
+
+src_compile() {
+       if ! use binary; then
+               # 1. build compiler binary first
+               emake ghc/stage2/build/tmp/ghc-stage2
+               # 2. pax-mark (bug #516430)
+               pax-mark -m ghc/stage2/build/tmp/ghc-stage2
+               # 3. and then all the rest
+               emake all
+       fi # ! use binary
+}
+
+src_install() {
+       if use binary; then
+               use prefix && mkdir -p "${ED}"
+               mv "${S}/usr" "${ED}"
+
+               # Remove the docs if not requested
+               if ! use doc; then
+                       rm -rf "${ED}/usr/share/doc/${P}/*/" \
+                               "${ED}/usr/share/doc/${P}/*.html" \
+                               || die "could not remove docs (P vs PF revision mismatch?)"
+               fi
+       else
+               # We only build docs if we were bootstrapping, otherwise
+               # we copy them out of the unpacked binary .tbz2
+               if use doc && ! use ghcbootstrap; then
+                       mkdir -p "${ED}/usr/share/doc"
+                       mv "${WORKDIR}/usr/share/doc/${P}" "${ED}/usr/share/doc" \
+                               || die "failed to copy docs"
+               else
+                       dodoc "${S}/distrib/README" "${S}/ANNOUNCE" "${S}/LICENSE" "${S}/VERSION"
+               fi
+
+               emake -j1 install DESTDIR="${D}"
+
+               # remove link, but leave 'haddock-${GHC_P}'
+               rm -f "${ED}"/usr/bin/haddock
+
+               if [[ ! -f "${S}/VERSION" ]]; then
+                       echo "${GHC_PV}" > "${S}/VERSION" \
+                               || die "Could not create file ${S}/VERSION"
+               fi
+               newbashcomp "${FILESDIR}/ghc-bash-completion" ghc-pkg
+
+       fi
+
+       # path to the package.cache
+       local package_confdir="${ED}/usr/$(get_libdir)/${GHC_P}/package.conf.d"
+       PKGCACHE="${package_confdir}"/package.cache
+       # copy the package.conf.d, including timestamp, save it so we can help
+       # users that have a broken package.conf.d
+       cp -pR "${package_confdir}"{,.initial} || die "failed to backup intial package.conf.d"
+
+       # copy the package.conf, including timestamp, save it so we later can put it
+       # back before uninstalling, or when upgrading.
+       cp -p "${PKGCACHE}"{,.shipped} \
+               || die "failed to copy package.conf.d/package.cache"
+}
+
+pkg_preinst() {
+       # have we got an earlier version of ghc installed?
+       if has_version "<${CATEGORY}/${PF}"; then
+               haskell_updater_warn="1"
+       fi
+}
+
+pkg_postinst() {
+       ghc-reregister
+
+       # path to the package.cache
+       PKGCACHE="${EROOT}/usr/$(get_libdir)/${GHC_P}/package.conf.d/package.cache"
+
+       # give the cache a new timestamp, it must be as recent as
+       # the package.conf.d directory.
+       touch "${PKGCACHE}"
+
+       if [[ "${haskell_updater_warn}" == "1" ]]; then
+               ewarn
+               ewarn "\e[1;31m************************************************************************\e[0m"
+               ewarn
+               ewarn "You have just upgraded from an older version of GHC."
+               ewarn "You may have to run"
+               ewarn "      'haskell-updater --upgrade'"
+               ewarn "to rebuild all ghc-based Haskell libraries."
+               ewarn
+               ewarn "\e[1;31m************************************************************************\e[0m"
+               ewarn
+       fi
+}
+
+pkg_prerm() {
+       # Be very careful here... Call order when upgrading is (according to PMS):
+       # * src_install for new package
+       # * pkg_preinst for new package
+       # * pkg_postinst for new package
+       # * pkg_prerm for the package being replaced
+       # * pkg_postrm for the package being replaced
+       # so you'll actually be touching the new packages files, not the one you
+       # uninstall, due to that or installation directory ${GHC_P} will be the same for
+       # both packages.
+
+       # Call order for reinstalling is (according to PMS):
+       # * src_install
+       # * pkg_preinst
+       # * pkg_prerm for the package being replaced
+       # * pkg_postrm for the package being replaced
+       # * pkg_postinst
+
+       # Overwrite the modified package.cache with a copy of the
+       # original one, so that it will be removed during uninstall.
+
+       PKGCACHE="${EROOT}/usr/$(get_libdir)/${GHC_P}/package.conf.d/package.cache"
+       rm -rf "${PKGCACHE}"
+
+       cp -p "${PKGCACHE}"{.shipped,}
+}