diff options
author | Tamar Christina <tamar@zhox.com> | 2018-09-17 22:06:05 +0100 |
---|---|---|
committer | Tamar Christina <tamar@zhox.com> | 2018-09-17 22:30:51 +0100 |
commit | 5840734379da5d494a368d0b8a6edf1b1216a7f4 (patch) | |
tree | 212d129ab357655f4361b04a0e1a27c82c586461 /rts/LinkerInternals.h | |
parent | e655aac18c5b240f27fcaf26317ad87be5ce8b96 (diff) | |
download | haskell-5840734379da5d494a368d0b8a6edf1b1216a7f4.tar.gz |
Updated PE linker, section alignment and cleanup.
Summary:
This patch is to address a couple of short comings of the PE linker.
The first thing it does is properly honor section alignments, so SSE code
will work reliably.
While doing this I've also changed how it reads and stores ObjectFile
information. Previously the entire object file was read in and treated
as one blob, including headers, symbol tables etc.
Now the ObjectFile is read in but stored in chunks, tables go into a temporary
info struct and code/data into a new private heap. This allows me to free all
meta data once we're done relocating. Which means we can reclaim this memory.
As I've mentioned above I've also moved from using VirtualAlloc to HeapAlloc.
The reason is VirtualAlloc is meant to be used for more low level memory
allocation, it's very fast because it can only allocate whole blocks,
(64k) by default, and the memory must be paged (4k) aligned.
So when you ask for e.g. 30k of memory, you're given a whole block where 34k
will be wasted memory. Nothing else can ever access that untill you free the 30k.
One downside of HeapAlloc is that you're not in control of how the heap grows,
and heap memory is always committed. So it's harder to tell how much we're
actually using now.
Another big upside of splitting off the ObjectCode tables to info structs
is that I can adjust them, so that later addressings can just use array
subscripts to index into them. This simplifies the code a lot and a lot of
complicated casts and indexing can be removed. Leaving less and more simple
code.
This patch doesn't fix the memprotection but it doesn't regress it either.
It does however make the next changes smaller and fixes the alignments.
Test Plan: ./validate , new test T13617
Reviewers: bgamari, erikd, simonmar, hvr, angerman
Reviewed By: angerman
Subscribers: nickkuk, carter, RyanGlScott, rwbarton, thomie
GHC Trac Issues: #13617
Differential Revision: https://phabricator.haskell.org/D3915
Diffstat (limited to 'rts/LinkerInternals.h')
-rw-r--r-- | rts/LinkerInternals.h | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h index 21602f15aa..04d873ca99 100644 --- a/rts/LinkerInternals.h +++ b/rts/LinkerInternals.h @@ -32,8 +32,12 @@ typedef SECTIONKIND_RWDATA, /* Static initializer section. e.g. .ctors. */ SECTIONKIND_INIT_ARRAY, + /* Static finalizer section. e.g. .dtors. */ + SECTIONKIND_FINIT_ARRAY, /* We don't know what the section is and don't care. */ SECTIONKIND_OTHER, + /* Section contains debug information. e.g. .debug$. */ + SECTIONKIND_DEBUG, /* Section belongs to an import section group. e.g. .idata$. */ SECTIONKIND_IMPORT, /* Section defines an import library entry, e.g. idata$7. */ @@ -46,7 +50,7 @@ typedef enum { SECTION_NOMEM, SECTION_M32, SECTION_MMAP, - SECTION_MALLOC, + SECTION_MALLOC } SectionAlloc; @@ -296,28 +300,6 @@ ObjectCode* mkOc( pathchar *path, char *image, int imageSize, int misalignment ); -#if defined(mingw32_HOST_OS) -/* We use myindex to calculate array addresses, rather than - simply doing the normal subscript thing. That's because - some of the above structs have sizes which are not - a whole number of words. GCC rounds their sizes up to a - whole number of words, which means that the address calcs - arising from using normal C indexing or pointer arithmetic - are just plain wrong. Sigh. -*/ -INLINE_HEADER unsigned char * -myindex ( int scale, void* base, int index ) -{ - return - ((unsigned char*)base) + scale * index; -} - -// Defined in linker/PEi386.c -char *cstring_from_section_name( - unsigned char* name, - unsigned char* strtab); -#endif /* mingw32_HOST_OS */ - /* MAP_ANONYMOUS is MAP_ANON on some systems, e.g. OS X (before Sierra), OpenBSD etc */ #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) @@ -334,8 +316,7 @@ char *cstring_from_section_name( # include "linker/ElfTypes.h" #elif defined (mingw32_HOST_OS) # define OBJFORMAT_PEi386 -struct SectionFormatInfo { void* placeholder; }; -struct ObjectCodeFormatInfo { void* placeholder; }; +# include "linker/PEi386Types.h" #elif defined(darwin_HOST_OS) || defined(ios_HOST_OS) # define OBJFORMAT_MACHO # include "linker/MachOTypes.h" |