diff options
author | Tamar Christina <tamar@zhox.com> | 2016-06-04 13:07:32 +0200 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-06-04 13:07:32 +0200 |
commit | b948a1da7a3929160cb7cb8d6cf2fe79c3081d0a (patch) | |
tree | cb0d4740fa4fdffb2d456f89a974211f6359ef46 /rts/Linker.c | |
parent | 4dbacbc89a999bf371d51194b4662a209ac907f1 (diff) | |
download | haskell-b948a1da7a3929160cb7cb8d6cf2fe79c3081d0a.tar.gz |
Refactor the SymbolName and SymbolAddr types to be pointers
Take the pointer notation out of the typedef such that it preserves the
fact that these are pointers at the use site.
Test Plan:
./validate on all platforms that use the runtime linker.
For unix platforms please ensure `DYNAMIC_GHC_PROGRAMS=NO` is
added to your validate file.
Continuation of D2250
Reviewers: austin, bgamari, simonmar, erikd
Reviewed By: erikd
Subscribers: thomie, #ghc_windows_task_force
Differential Revision: https://phabricator.haskell.org/D2302
GHC Trac Issues: #11816
Diffstat (limited to 'rts/Linker.c')
-rw-r--r-- | rts/Linker.c | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/rts/Linker.c b/rts/Linker.c index f64ca0f6bb..5a6a8c2d4c 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -119,7 +119,7 @@ in the `ObjectCode` but in the `RtsSymbolInfo` it won't be. */ typedef struct _RtsSymbolInfo { - SymbolAddr value; + SymbolAddr* value; ObjectCode *owner; HsBool weak; } RtsSymbolInfo; @@ -478,7 +478,7 @@ static void freeProddableBlocks (ObjectCode *oc); static void *mmap_32bit_base = (void *)MMAP_32BIT_BASE_DEFAULT; #endif -static void ghciRemoveSymbolTable(HashTable *table, const SymbolName key, +static void ghciRemoveSymbolTable(HashTable *table, const SymbolName* key, ObjectCode *owner) { RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); @@ -511,8 +511,8 @@ static void ghciRemoveSymbolTable(HashTable *table, const SymbolName key, static int ghciInsertSymbolTable( pathchar* obj_name, HashTable *table, - const SymbolName key, - SymbolAddr data, + const SymbolName* key, + SymbolAddr* data, HsBool weak, ObjectCode *owner) { @@ -622,7 +622,7 @@ static int ghciInsertSymbolTable( * nonzero on success and result set to nonzero pointer */ static HsBool ghciLookupSymbolInfo(HashTable *table, - const SymbolName key, RtsSymbolInfo **result) + const SymbolName* key, RtsSymbolInfo **result) { RtsSymbolInfo *pinfo = lookupStrHashTable(table, key); if (!pinfo) { @@ -835,7 +835,7 @@ static OpenedDLL* opened_dlls = NULL; /* A record for storing indirectly linked functions from DLLs. */ typedef struct _IndirectAddr { - SymbolAddr addr; + SymbolAddr* addr; struct _IndirectAddr* next; } IndirectAddr; @@ -1295,7 +1295,7 @@ HsBool removeLibrarySearchPath(HsPtr dll_path_index) * * Returns: 0 on failure, nozero on success */ -HsInt insertSymbol(pathchar* obj_name, SymbolName key, SymbolAddr data) +HsInt insertSymbol(pathchar* obj_name, SymbolName* key, SymbolAddr* data) { return ghciInsertSymbolTable(obj_name, symhash, key, data, HS_BOOL_FALSE, NULL); } @@ -1303,7 +1303,7 @@ HsInt insertSymbol(pathchar* obj_name, SymbolName key, SymbolAddr data) /* ----------------------------------------------------------------------------- * lookup a symbol in the hash table */ -static SymbolAddr lookupSymbol_ (SymbolName lbl) +static SymbolAddr* lookupSymbol_ (SymbolName* lbl) { IF_DEBUG(linker, debugBelch("lookupSymbol: looking up %s\n", lbl)); @@ -1327,7 +1327,7 @@ static SymbolAddr lookupSymbol_ (SymbolName lbl) ASSERT(lbl[0] == '_'); return internal_dlsym(lbl + 1); # elif defined(OBJFORMAT_PEi386) - SymbolAddr sym; + SymbolAddr* sym; /* See Note [mingw-w64 name decoration scheme] */ #ifndef x86_64_HOST_ARCH @@ -1341,7 +1341,7 @@ static SymbolAddr lookupSymbol_ (SymbolName lbl) return NULL; # endif } else { - SymbolAddr val = pinfo->value; + SymbolAddr* val = pinfo->value; IF_DEBUG(linker, debugBelch("lookupSymbol: value of %s is %p\n", lbl, val)); int r; @@ -1364,10 +1364,10 @@ static SymbolAddr lookupSymbol_ (SymbolName lbl) } } -SymbolAddr lookupSymbol( SymbolName lbl ) +SymbolAddr* lookupSymbol( SymbolName* lbl ) { ACQUIRE_LOCK(&linker_mutex); - SymbolAddr r = lookupSymbol_(lbl); + SymbolAddr* r = lookupSymbol_(lbl); RELEASE_LOCK(&linker_mutex); return r; } @@ -1408,12 +1408,12 @@ StgStablePtr foreignExportStablePtr (StgPtr p) * within DELTA bytes of the specified address, and show their names. */ #ifdef DEBUG -void ghci_enquire ( SymbolAddr addr ); +void ghci_enquire ( SymbolAddr* addr ); -void ghci_enquire(SymbolAddr addr) +void ghci_enquire(SymbolAddr* addr) { int i; - SymbolName sym; + SymbolName* sym; RtsSymbolInfo* a; const int DELTA = 64; ObjectCode* oc; @@ -2506,7 +2506,7 @@ int ocTryLoad (ObjectCode* oc) { symbols. Duplicate symbols are distinguished by name and oc. */ int x; - SymbolName symbol; + SymbolName* symbol; for (x = 0; x < oc->n_symbols; x++) { symbol = oc->symbols[x]; if ( symbol @@ -3372,11 +3372,11 @@ zapTrailingAtSign ( UChar* sym ) See #9218 */ -static SymbolAddr +static SymbolAddr* lookupSymbolInDLLs ( UChar *lbl ) { OpenedDLL* o_dll; - SymbolAddr sym; + SymbolAddr* sym; for (o_dll = opened_dlls; o_dll != NULL; o_dll = o_dll->next) { /* debugBelch("look in %ls for %s\n", o_dll->name, lbl); */ @@ -3639,7 +3639,7 @@ ocGetNames_PEi386 ( ObjectCode* oc ) UChar* strtab; UChar* sname; - SymbolAddr addr; + SymbolAddr* addr; int i; hdr = (COFF_header*)(oc->image); @@ -3762,7 +3762,7 @@ ocGetNames_PEi386 ( ObjectCode* oc ) /* Copy exported symbols into the ObjectCode. */ oc->n_symbols = hdr->NumberOfSymbols; - oc->symbols = stgCallocBytes(sizeof(SymbolName), oc->n_symbols, + oc->symbols = stgCallocBytes(sizeof(SymbolName*), oc->n_symbols, "ocGetNames_PEi386(oc->symbols)"); /* Work out the size of the global BSS section */ @@ -3780,7 +3780,7 @@ ocGetNames_PEi386 ( ObjectCode* oc ) } /* Allocate BSS space */ - SymbolAddr bss = NULL; + SymbolAddr* bss = NULL; if (globalBssSize > 0) { bss = stgCallocBytes(1, globalBssSize, "ocGetNames_PEi386(non-anonymous bss)"); @@ -3833,7 +3833,7 @@ ocGetNames_PEi386 ( ObjectCode* oc ) /* This symbol isn't in any section at all, ie, global bss. Allocate zeroed space for it from the BSS section */ addr = bss; - bss = (SymbolAddr)((StgWord)bss + (StgWord)symtab_i->Value); + bss = (SymbolAddr*)((StgWord)bss + (StgWord)symtab_i->Value); IF_DEBUG(linker, debugBelch("bss symbol @ %p %u\n", addr, symtab_i->Value)); } @@ -3844,12 +3844,12 @@ ocGetNames_PEi386 ( ObjectCode* oc ) IF_DEBUG(linker, debugBelch("addSymbol %p `%s'\n", addr,sname);) ASSERT(i >= 0 && i < oc->n_symbols); /* cstring_from_COFF_symbol_name always succeeds. */ - oc->symbols[i] = (SymbolName)sname; + oc->symbols[i] = (SymbolName*)sname; if (isWeak == HS_BOOL_TRUE) { setWeakSymbol(oc, sname); } - if (! ghciInsertSymbolTable(oc->fileName, symhash, (SymbolName)sname, addr, + if (! ghciInsertSymbolTable(oc->fileName, symhash, (SymbolName*)sname, addr, isWeak, oc)) { return 0; } @@ -3938,7 +3938,7 @@ ocResolve_PEi386 ( ObjectCode* oc ) UInt32 A; size_t S; - SymbolAddr pP; + SymbolAddr* pP; int i; UInt32 j, noRelocs; @@ -4905,7 +4905,7 @@ ocGetNames_ELF ( ObjectCode* oc ) nent = shdr[i].sh_size / sizeof(Elf_Sym); oc->n_symbols = nent; - oc->symbols = stgCallocBytes(oc->n_symbols, sizeof(SymbolName), + oc->symbols = stgCallocBytes(oc->n_symbols, sizeof(SymbolName*), "ocGetNames_ELF(oc->symbols)"); // Note calloc: if we fail partway through initializing symbols, we need // to undo the additions to the symbol table so far. We know which ones @@ -4918,8 +4918,8 @@ ocGetNames_ELF ( ObjectCode* oc ) char isLocal = FALSE; /* avoids uninit-var warning */ HsBool isWeak = HS_BOOL_FALSE; - SymbolAddr ad = NULL; - SymbolName nm = strtab + stab[j].st_name; + SymbolAddr* ad = NULL; + SymbolName* nm = strtab + stab[j].st_name; unsigned short shndx = stab[j].st_shndx; Elf_Word secno; @@ -4976,7 +4976,7 @@ ocGetNames_ELF ( ObjectCode* oc ) stab[j].st_size, stab[j].st_value, nm); } */ - ad = (SymbolAddr)((intptr_t)sections[secno].start + + ad = (SymbolAddr*)((intptr_t)sections[secno].start + (intptr_t)stab[j].st_value); if (ELF_ST_BIND(stab[j].st_info)==STB_LOCAL) { isLocal = TRUE; @@ -4987,7 +4987,7 @@ ocGetNames_ELF ( ObjectCode* oc ) * descriptors, so to be consistent we store function descriptors * in the symbol table */ if (ELF_ST_TYPE(stab[j].st_info) == STT_FUNC) - ad = (SymbolAddr)allocateFunctionDesc((Elf_Addr)ad); + ad = (SymbolAddr*)allocateFunctionDesc((Elf_Addr)ad); #endif IF_DEBUG(linker,debugBelch( "addOTabName(GLOB): %10p %s %s\n", ad, oc->fileName, nm )); @@ -5074,7 +5074,7 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC, Elf_Shdr* shdr, int shnum ) { int j; - SymbolName symbol; + SymbolName* symbol; Elf_Word* targ; Elf_Rel* rtab = (Elf_Rel*) (ehdrC + shdr[shnum].sh_offset); Elf_Sym* stab; @@ -5391,7 +5391,7 @@ do_Elf_Rela_relocations ( ObjectCode* oc, char* ehdrC, Elf_Shdr* shdr, int shnum ) { int j; - SymbolName symbol = NULL; + SymbolName* symbol = NULL; Elf_Rela* rtab = (Elf_Rela*) (ehdrC + shdr[shnum].sh_offset); Elf_Sym* stab; char* strtab; @@ -6038,14 +6038,14 @@ resolveImports( { // according to otool, reserved1 contains the first index into the indirect symbol table struct nlist *symbol = &nlist[indirectSyms[sect->reserved1+i]]; - SymbolName nm = image + symLC->stroff + symbol->n_un.n_strx; - SymbolAddr addr = NULL; + SymbolName* nm = image + symLC->stroff + symbol->n_un.n_strx; + SymbolAddr* addr = NULL; IF_DEBUG(linker, debugBelch("resolveImports: resolving %s\n", nm)); if ((symbol->n_type & N_TYPE) == N_UNDF && (symbol->n_type & N_EXT) && (symbol->n_value != 0)) { - addr = (SymbolAddr) (symbol->n_value); + addr = (SymbolAddr*) (symbol->n_value); IF_DEBUG(linker, debugBelch("resolveImports: undefined external %s has value %p\n", nm, addr)); } else { addr = lookupSymbol_(nm); @@ -6066,7 +6066,7 @@ resolveImports( *(image + sect->offset + i * itemSize) = 0xe9; // jmp opcode *(unsigned*)(image + sect->offset + i*itemSize + 1) - = (SymbolAddr)addr - (image + sect->offset + i*itemSize + 5); + = (SymbolAddr*)addr - (image + sect->offset + i*itemSize + 5); } else #endif @@ -6188,8 +6188,8 @@ relocateSection( || type == X86_64_RELOC_GOT_LOAD) { struct nlist *symbol = &nlist[reloc->r_symbolnum]; - SymbolName nm = image + symLC->stroff + symbol->n_un.n_strx; - SymbolAddr addr = NULL; + SymbolName* nm = image + symLC->stroff + symbol->n_un.n_strx; + SymbolAddr* addr = NULL; IF_DEBUG(linker, debugBelch("relocateSection: making jump island for %s, extern = %d, X86_64_RELOC_GOT\n", nm, reloc->r_extern)); @@ -6241,8 +6241,8 @@ relocateSection( else if (reloc->r_extern) { struct nlist *symbol = &nlist[reloc->r_symbolnum]; - SymbolName nm = image + symLC->stroff + symbol->n_un.n_strx; - SymbolAddr addr = NULL; + SymbolName* nm = image + symLC->stroff + symbol->n_un.n_strx; + SymbolAddr* addr = NULL; IF_DEBUG(linker, debugBelch("relocateSection: looking up external symbol %s\n", nm)); IF_DEBUG(linker, debugBelch(" : type = %d\n", symbol->n_type)); @@ -6680,7 +6680,7 @@ ocGetNames_MachO(ObjectCode* oc) struct symtab_command *symLC = NULL; struct nlist *nlist; unsigned long commonSize = 0; - SymbolAddr commonStorage = NULL; + SymbolAddr* commonStorage = NULL; unsigned long commonCounter; IF_DEBUG(linker,debugBelch("ocGetNames_MachO: start\n")); @@ -6782,7 +6782,7 @@ ocGetNames_MachO(ObjectCode* oc) } } IF_DEBUG(linker, debugBelch("ocGetNames_MachO: %d external symbols\n", oc->n_symbols)); - oc->symbols = stgMallocBytes(oc->n_symbols * sizeof(SymbolName), + oc->symbols = stgMallocBytes(oc->n_symbols * sizeof(SymbolName*), "ocGetNames_MachO(oc->symbols)"); if(symLC) @@ -6795,7 +6795,7 @@ ocGetNames_MachO(ObjectCode* oc) { if(nlist[i].n_type & N_EXT) { - SymbolName nm = image + symLC->stroff + nlist[i].n_un.n_strx; + SymbolName* nm = image + symLC->stroff + nlist[i].n_un.n_strx; if ((nlist[i].n_desc & N_WEAK_DEF) && lookupSymbol_(nm)) { // weak definition, and we already have a definition IF_DEBUG(linker, debugBelch(" weak: %s\n", nm)); @@ -6803,7 +6803,7 @@ ocGetNames_MachO(ObjectCode* oc) else { IF_DEBUG(linker, debugBelch("ocGetNames_MachO: inserting %s\n", nm)); - SymbolAddr addr = image + SymbolAddr* addr = image + sections[nlist[i].n_sect - 1].offset - sections[nlist[i].n_sect - 1].addr + nlist[i].n_value; @@ -6840,7 +6840,7 @@ ocGetNames_MachO(ObjectCode* oc) && (nlist[i].n_type & N_EXT) && (nlist[i].n_value != 0)) { - SymbolName nm = image + symLC->stroff + nlist[i].n_un.n_strx; + SymbolName* nm = image + symLC->stroff + nlist[i].n_un.n_strx; unsigned long sz = nlist[i].n_value; nlist[i].n_value = commonCounter; |