• Erik de Castro Lopo's avatar
    Fix GHCi segfault during startup on linux-powerpc (#2972). · 3e6c9308
    Erik de Castro Lopo authored
    Slightly modified version of a patch from Ben Collins <bcollins@ubuntu.com>
    who did the final debugging that showed the segfault was being caused the
    memory protection mechanism.
    Due to the requirement of "jump islands" to handle 24 bit relative jump
    offsets, GHCi on PowerPC did not use mmap to load object files like the
    other architectures. Instead, it allocated memory using malloc and fread
    to load the object code. However there is a quirk in the GNU libc malloc
    implementation. For memory regions over certain size (dynamic and
    configurable), malloc will use mmap to obtain the required memory instead
    of sbrk and malloc's call to mmap sets the memory readable and writable,
    but not executable. That means when GHCi loads code into a memory region
    that was mmapped instead of malloc-ed and tries to execute it we get a
    This solution drops the malloc/fread object loading in favour of using
    mmap and then puts the jump island for each object code module at the
    end of the mmaped region for that object.
    This patch may also be a solution on other ELF based powerpc systems
    but does not work on darwin-powerpc.
Linker.c 234 KB