diff options
author | Zejun Wu <watashi@fb.com> | 2018-12-28 20:37:13 -0800 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2019-01-30 10:06:32 -0500 |
commit | e29b1ee72d77d5a06ac949f9dcc80108243a25c0 (patch) | |
tree | 3c2104b52c52d77b130c98d3cd486eb47ed2f347 /rts/linker/Elf.c | |
parent | 4bf35da4fccd2a21153a1c19bfa80006e99e02a1 (diff) | |
download | haskell-e29b1ee72d77d5a06ac949f9dcc80108243a25c0.tar.gz |
Add a RTS option -xp to load PIC object anywhere in address space
Summary:
This re-applies {D5195} with fixes for i386:
* Fix unused label warnings, see {D5230} or {D5273}
* Fix a silly bug introduced by moving `#if`
{P190}
Add a RTS option -xp to load PIC object anywhere in address space. We do
this by relaxing the requirement of <0x80000000 result of
`mmapForLinker` and implying USE_CONTIGUOUS_MMAP.
We also need to change calls to `ocInit` and `ocGetNames` to avoid
dangling pointers when the address of `oc->image` is changed by
`ocAllocateSymbolExtra`.
Test Plan:
See {D5195}, also test under i386:
```
$ uname -a
Linux watashi-arch32 4.18.5-arch1-1.0-ARCH #1 SMP PREEMPT Tue Aug 28
20:45:30 CEST 2018 i686 GNU/Linux
$ cd testsuite/tests/th/ && make test
...
```
will run `./validate` on stacked diff.
Reviewers: simonmar, bgamari, alpmestan, trommler, hvr, erikd
Reviewed By: simonmar
Subscribers: rwbarton, carter
Differential Revision: https://phabricator.haskell.org/D5289
Diffstat (limited to 'rts/linker/Elf.c')
-rw-r--r-- | rts/linker/Elf.c | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c index 9ea10d443f..ae85d73170 100644 --- a/rts/linker/Elf.c +++ b/rts/linker/Elf.c @@ -169,6 +169,8 @@ get_shndx_table(Elf_Ehdr* ehdr) void ocInit_ELF(ObjectCode * oc) { + ocDeinit_ELF(oc); + oc->info = (struct ObjectCodeFormatInfo*)stgCallocBytes( 1, sizeof *oc->info, "ocInit_Elf(ObjectCodeFormatInfo)"); @@ -318,6 +320,7 @@ ocDeinit_ELF(ObjectCode * oc) } stgFree(oc->info); + oc->info = NULL; } } @@ -754,7 +757,7 @@ ocGetNames_ELF ( ObjectCode* oc ) start = mem; mapped_start = mem; #else - if (USE_CONTIGUOUS_MMAP) { + if (USE_CONTIGUOUS_MMAP || RtsFlags.MiscFlags.linkerAlwaysPic) { // already mapped. start = oc->image + offset; alloc = SECTION_NOMEM; @@ -1585,9 +1588,6 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, case COMPAT_R_X86_64_PC32: { -#if defined(ALWAYS_PIC) - barf("R_X86_64_PC32 relocation, but ALWAYS_PIC."); -#else StgInt64 off = value - P; if (off != (Elf64_Sword)off && X86_64_ELF_NONPIC_HACK) { StgInt64 pltAddress = @@ -1604,7 +1604,6 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, } Elf64_Sword payload = off; memcpy((void*)P, &payload, sizeof(payload)); -#endif break; } @@ -1617,9 +1616,6 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, case COMPAT_R_X86_64_32: { -#if defined(ALWAYS_PIC) - barf("R_X86_64_32 relocation, but ALWAYS_PIC."); -#else if (value != (Elf64_Word)value && X86_64_ELF_NONPIC_HACK) { StgInt64 pltAddress = (StgInt64) &makeSymbolExtra(oc, ELF_R_SYM(info), S) @@ -1635,15 +1631,11 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, } Elf64_Word payload = value; memcpy((void*)P, &payload, sizeof(payload)); -#endif break; } case COMPAT_R_X86_64_32S: { -#if defined(ALWAYS_PIC) - barf("R_X86_64_32S relocation, but ALWAYS_PIC."); -#else if ((StgInt64)value != (Elf64_Sword)value && X86_64_ELF_NONPIC_HACK) { StgInt64 pltAddress = (StgInt64) &makeSymbolExtra(oc, ELF_R_SYM(info), S) @@ -1659,7 +1651,6 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, } Elf64_Sword payload = value; memcpy((void*)P, &payload, sizeof(payload)); -#endif break; } case COMPAT_R_X86_64_REX_GOTPCRELX: @@ -1681,9 +1672,6 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, #if defined(dragonfly_HOST_OS) case COMPAT_R_X86_64_GOTTPOFF: { -#if defined(ALWAYS_PIC) - barf("R_X86_64_GOTTPOFF relocation, but ALWAYS_PIC."); -#else /* determine the offset of S to the current thread's tls area XXX: Move this to the beginning of function */ @@ -1701,16 +1689,12 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, } Elf64_SWord payload = off; memcpy((void*)P, &payload, sizeof(payload)); -#endif break; } #endif case COMPAT_R_X86_64_PLT32: { -#if defined(ALWAYS_PIC) - barf("R_X86_64_PLT32 relocation, but ALWAYS_PIC."); -#else StgInt64 off = value - P; if (off != (Elf64_Sword)off) { StgInt64 pltAddress = (StgInt64) &makeSymbolExtra(oc, ELF_R_SYM(info), S) @@ -1725,7 +1709,6 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, } Elf64_Sword payload = off; memcpy((void*)P, &payload, sizeof(payload)); -#endif break; } #endif |