[commit: ghc] master: Make mmap r+w only during preload for iOS. (fdbbd63)

git at git.haskell.org git at git.haskell.org
Mon Mar 27 03:01:06 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/fdbbd63db18cf3ba0cd8f0d61da904317ae5ae01/ghc

>---------------------------------------------------------------

commit fdbbd63db18cf3ba0cd8f0d61da904317ae5ae01
Author: Moritz Angermann <moritz.angermann at gmail.com>
Date:   Tue Mar 21 10:58:28 2017 -0400

    Make mmap r+w only during preload for iOS.
    
    While we do not yet enable mmap for ios builds.  If we later do, we must
    not try to mmap r+w+x, on iOS as that clearly fails.
    
    This diff also adds a check for the successful mmaping.
    
    I don't think we can blanket change this to r+w for every case, unless
    we are absolutely sure that we are going to remap this and set +x where
    needed.
    
    This is just one of the pieces for the rts linker support for ios
    (aarch64-macho)
    
    ---
    
    The following diagram and legend tries to explain the dependencies a
    bit:
    ```
      .- D3240
      v
    D3255 <- D3252 <- D3251 <- D3239
      ^
      '- This
    ```
    
    - In D3238 we started allowing preloading object code with mmap
      in iOS, where we can't have r+w+x.
    - In D3239 we introduced a richer extension of the object code
      data type to make working with mach-o files easier.
    - In D3240 we set the stage to allow loading archives (.a) on iOS
    - In D3251 we added init and deinit functions to populate and
      depopulate the enriched object code data structure for mach-o
      files.
    - In D3252 we refactored most of the MachO.c file to use the
      new types and data structure.
    - in D3255 we finally introduce the aarch64-mach-o linker.
    
    Reviewers: ezyang, austin, erikd, simonmar, bgamari, rwbarton
    
    Reviewed By: bgamari
    
    Subscribers: rwbarton, ryantrinkle, thomie
    
    Differential Revision: https://phabricator.haskell.org/D3238


>---------------------------------------------------------------

fdbbd63db18cf3ba0cd8f0d61da904317ae5ae01
 rts/Linker.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 247f246..7654f2b 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1308,9 +1308,26 @@ preloadObjectFile (pathchar *path)
       return NULL;
    }
 
+   /* iOS does not permit to mmap with r+w+x, however while the comment for
+    * this function says this is not the final resting place, for some
+    * architectures / hosts (at least mach-o non-iOS -- see ocGetNames_MachO)
+    * the image mmaped here in fact ends up being the final resting place for
+    * the sections. And hence we need to leave r+w+x here for other hosts
+    * until all hosts have been made aware of the initial image being r+w only.
+    *
+    * See also the misalignment logic for darwin below.
+    */
+#if defined(ios_HOST_OS)
+   image = mmap(NULL, fileSize, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
+#else
    image = mmap(NULL, fileSize, PROT_READ|PROT_WRITE|PROT_EXEC,
                 MAP_PRIVATE, fd, 0);
-       // not 32-bit yet, we'll remap later
+#endif
+
+   if (image == MAP_FAILED) {
+       errorBelch("mmap: failed. errno = %d", errno);
+   }
+   // not 32-bit yet, we'll remap later
    close(fd);
 
 #else /* !RTS_LINKER_USE_MMAP */



More information about the ghc-commits mailing list