summaryrefslogtreecommitdiff
path: root/compiler/utils/Binary.hs
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2009-02-06 14:02:49 +0000
committerIan Lynagh <igloo@earth.li>2009-02-06 14:02:49 +0000
commit497302c44ad08c6c27d0e15d94a787f332c0cfec (patch)
treea78fd252a39c2d49b5a5219a2c968004c5a1c029 /compiler/utils/Binary.hs
parent1353826e5159c9a5a81e75e0b7459271f27c08ea (diff)
downloadhaskell-497302c44ad08c6c27d0e15d94a787f332c0cfec.tar.gz
When generating C, don't pretend functions are data
We used to generated things like: extern StgWordArray (newCAF) __attribute__((aligned (8))); ((void (*)(void *))(W_)&newCAF)((void *)R1.w); (which is to say, pretend that newCAF is some data, then cast it to a function and call it). This goes wrong on at least IA64, where: A function pointer on the ia64 does not point to the first byte of code. Intsead, it points to a structure that describes the function. The first quadword in the structure is the address of the first byte of code so we end up dereferencing function pointers one time too many, and segfaulting.
Diffstat (limited to 'compiler/utils/Binary.hs')
-rw-r--r--compiler/utils/Binary.hs11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs
index 4f48a424b3..c61f8a6baa 100644
--- a/compiler/utils/Binary.hs
+++ b/compiler/utils/Binary.hs
@@ -67,6 +67,7 @@ import Panic
import UniqFM
import FastMutInt
import Fingerprint
+import BasicTypes
import Foreign
import Data.Array
@@ -726,3 +727,13 @@ instance Binary Fingerprint where
put_ h (Fingerprint w1 w2) = do put_ h w1; put_ h w2
get h = do w1 <- get h; w2 <- get h; return (Fingerprint w1 w2)
+instance Binary FunctionOrData where
+ put_ bh IsFunction = putByte bh 0
+ put_ bh IsData = putByte bh 1
+ get bh = do
+ h <- getByte bh
+ case h of
+ 0 -> return IsFunction
+ 1 -> return IsData
+ _ -> panic "Binary FunctionOrData"
+