diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-11-21 11:17:27 -0500 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-11-30 19:48:53 -0500 |
commit | 6ac3db5fefbac6bea6c8fd0ac64daf036d9a8e60 (patch) | |
tree | 4e7b1a67545901ffa4d61b4594d5e6d65c9edbba /rts/LinkerInternals.h | |
parent | 490aa14dbc98e4713f913c4417d454e53b8b278a (diff) | |
download | haskell-6ac3db5fefbac6bea6c8fd0ac64daf036d9a8e60.tar.gz |
rts/linker: Move shared library loading logic into Elf.c
Diffstat (limited to 'rts/LinkerInternals.h')
-rw-r--r-- | rts/LinkerInternals.h | 91 |
1 files changed, 51 insertions, 40 deletions
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h index f060e4d38a..27ca52f0e3 100644 --- a/rts/LinkerInternals.h +++ b/rts/LinkerInternals.h @@ -20,8 +20,34 @@ void printLoadedObjects(void); #include "BeginPrivate.h" +/* Which object file format are we targeting? */ +#if defined(linux_HOST_OS) || defined(solaris2_HOST_OS) \ +|| defined(linux_android_HOST_OS) \ +|| defined(freebsd_HOST_OS) || defined(kfreebsdgnu_HOST_OS) \ +|| defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) \ +|| defined(openbsd_HOST_OS) || defined(gnu_HOST_OS) +# define OBJFORMAT_ELF +#elif defined(mingw32_HOST_OS) +# define OBJFORMAT_PEi386 +#elif defined(darwin_HOST_OS) || defined(ios_HOST_OS) +# define OBJFORMAT_MACHO +#endif + typedef void SymbolAddr; typedef char SymbolName; +typedef struct _ObjectCode ObjectCode; +typedef struct _Section Section; + +#if defined(OBJFORMAT_ELF) +# include "linker/ElfTypes.h" +#elif defined(OBJFORMAT_PEi386) +# include "linker/PEi386Types.h" +#elif defined(OBJFORMAT_MACHO) +# include "linker/MachOTypes.h" +#else +# error "Unknown OBJECT_FORMAT for HOST_OS" +#endif + /* Hold extended information about a symbol in case we need to resolve it at a late stage. */ @@ -102,26 +128,24 @@ typedef enum { * and always refer to it with the 'struct' qualifier. */ -typedef - struct _Section { - void* start; /* actual start of section in memory */ - StgWord size; /* actual size of section in memory */ - SectionKind kind; - SectionAlloc alloc; - - /* - * The following fields are relevant for SECTION_MMAP sections only - */ - StgWord mapped_offset; /* offset from the image of mapped_start */ - void* mapped_start; /* start of mmap() block */ - StgWord mapped_size; /* size of mmap() block */ - - /* A customizable type to augment the Section type. - * See Note [No typedefs for customizable types] - */ - struct SectionFormatInfo* info; - } - Section; +struct _Section { + void* start; /* actual start of section in memory */ + StgWord size; /* actual size of section in memory */ + SectionKind kind; + SectionAlloc alloc; + + /* + * The following fields are relevant for SECTION_MMAP sections only + */ + StgWord mapped_offset; /* offset from the image of mapped_start */ + void* mapped_start; /* start of mmap() block */ + StgWord mapped_size; /* size of mmap() block */ + + /* A customizable type to augment the Section type. + * See Note [No typedefs for customizable types] + */ + struct SectionFormatInfo* info; +}; typedef struct _ProddableBlock { @@ -175,7 +199,7 @@ typedef enum { /* Top-level structure for an object module. One of these is allocated * for each object file in use. */ -typedef struct _ObjectCode { +struct _ObjectCode { OStatus status; pathchar *fileName; int fileSize; /* also mapped image size when using mmap() */ @@ -295,7 +319,7 @@ typedef struct _ObjectCode { /* virtual memory ranges of loaded code */ NativeCodeRange *nc_ranges; -} ObjectCode; +}; #define OC_INFORMATIVE_FILENAME(OC) \ ( (OC)->archiveMemberName ? \ @@ -306,6 +330,10 @@ typedef struct _ObjectCode { #if defined(THREADED_RTS) extern Mutex linker_mutex; + +#if defined(OBJFORMAT_ELF) || defined(OBJFORMAT_MACHO) +extern Mutex dl_mutex; +#endif #endif /* Type of the initializer */ @@ -388,6 +416,7 @@ resolveSymbolAddr (pathchar* buffer, int size, #endif HsInt isAlreadyLoaded( pathchar *path ); +OStatus getObjectLoadStatus_ (pathchar *path); HsInt loadOc( ObjectCode* oc ); ObjectCode* mkOc( ObjectType type, pathchar *path, char *image, int imageSize, bool mapped, pathchar *archiveMemberName, @@ -403,24 +432,6 @@ void freeSegments(ObjectCode *oc); #define MAP_ANONYMOUS MAP_ANON #endif -/* Which object file format are we targeting? */ -#if defined(linux_HOST_OS) || defined(solaris2_HOST_OS) \ -|| defined(linux_android_HOST_OS) \ -|| defined(freebsd_HOST_OS) || defined(kfreebsdgnu_HOST_OS) \ -|| defined(dragonfly_HOST_OS) || defined(netbsd_HOST_OS) \ -|| defined(openbsd_HOST_OS) || defined(gnu_HOST_OS) -# define OBJFORMAT_ELF -# include "linker/ElfTypes.h" -#elif defined(mingw32_HOST_OS) -# define OBJFORMAT_PEi386 -# include "linker/PEi386Types.h" -#elif defined(darwin_HOST_OS) || defined(ios_HOST_OS) -# define OBJFORMAT_MACHO -# include "linker/MachOTypes.h" -#else -#error "Unknown OBJECT_FORMAT for HOST_OS" -#endif - /* In order to simplify control flow a bit, some references to mmap-related definitions are blocked off by a C-level if statement rather than a CPP-level #if statement. Since those are dead branches when !RTS_LINKER_USE_MMAP, we |