summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-23 15:15:09 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-01 19:58:18 -0500
commitc35d0e03514ce111ff8265426a7b911456984f50 (patch)
treecc6dcc192d544638be5a4fd7582f2876c5c56ddd
parentd8872af08d205c3067371d56200e68cf2f0c1ffc (diff)
downloadhaskell-c35d0e03514ce111ff8265426a7b911456984f50.tar.gz
rts/m32: Introduce NEEDS_M32 macro
Instead of relying on RTS_LINKER_USE_MMAP
-rw-r--r--rts/Linker.c10
-rw-r--r--rts/LinkerInternals.h10
-rw-r--r--rts/linker/Elf.c1
-rw-r--r--rts/linker/M32Alloc.c22
-rw-r--r--rts/linker/M32Alloc.h16
5 files changed, 32 insertions, 27 deletions
diff --git a/rts/Linker.c b/rts/Linker.c
index c84cfe27ba..57c76510d7 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -45,6 +45,8 @@
#include <sys/types.h>
#endif
+#include <fcntl.h>
+#include <unistd.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
@@ -1327,10 +1329,10 @@ void freeObjectCode (ObjectCode *oc)
oc->sections[i].mapped_size,
"freeObjectCode");
break;
+#endif
case SECTION_M32:
// Freed by m32_allocator_free
break;
-#endif
case SECTION_MALLOC:
IF_DEBUG(zero_on_gc,
memset(oc->sections[i].start,
@@ -1373,7 +1375,7 @@ void freeObjectCode (ObjectCode *oc)
ocDeinit_ELF(oc);
#endif
-#if RTS_LINKER_USE_MMAP == 1
+#if defined(NEED_M32)
m32_allocator_free(oc->rx_m32);
m32_allocator_free(oc->rw_m32);
#endif
@@ -1451,7 +1453,7 @@ mkOc( ObjectType type, pathchar *path, char *image, int imageSize,
oc->mark = object_code_mark_bit;
oc->dependencies = allocHashSet();
-#if RTS_LINKER_USE_MMAP
+#if defined(NEED_M32)
oc->rw_m32 = m32_allocator_new(false);
oc->rx_m32 = m32_allocator_new(true);
#endif
@@ -1788,7 +1790,7 @@ int ocTryLoad (ObjectCode* oc) {
// We have finished loading and relocating; flush the m32 allocators to
// setup page protections.
-#if RTS_LINKER_USE_MMAP
+#if defined(NEED_M32)
m32_allocator_flush(oc->rx_m32);
m32_allocator_flush(oc->rw_m32);
#endif
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
index 84a67753bd..cf8017a12f 100644
--- a/rts/LinkerInternals.h
+++ b/rts/LinkerInternals.h
@@ -169,6 +169,14 @@ typedef struct _Segment {
#define NEED_SYMBOL_EXTRAS 1
#endif
+/*
+ * We use the m32 allocator for symbol extras on Windows and other mmap-using
+ * platforms.
+ */
+#if RTS_LINKER_USE_MMAP
+#define NEED_M32 1
+#endif
+
/* Jump Islands are sniplets of machine code required for relative
* address relocations on the PowerPC, x86_64 and ARM.
*/
@@ -300,7 +308,7 @@ struct _ObjectCode {
require extra information.*/
StrHashTable *extraInfos;
-#if RTS_LINKER_USE_MMAP == 1
+#if defined(NEED_M32)
/* The m32 allocators used for allocating small sections and symbol extras
* during loading. We have two: one for (writeable) data and one for
* (read-only/executable) code. */
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
index 050de23dac..92bf43abd4 100644
--- a/rts/linker/Elf.c
+++ b/rts/linker/Elf.c
@@ -30,6 +30,7 @@
#include <link.h>
#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
#if defined(HAVE_SYS_STAT_H)
#include <sys/stat.h>
diff --git a/rts/linker/M32Alloc.c b/rts/linker/M32Alloc.c
index 678df95485..e7c697bf60 100644
--- a/rts/linker/M32Alloc.c
+++ b/rts/linker/M32Alloc.c
@@ -24,25 +24,25 @@ Note [Compile Time Trickery]
This file implements two versions of each of the `m32_*` functions. At the top
of the file there is the real implementation (compiled in when
-`RTS_LINKER_USE_MMAP` is true) and a dummy implementation that exists only to
+`NEED_M32` is true) and a dummy implementation that exists only to
satisfy the compiler and which should never be called. If any of these dummy
implementations are called the program will abort.
The rationale for this is to allow the calling code to be written without using
-the C pre-processor (CPP) `#if` hackery. The value of `RTS_LINKER_USE_MMAP` is
-known at compile time, code like:
+the C pre-processor (CPP) `#if` hackery. The value of `NEED_M32` is
+known at compile time, allowing code like:
- if (RTS_LINKER_USE_MMAP)
+ if (NEED_M32)
m32_allocator_init();
-will be compiled to call to `m32_allocator_init` if `RTS_LINKER_USE_MMAP` is
-true and will be optimised away to nothing if `RTS_LINKER_USE_MMAP` is false.
-However, regardless of the value of `RTS_LINKER_USE_MMAP` the compiler will
+will be compiled to call to `m32_allocator_init` if `NEED_M32` is
+true and will be optimised away to nothing if `NEED_M32` is false.
+However, regardless of the value of `NEED_M32` the compiler will
still check the call for syntax and correct function parameter types.
*/
-#if RTS_LINKER_USE_MMAP == 1
+#if defined(NEED_M32)
/*
@@ -448,7 +448,7 @@ m32_alloc(struct m32_allocator_t *alloc, size_t size, size_t alignment)
return (char*)page + ROUND_UP(sizeof(struct m32_page_t),alignment);
}
-#elif RTS_LINKER_USE_MMAP == 0
+#else
// The following implementations of these functions should never be called. If
// they are, there is a bug at the call site.
@@ -479,8 +479,4 @@ m32_alloc(m32_allocator *alloc STG_UNUSED,
barf("%s: RTS_LINKER_USE_MMAP is %d", __func__, RTS_LINKER_USE_MMAP);
}
-#else
-
-#error RTS_LINKER_USE_MMAP should be either `0` or `1`.
-
#endif
diff --git a/rts/linker/M32Alloc.h b/rts/linker/M32Alloc.h
index 892588082f..8a349a3b3e 100644
--- a/rts/linker/M32Alloc.h
+++ b/rts/linker/M32Alloc.h
@@ -8,19 +8,17 @@
#pragma once
-#if RTS_LINKER_USE_MMAP == 1
-#include <fcntl.h>
-#include <sys/mman.h>
-
-#if defined(HAVE_UNISTD_H)
-#include <unistd.h>
-#endif
-
+/*
+ * We use the m32 allocator for symbol extras on Windows and other mmap-using
+ * platforms.
+ */
+#if RTS_LINKER_USE_MMAP
+#define NEED_M32 1
#endif
#include "BeginPrivate.h"
-#if RTS_LINKER_USE_MMAP
+#if defined(NEED_M32)
#define M32_NO_RETURN /* Nothing */
#else
#define M32_NO_RETURN GNUC3_ATTRIBUTE(__noreturn__)