diff options
author | Zejun Wu <watashi@fb.com> | 2018-10-15 13:52:53 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-10-30 12:21:46 -0400 |
commit | e019ec94f12268dd92ea5d5204e9e57e7ebf10ca (patch) | |
tree | 7c33b231d857973084b04f575ee60960cdf0a5c4 /rts/linker/SymbolExtras.c | |
parent | 5403a8636fe82f971234873564f3a05393b89b7a (diff) | |
download | haskell-wip/fix-i386-2.tar.gz |
Allocate bss section within proper range of other sectionswip/fix-i386-2
Allocate bss section within proper range of other sections:
* when `+RTS -xp` is passed, allocate it contiguously as we did for
jump islands
* when we mmap the code to lower 2Gb, we should allocate bss section
there too
This depends on {D5195}
Test Plan:
1. `./validate`
2.
with
```
DYNAMIC_GHC_PROGRAMS = NO
DYNAMIC_BY_DEFAULT = NO
```
`TEST="T15729" make test` passed in both linux and macos.
3.
Also test in a use case where we used to encouter error like:
```
ghc-iserv-prof: R_X86_64_PC32 relocation out of range: (noname) =
b90282ba
```
and now, everything works fine.
Reviewers: simonmar, bgamari, angerman, erikd
Reviewed By: simonmar
Subscribers: rwbarton, carter
GHC Trac Issues: #15729
Differential Revision: https://phabricator.haskell.org/D5219
Diffstat (limited to 'rts/linker/SymbolExtras.c')
-rw-r--r-- | rts/linker/SymbolExtras.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/rts/linker/SymbolExtras.c b/rts/linker/SymbolExtras.c index 4c40b10877..a9e4c37967 100644 --- a/rts/linker/SymbolExtras.c +++ b/rts/linker/SymbolExtras.c @@ -31,10 +31,11 @@ #endif /* RTS_LINKER_USE_MMAP */ /* - ocAllocateSymbolExtras + ocAllocateExtras Allocate additional space at the end of the object file image to make room - for jump islands (powerpc, x86_64, arm) and GOT entries (x86_64). + for jump islands (powerpc, x86_64, arm), GOT entries (x86_64) and + bss sections. PowerPC relative branch instructions have a 24 bit displacement field. As PPC code is always 4-byte-aligned, this yields a +-32MB range. @@ -49,12 +50,11 @@ filled in by makeSymbolExtra below. */ -int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first ) +int ocAllocateExtras(ObjectCode* oc, int count, int first, int bssSize) { - size_t n; void* oldImage = oc->image; - if (count > 0) { + if (count > 0 || bssSize > 0) { if (!RTS_LINKER_USE_MMAP) { // round up to the nearest 4 @@ -65,16 +65,15 @@ int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first ) oc->image = stgReallocBytes( oc->image, misalignment + aligned + sizeof (SymbolExtra) * count, - "ocAllocateSymbolExtras" ); + "ocAllocateExtras" ); oc->image += misalignment; oc->symbol_extras = (SymbolExtra *) (oc->image + aligned); } else if (USE_CONTIGUOUS_MMAP || RtsFlags.MiscFlags.linkerAlwaysPic) { - n = roundUpToPage(oc->fileSize); - - /* Keep image and symbol_extras contiguous */ - - size_t allocated_size = n + (sizeof(SymbolExtra) * count); + /* Keep image, bssExtras and symbol_extras contiguous */ + size_t n = roundUpToPage(oc->fileSize); + bssSize = roundUpToAlign(bssSize, 8); + size_t allocated_size = n + bssSize + (sizeof(SymbolExtra) * count); void *new = mmapForLinker(allocated_size, MAP_ANONYMOUS, -1, 0); if (new) { memcpy(new, oc->image, oc->fileSize); @@ -83,12 +82,10 @@ int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first ) } oc->image = new; oc->imageMapped = true; - oc->fileSize = n + (sizeof(SymbolExtra) * count); - oc->symbol_extras = (SymbolExtra *) (oc->image + n); - if (mprotect(new, allocated_size, - PROT_READ | PROT_WRITE | PROT_EXEC) != 0) { - sysErrorBelch("unable to protect memory"); - } + oc->fileSize = allocated_size; + oc->symbol_extras = (SymbolExtra *) (oc->image + n + bssSize); + oc->bssBegin = oc->image + n; + oc->bssEnd = oc->image + n + bssSize; } else { oc->symbol_extras = NULL; |