diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2023-07-15 16:57:57 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2023-07-15 16:57:57 +0200 |
| commit | 0b3097cd0b15eedd3e33ae2331f32fc261ee1231 (patch) | |
| tree | 3f2034d75b595670e68971d0c9dc125000960da4 /src | |
| parent | c7e0ba82b4a586fed8f4d45acd0c774ddf0f777b (diff) | |
| download | box64-0b3097cd0b15eedd3e33ae2331f32fc261ee1231.tar.gz box64-0b3097cd0b15eedd3e33ae2331f32fc261ee1231.zip | |
[ELFLOADER] Reworked R_X86_64_COPY and R_X86_64_GLOB_DAT handling, improving c++ program compatibility
Diffstat (limited to 'src')
| -rwxr-xr-x | src/box64context.c | 4 | ||||
| -rwxr-xr-x | src/elfs/elfloader.c | 10 | ||||
| -rwxr-xr-x | src/include/box64context.h | 1 | ||||
| -rwxr-xr-x | src/librarian/librarian.c | 4 | ||||
| -rw-r--r-- | src/wrapped/generated/wrapper.h | 1 |
5 files changed, 15 insertions, 5 deletions
diff --git a/src/box64context.c b/src/box64context.c index 5c85f3fa..234657ca 100755 --- a/src/box64context.c +++ b/src/box64context.c @@ -259,6 +259,8 @@ box64context_t *NewBox64Context(int argc) context->segtls[4].present = 1; context->segtls[4].is32bits = 1; + context->globdata = NewMapSymbols(); + initAllHelpers(context); return context; @@ -353,6 +355,8 @@ void FreeBox64Context(box64context_t** context) if(ctx->emu_sig) FreeX64Emu(&ctx->emu_sig); + FreeMapSymbols(&ctx->globdata); + finiAllHelpers(ctx); #ifdef DYNAREC diff --git a/src/elfs/elfloader.c b/src/elfs/elfloader.c index 24255c84..5a0890cf 100755 --- a/src/elfs/elfloader.c +++ b/src/elfs/elfloader.c @@ -520,7 +520,8 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t* if(sym->st_size && offs) { printf_dump(LOG_NEVER, "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 + head->delta), (void*)globoffs, sym->st_size, symname); memmove((void*)globoffs, (void*)offs, sym->st_size); // preapply to copy part from lib to main elf - AddUniqueSymbol(GetGlobalData(maplib), symname, offs + head->delta, sym->st_size, version, vername); + AddUniqueSymbol(GetGlobalData(maplib), symname, globoffs, sym->st_size, version, vername); + AddUniqueSymbol(my_context->globdata, symname, offs + head->delta, sym->st_size, version, vername); } else { printf_dump(LOG_NEVER, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) null sized on sym=%s \n", (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), (void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, symname); } @@ -545,7 +546,7 @@ int RelocateElfREL(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t* uintptr_t old_offs = offs; uintptr_t old_end = end; offs = 0; - GetSizedSymbolStartEnd(GetGlobalData(maplib), symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first + GetSizedSymbolStartEnd(my_context->globdata, symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first if(offs==0) { GetNoSelfSymbolStartEnd(maplib, symname, &offs, &end, head, size, version, vername, globdefver, weakdefver); // get original copy if any if(!offs && local_maplib) @@ -729,7 +730,7 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t globoffs = offs; globend = end; offs = end = 0; - GetSizedSymbolStartEnd(GetGlobalData(maplib), symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first + GetSizedSymbolStartEnd(my_context->globdata, symname, &offs, &end, size, version, vername, 1, globdefver); // try globaldata symbols first if(!offs && local_maplib) GetNoSelfSymbolStartEnd(local_maplib, symname, &offs, &end, head, size, version, vername, globdefver, weakdefver); if(!offs) @@ -754,7 +755,8 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), (void*)(globp?(*globp):0), (void*)offs, (void*)globoffs, sym->st_size, symname, version, vername?vername:"(none)"); //memmove((void*)globoffs, (void*)offs, sym->st_size); // preapply to copy part from lib to main elf - AddUniqueSymbol(GetGlobalData(maplib), symname, offs, sym->st_size, version, vername); + AddUniqueSymbol(GetGlobalData(maplib), symname, globoffs, sym->st_size, version, vername); + AddUniqueSymbol(my_context->globdata, symname, offs, sym->st_size, version, vername); } else { printf_dump(LOG_NEVER, "Apply %s R_X86_64_GLOB_DAT with R_X86_64_COPY @%p/%p (%p/%p -> %p/%p) null sized on sym=%s (ver=%d/%s)\n", (bind==STB_LOCAL)?"Local":"Global", p, globp, (void*)(p?(*p):0), diff --git a/src/include/box64context.h b/src/include/box64context.h index 5b2c5a63..e87aa0e3 100755 --- a/src/include/box64context.h +++ b/src/include/box64context.h @@ -117,6 +117,7 @@ typedef struct box64context_s { lib_t *maplib; // lib and symbols handling lib_t *local_maplib; // libs and symbols openned has local (only collection of libs, no symbols) dic_t *versym; // dictionnary of versioned symbols + kh_symbolmap_t *globdata; // GLOBAL_DAT relocation for COPY mapping in main elf kh_threadstack_t *stacksizes; // stack sizes attributes for thread (temporary) bridge_t *system; // other bridges diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c index 8ed3fe8b..5de70936 100755 --- a/src/librarian/librarian.c +++ b/src/librarian/librarian.c @@ -590,6 +590,10 @@ int GetGlobalNoWeakSymbolStartEnd(lib_t *maplib, const char* name, uintptr_t* st { int weak = 0; size_t size = 0; + // check global GLOB_DAT kind of symbols + if(GetSymbolStartEnd(GetGlobalData(maplib), name, start, end, version, vername, 1, defver)) + if(*start || *end) + return 1; // check with default version... if(GetSymbolStartEnd(GetMapSymbols(my_context->elfs[0]), name, start, end, version, vername, 1, defver)) if(*start || *end) diff --git a/src/wrapped/generated/wrapper.h b/src/wrapped/generated/wrapper.h index 6bf6617d..8bd47ed1 100644 --- a/src/wrapped/generated/wrapper.h +++ b/src/wrapped/generated/wrapper.h @@ -2870,6 +2870,5 @@ void iFEpvvppp(x64emu_t *emu, uintptr_t fnc); void iFEpuvvppp(x64emu_t *emu, uintptr_t fnc); int isSimpleWrapper(wrapper_t fun); -int isRetX87Wrapper(wrapper_t fun); #endif // __WRAPPER_H_ |