[Git][ghc/ghc][master] 2 commits: rts/linker: Mmap into low memory on AArch64

Marge Bot gitlab at gitlab.haskell.org
Tue Jun 11 22:43:10 UTC 2019



 Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
cf7f36ae by Ben Gamari at 2019-06-11T22:43:05Z
rts/linker: Mmap into low memory on AArch64

This extends mmapForLinker to use the same low-memory mapping
strategy used on x86_64 on AArch64. See #16784.

- - - - -
0b7f81f5 by Ben Gamari at 2019-06-11T22:43:05Z
rts/linker: Use mmapForLinker to map PLT

The PLT needs to be located within a close distance of
the code calling it under the small memory model.

Fixes #16784.

- - - - -


2 changed files:

- rts/Linker.c
- rts/linker/Elf.c


Changes:

=====================================
rts/Linker.c
=====================================
@@ -182,28 +182,37 @@ Mutex linker_unloaded_mutex;
 /* Generic wrapper function to try and Resolve and RunInit oc files */
 int ocTryLoad( ObjectCode* oc );
 
-/* Link objects into the lower 2Gb on x86_64.  GHC assumes the
+/* Link objects into the lower 2Gb on x86_64 and AArch64.  GHC assumes the
  * small memory model on this architecture (see gcc docs,
  * -mcmodel=small).
  *
  * MAP_32BIT not available on OpenBSD/amd64
  */
-#if defined(x86_64_HOST_ARCH) && defined(MAP_32BIT)
+#if defined(MAP_32BIT) && defined(x86_64_HOST_ARCH)
+#define MAP_LOW_MEM
 #define TRY_MAP_32BIT MAP_32BIT
 #else
 #define TRY_MAP_32BIT 0
 #endif
 
+#if defined(aarch64_HOST_ARCH)
+// On AArch64 MAP_32BIT is not available but we are still bound by the small
+// memory model. Consequently we still try using the MAP_LOW_MEM allocation
+// strategy.
+#define MAP_LOW_MEM
+#endif
+
 /*
- * Due to the small memory model (see above), on x86_64 we have to map
- * all our non-PIC object files into the low 2Gb of the address space
- * (why 2Gb and not 4Gb?  Because all addresses must be reachable
- * using a 32-bit signed PC-relative offset). On Linux we can do this
- * using the MAP_32BIT flag to mmap(), however on other OSs
- * (e.g. *BSD, see #2063, and also on Linux inside Xen, see #2512), we
- * can't do this.  So on these systems, we have to pick a base address
- * in the low 2Gb of the address space and try to allocate memory from
- * there.
+ * Note [MAP_LOW_MEM]
+ * ~~~~~~~~~~~~~~~~~~
+ * Due to the small memory model (see above), on x86_64 and AArch64 we have to
+ * map all our non-PIC object files into the low 2Gb of the address space (why
+ * 2Gb and not 4Gb?  Because all addresses must be reachable using a 32-bit
+ * signed PC-relative offset). On x86_64 Linux we can do this using the
+ * MAP_32BIT flag to mmap(), however on other OSs (e.g. *BSD, see #2063, and
+ * also on Linux inside Xen, see #2512), we can't do this.  So on these
+ * systems, we have to pick a base address in the low 2Gb of the address space
+ * and try to allocate memory from there.
  *
  * We pick a default address based on the OS, but also make this
  * configurable via an RTS flag (+RTS -xm)
@@ -1006,7 +1015,7 @@ mmapForLinker (size_t bytes, uint32_t flags, int fd, int offset)
    IF_DEBUG(linker, debugBelch("mmapForLinker: start\n"));
    size = roundUpToPage(bytes);
 
-#if defined(x86_64_HOST_ARCH)
+#if defined(MAP_LOW_MEM)
 mmap_again:
 #endif
 
@@ -1031,7 +1040,7 @@ mmap_again:
        return NULL;
    }
 
-#if defined(x86_64_HOST_ARCH)
+#if defined(MAP_LOW_MEM)
    if (RtsFlags.MiscFlags.linkerAlwaysPic) {
    } else if (mmap_32bit_base != 0) {
        if (result == map_addr) {


=====================================
rts/linker/Elf.c
=====================================
@@ -745,12 +745,8 @@ ocGetNames_ELF ( ObjectCode* oc )
           unsigned nstubs = numberOfStubsForSection(oc, i);
           unsigned stub_space = STUB_SIZE * nstubs;
 
-          void * mem = mmap(NULL, size+stub_space,
-                            PROT_READ | PROT_WRITE | PROT_EXEC,
-                            MAP_ANON | MAP_PRIVATE,
-                            -1, 0);
-
-          if( mem == MAP_FAILED ) {
+          void * mem = mmapForLinker(size+stub_space, MAP_ANON, -1, 0);
+          if( mem == NULL ) {
               barf("failed to mmap allocated memory to load section %d. "
                    "errno = %d", i, errno);
           }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/457fe7897d42e4359b6da6b359fd7ea8ae0f1d75...0b7f81f560c602f32cfc90fd3fb5f1c52f06ad49

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/compare/457fe7897d42e4359b6da6b359fd7ea8ae0f1d75...0b7f81f560c602f32cfc90fd3fb5f1c52f06ad49
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20190611/8080d8e7/attachment-0001.html>


More information about the ghc-commits mailing list