Always check the relocation value for x86_64
authorZejun Wu <watashi@watashi.ws>
Mon, 1 Oct 2018 13:12:29 +0000 (15:12 +0200)
committerKrzysztof Gogolewski <krz.gogolewski@gmail.com>
Mon, 1 Oct 2018 13:12:29 +0000 (15:12 +0200)
commite44c992ff62ae8d55b297db9f721ee7a40357a76
tree8a8fc3e4f9ca39911d94b67bb803ddabf52a5982
parentdf67f95b2fc1c8b7200d98643e76c5feab4ed876
Always check the relocation value for x86_64

Summary:
Always check that no overflow happens during relocation for x86_64.
It's not safe to assume the result returned by `ocAllocateSymbolExtras` is
always valid if we allocate it neither in lower 2G nor in a contiguous range
with the image.

There are also some minor fixes in this diff:

* `off >= 0x7fffffffL` should be `>`
* use of unaligned pointer is undefined behavior, use `memcpy` instead, gcc
  will be able to optimize it to `mov %edx, (%rax)`.

Test Plan:
build ghci with:

```
DYNAMIC_GHC_PROGRAMS = NO
DYNAMIC_BY_DEFAULT = NO
```

and play with it.

  ./validate

Reviewers: simonmar, austin, bgamari, erikd

Reviewed By: simonmar

Subscribers: alpmestan, rwbarton, carter

Differential Revision: https://phabricator.haskell.org/D5168
rts/linker/Elf.c