fix: consider relocatable data as writable (#570)
When declared as constant, read-only relocatable data are written to an unwriteable .rel.ro.data section. Being unwriteable, the gold linker doesn't put them inside the GNU_RELRO segment, but in a always read-only segment. Starting the relocation phase of such a built program then ends in a segmentation fault.
By declaring read-only relocatable data as writeable, they will be put inside a writeable .rel.ro.data section. The gold linker will then assume that those can be put inside the GNU_RELRO segment, that will only be writeable during the relocation phase.
The as assembler and ld linker will always consider the .rel.ro.data as writeable before relocation, and put the associated data in the GNU_RELRO.
Co-authored-by: Michivi <webmaster@michvi.com>
commit49ecc0e4dbe47756f130aa440a7f85ad29c682dd
authorLe Tuan <webmaster@michivi.com>
dateSat 9 May 2020, 01:04 (6 years ago)
parentde3f82a
compiler/ghc/default.nix+3
@@ -102,6 +102,9 @@ let
102102 GhcRtsHcOpts += -fPIC
103103 '' + stdenv.lib.optionalString targetPlatform.useAndroidPrebuilt ''
104104 EXTRA_CC_OPTS += -std=gnu99
105+ '' + stdenv.lib.optionalString useLLVM ''
106+ GhcStage2HcOpts += -fast-llvm
107+ GhcLibHcOpts += -fast-llvm
105108 '' + stdenv.lib.optionalString (!enableTerminfo) ''
106109 WITH_TERMINFO=NO
107110 ''
overlays/bootstrap.nix+1
@@ -107,6 +107,7 @@ in {
107107 ++ final.lib.optional (version == "8.6.4") ./patches/ghc/ghc-8.6.4-reinstallable-lib-ghc.patch
108108 ++ final.lib.optional (version == "8.6.5") ./patches/ghc/ghc-8.6.5-reinstallable-lib-ghc.patch
109109 ++ final.lib.optional (version == "8.6.5") ./patches/ghc/ghc-8.6.5-atomic-arm-arch.patch
110+ ++ final.lib.optional (version == "8.6.5") ./patches/ghc/MR3214-writable-rel-ro-data.patch
110111 ++ final.lib.optional (version == "8.8.1") ./patches/ghc/ghc-8.8.1-reinstallable-lib-ghc.patch
111112 ++ fromUntil "8.8.2" "8.9" ./patches/ghc/ghc-8.8.2-reinstallable-lib-ghc.patch
112113 ++ final.lib.optional (version == "8.6.4") ./patches/ghc/ghc-8.6.4-better-plusSimplCountErrors.patch
overlays/patches/ghc/MR3214-writable-rel-ro-data.patchnew file+13
@@ -0,0 +1,13 @@
1+diff --git a/compiler/cmm/Cmm.hs b/compiler/cmm/Cmm.hs
2+index eb34618..f2cc32f 100644
3+--- a/compiler/cmm/Cmm.hs
4++++ b/compiler/cmm/Cmm.hs
5+@@ -181,7 +181,7 @@ isSecConstant :: Section -> Bool
6+ isSecConstant (Section t _) = case t of
7+ Text -> True
8+ ReadOnlyData -> True
9+- RelocatableReadOnlyData -> True
10++ RelocatableReadOnlyData -> False
11+ ReadOnlyData16 -> True
12+ CString -> True
13+ Data -> False