Commit eef83b38 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

- some more fixes to elf module's symbol table handling (including

static/global diff for variables) - now re-synchronizing ELF list in all cases (no longer depending on RT_CONSISTENT state) - now should be able to differentiate properly a native from a builtin module - in symbol lookup, now using size of symbol (if known) - SymGetTypeInfo now checks and uses BaseAddress - in MSC-CV, really generate thunk objects
parent 20f25c34
...@@ -35,6 +35,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(dbghelp); ...@@ -35,6 +35,12 @@ WINE_DEFAULT_DEBUG_CHANNEL(dbghelp);
* + we should store the underlying type for an enum in the symt_enum struct * + we should store the underlying type for an enum in the symt_enum struct
* - most options (dbghelp_options) are not used (loading lines, decoration, * - most options (dbghelp_options) are not used (loading lines, decoration,
* deferring reading of module symbols, public symbols...) * deferring reading of module symbols, public symbols...)
* - in symbol lookup by name, we don't use RE everywhere we should. Moreover, when
* we're supposed to use RE, it doesn't make use of our hash tables. Therefore,
* we could use hash if name isn't a RE, and fall back to a full search when we
* get a full RE
* - in most of the module enumeration for symbol lookup, we don't search in
* the ELF modules (should we turn wine extented flag for ELF modules on ?)
* - (un)decoration is not handled (should make winedump's code a (.a) library * - (un)decoration is not handled (should make winedump's code a (.a) library
* and link it to winedump, and potentially to msvcrt and dbghelp (check best * and link it to winedump, and potentially to msvcrt and dbghelp (check best
* way not to duplicate code in msvcrt & dbghelp) * way not to duplicate code in msvcrt & dbghelp)
......
...@@ -253,8 +253,11 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt ...@@ -253,8 +253,11 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt
switch (sym->symt.tag) switch (sym->symt.tag)
{ {
case SymTagFunction: case SymTagFunction:
if (((struct symt_function*)sym)->address != module->elf_info->elf_addr) if (((struct symt_function*)sym)->address != module->elf_info->elf_addr &&
((struct symt_function*)sym)->size)
{
break; break;
}
symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name, symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name,
((struct symt_function*)sym)->container); ((struct symt_function*)sym)->container);
if (symp) if (symp)
...@@ -274,8 +277,12 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt ...@@ -274,8 +277,12 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt
symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name, symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name,
((struct symt_data*)sym)->container); ((struct symt_data*)sym)->container);
if (symp) if (symp)
{
((struct symt_data*)sym)->u.address = module->elf_info->elf_addr + ((struct symt_data*)sym)->u.address = module->elf_info->elf_addr +
symp->st_value; symp->st_value;
((struct symt_data*)sym)->kind = (ELF32_ST_BIND(symp->st_info) == STB_LOCAL) ?
DataIsFileStatic : DataIsGlobal;
}
break; break;
default:; default:;
} }
...@@ -285,6 +292,8 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt ...@@ -285,6 +292,8 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt
break; break;
} }
} }
/* since we may have changed some addresses & sizes, mark the module to be resorted */
module->sortlist_valid = FALSE;
} }
/****************************************************************** /******************************************************************
...@@ -301,6 +310,7 @@ static int elf_new_wine_thunks(struct module* module, struct hash_table* ht_symt ...@@ -301,6 +310,7 @@ static int elf_new_wine_thunks(struct module* module, struct hash_table* ht_symt
struct hash_table_iter hti; struct hash_table_iter hti;
struct symtab_elt* ste; struct symtab_elt* ste;
DWORD addr; DWORD addr;
int idx;
hash_table_iter_init(ht_symtab, &hti, NULL); hash_table_iter_init(ht_symtab, &hti, NULL);
while ((ste = hash_table_iter_up(&hti))) while ((ste = hash_table_iter_up(&hti)))
...@@ -330,25 +340,56 @@ static int elf_new_wine_thunks(struct module* module, struct hash_table* ht_symt ...@@ -330,25 +340,56 @@ static int elf_new_wine_thunks(struct module* module, struct hash_table* ht_symt
symt_new_thunk(module, compiland, ste->ht_elt.name, thunks[j].ordinal, symt_new_thunk(module, compiland, ste->ht_elt.name, thunks[j].ordinal,
addr, ste->symp->st_size); addr, ste->symp->st_size);
} }
else if (symt_find_nearest(module, addr) == -1) else
{ {
/* creating public symbols for all the ELF symbols which haven't been DWORD ref_addr;
* used yet (ie we have no debug information on them)
* That's the case, for example, of the .spec.c files idx = symt_find_nearest(module, addr);
*/ if (idx != -1)
if (ELF32_ST_TYPE(ste->symp->st_info) == STT_FUNC) symt_get_info(&module->addr_sorttab[idx]->symt,
TI_GET_ADDRESS, &ref_addr);
if (idx == -1 || addr != ref_addr)
{ {
symt_new_function(module, compiland, ste->ht_elt.name, /* creating public symbols for all the ELF symbols which haven't been
addr, ste->symp->st_size, NULL); * used yet (ie we have no debug information on them)
* That's the case, for example, of the .spec.c files
*/
if (ELF32_ST_TYPE(ste->symp->st_info) == STT_FUNC)
{
symt_new_function(module, compiland, ste->ht_elt.name,
addr, ste->symp->st_size, NULL);
}
else
{
symt_new_global_variable(module, compiland, ste->ht_elt.name,
ELF32_ST_BIND(ste->symp->st_info) == STB_LOCAL,
addr, ste->symp->st_size, NULL);
}
/* FIXME: this is a hack !!!
* we are adding new symbols, but as we're parsing a symbol table
* (hopefully without duplicate symbols) we delay rebuilding the sorted
* module table until we're done with the symbol table
* Otherwise, as we intertwine symbols's add and lookup, performance
* is rather bad
*/
module->sortlist_valid = TRUE;
} }
else else if (strcmp(ste->ht_elt.name, module->addr_sorttab[idx]->hash_elt.name))
{ {
symt_new_global_variable(module, compiland, ste->ht_elt.name, DWORD xaddr = 0, xsize = 0;
FALSE /* FIXME */,
addr, ste->symp->st_size, NULL); symt_get_info(&module->addr_sorttab[idx]->symt, TI_GET_ADDRESS, &xaddr);
symt_get_info(&module->addr_sorttab[idx]->symt, TI_GET_LENGTH, &xsize);
FIXME("Duplicate in %s: %s<%08lx-%08x> %s<%08lx-%08lx>\n",
module->module.ModuleName,
ste->ht_elt.name, addr, ste->symp->st_size,
module->addr_sorttab[idx]->hash_elt.name, xaddr, xsize);
} }
} }
} }
/* see comment above */
module->sortlist_valid = FALSE;
return TRUE; return TRUE;
} }
...@@ -522,7 +563,8 @@ SYM_TYPE elf_load_debug_info(struct module* module) ...@@ -522,7 +563,8 @@ SYM_TYPE elf_load_debug_info(struct module* module)
FIXME("Unsupported Dwarf2 information\n"); FIXME("Unsupported Dwarf2 information\n");
sym_type = SymNone; sym_type = SymNone;
} }
if (strstr(module->module.ModuleName, "<elf>")) if (strstr(module->module.ModuleName, "<elf>") ||
!strcmp(module->module.ModuleName, "<wine-loader>"))
{ {
/* add the thunks for native libraries */ /* add the thunks for native libraries */
if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY)) if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY))
...@@ -788,8 +830,7 @@ BOOL elf_synchronize_module_list(struct process* pcs) ...@@ -788,8 +830,7 @@ BOOL elf_synchronize_module_list(struct process* pcs)
struct module* module; struct module* module;
if (!pcs->dbg_hdr_addr) return FALSE; if (!pcs->dbg_hdr_addr) return FALSE;
if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)) || if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)))
dbg_hdr.r_state != RT_CONSISTENT)
return FALSE; return FALSE;
for (module = pcs->lmodules; module; module = module->next) for (module = pcs->lmodules; module; module = module->next)
...@@ -889,8 +930,7 @@ struct module* elf_load_module(struct process* pcs, const char* name) ...@@ -889,8 +930,7 @@ struct module* elf_load_module(struct process* pcs, const char* name)
xname = strrchr(name, '/'); xname = strrchr(name, '/');
if (!xname++) xname = name; if (!xname++) xname = name;
if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)) || if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)))
dbg_hdr.r_state != RT_CONSISTENT)
return NULL; return NULL;
for (lm_addr = (void*)dbg_hdr.r_map; lm_addr; lm_addr = (void*)lm.l_next) for (lm_addr = (void*)dbg_hdr.r_map; lm_addr; lm_addr = (void*)lm.l_next)
......
...@@ -48,10 +48,18 @@ static void module_fill_module(const char* in, char* out, unsigned size) ...@@ -48,10 +48,18 @@ static void module_fill_module(const char* in, char* out, unsigned size)
if (len > 4 && if (len > 4 &&
(!strcasecmp(&out[len - 4], ".dll") || !strcasecmp(&out[len - 4], ".exe"))) (!strcasecmp(&out[len - 4], ".dll") || !strcasecmp(&out[len - 4], ".exe")))
out[len - 4] = '\0'; out[len - 4] = '\0';
else else
{
if (len > 7 && if (len > 7 &&
(!strcasecmp(&out[len - 7], ".dll.so") || !strcasecmp(&out[len - 7], ".exe.so"))) (!strcasecmp(&out[len - 7], ".dll.so") || !strcasecmp(&out[len - 7], ".exe.so")))
strcpy(&out[len - 7], "<elf>"); strcpy(&out[len - 7], "<elf>");
else if (len > 7 &&
out[len - 7] == '.' && !strcasecmp(&out[len - 3], ".so"))
{
if (len + 3 < size) strcpy(&out[len - 3], "<elf>");
else WARN("Buffer too short: %s\n", out);
}
}
while ((*out = tolower(*out))) out++; while ((*out = tolower(*out))) out++;
} }
...@@ -227,6 +235,29 @@ struct module* module_find_by_addr(const struct process* pcs, unsigned long addr ...@@ -227,6 +235,29 @@ struct module* module_find_by_addr(const struct process* pcs, unsigned long addr
return module; return module;
} }
static BOOL module_is_elf_container_loaded(struct process* pcs, const char* ImageName,
const char* ModuleName)
{
char buffer[MAX_PATH];
size_t len;
struct module* module;
if (!ModuleName)
{
module_fill_module(ImageName, buffer, sizeof(buffer));
ModuleName = buffer;
}
len = strlen(ModuleName);
for (module = pcs->lmodules; module; module = module->next)
{
if (!strncasecmp(module->module.ModuleName, ModuleName, len) &&
module->type == DMT_ELF &&
!strcmp(module->module.ModuleName + len, "<elf>"))
return TRUE;
}
return FALSE;
}
/*********************************************************************** /***********************************************************************
* SymLoadModule (DBGHELP.@) * SymLoadModule (DBGHELP.@)
*/ */
...@@ -243,19 +274,28 @@ DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, char* ImageName, ...@@ -243,19 +274,28 @@ DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, char* ImageName,
pcs = process_find_by_handle(hProcess); pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE; if (!pcs) return FALSE;
/* this is a Wine extension to the API */ /* force transparent ELF loading / unloading */
if (!ImageName && !hFile) elf_synchronize_module_list(pcs);
/* this is a Wine extension to the API just to redo the synchronisation */
if (!ImageName && !hFile) return 0;
if (module_is_elf_container_loaded(pcs, ImageName, ModuleName))
{ {
elf_synchronize_module_list(pcs); /* force the loading of DLL as builtin */
if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName, BaseOfDll, SizeOfDll)))
goto done;
WARN("Couldn't locate %s\n", ImageName);
return 0; return 0;
} }
TRACE("Assuming %s as native DLL\n", ImageName);
if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll))) if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
{ {
unsigned len = strlen(ImageName); unsigned len = strlen(ImageName);
if (!strcmp(ImageName + len - 3, ".so") && if (!strcmp(ImageName + len - 3, ".so") &&
(module = elf_load_module(pcs, ImageName))) goto done; (module = elf_load_module(pcs, ImageName))) goto done;
FIXME("should no longer happen\n");
if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName, BaseOfDll, SizeOfDll))) if ((module = pe_load_module_from_pcs(pcs, ImageName, ModuleName, BaseOfDll, SizeOfDll)))
goto done; goto done;
WARN("Couldn't locate %s\n", ImageName); WARN("Couldn't locate %s\n", ImageName);
...@@ -274,8 +314,6 @@ done: ...@@ -274,8 +314,6 @@ done:
} }
strncpy(module->module.ImageName, ImageName, sizeof(module->module.ImageName)); strncpy(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
module->module.ImageName[sizeof(module->module.ImageName) - 1] = '\0'; module->module.ImageName[sizeof(module->module.ImageName) - 1] = '\0';
/* force transparent ELF loading / unloading */
if (module->type != DMT_ELF) elf_synchronize_module_list(pcs);
return module->module.BaseOfImage; return module->module.BaseOfImage;
} }
......
...@@ -2240,11 +2240,10 @@ static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root ...@@ -2240,11 +2240,10 @@ static int codeview_snarf(const struct msc_debug_info* msc_dbg, const BYTE* root
memcpy(symname, sym->thunk.name, sym->thunk.namelen); memcpy(symname, sym->thunk.name, sym->thunk.namelen);
symname[sym->thunk.namelen] = '\0'; symname[sym->thunk.namelen] = '\0';
flt = codeview_get_linetab(linetab, sym->thunk.segment, sym->thunk.offset); flt = codeview_get_linetab(linetab, sym->thunk.segment, sym->thunk.offset);
symt_new_function(msc_dbg->module, flt ? flt->compiland : NULL, symt_new_thunk(msc_dbg->module, flt ? flt->compiland : NULL,
symname, symname, sym->thunk.thtype,
codeview_get_address(msc_dbg, sym->thunk.segment, sym->thunk.offset), codeview_get_address(msc_dbg, sym->thunk.segment, sym->thunk.offset),
sym->thunk.thunk_len, sym->thunk.thunk_len);
codeview_get_type(sym->thunk.thtype, FALSE));
break; break;
/* /*
......
...@@ -89,6 +89,7 @@ static SYM_TYPE pe_load_dbg_file(const struct process* pcs, struct module* modul ...@@ -89,6 +89,7 @@ static SYM_TYPE pe_load_dbg_file(const struct process* pcs, struct module* modul
WINE_TRACE("Processing DBG file %s\n", dbg_name); WINE_TRACE("Processing DBG file %s\n", dbg_name);
tmp[0] = '\0';
if ((hFile = FindDebugInfoFile((char*)dbg_name, pcs->search_path, tmp)) != NULL && if ((hFile = FindDebugInfoFile((char*)dbg_name, pcs->search_path, tmp)) != NULL &&
((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) && ((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
((dbg_mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)) ((dbg_mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL))
...@@ -114,10 +115,8 @@ static SYM_TYPE pe_load_dbg_file(const struct process* pcs, struct module* modul ...@@ -114,10 +115,8 @@ static SYM_TYPE pe_load_dbg_file(const struct process* pcs, struct module* modul
hdr->DebugDirectorySize / sizeof(*dbg)); hdr->DebugDirectorySize / sizeof(*dbg));
} }
else else
{ WINE_ERR("-Unable to peruse .DBG file %s (%s)\n", dbg_name, debugstr_a(tmp));
WINE_ERR("-Unable to peruse .DBG file %s (%s)\n",
dbg_name, debugstr_a(tmp));
}
if (dbg_mapping) UnmapViewOfFile((void*)dbg_mapping); if (dbg_mapping) UnmapViewOfFile((void*)dbg_mapping);
if (hMap) CloseHandle(hMap); if (hMap) CloseHandle(hMap);
if (hFile != NULL) CloseHandle(hFile); if (hFile != NULL) CloseHandle(hFile);
...@@ -324,7 +323,8 @@ struct module* pe_load_module(struct process* pcs, char* name, ...@@ -324,7 +323,8 @@ struct module* pe_load_module(struct process* pcs, char* name,
else if (name) strcpy(loaded_name, name); else if (name) strcpy(loaded_name, name);
else if (dbghelp_options & SYMOPT_DEFERRED_LOADS) else if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
FIXME("Trouble ahead (no module name passed in deferred mode)\n"); FIXME("Trouble ahead (no module name passed in deferred mode)\n");
if ((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) if (!(module = module_find_by_name(pcs, loaded_name, DMT_PE)) &&
(hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
{ {
if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL) if ((mapping = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
{ {
......
...@@ -361,8 +361,7 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, unsigned long BaseOfDll, ...@@ -361,8 +361,7 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, unsigned long BaseOfDll,
TRACE("(%p %08lx %p %p)\n", TRACE("(%p %08lx %p %p)\n",
hProcess, BaseOfDll, EnumSymbolsCallback, UserContext); hProcess, BaseOfDll, EnumSymbolsCallback, UserContext);
pcs = process_find_by_handle(hProcess); if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
if (!pcs) return FALSE;
module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN); module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE; if (!(module = module_get_debug(pcs, module))) return FALSE;
...@@ -730,13 +729,16 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, unsigned long ModBase, ...@@ -730,13 +729,16 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, unsigned long ModBase,
PVOID pInfo) PVOID pInfo)
{ {
struct process* pcs = process_find_by_handle(hProcess); struct process* pcs = process_find_by_handle(hProcess);
struct module* module;
if (!pcs) return FALSE; if (!pcs) return FALSE;
#if 0
struct module* module;
module = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN); module = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE; if (!(module = module_get_debug(pcs, module)))
#endif {
FIXME("Someone didn't properly set ModBase (0x%08lx)\n", ModBase);
return FALSE;
}
return symt_get_info((struct symt*)TypeId, GetType, pInfo); return symt_get_info((struct symt*)TypeId, GetType, pInfo);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment