diff options
author | Tuan Le <ihnaut.if@gmail.com> | 2020-05-04 16:40:01 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-05-21 12:16:46 -0400 |
commit | 0004ccb885e534c386ceae21580fc59ec7ad0ede (patch) | |
tree | eb377eaf30ed7e5e02d02005210b515b869bd88d /compiler/GHC/Cmm.hs | |
parent | cf5663300c3d8b8b3c7dc2cd0dce2c923ec68987 (diff) | |
download | haskell-0004ccb885e534c386ceae21580fc59ec7ad0ede.tar.gz |
llvmGen: Consider Relocatable read-only data as not constantReferences: #18137
Diffstat (limited to 'compiler/GHC/Cmm.hs')
-rw-r--r-- | compiler/GHC/Cmm.hs | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/compiler/GHC/Cmm.hs b/compiler/GHC/Cmm.hs index 48ffd25f1b..440b6fd9d0 100644 --- a/compiler/GHC/Cmm.hs +++ b/compiler/GHC/Cmm.hs @@ -12,7 +12,7 @@ module GHC.Cmm ( CmmBlock, RawCmmDecl, Section(..), SectionType(..), GenCmmStatics(..), type CmmStatics, type RawCmmStatics, CmmStatic(..), - isSecConstant, + SectionProtection(..), sectionProtection, -- ** Blocks containing lists GenBasicBlock(..), blockId, @@ -185,17 +185,33 @@ data SectionType | OtherSection String deriving (Show) --- | Should a data in this section be considered constant -isSecConstant :: Section -> Bool -isSecConstant (Section t _) = case t of - Text -> True - ReadOnlyData -> True - RelocatableReadOnlyData -> True - ReadOnlyData16 -> True - CString -> True - Data -> False - UninitialisedData -> False - (OtherSection _) -> False +data SectionProtection + = ReadWriteSection + | ReadOnlySection + | WriteProtectedSection -- See Note [Relocatable Read-Only Data] + deriving (Eq) + +-- | Should a data in this section be considered constant at runtime +sectionProtection :: Section -> SectionProtection +sectionProtection (Section t _) = case t of + Text -> ReadOnlySection + ReadOnlyData -> ReadOnlySection + RelocatableReadOnlyData -> WriteProtectedSection + ReadOnlyData16 -> ReadOnlySection + CString -> ReadOnlySection + Data -> ReadWriteSection + UninitialisedData -> ReadWriteSection + (OtherSection _) -> ReadWriteSection + +{- +Note [Relocatable Read-Only Data] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Relocatable data are only read-only after relocation at the start of the +program. They should be writable from the source code until then. Failure to +do so would end up in segfaults at execution when using linkers that do not +enforce writability of those sections, such as the gold linker. +-} data Section = Section SectionType CLabel |