Skip to content

Commit

Permalink
Small fixes after big elfloader rework
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed May 29, 2021
1 parent 5d0d1e4 commit 2b9645e
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
4 changes: 2 additions & 2 deletions src/elfs/elfparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/include/wrappedlibs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/librarian/librarian.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/librarian/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/librarian/library_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
2 changes: 1 addition & 1 deletion src/librarian/symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/wrapped/wrappedlib_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ 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;
#ifdef CUSTOM_FAIL
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
Expand All @@ -225,15 +225,15 @@ 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;
#ifdef CUSTOM_FAIL
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
Expand Down
35 changes: 16 additions & 19 deletions src/wrapped/wrappedlibdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<n; ++i) {
Expand Down Expand Up @@ -433,25 +432,23 @@ void* my_dlvsym(x86emu_t* emu, void *handle, void *symbol, const char* vername)
}
} else {
// still usefull?
for(int step=0; step<=MAX_STEP; ++step) {
if(GetSymbolStartEnd(GetLocalSymbol(emu->context->maplib), rsymbol, &start, &end, version, vername, step)) {
if(dlsym_error && box86_log<LOG_DEBUG) {
printf_log(LOG_NONE, "%p\n", (void*)start);
}
return (void*)start;
if(GetSymbolStartEnd(GetLocalSymbol(emu->context->maplib), rsymbol, &start, &end, version, vername, 1)) {
if(dlsym_error && box86_log<LOG_DEBUG) {
printf_log(LOG_NONE, "%p\n", (void*)start);
}
if(GetSymbolStartEnd(GetWeakSymbol(emu->context->maplib), rsymbol, &start, &end, version, vername, step)) {
if(dlsym_error && box86_log<LOG_DEBUG) {
printf_log(LOG_NONE, "%p\n", (void*)start);
}
return (void*)start;
return (void*)start;
}
if(GetSymbolStartEnd(GetWeakSymbol(emu->context->maplib), rsymbol, &start, &end, version, vername, 1)) {
if(dlsym_error && box86_log<LOG_DEBUG) {
printf_log(LOG_NONE, "%p\n", (void*)start);
}
if(GetSymbolStartEnd(GetMapSymbol(emu->context->maplib), rsymbol, &start, &end, version, vername, step)) {
if(dlsym_error && box86_log<LOG_DEBUG) {
printf_log(LOG_NONE, "%p\n", (void*)start);
}
return (void*)start;
return (void*)start;
}
if(GetSymbolStartEnd(GetMapSymbol(emu->context->maplib), rsymbol, &start, &end, version, vername, 1)) {
if(dlsym_error && box86_log<LOG_DEBUG) {
printf_log(LOG_NONE, "%p\n", (void*)start);
}
return (void*)start;
}
// not found
if(dlsym_error && box86_log<LOG_DEBUG) {
Expand Down

0 comments on commit 2b9645e

Please sign in to comment.