diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-11-28 18:51:08 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-11-28 18:51:08 +0100 |
| commit | 4e92269ae1d7957c5d37cb116fa25c5976785e95 (patch) | |
| tree | d8a2d4ce6a881a1cc9bbdacd183fe8300ac94ddd /src | |
| parent | 994971b08f59c5868ae25333e4421fc12598b6e2 (diff) | |
| download | box64-4e92269ae1d7957c5d37cb116fa25c5976785e95.tar.gz box64-4e92269ae1d7957c5d37cb116fa25c5976785e95.zip | |
[ELFLOADER] Some fixes to localy openned libs when symbols might collide with main binary
Diffstat (limited to 'src')
| -rw-r--r-- | src/elfs/elfloader.c | 15 | ||||
| -rw-r--r-- | src/librarian/librarian.c | 58 |
2 files changed, 38 insertions, 35 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 97de8a49..45c7ce34 100644 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -458,14 +458,14 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t* if(!offs && !end) { if(!offs && !end && local_maplib) GetGlobalWeakSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); - if(!offs && !end && local_maplib) + if(!offs && !end) GetGlobalWeakSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); } } else { if(!offs && !end) { if(!offs && !end && local_maplib) GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); - if(!offs && !end && local_maplib) + if(!offs && !end) GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); } } @@ -503,10 +503,10 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t* *p = globoffs; } else { // Look for same symbol already loaded but not in self (so no need for local_maplib here) - if (GetGlobalNoWeakSymbolStartEnd(local_maplib?local_maplib:maplib, symname, &globoffs, &globend, version, vername, globdefver)) { + /*if (GetGlobalNoWeakSymbolStartEnd(local_maplib?local_maplib:maplib, symname, &globoffs, &globend, version, vername, globdefver)) { offs = globoffs; end = globend; - } + }*/ if (!offs) { if(strcmp(symname, "__gmon_start__") && strcmp(symname, "data_start") && strcmp(symname, "__data_start") && strcmp(symname, "collector_func_load")) printf_log(LOG_NONE, "%s: Global Symbol %s (ver=%d/%s) not found, cannot apply R_X86_64_GLOB_DAT @%p (%p) in %s\n", (bind==STB_WEAK)?"Warning":"Error", symname, version, vername?vername:"(none)", p, *(void**)p, head->name); @@ -679,9 +679,10 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t offs = old_offs; end = old_end; } else { - GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); if(!offs && !end && local_maplib) GetGlobalSymbolStartEnd(local_maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); + if(!offs && !end) + GetGlobalSymbolStartEnd(maplib, symname, &offs, &end, head, version, vername, globdefver, weakdefver); } } } @@ -751,10 +752,10 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t *p = globoffs; } else { // Look for same symbol already loaded but not in self (so no need for local_maplib here) - if (GetGlobalNoWeakSymbolStartEnd(local_maplib?local_maplib:maplib, symname, &globoffs, &globend, version, vername, globdefver)) { + /*if (GetGlobalNoWeakSymbolStartEnd(local_maplib?local_maplib:maplib, symname, &globoffs, &globend, version, vername, globdefver)) { offs = globoffs; end = globend; - } + }*/ if (!offs) { if(strcmp(symname, "__gmon_start__") && strcmp(symname, "data_start") && strcmp(symname, "__data_start") && strcmp(symname, "collector_func_load")) printf_log((bind==STB_WEAK)?LOG_INFO:LOG_NONE, "%s: Global Symbol %s not found, cannot apply R_X86_64_GLOB_DAT @%p (%p) in %s\n", (bind==STB_WEAK)?"Warning":"Error", symname, p, *(void**)p, head->name); diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c index fad45e4f..1f103ad8 100644 --- a/src/librarian/librarian.c +++ b/src/librarian/librarian.c @@ -199,7 +199,7 @@ int isLibLocal(library_t* lib) return libraryInMapLib(my_context->local_maplib, lib); } -static int AddNeededLib_add(lib_t* maplib, int local, needed_libs_t* needed, int n, elfheader_t* verneeded, box64context_t* box64, x64emu_t* emu) +static int AddNeededLib_add(lib_t** maplib, int local, needed_libs_t* needed, int n, elfheader_t* verneeded, box64context_t* box64, x64emu_t* emu) { const char* path = needed->names[n]; printf_dump(LOG_DEBUG, "Trying to add \"%s\" to maplib%s\n", path, local?" (local)":""); @@ -219,11 +219,11 @@ static int AddNeededLib_add(lib_t* maplib, int local, needed_libs_t* needed, int IncRefCount(lib, emu); // increment cntref if(local) { // add lib to maplib... - if(maplib) { - if(!libraryInMapLib(maplib, lib)) - MapLibPrependLib(maplib, lib, NULL); // todo: Also insert libs needed by lib, after lib? But current lib->maplib is probably not the solution - if(maplib->ownlibs) - MapLibRemoveMapLib(my_context->local_maplib, maplib); + if(*maplib) { + if(!libraryInMapLib(*maplib, lib)) + MapLibPrependLib(*maplib, lib, NULL); // todo: Also insert libs needed by lib, after lib? But current lib->maplib is probably not the solution + if((*maplib)->ownlibs) + MapLibRemoveMapLib(my_context->local_maplib, *maplib); } } else { // promote lib from local to global... @@ -241,8 +241,8 @@ static int AddNeededLib_add(lib_t* maplib, int local, needed_libs_t* needed, int // add lib now if(local) { MapLibAddLib(my_context->local_maplib, lib); - if(maplib) { - MapLibAddLib(maplib, lib); + if(*maplib) { + MapLibAddLib(*maplib, lib); } else { lib->maplib = NewLibrarian(box64, 0); MapLibAddLib(lib->maplib, lib); @@ -251,10 +251,10 @@ static int AddNeededLib_add(lib_t* maplib, int local, needed_libs_t* needed, int MapLibAddLib(my_context->maplib, lib); } - if(!maplib) - maplib = (local)?lib->maplib:my_context->maplib; + if(!*maplib) + *maplib = (local)?lib->maplib:my_context->maplib; - if(AddSymbolsLibrary(maplib, lib, emu)) { // also add needed libs + if(AddSymbolsLibrary(*maplib, lib, emu)) { // also add needed libs printf_dump(LOG_DEBUG, "Failure to Add lib => fail\n"); return 1; } @@ -343,7 +343,7 @@ int AddNeededLib(lib_t* maplib, int local, int bindnow, needed_libs_t* needed, e int ret = 0; // Add libs and symbol for(int i=0; i<needed->size; ++i) { - if(AddNeededLib_add(maplib, local, needed, i, verneeded, box64, emu)) { + if(AddNeededLib_add(&maplib, local, needed, i, verneeded, box64, emu)) { printf_log(strchr(needed->names[i],'/')?LOG_DEBUG:LOG_INFO, "Error loading needed lib %s\n", needed->names[i]); ret = 1; } @@ -483,24 +483,26 @@ static int GetGlobalSymbolStartEnd_internal(lib_t *maplib, const char* name, uin if(*start) { return 1; } - // search non-weak symbol, from older to newer (first GLOBAL object wins, starting with self) - if(GetSymbolStartEnd(GetMapSymbols(my_context->elfs[0]), name, start, end, version, vername, (my_context->elfs[0]==self || !self)?1:0, globdefver)) - if(*start) { - return 1; - } - // This kind-of create a map to search lib only 1 time, and in order of needed... - if(my_context->neededlibs) - CheckNeededLibs(my_context->neededlibs); - // search in needed libs from neededlibs first, in order - if(my_context->neededlibs) - for(int i=0; i<my_context->neededlibs->size; ++i) - if(GetLibGlobalSymbolStartEnd(my_context->neededlibs->libs[i], name, start, end, size, &weak, version, vername, isLocal(self, my_context->neededlibs->libs[i]), globdefver)) - if(*start) { - return 1; - } + if(maplib==my_context->maplib) { + // search non-weak symbol, from older to newer (first GLOBAL object wins, starting with self) + if(GetSymbolStartEnd(GetMapSymbols(my_context->elfs[0]), name, start, end, version, vername, (my_context->elfs[0]==self || !self)?1:0, globdefver)) + if(*start) { + return 1; + } + // This kind-of create a map to search lib only 1 time, and in order of needed... + if(my_context->neededlibs) + CheckNeededLibs(my_context->neededlibs); + // search in needed libs from neededlibs first, in order + if(my_context->neededlibs) + for(int i=0; i<my_context->neededlibs->size; ++i) + if(GetLibGlobalSymbolStartEnd(my_context->neededlibs->libs[i], name, start, end, size, &weak, version, vername, isLocal(self, my_context->neededlibs->libs[i]), globdefver)) + if(*start) { + return 1; + } + } // search in global symbols if(maplib) { - if(self && self!=my_context->elfs[0] && self!=(void*)1) + if((maplib==my_context->maplib) && self && self!=my_context->elfs[0] && self!=(void*)1) if(GetSymbolStartEnd(GetMapSymbols(self), name, start, end, version, vername, 1, globdefver)) if(*start) { return 1; |