[Git][ghc/ghc][wip/bss-alignment] rts/linker: Align bssSize to page size when mapping symbol extras

Ben Gamari gitlab at gitlab.haskell.org
Wed Nov 18 16:42:48 UTC 2020



Ben Gamari pushed to branch wip/bss-alignment at Glasgow Haskell Compiler / GHC


Commits:
0ab1a308 by Ben Gamari at 2020-11-18T11:42:43-05:00
rts/linker: Align bssSize to page size when mapping symbol extras

We place symbol_extras right after bss. We also need
to ensure that symbol_extras can be mprotect'd independently from the
rest of the image. To ensure this we round up the size of bss to a page
boundary, thus ensuring that symbol_extras is also page-aligned.

- - - - -


1 changed file:

- rts/linker/SymbolExtras.c


Changes:

=====================================
rts/linker/SymbolExtras.c
=====================================
@@ -77,7 +77,9 @@ int ocAllocateExtras(ObjectCode* oc, int count, int first, int bssSize)
       /* N.B. We currently can't mark symbol extras as non-executable in this
        * case. */
       size_t n = roundUpToPage(oc->fileSize);
-      bssSize = roundUpToAlign(bssSize, 8);
+      // round bssSize up to the nearest page size since we need to ensure that
+      // symbol_extras is aligned to a page boundary so it can be mprotect'd.
+      bssSize = roundUpToPage(bssSize);
       size_t allocated_size = n + bssSize + extras_size;
       void *new = mmapForLinker(allocated_size, PROT_READ | PROT_WRITE, MAP_ANONYMOUS, -1, 0);
       if (new) {



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0ab1a308139e73070b23b156a83eb094a97ba0ec

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0ab1a308139e73070b23b156a83eb094a97ba0ec
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/20201118/cffd3cba/attachment-0001.html>


More information about the ghc-commits mailing list