T13624 section alignment (Mach-O, x64)
Fixes #13624 for MacOS.
This is my fist MR to GHC, so any pieces of feedback are highly appreciated.
Changes (affects only x64):
- Sections are grouped into Segments and memcopied from image with proper alignment.
- Relocation logic is adjusted to work with object code
Sections rather then hardwired to work with in-image
macho_sections (mostly affected internal relocations).
- 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).
- Add tests: internal relocs and section alignment.
- Remove branching on
RTS_LINKER_USE_MMAP(see. Q1 below).
- Relocation should probably be a tad faster now, since we don't call
relocateAddressfor every external relocation, but rather use
RTS_LINKER_USE_MMAPis 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):
- Memprotect RX segment after ocResolve.
- Create 1 jump island per symbol rather than per relocation here.
- Remove misalignment logic as it doesn't seem to be needed now.
- Move linker-specific tests to
- Fix other other platforms/formats