Make constructor names in info tables position independent
authorwolfgang.thaller@gmx.net <unknown>
Thu, 8 Mar 2007 02:05:03 +0000 (02:05 +0000)
committerwolfgang.thaller@gmx.net <unknown>
Thu, 8 Mar 2007 02:05:03 +0000 (02:05 +0000)
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.)

compiler/codeGen/CgInfoTbls.hs
compiler/ghci/ByteCodeItbls.lhs
compiler/ghci/Linker.lhs
driver/mangler/ghc-asm.lprl

index fed5d80..da48005 100644 (file)
@@ -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 }
index 887f637..2973c03 100644 (file)
@@ -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
index 37fe289..4508e4b 100644 (file)
@@ -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
index 941d608..0cd4781 100644 (file)
@@ -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/