diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2024-03-04 13:40:49 +0100 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2024-03-04 13:40:57 +0100 |
| commit | 9e37dd008d5710f03385c8afd1ef2aed728a8fe0 (patch) | |
| tree | a3838216baa79629472cffda264ba971fb3674a2 /src | |
| parent | 5b1057fe08f08c0c9c5dba5c9b7069a48b55c4ee (diff) | |
| download | box64-9e37dd008d5710f03385c8afd1ef2aed728a8fe0.tar.gz box64-9e37dd008d5710f03385c8afd1ef2aed728a8fe0.zip | |
[ELFLOADER] Fixes some issue with symbol version matching and unload of failled libs (for #1311, probably other too)
Diffstat (limited to 'src')
| -rw-r--r-- | src/elfs/elfhash.c | 2 | ||||
| -rw-r--r-- | src/elfs/elfloader.c | 19 | ||||
| -rw-r--r-- | src/librarian/librarian.c | 9 |
3 files changed, 16 insertions, 14 deletions
diff --git a/src/elfs/elfhash.c b/src/elfs/elfhash.c index 7c3b1138..c0a62b51 100644 --- a/src/elfs/elfhash.c +++ b/src/elfs/elfhash.c @@ -177,7 +177,7 @@ static int SymbolMatch(elfheader_t* h, uint32_t i, int ver, const char* vername, return 1; if(ver==1 && version<2) return 1; - if(ver<2 && version>2 && flags==0) // flag is not WEAK, so global works + if(ver<2 && version>1 && flags==0) // flag is not WEAK, so global works return 1; if(ver<2 || !symvername) return 0; diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index d6f0dc02..93d3f224 100644 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -686,14 +686,9 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbin break; case R_X86_64_64: if (!offs && !elfsym) { - if(symname && !strcmp(symname, "__gxx_personality_v0")) { - printf_dump(LOG_NEVER, "Warning: Symbol %s not found, cannot apply R_X86_64_64 @%p (%p) in %s\n", symname, p, *(void**)p, head->name); - } else { - printf_log(LOG_INFO, "%s: Symbol %s not found, cannot apply R_X86_64_64 @%p (%p) in %s\n", (bind==STB_GLOBAL)?"Error":"Warning", symname, p, *(void**)p, head->name); - if(bind==STB_GLOBAL) - ret_ok = 1; - // return -1; - } + printf_log(LOG_INFO, "%s: Symbol %s not found, cannot apply R_X86_64_64 @%p (%p) in %s\n", (bind==STB_GLOBAL)?"Error":"Warning", symname, p, *(void**)p, head->name); + if(bind==STB_GLOBAL) + ret_ok = 1; } else { printf_dump(LOG_NEVER, "Apply %s R_X86_64_64 @%p with sym=%s (%sver=%d/%s) addend=0x%lx (%p -> %p)\n", BindSym(bind), p, symname, veropt?"opt":"", version, vername?vername:"(none)", rela[i].r_addend, *(void**)p, (void*)(offs+rela[i].r_addend/*+*(uint64_t*)p*/)); @@ -785,14 +780,14 @@ int RelocateElf(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbind, e if(head->rel) { int cnt = head->relsz / head->relent; DumpRelTable(head, cnt, (Elf64_Rel *)(head->rel + head->delta), "Rel"); - printf_dump(LOG_DEBUG, "Applying %d Relocation(s) for %s\n", cnt, head->name); + printf_dump(LOG_DEBUG, "Applying %d Relocation(s) for %s bindnow=%d, deepbind=%d\n", cnt, head->name, bindnow, deepbind); if(RelocateElfREL(maplib, local_maplib, bindnow, deepbind, head, cnt, (Elf64_Rel *)(head->rel + head->delta))) return -1; } if(head->rela) { int cnt = head->relasz / head->relaent; DumpRelATable(head, cnt, (Elf64_Rela *)(head->rela + head->delta), "RelA"); - printf_dump(LOG_DEBUG, "Applying %d Relocation(s) with Addend for %s\n", cnt, head->name); + printf_dump(LOG_DEBUG, "Applying %d Relocation(s) with Addend for %s bindnow=%d, deepbind=%d\n", cnt, head->name, bindnow, deepbind); if(RelocateElfRELA(maplib, local_maplib, bindnow, deepbind, head, cnt, (Elf64_Rela *)(head->rela + head->delta), NULL)) return -1; } @@ -810,12 +805,12 @@ int RelocateElfPlt(lib_t *maplib, lib_t *local_maplib, int bindnow, int deepbind int cnt = head->pltsz / head->pltent; if(head->pltrel==DT_REL) { DumpRelTable(head, cnt, (Elf64_Rel *)(head->jmprel + head->delta), "PLT"); - printf_dump(LOG_DEBUG, "Applying %d PLT Relocation(s) for %s\n", cnt, head->name); + printf_dump(LOG_DEBUG, "Applying %d PLT Relocation(s) for %s bindnow=%d, deepbind=%d\n", cnt, head->name, bindnow, deepbind); if(RelocateElfREL(maplib, local_maplib, bindnow, deepbind, head, cnt, (Elf64_Rel *)(head->jmprel + head->delta))) return -1; } else if(head->pltrel==DT_RELA) { DumpRelATable(head, cnt, (Elf64_Rela *)(head->jmprel + head->delta), "PLT"); - printf_dump(LOG_DEBUG, "Applying %d PLT Relocation(s) with Addend for %s\n", cnt, head->name); + printf_dump(LOG_DEBUG, "Applying %d PLT Relocation(s) with Addend for %s bindnow=%d, deepbind=%d\n", cnt, head->name, bindnow, deepbind); if(RelocateElfRELA(maplib, local_maplib, bindnow, deepbind, head, cnt, (Elf64_Rela *)(head->jmprel + head->delta), &need_resolver)) return -1; } diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c index 9b5e82ac..4aff1864 100644 --- a/src/librarian/librarian.c +++ b/src/librarian/librarian.c @@ -333,9 +333,16 @@ int AddNeededLib(lib_t* maplib, int local, int bindnow, int deepbind, needed_lib for (int i=0; i<n; ++i) if(AddNeededLib_init(maplib, local, bindnow, deepbind, needed->libs[n-i-1], verneeded, box64, emu)) { printf_log(LOG_INFO, "Error initializing needed lib %s\n", needed->names[i]); - if(!allow_missing_libs) ret = 1; + ret = 1; } // error while loadind lib, unload... + if(ret) { + int n = needed->size; + for (int i=0; i<n; ++i) + DecRefCount(&needed->libs[n-i-1], emu); + } + // all done + if(allow_missing_libs) return 0; return ret; } EXPORTDYN |