diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-04-02 11:04:34 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-04-02 11:04:34 +0200 |
| commit | 7822f29140cc4323943c0416d7ee0fd8eec6819c (patch) | |
| tree | effc6f0f1f8889dda4d05e07f28c0e6a7a286d80 | |
| parent | 98d434a0a9c93f2994233dec486b6a67a2dc6e68 (diff) | |
| download | box64-7822f29140cc4323943c0416d7ee0fd8eec6819c.tar.gz box64-7822f29140cc4323943c0416d7ee0fd8eec6819c.zip | |
Change Elfloader handling of R_X86_64_GLOB_DAT with R_X86_64_COPY by preapplying the Copy (it fixed Knytt Underground)
| -rwxr-xr-x | src/elfs/elfloader.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index f734606e..a291d21f 100755 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -355,7 +355,7 @@ int FindR64COPYRel(elfheader_t* h, const char* name, uintptr_t *offs, uint64_t** if(!h) return 0; Elf64_Rela * rel = (Elf64_Rela *)(h->rela + h->delta); - if(!h->rel) + if(!h->rela) return 0; int cnt = h->relasz / h->relaent; for (int i=0; i<cnt; ++i) { @@ -364,7 +364,7 @@ int FindR64COPYRel(elfheader_t* h, const char* name, uintptr_t *offs, uint64_t** const char* symname = SymName(h, sym); if(!strcmp(symname, name) && t==R_X86_64_COPY) { *offs = sym->st_value + h->delta; - *p = (uint64_t*)(rel[i].r_offset + h->delta); + *p = (uint64_t*)(rel[i].r_offset + h->delta + rel[i].r_addend); return 1; } } @@ -590,7 +590,10 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, elfheader_t* head, int c // set global offs / size for the symbol offs = sym->st_value + head->delta; end = offs + sym->st_size; - printf_log(LOG_DUMP, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) size=%ld on sym=%s \n", (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), (void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, sym->st_size, symname); + printf_log(LOG_DUMP, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) size=%ld on sym=%s \n", + (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), + (void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, sym->st_size, symname); + memmove((void*)globoffs, (void*)offs, sym->st_size); // preapply to copy part from lib to main elf *p = globoffs/* + rela[i].r_addend*/; //no addend? AddWeakSymbol(GetGlobalData(maplib), symname, offs, end-offs+1); } else { |