summaryrefslogtreecommitdiff
path: root/rts/linker
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2018-10-30 20:38:24 -0400
committerBen Gamari <ben@smart-cactus.org>2018-10-30 22:07:10 -0400
commit82a716431cc680392e332bc2b1a1fd0d7faa4cd8 (patch)
treec04c7bc5e265603ca5d3abea21e91a9a5d0be54e /rts/linker
parent9cbf6f2baf793e361d41b9c36497c5601ff22253 (diff)
downloadhaskell-82a716431cc680392e332bc2b1a1fd0d7faa4cd8.tar.gz
Revert "Add a RTS option -xp to load PIC object anywhere in address space"
This reverts commit 5403a8636fe82f971234873564f3a05393b89b7a.
Diffstat (limited to 'rts/linker')
-rw-r--r--rts/linker/Elf.c25
-rw-r--r--rts/linker/MachO.c21
-rw-r--r--rts/linker/SymbolExtras.c61
3 files changed, 51 insertions, 56 deletions
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index fe87aed0b0..fd24a92630 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -169,8 +169,6 @@ 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)");
@@ -320,7 +318,6 @@ ocDeinit_ELF(ObjectCode * oc)
}
stgFree(oc->info);
- oc->info = NULL;
}
}
@@ -757,7 +754,7 @@ ocGetNames_ELF ( ObjectCode* oc )
start = mem;
mapped_start = mem;
#else
- if (USE_CONTIGUOUS_MMAP || RtsFlags.MiscFlags.linkerAlwaysPic) {
+ if (USE_CONTIGUOUS_MMAP) {
// already mapped.
start = oc->image + offset;
alloc = SECTION_NOMEM;
@@ -1587,6 +1584,9 @@ 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 =
@@ -1603,6 +1603,7 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
}
Elf64_Sword payload = off;
memcpy((void*)P, &payload, sizeof(payload));
+#endif
break;
}
@@ -1615,6 +1616,9 @@ 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)
@@ -1630,11 +1634,15 @@ 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)
@@ -1650,6 +1658,7 @@ 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:
@@ -1671,6 +1680,9 @@ 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 */
@@ -1688,12 +1700,16 @@ 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)
@@ -1708,6 +1724,7 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC,
}
Elf64_Sword payload = off;
memcpy((void*)P, &payload, sizeof(payload));
+#endif
break;
}
#endif
diff --git a/rts/linker/MachO.c b/rts/linker/MachO.c
index ff8ef7a1e4..5812e89cda 100644
--- a/rts/linker/MachO.c
+++ b/rts/linker/MachO.c
@@ -99,8 +99,6 @@ bool ocMprotect_MachO( ObjectCode *oc );
void
ocInit_MachO(ObjectCode * oc)
{
- ocDeinit_MachO(oc);
-
oc->info = (struct ObjectCodeFormatInfo*)stgCallocBytes(
1, sizeof *oc->info,
"ocInit_MachO(ObjectCodeFormatInfo)");
@@ -162,19 +160,16 @@ ocInit_MachO(ObjectCode * oc)
void
ocDeinit_MachO(ObjectCode * oc) {
- if (oc->info != NULL) {
- if(oc->info->n_macho_symbols > 0) {
- stgFree(oc->info->macho_symbols);
- }
+ if(oc->info->n_macho_symbols > 0) {
+ stgFree(oc->info->macho_symbols);
+ }
#if defined(aarch64_HOST_ARCH)
- freeGot(oc);
- for(int i = 0; i < oc->n_sections; i++) {
- freeStubs(&oc->sections[i]);
- }
-#endif
- stgFree(oc->info);
- oc->info = NULL;
+ freeGot(oc);
+ for(int i = 0; i < oc->n_sections; i++) {
+ freeStubs(&oc->sections[i]);
}
+#endif
+ stgFree(oc->info);
}
static int
diff --git a/rts/linker/SymbolExtras.c b/rts/linker/SymbolExtras.c
index 4c40b10877..88541f44d0 100644
--- a/rts/linker/SymbolExtras.c
+++ b/rts/linker/SymbolExtras.c
@@ -19,12 +19,6 @@
#include "linker/SymbolExtras.h"
#include "linker/M32Alloc.h"
-#if defined(OBJFORMAT_ELF)
-# include "linker/Elf.h"
-#elif defined(OBJFORMAT_MACHO)
-# include "linker/MachO.h"
-#endif
-
#include <string.h>
#if RTS_LINKER_USE_MMAP
#include <sys/mman.h>
@@ -52,24 +46,8 @@
int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
{
size_t n;
- void* oldImage = oc->image;
-
- if (count > 0) {
- if (!RTS_LINKER_USE_MMAP) {
-
- // round up to the nearest 4
- int aligned = (oc->fileSize + 3) & ~3;
- int misalignment = oc->misalignment;
- oc->image -= misalignment;
- oc->image = stgReallocBytes( oc->image,
- misalignment +
- aligned + sizeof (SymbolExtra) * count,
- "ocAllocateSymbolExtras" );
- oc->image += misalignment;
-
- oc->symbol_extras = (SymbolExtra *) (oc->image + aligned);
- } else if (USE_CONTIGUOUS_MMAP || RtsFlags.MiscFlags.linkerAlwaysPic) {
+ if (RTS_LINKER_USE_MMAP && USE_CONTIGUOUS_MMAP) {
n = roundUpToPage(oc->fileSize);
/* Keep image and symbol_extras contiguous */
@@ -85,37 +63,42 @@ int ocAllocateSymbolExtras( ObjectCode* oc, int count, int first )
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");
+ if(mprotect(new, allocated_size, PROT_READ | PROT_EXEC) != 0) {
+ sysErrorBelch("unable to protect memory");
}
}
else {
oc->symbol_extras = NULL;
return 0;
}
- } else {
+ }
+ else if( count > 0 ) {
+ if (RTS_LINKER_USE_MMAP) {
+ n = roundUpToPage(oc->fileSize);
+
oc->symbol_extras = m32_alloc(sizeof(SymbolExtra) * count, 8);
if (oc->symbol_extras == NULL) return 0;
}
+ else {
+ // round up to the nearest 4
+ int aligned = (oc->fileSize + 3) & ~3;
+ int misalignment = oc->misalignment;
+
+ oc->image -= misalignment;
+ oc->image = stgReallocBytes( oc->image,
+ misalignment +
+ aligned + sizeof (SymbolExtra) * count,
+ "ocAllocateSymbolExtras" );
+ oc->image += misalignment;
+
+ oc->symbol_extras = (SymbolExtra *) (oc->image + aligned);
+ }
}
if (oc->symbol_extras != NULL) {
memset( oc->symbol_extras, 0, sizeof (SymbolExtra) * count );
}
- // ObjectCodeFormatInfo contains computed addresses based on offset to
- // image, if the address of image changes, we need to invalidate
- // the ObjectCodeFormatInfo and recompute it.
- if (oc->image != oldImage) {
-#if defined(OBJFORMAT_MACHO)
- ocInit_MachO( oc );
-#endif
-#if defined(OBJFORMAT_ELF)
- ocInit_ELF( oc );
-#endif
- }
-
oc->first_symbol_extra = first;
oc->n_symbol_extras = count;