From b648333f6b4c78f7ac1528cd9f780221a058591e Mon Sep 17 00:00:00 2001 From: "wolfgang.thaller@gmx.net" Date: Thu, 8 Mar 2007 02:05:03 +0000 Subject: [PATCH] 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.) --- compiler/codeGen/CgInfoTbls.hs | 3 ++- compiler/ghci/ByteCodeItbls.lhs | 19 +++++++++++++++++-- compiler/ghci/Linker.lhs | 4 +++- driver/mangler/ghc-asm.lprl | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/compiler/codeGen/CgInfoTbls.hs b/compiler/codeGen/CgInfoTbls.hs index fed5d80..da48005 100644 --- a/compiler/codeGen/CgInfoTbls.hs +++ b/compiler/codeGen/CgInfoTbls.hs @@ -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 } diff --git a/compiler/ghci/ByteCodeItbls.lhs b/compiler/ghci/ByteCodeItbls.lhs index 887f637..2973c03 100644 --- a/compiler/ghci/ByteCodeItbls.lhs +++ b/compiler/ghci/ByteCodeItbls.lhs @@ -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 diff --git a/compiler/ghci/Linker.lhs b/compiler/ghci/Linker.lhs index 37fe289..4508e4b 100644 --- a/compiler/ghci/Linker.lhs +++ b/compiler/ghci/Linker.lhs @@ -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 diff --git a/driver/mangler/ghc-asm.lprl b/driver/mangler/ghc-asm.lprl index 941d608..0cd4781 100644 --- a/driver/mangler/ghc-asm.lprl +++ b/driver/mangler/ghc-asm.lprl @@ -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/ -- 1.7.10.4