From: wolfgang Date: Sun, 23 Jan 2005 18:50:45 +0000 (+0000) Subject: [project @ 2005-01-23 18:50:40 by wolfgang] X-Git-Tag: Initial_conversion_from_CVS_complete~1198 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=e171a977fee973066ab0fd871a6b8ac9cfe20a58 [project @ 2005-01-23 18:50:40 by wolfgang] Make the NCG distinguish between the read-only data section and the "relocatable read-only data" section. Read-only data is supposed to be _really_ read-only, whereas "relrodata" can have relocations, but should not be modified by the program at runtime. For Linux, put relrodata into ".data" by default, as the dynamic linker tends to do evil things to avoid relocating things in read-only sections. --- diff --git a/ghc/compiler/cmm/Cmm.hs b/ghc/compiler/cmm/Cmm.hs index 9fcc96e..aa92e01 100644 --- a/ghc/compiler/cmm/Cmm.hs +++ b/ghc/compiler/cmm/Cmm.hs @@ -239,6 +239,7 @@ data Section = Text | Data | ReadOnlyData + | RelocatableReadOnlyData | UninitialisedData | OtherSection String diff --git a/ghc/compiler/cmm/PprCmm.hs b/ghc/compiler/cmm/PprCmm.hs index 5279f05..7023432 100644 --- a/ghc/compiler/cmm/PprCmm.hs +++ b/ghc/compiler/cmm/PprCmm.hs @@ -444,6 +444,8 @@ pprSection s = case s of Text -> section <+> doubleQuotes (ptext SLIT("text")) Data -> section <+> doubleQuotes (ptext SLIT("data")) ReadOnlyData -> section <+> doubleQuotes (ptext SLIT("readonly")) + RelocatableReadOnlyData + -> section <+> doubleQuotes (ptext SLIT("relreadonly")) UninitialisedData -> section <+> doubleQuotes (ptext SLIT("uninitialised")) OtherSection s' -> section <+> doubleQuotes (text s') where diff --git a/ghc/compiler/codeGen/CgUtils.hs b/ghc/compiler/codeGen/CgUtils.hs index 414e90a..8c29e9c 100644 --- a/ghc/compiler/codeGen/CgUtils.hs +++ b/ghc/compiler/codeGen/CgUtils.hs @@ -299,7 +299,12 @@ emitDataLits lbl lits emitRODataLits :: CLabel -> [CmmLit] -> Code -- Emit a read-only data block emitRODataLits lbl lits - = emitData ReadOnlyData (CmmDataLabel lbl : map CmmStaticLit lits) + = emitData section (CmmDataLabel lbl : map CmmStaticLit lits) + where section | any needsRelocation lits = RelocatableReadOnlyData + | otherwise = ReadOnlyData + needsRelocation (CmmLabel _) = True + needsRelocation (CmmLabelOff _ _) = True + needsRelocation _ = False mkStringCLit :: String -> FCode CmmLit -- Make a global definition for the string, diff --git a/ghc/compiler/nativeGen/MachCodeGen.hs b/ghc/compiler/nativeGen/MachCodeGen.hs index 6f0b2f44..20aad78 100644 --- a/ghc/compiler/nativeGen/MachCodeGen.hs +++ b/ghc/compiler/nativeGen/MachCodeGen.hs @@ -3388,12 +3388,19 @@ genSwitch expr ids dynRef <- cmmMakeDynamicReference addImportNat False lbl (tableReg,t_code) <- getSomeReg $ dynRef let - jumpTable = map jumpTableEntry ids - + jumpTable = map jumpTableEntryRel ids + + jumpTableEntryRel Nothing + = CmmStaticLit (CmmInt 0 wordRep) + jumpTableEntryRel (Just (BlockId id)) + = CmmStaticLit (CmmLabelDiffOff blockLabel lbl 0) + where blockLabel = mkAsmTempLabel id + code = e_code `appOL` t_code `appOL` toOL [ LDATA ReadOnlyData (CmmDataLabel lbl : jumpTable), SLW tmp reg (RIImm (ImmInt 2)), LD I32 tmp (AddrRegReg tableReg tmp), + ADD tmp tmp (RIReg tableReg), MTCTR tmp, BCTR [ id | Just id <- ids ] ] diff --git a/ghc/compiler/nativeGen/PprMach.hs b/ghc/compiler/nativeGen/PprMach.hs index 9c73def..0f33ca3 100644 --- a/ghc/compiler/nativeGen/PprMach.hs +++ b/ghc/compiler/nativeGen/PprMach.hs @@ -535,15 +535,6 @@ pprAddr (AddrRegImm r1 imm) = hcat [ pprImm imm, char '(', pprReg r1, char ')' ] -- ----------------------------------------------------------------------------- -- pprData: print a 'CmmStatic' -#if defined(linux_TARGET_OS) -#if defined(powerpc_TARGET_ARCH) || defined(i386_TARGET_ARCH) - -- Hack to make dynamic linking work -pprSectionHeader ReadOnlyData - | not opt_PIC && not opt_Static - = pprSectionHeader Data -#endif -#endif - pprSectionHeader Text = ptext IF_ARCH_alpha(SLIT("\t.text\n\t.align 3") {-word boundary-} @@ -563,9 +554,17 @@ pprSectionHeader ReadOnlyData IF_ARCH_alpha(SLIT("\t.data\n\t.align 3") ,IF_ARCH_sparc(SLIT(".data\n\t.align 8") {-<8 will break double constants -} ,IF_ARCH_i386(SLIT(".section .rodata\n\t.align 4") - ,IF_ARCH_powerpc(IF_OS_darwin(SLIT(".const_data\n.align 2"), + ,IF_ARCH_powerpc(IF_OS_darwin(SLIT(".const\n.align 2"), SLIT(".section .rodata\n\t.align 2")) ,)))) +pprSectionHeader RelocatableReadOnlyData + = ptext + IF_ARCH_alpha(SLIT("\t.data\n\t.align 3") + ,IF_ARCH_sparc(SLIT(".data\n\t.align 8") {-<8 will break double constants -} + ,IF_ARCH_i386(SLIT(".data\n\t.align 4") + ,IF_ARCH_powerpc(IF_OS_darwin(SLIT(".const_data\n.align 2"), + SLIT(".data\n\t.align 2")) + ,)))) pprSectionHeader UninitialisedData = ptext IF_ARCH_alpha(SLIT("\t.bss\n\t.align 3")