diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-06-23 11:11:29 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-06-23 11:11:29 +0200 |
| commit | c60e4839ebde63937d37aa751235c86a00379f7c (patch) | |
| tree | 6563e505a0e3573c88562aa49521db35ad903e35 /src | |
| parent | b626fc5095ac4a265cc5ded25539d4acfeec20a1 (diff) | |
| download | box64-c60e4839ebde63937d37aa751235c86a00379f7c.tar.gz box64-c60e4839ebde63937d37aa751235c86a00379f7c.zip | |
More improvments to elfloader
Diffstat (limited to 'src')
| -rwxr-xr-x | src/elfs/elfloader.c | 33 | ||||
| -rwxr-xr-x | src/librarian/librarian.c | 10 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibc_private.h | 4 | ||||
| -rwxr-xr-x | src/wrapped/wrappedlibdl.c | 2 |
4 files changed, 34 insertions, 15 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index e6c68393..b2ba5aac 100755 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -407,10 +407,10 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int cn }*/ // so weak symbol are the one left if(!offs && !end) { - GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername); - if(!offs && !end && local_maplib) { + if(!offs && !end && local_maplib) GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername); - } + if(!offs && !end && local_maplib) + GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername); } } uintptr_t globoffs, globend; @@ -444,7 +444,7 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int cn *p = globoffs; } else { // Look for same symbol already loaded but not in self (so no need for local_maplib here) - if (GetGlobalNoWeakSymbolStartEnd(maplib, symname, &globoffs, &globend, version, vername)) { + if (GetGlobalNoWeakSymbolStartEnd(local_maplib?local_maplib:maplib, symname, &globoffs, &globend, version, vername)) { offs = globoffs; end = globend; } @@ -635,7 +635,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c *p = globoffs; } else { // Look for same symbol already loaded but not in self (so no need for local_maplib here) - if (GetGlobalNoWeakSymbolStartEnd(maplib, symname, &globoffs, &globend, version, vername)) { + if (GetGlobalNoWeakSymbolStartEnd(local_maplib?local_maplib:maplib, symname, &globoffs, &globend, version, vername)) { offs = globoffs; end = globend; } @@ -1144,11 +1144,13 @@ void RunDeferedElfInit(x64emu_t *emu) context->deferedInit = 0; if(!context->deferedInitList) return; - for (int i=0; i<context->deferedInitSz; ++i) - RunElfInit(context->deferedInitList[i], emu); - free(context->deferedInitList); + int Sz = context->deferedInitSz; + elfheader_t** List = context->deferedInitList; context->deferedInitList = NULL; context->deferedInitCap = context->deferedInitSz = 0; + for (int i=0; i<Sz; ++i) + RunElfInit(List[i], emu); + free(List); } void RunElfFini(elfheader_t* h, x64emu_t *emu) @@ -1442,6 +1444,21 @@ void ResetSpecialCaseMainElf(elfheader_t* h) memcpy((void*)sym->st_value+h->delta, stdout, sym->st_size); my__IO_2_1_stdout_ = (void*)sym->st_value+h->delta; printf_log(LOG_DEBUG, "BOX64: Set @_IO_2_1_stdout_ to %p\n", my__IO_2_1_stdout_); + } else + if(strcmp(symname, "_IO_stderr_")==0 && ((void*)sym->st_value+h->delta)) { + memcpy((void*)sym->st_value+h->delta, stderr, sym->st_size); + my__IO_2_1_stderr_ = (void*)sym->st_value+h->delta; + printf_log(LOG_DEBUG, "BOX64: Set @_IO_stderr_ to %p\n", my__IO_2_1_stderr_); + } else + if(strcmp(symname, "_IO_stdin_")==0 && ((void*)sym->st_value+h->delta)) { + memcpy((void*)sym->st_value+h->delta, stdin, sym->st_size); + my__IO_2_1_stdin_ = (void*)sym->st_value+h->delta; + printf_log(LOG_DEBUG, "BOX64: Set @_IO_stdin_ to %p\n", my__IO_2_1_stdin_); + } else + if(strcmp(symname, "_IO_stdout_")==0 && ((void*)sym->st_value+h->delta)) { + memcpy((void*)sym->st_value+h->delta, stdout, sym->st_size); + my__IO_2_1_stdout_ = (void*)sym->st_value+h->delta; + printf_log(LOG_DEBUG, "BOX64: Set @_IO_stdout_ to %p\n", my__IO_2_1_stdout_); } } } diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c index 93344c9c..39045480 100755 --- a/src/librarian/librarian.c +++ b/src/librarian/librarian.c @@ -439,15 +439,15 @@ static int GetGlobalSymbolStartEnd_internal(lib_t *maplib, const char* name, uin return 1; } - // library from newer to older, weak only now - for(int i=maplib->libsz-1; i>=0; --i) { + if(GetSymbolStartEnd(maplib->weaksymbols, name, start, end, version, vername, (maplib->context->elfs[0]==self || !self)?1:0)) + if(*start) + return 1; + + for(int i=0; i<maplib->libsz; ++i) { if(GetLibSymbolStartEnd(maplib->libraries[i], name, start, end, version, vername, isLocal(self, maplib->libraries[i]))) // only weak symbol haven't been found yet if(*start) return 1; } - if(GetSymbolStartEnd(maplib->weaksymbols, name, start, end, version, vername, (maplib->context->elfs[0]==self || !self)?1:0)) - if(*start) - return 1; // nope, not found return 0; } diff --git a/src/wrapped/wrappedlibc_private.h b/src/wrapped/wrappedlibc_private.h index 685b3933..7b5d8f72 100755 --- a/src/wrapped/wrappedlibc_private.h +++ b/src/wrapped/wrappedlibc_private.h @@ -333,8 +333,8 @@ GOW(feof_unlocked, iFp) GOW(ferror, iFp) GOW(ferror_unlocked, iFp) //GO(fexecve, -GOW(fflush, iFp) -GO(fflush_unlocked, iFp) +GOW(fflush, iFS) +GO(fflush_unlocked, iFS) //GO(__ffs, //GO(ffs, //GOW(ffsl, diff --git a/src/wrapped/wrappedlibdl.c b/src/wrapped/wrappedlibdl.c index 8f829270..33835292 100755 --- a/src/wrapped/wrappedlibdl.c +++ b/src/wrapped/wrappedlibdl.c @@ -95,6 +95,7 @@ void* my_dlopen(x64emu_t* emu, void *filename, int flag) dlopened = (GetLibInternal(rfilename)==NULL); // Then open the lib const char* libs[] = {rfilename}; + my_context->deferedInit = 1; if(AddNeededLib(NULL, NULL, NULL, is_local, libs, 1, emu->context, emu)) { printf_log(LOG_INFO, "Warning: Cannot dlopen(\"%s\"/%p, %X)\n", rfilename, filename, flag); if(!dl->last_error) @@ -103,6 +104,7 @@ void* my_dlopen(x64emu_t* emu, void *filename, int flag) return NULL; } lib = GetLibInternal(rfilename); + RunDeferedElfInit(emu); } else { // check if already dlopenned... for (size_t i=0; i<dl->lib_sz; ++i) { |