Open ZirakC opened 9 months ago
Those symbols comes from libunwind. There is an x86_64 copy shipped with box64. What is strange is that it's notloaded as needed, if it's needed?
You can try to preload it, like with BOX64_LD_PRELOAD=libunwind.so.8
BOX64_LD_PRELOAD=libunwind.so.8
did the trick, but it appears like Error: Symbol __udivti3 not found
still causes an error. It did resolve all the Unwind errors.
Edit: What's strange is that I figured "__udivti3" is apart of libgcc_s.so.1, and it appears to be using the emulated version of it based on the logs.
I tried force loading it this way as well and it still resulted in the same error:
BOX64_LD_PRELOAD=libgcc_s.so.1:libunwind.so.8 ./CustomApp 2024
Edit2: After additional debugging I can see it tries to load the __udivti3 symbol from libstdc++.so.6 and libgcc_s.so.1, but it doesn't appear to be used
/lib/x86_64-linux-gnu/libgcc_s.so.1:DynSym[62] = "__udivti3", value=0x7330, size=256, info/other=18/0 index=13 (optver=2/GCC_3.0)
/lib/x86_64-linux-gnu/libstdc++.so.6:DynSym[66] = "__udivti3", value=(nil), size=0, info/other=18/0 index=0 (optver=56/GCC_3.0)
/lib/x86_64-linux-gnu/libstdc++.so.6:PLT[367] = 0x24fb78 (0x4200000007: type: R_X86_64_JUMP_SLOT, sym=0x42/__udivti3) Addend=0x0
Preparing (if needed) STB_GLOBAL R_X86_64_JUMP_SLOT @0x7fff0224fb78 (0x9d726->0x7fff0209d726) with sym=__udivti3 to be apply later (addend=0)
/home/zirak/Test/TestLib_x64.so:DynSym[61] = "__udivti3", value=(nil), size=0, info/other=16/0 index=0 (ver=0/*local*)
/home/zirak/Test/TestLib_x64.so:PLT[236] = 0x242778 (0x3D00000007: type: R_X86_64_JUMP_SLOT, sym=0x3D/__udivti3) Addend=0x0
Error: Symbol __udivti3 not found, cannot apply R_X86_64_JUMP_SLOT @0x7fff08642778 (0xa2c6) in /home/zirak/Test/TestLib_x64.so
I'm not sure if this is the correct symbol, but even then it complains about it not being found...
Edit 3: I can call the "__udivti3" function successfully through my wrapper program, so it doesn't make sense why box64 can't find it for the lib, I checked the function parameters in the library via IDA and it appears to be correct. Any ideas @ptitSeb?
I ended up doing a hack solution to box64 since I couldn't figure it out what the actual root cause was. I ended up just saving the "__udivti3" during the "preparing" step and then use that offset for the actual bind. This appears to work for my use case.
case R_X86_64_JUMP_SLOT:
// apply immediatly for gobject closure marshal or for LOCAL binding. Also, apply immediatly if it doesn't jump in the got
tmp = (uintptr_t)(*p);
if (bind==STB_LOCAL
|| ((symname && strstr(symname, "g_cclosure_marshal_")==symname))
|| ((symname && strstr(symname, "__pthread_unwind_next")==symname))
|| !tmp
|| !((tmp>=head->plt && tmp<head->plt_end) || (tmp>=head->gotplt && tmp<head->gotplt_end))
|| !need_resolv
|| bindnow
) {
if (!offs) {
if(bind==STB_WEAK) {
printf_log(LOG_INFO, "Warning: Weak Symbol %s not found, cannot apply R_X86_64_JUMP_SLOT @%p (%p)\n", symname, p, *(void**)p);
} else {
printf_log(LOG_NONE, "Error: Symbol %s not found, cannot apply R_X86_64_JUMP_SLOT @%p (%p) in %s\n", symname, p, *(void**)p, head->name);
if (strstr(symname, "__udivti3") == symname) {
if (p) {
printf_log(LOG_INFO, "Using offs: %p\n", symname, p, *(void**)p, offs);
offs = g_offs;
printf_log(LOG_INFO, "Force Apply %s R_X86_64_JUMP_SLOT @%p with sym=%s (%p -> %p / %s (%sver=%d / %s))\n",
BindSym(bind), p, symname, *(void**)p, (void*)(offs + rela[i].r_addend), sym_elf ? sym_elf->name : "native", veropt ? "opt" : "", version, vername ? vername : "(none)");
*p = offs + rela[i].r_addend;
if (sym_elf && sym_elf != last_elf && sym_elf != head) last_elf = checkElfLib(head, sym_elf->lib);
} else {
ret_ok = 1;
printf_log(LOG_NONE, "Error: Symbol %s Jump Slot Offset is NULL\n", symname);
}
} else {
ret_ok = 1;
}
}
} else {
if(p) {
printf_dump(LOG_NEVER, "Apply %s R_X86_64_JUMP_SLOT @%p with sym=%s (%p -> %p / %s (%sver=%d / %s))\n",
BindSym(bind), p, symname, *(void**)p, (void*)(offs+rela[i].r_addend), sym_elf?sym_elf->name:"native", veropt?"opt":"", version, vername?vername:"(none)");
*p = offs + rela[i].r_addend;
if(sym_elf && sym_elf!=last_elf && sym_elf!=head) last_elf = checkElfLib(head, sym_elf->lib);
} else {
printf_log(LOG_INFO, "Warning, Symbol %s found, but Jump Slot Offset is NULL \n", symname);
}
}
} else {
printf_dump(LOG_NEVER, "Preparing (if needed) %s R_X86_64_JUMP_SLOT @%p (0x%lx->0x%0lx) with sym=%s to be apply later (addend=%ld)\n",
BindSym(bind), p, *p, *p+head->delta, symname, rela[i].r_addend);
if (strstr(symname, "__udivti3") == symname) {
printf_log(LOG_INFO, "INFO: Symbol %s storing offs for R_X86_64_JUMP_SLOT @%p (%p) offs: %p\n", symname, p, *(void**)p, offs);
g_offs = offs;
}
*p += head->delta;
*need_resolv = 1;
}
break;
Issue loading TestLib_x64.so (This is a precompiled binary that I am trying to load, I don't have access to the code). This is happening on Raspberry Pi 5 on Raspberry Pi OS x64