Skip to content

T13624 section alignment (Mach-O, x64)

Artem Pyanykh requested to merge artempyanykh/ghc:T13624-sec-align into master

Fixes #13624 for MacOS.

This is my fist MR to GHC, so any pieces of feedback are highly appreciated.

Changes (affects only x64):

  1. Sections are grouped into Segments and memcopied from image with proper alignment.
  2. Relocation logic is adjusted to work with object code Sections rather then hardwired to work with in-image macho_sections (mostly affected internal relocations).
  3. Fixed a potential segfault (when kernel gives a page with address before image while offset is unsigned) and memleak (page is mmapped but marked as NOMEM) in handling of zerofill sections (e.g. bss).
  4. Add tests: internal relocs and section alignment.
  5. Remove branching on RTS_LINKER_USE_MMAP (see. Q1 below).
  6. Relocation should probably be a tad faster now, since we don't call relocateAddress for every external relocation, but rather use addr from MachoSymbol.

Questions:

  1. RTS_LINKER_USE_MMAP is configured with autoconf to be 1 for all platforms except Windows. Is there any reason one would redefine it to 0 in ghcautoconf.h? If not then branching on this constant in darwin-specific code don't make much sense to me.

Todo (preferably in separate MRs):

  1. Memprotect RX segment after ocResolve.
  2. Create 1 jump island per symbol rather than per relocation here.
  3. Remove misalignment logic as it doesn't seem to be needed now.
  4. Move linker-specific tests to rts/linker for convenience.
  5. Fix other other platforms/formats 😄
Edited by Artem Pyanykh

Merge request reports