Make constructor names in info tables position independent

Info tables, like everything else in the text section, MUST NOT contain
pointers. A pointer is, by definition, position dependent and is therefore
fundamentally incompatible with generating position independent code.

Therefore, we have to store an offset from the info label to the string
instead of the pointer, just as we already did for other things referred
to by the info table (SRTs, large bitmaps, etc.)
parent a6484221
......@@ -89,7 +89,8 @@ emitClosureCodeAndInfoTable cl_info args body
; conName <-
if is_con
then mkStringCLit $ fromJust conIdentity
then do cstr <- mkStringCLit $ fromJust conIdentity
return (makeRelativeRefTo info_lbl cstr)
else return (mkIntCLit 0)
; emitInfoTableAndCode info_lbl std_info (extra_bits conName) args blks }
......
......@@ -279,17 +279,32 @@ instance Storable StgConInfoTable where
alignment conInfoTable = SIZEOF_VOID_P
peek ptr
= runState (castPtr ptr) $ do
#ifdef GHCI_TABLES_NEXT_TO_CODE
desc <- load
#endif
itbl <- load
#ifndef GHCI_TABLES_NEXT_TO_CODE
desc <- load
#endif
return
StgConInfoTable
{ conDesc = desc
{
#ifdef GHCI_TABLES_NEXT_TO_CODE
conDesc = castPtr $ ptr `plusPtr` wORD_SIZE `plusPtr` desc
#else
conDesc = desc
#endif
, infoTable = itbl
}
poke ptr itbl
= runState (castPtr ptr) $ do
store (conDesc itbl)
#ifdef GHCI_TABLES_NEXT_TO_CODE
store (conDesc itbl `minusPtr` (ptr `plusPtr` wORD_SIZE))
#endif
store (infoTable itbl)
#ifndef GHCI_TABLES_NEXT_TO_CODE
store (conDesc itbl)
#endif
data StgInfoTable = StgInfoTable {
#ifndef GHCI_TABLES_NEXT_TO_CODE
......
......@@ -213,13 +213,15 @@ recoverDataCon x = do
getConDescAddress :: Ptr StgInfoTable -> IO (Ptr CChar)
getConDescAddress ptr = do
peek $ intPtrToPtr $ (ptrToIntPtr ptr) + offset
#ifdef GHCI_TABLES_NEXT_TO_CODE
offsetToString <- peek $ intPtrToPtr $ (ptrToIntPtr ptr) + offset
return $ ptr `plusPtr` offsetToString
where
-- subtract a word number of bytes
offset = negate (fromIntegral SIZEOF_VOID_P)
#endif
#ifndef GHCI_TABLES_NEXT_TO_CODE
peek $ intPtrToPtr $ (ptrToIntPtr ptr) + offset
where
-- add the standard info table size in bytes
infoTableSizeBytes = sTD_ITBL_SIZE * wORD_SIZE
......
......@@ -1779,6 +1779,7 @@ sub rev_tbl {
$line =~ s/$infoname/0/
|| $line =~ s/([A-Za-z0-9_]+_srtd)$/\1 - $infoname/
|| $line =~ s/([A-Za-z0-9_]+_srt(\+\d+)?)$/\1 - $infoname/
|| $line =~ s/([A-Za-z0-9_]+_str)$/\1 - $infoname/
|| $line =~ s/([A-Za-z0-9_]+_slow)$/\1 - $infoname/
|| $line =~ s/([A-Za-z0-9_]+_btm)$/\1 - $infoname/
|| $line =~ s/([A-Za-z0-9_]+_alt)$/\1 - $infoname/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment