From d21dedbe4f7afbc8f05fb1af1ac37370e8a88b75 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Sat, 6 Mar 2021 13:55:06 +0100 Subject: More work on elfloader reloc and addend handling --- src/elfs/elfloader.c | 12 ++++++------ src/emu/x64run66.c | 3 +++ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 24d20bab..252960c6 100755 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -354,10 +354,10 @@ int FindR64COPYRel(elfheader_t* h, const char* name, uintptr_t *offs, uint64_t** { if(!h) return 0; - Elf64_Rel * rel = (Elf64_Rel *)(h->rel + h->delta); + Elf64_Rela * rel = (Elf64_Rela *)(h->rela + h->delta); if(!h->rel) return 0; - int cnt = h->relsz / h->relent; + int cnt = h->relasz / h->relaent; for (int i=0; iDynSym[ELF64_R_SYM(rel[i].r_info)]; @@ -584,7 +584,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c AddWeakSymbol(GetGlobalData(maplib), symname, offs, end-offs+1); } else { // Look for same symbol already loaded but not in self (so no need for local_maplib here) - if (GetGlobalSymbolStartEnd(maplib, symname, &globoffs, &globend)) { + if (GetGlobalNoWeakSymbolStartEnd(maplib, symname, &globoffs, &globend)) { offs = globoffs; end = globend; } @@ -614,7 +614,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c // return -1; } else { if(p) { - printf_log(LOG_DUMP, "Apply %s R_X86_64_JUMP_SLOT @%p with sym=%s (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, symname, *(void**)p, (void*)offs); + printf_log(LOG_DUMP, "Apply %s R_X86_64_JUMP_SLOT @%p with sym=%s (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, symname, *(void**)p, (void*)(offs+rela[i].r_addend)); *p = offs + rela[i].r_addend; } else { printf_log(LOG_NONE, "Warning, Symbol %s found, but Jump Slot Offset is NULL \n", symname); @@ -630,8 +630,8 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c printf_log(LOG_NONE, "Error: Symbol %s not found, cannot apply R_X86_64_64 @%p (%p) in %s\n", symname, p, *(void**)p, head->name); // return -1; } else { - printf_log(LOG_DUMP, "Apply %s R_X86_64_64 @%p with sym=%s (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, symname, *(void**)p, (void*)(offs+*(uint64_t*)p)); - *p += offs; + printf_log(LOG_DUMP, "Apply %s R_X86_64_64 @%p with sym=%s addend=0x%lx (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, symname, rela[i].r_addend, *(void**)p, (void*)(offs+rela[i].r_addend+*(uint64_t*)p)); + *p += offs+rela[i].r_addend; } break; case R_X86_64_DTPMOD64: diff --git a/src/emu/x64run66.c b/src/emu/x64run66.c index 2ad8590b..77dd7b06 100644 --- a/src/emu/x64run66.c +++ b/src/emu/x64run66.c @@ -78,6 +78,9 @@ int Run66(x64emu_t *emu, rex_t rex) EW->word[0] = GW->word[0]; break; + case 0x90: /* NOP */ + break; + case 0xC1: /* GRP2 Ew,Ib */ nextop = F8; GETEW; -- cgit 1.4.1