From 2b9645e3a632586c59d0cecb006156edd4318a01 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 29 May 2021 18:23:20 +0200 Subject: [PATCH] Small fixes after big elfloader rework --- src/elfs/elfparser.c | 4 ++-- src/include/wrappedlibs.h | 2 +- src/librarian/librarian.c | 1 + src/librarian/library.c | 4 ++-- src/librarian/library_private.h | 2 +- src/librarian/symbols.c | 2 +- src/wrapped/wrappedlib_init.h | 8 ++++---- src/wrapped/wrappedlibdl.c | 35 +++++++++++++++------------------ 8 files changed, 28 insertions(+), 30 deletions(-) diff --git a/src/elfs/elfparser.c b/src/elfs/elfparser.c index 9a82f66923..315dce14b3 100755 --- a/src/elfs/elfparser.c +++ b/src/elfs/elfparser.c @@ -212,7 +212,7 @@ elfheader_t* ParseElfHeader(FILE* f, const char* name, int exec) h->relaent = val; break; case DT_PLTGOT: - h->pltgot = val; + h->pltgot = ptr; break; case DT_PLTREL: h->pltrel = val; @@ -221,7 +221,7 @@ elfheader_t* ParseElfHeader(FILE* f, const char* name, int exec) h->pltsz = val; break; case DT_JMPREL: - h->jmprel = val; + h->jmprel = ptr; break; case DT_STRTAB: h->DynStrTab = (char *)(ptr); diff --git a/src/include/wrappedlibs.h b/src/include/wrappedlibs.h index 4f32f6d9a2..484c253709 100755 --- a/src/include/wrappedlibs.h +++ b/src/include/wrappedlibs.h @@ -7,7 +7,7 @@ typedef struct box86context_s box86context_t; typedef int (*wrappedlib_init_t)(library_t * lib, box86context_t* box86); // 0 = success typedef void (*wrappedlib_fini_t)(library_t * lib); -typedef int (*wrappedlib_get_t)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, int version, const char* vername, int step); +typedef int (*wrappedlib_get_t)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, int version, const char* vername, int local); typedef struct wrappedlib_s { const char* name; diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c index 7e24a78741..38a79ae2f7 100755 --- a/src/librarian/librarian.c +++ b/src/librarian/librarian.c @@ -276,6 +276,7 @@ int AddNeededLib_add(lib_t* maplib, needed_libs_t* neededlibs, library_t* deplib printf_log(LOG_DEBUG, "Failure to Add lib => fail\n"); return 1; } + return 0; } int AddNeededLib_init(lib_t* maplib, needed_libs_t* neededlibs, library_t* deplib, int local, library_t* lib, box86context_t* box86, x86emu_t* emu) diff --git a/src/librarian/library.c b/src/librarian/library.c index 4cf6979088..37cab8495b 100755 --- a/src/librarian/library.c +++ b/src/librarian/library.c @@ -302,6 +302,7 @@ int FinalizeLibrary(library_t* lib, lib_t* local_maplib, x86emu_t* emu) return 1; } RelocateElfPlt(my_context->maplib, local_maplib, elf_header); +#ifdef HAVE_TRACE if(trace_func) { if (GetGlobalSymbolStartEnd(my_context->maplib, trace_func, &trace_start, &trace_end, elf_header, -1, NULL)) { SetTraceEmu(trace_start, trace_end); @@ -315,6 +316,7 @@ int FinalizeLibrary(library_t* lib, lib_t* local_maplib, x86emu_t* emu) trace_func = NULL; } } +#endif RunElfInit(elf_header, emu); } return 0; @@ -676,8 +678,6 @@ int getSymbolInMaps(library_t*lib, const char* name, int noweak, uintptr_t *addr { if(!lib->active) return 0; - khint_t k; - void* symbol; // check in datamaps (but no version, it's not handled there) if(getSymbolInDataMaps(lib, name, noweak, addr, size)) return 1; diff --git a/src/librarian/library_private.h b/src/librarian/library_private.h index 5b9e21ce7a..fe56cad345 100755 --- a/src/librarian/library_private.h +++ b/src/librarian/library_private.h @@ -101,6 +101,6 @@ typedef struct map_onedata_s { int weak; } map_onedata_t; -int getSymbolInMaps(library_t*lib, const char* name, int noweak, uintptr_t *addr, uint32_t *size, int vezrsion, const char* vername, int local); // Add bridges to functions +int getSymbolInMaps(library_t*lib, const char* name, int noweak, uintptr_t *addr, uint32_t *size, int version, const char* vername, int local); // Add bridges to functions #endif //__LIBRARY_PRIVATE_H_ diff --git a/src/librarian/symbols.c b/src/librarian/symbols.c index aa3b4bc65e..6fd8e78627 100644 --- a/src/librarian/symbols.c +++ b/src/librarian/symbols.c @@ -109,7 +109,7 @@ static versymbol_t* MatchVersion(versymbols_t* s, int ver, const char* vername, { if(!s || !s->sz) return NULL; - versymbol_t* ret; + versymbol_t* ret = NULL; if(ver==0) { if(local) ret = FindVersionLocal(s); if(!ret) ret = FindNoVersion(s); diff --git a/src/wrapped/wrappedlib_init.h b/src/wrapped/wrappedlib_init.h index cdfd35c368..c090414119 100755 --- a/src/wrapped/wrappedlib_init.h +++ b/src/wrapped/wrappedlib_init.h @@ -202,7 +202,7 @@ int FUNC(_fini)(library_t* lib) return 1; } -int FUNC(_get)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, int version, const char* vername, int step) +int FUNC(_get)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, int version, const char* vername, int local) { uintptr_t addr = 0; uint32_t size = 0; @@ -210,7 +210,7 @@ int FUNC(_get)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, void* symbol = NULL; #endif //PRE - if (!getSymbolInMaps(lib, name, 0, &addr, &size, version, vername, step)) { + if (!getSymbolInMaps(lib, name, 0, &addr, &size, version, vername, local)) { #ifdef CUSTOM_FAIL CUSTOM_FAIL #else @@ -225,7 +225,7 @@ int FUNC(_get)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, return 1; } -int FUNC(_getnoweak)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, int version, const char* vername, int step) +int FUNC(_getnoweak)(library_t* lib, const char* name, uintptr_t *offs, uint32_t *sz, int version, const char* vername, int local) { uintptr_t addr = 0; uint32_t size = 0; @@ -233,7 +233,7 @@ int FUNC(_getnoweak)(library_t* lib, const char* name, uintptr_t *offs, uint32_t void* symbol = NULL; #endif //PRE - if (!getSymbolInMaps(lib, name, 1, &addr, &size, version, vername, step)) { + if (!getSymbolInMaps(lib, name, 1, &addr, &size, version, vername, local)) { #ifdef CUSTOM_FAIL CUSTOM_FAIL #else diff --git a/src/wrapped/wrappedlibdl.c b/src/wrapped/wrappedlibdl.c index daa975a018..961843a3dc 100755 --- a/src/wrapped/wrappedlibdl.c +++ b/src/wrapped/wrappedlibdl.c @@ -169,9 +169,8 @@ int recursive_dlsym_lib(kh_libs_t* collection, library_t* lib, const char* rsymb int ret; kh_put(libs, collection, (uintptr_t)lib, &ret); // look in the library itself - for(int step=0; step<=MAX_STEP; ++step) - if(lib->get(lib, rsymbol, start, end, version, vername, step)) - return 1; + if(lib->get(lib, rsymbol, start, end, version, vername, 1)) + return 1; // look in other libs int n = GetNeededLibN(lib); for (int i=0; icontext->maplib), rsymbol, &start, &end, version, vername, step)) { - if(dlsym_error && box86_logcontext->maplib), rsymbol, &start, &end, version, vername, 1)) { + if(dlsym_error && box86_logcontext->maplib), rsymbol, &start, &end, version, vername, step)) { - if(dlsym_error && box86_logcontext->maplib), rsymbol, &start, &end, version, vername, 1)) { + if(dlsym_error && box86_logcontext->maplib), rsymbol, &start, &end, version, vername, step)) { - if(dlsym_error && box86_logcontext->maplib), rsymbol, &start, &end, version, vername, 1)) { + if(dlsym_error && box86_log