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);
* + we should store the underlying type for an enum in the symt_enum struct
* - most options (dbghelp_options) are not used (loading lines, decoration,
* 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
* and link it to winedump, and potentially to msvcrt and dbghelp (check best
* 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
switch (sym->symt.tag)
{
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;
}
symp = elf_lookup_symtab(module, symtab, sym->hash_elt.name,
((struct symt_function*)sym)->container);
if (symp)
......@@ -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,
((struct symt_data*)sym)->container);
if (symp)
{
((struct symt_data*)sym)->u.address = module->elf_info->elf_addr +
symp->st_value;
((struct symt_data*)sym)->kind = (ELF32_ST_BIND(symp->st_info) == STB_LOCAL) ?
DataIsFileStatic : DataIsGlobal;
}
break;
default:;
}
......@@ -285,6 +292,8 @@ static void elf_finish_stabs_info(struct module* module, struct hash_table* symt
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
struct hash_table_iter hti;
struct symtab_elt* ste;
DWORD addr;
int idx;
hash_table_iter_init(ht_symtab, &hti, NULL);
while ((ste = hash_table_iter_up(&hti)))
......@@ -330,7 +340,15 @@ 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,
addr, ste->symp->st_size);
}
else if (symt_find_nearest(module, addr) == -1)
else
{
DWORD ref_addr;
idx = symt_find_nearest(module, addr);
if (idx != -1)
symt_get_info(&module->addr_sorttab[idx]->symt,
TI_GET_ADDRESS, &ref_addr);
if (idx == -1 || addr != ref_addr)
{
/* creating public symbols for all the ELF symbols which haven't been
* used yet (ie we have no debug information on them)
......@@ -344,11 +362,34 @@ static int elf_new_wine_thunks(struct module* module, struct hash_table* ht_symt
else
{
symt_new_global_variable(module, compiland, ste->ht_elt.name,
FALSE /* FIXME */,
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 if (strcmp(ste->ht_elt.name, module->addr_sorttab[idx]->hash_elt.name))
{
DWORD xaddr = 0, xsize = 0;
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;
}
......@@ -522,7 +563,8 @@ SYM_TYPE elf_load_debug_info(struct module* module)
FIXME("Unsupported Dwarf2 information\n");
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 */
if (!(dbghelp_options & SYMOPT_PUBLICS_ONLY))
......@@ -788,8 +830,7 @@ BOOL elf_synchronize_module_list(struct process* pcs)
struct module* module;
if (!pcs->dbg_hdr_addr) return FALSE;
if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)) ||
dbg_hdr.r_state != RT_CONSISTENT)
if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)))
return FALSE;
for (module = pcs->lmodules; module; module = module->next)
......@@ -889,8 +930,7 @@ struct module* elf_load_module(struct process* pcs, const char* name)
xname = strrchr(name, '/');
if (!xname++) xname = name;
if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)) ||
dbg_hdr.r_state != RT_CONSISTENT)
if (!read_mem(pcs->handle, pcs->dbg_hdr_addr, &dbg_hdr, sizeof(dbg_hdr)))
return NULL;
for (lm_addr = (void*)dbg_hdr.r_map; lm_addr; lm_addr = (void*)lm.l_next)
......
......@@ -49,9 +49,17 @@ static void module_fill_module(const char* in, char* out, unsigned size)
(!strcasecmp(&out[len - 4], ".dll") || !strcasecmp(&out[len - 4], ".exe")))
out[len - 4] = '\0';
else
{
if (len > 7 &&
(!strcasecmp(&out[len - 7], ".dll.so") || !strcasecmp(&out[len - 7], ".exe.so")))
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++;
}
......@@ -227,6 +235,29 @@ struct module* module_find_by_addr(const struct process* pcs, unsigned long addr
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.@)
*/
......@@ -243,19 +274,28 @@ DWORD WINAPI SymLoadModule(HANDLE hProcess, HANDLE hFile, char* ImageName,
pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE;
/* this is a Wine extension to the API */
if (!ImageName && !hFile)
{
/* force transparent ELF loading / unloading */
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))
{
/* 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;
}
TRACE("Assuming %s as native DLL\n", ImageName);
if (!(module = pe_load_module(pcs, ImageName, hFile, BaseOfDll, SizeOfDll)))
{
unsigned len = strlen(ImageName);
if (!strcmp(ImageName + len - 3, ".so") &&
(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)))
goto done;
WARN("Couldn't locate %s\n", ImageName);
......@@ -274,8 +314,6 @@ done:
}
strncpy(module->module.ImageName, ImageName, sizeof(module->module.ImageName));
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;
}
......
......@@ -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);
symname[sym->thunk.namelen] = '\0';
flt = codeview_get_linetab(linetab, sym->thunk.segment, sym->thunk.offset);
symt_new_function(msc_dbg->module, flt ? flt->compiland : NULL,
symname,
symt_new_thunk(msc_dbg->module, flt ? flt->compiland : NULL,
symname, sym->thunk.thtype,
codeview_get_address(msc_dbg, sym->thunk.segment, sym->thunk.offset),
sym->thunk.thunk_len,
codeview_get_type(sym->thunk.thtype, FALSE));
sym->thunk.thunk_len);
break;
/*
......
......@@ -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);
tmp[0] = '\0';
if ((hFile = FindDebugInfoFile((char*)dbg_name, pcs->search_path, tmp)) != NULL &&
((hMap = CreateFileMappingA(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != 0) &&
((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
hdr->DebugDirectorySize / sizeof(*dbg));
}
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 (hMap) CloseHandle(hMap);
if (hFile != NULL) CloseHandle(hFile);
......@@ -324,7 +323,8 @@ struct module* pe_load_module(struct process* pcs, char* name,
else if (name) strcpy(loaded_name, name);
else if (dbghelp_options & SYMOPT_DEFERRED_LOADS)
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)
{
......
......@@ -361,8 +361,7 @@ BOOL WINAPI SymEnumTypes(HANDLE hProcess, unsigned long BaseOfDll,
TRACE("(%p %08lx %p %p)\n",
hProcess, BaseOfDll, EnumSymbolsCallback, UserContext);
pcs = process_find_by_handle(hProcess);
if (!pcs) return FALSE;
if (!(pcs = process_find_by_handle(hProcess))) return FALSE;
module = module_find_by_addr(pcs, BaseOfDll, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE;
......@@ -730,13 +729,16 @@ BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, unsigned long ModBase,
PVOID pInfo)
{
struct process* pcs = process_find_by_handle(hProcess);
struct module* module;
if (!pcs) return FALSE;
#if 0
struct module* module;
module = module_find_by_addr(pcs, ModBase, DMT_UNKNOWN);
if (!(module = module_get_debug(pcs, module))) return FALSE;
#endif
if (!(module = module_get_debug(pcs, module)))
{
FIXME("Someone didn't properly set ModBase (0x%08lx)\n", ModBase);
return FALSE;
}
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