From d38f659f428544de524fe6f2a49355a104055555 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 9 May 2024 21:59:32 +0200 Subject: [PATCH] Changed the workaround for MiniMetro/Steam, using rcfile now (for #1311) --- src/core.c | 45 +++++++++++++++++++++++--------------- src/elfs/elfloader.c | 9 ++++++-- src/include/box64context.h | 1 + src/librarian/library.c | 19 ++++++++++++++++ src/tools/rcfile.c | 8 +++++++ src/wrapped/wrappedlibgl.c | 6 ----- system/box64.box64rc | 3 +++ 7 files changed, 65 insertions(+), 26 deletions(-) diff --git a/src/core.c b/src/core.c index bc58b0401..36ce41dd7 100644 --- a/src/core.c +++ b/src/core.c @@ -55,6 +55,7 @@ int box64_cefdisablegpu = 0; int box64_cefdisablegpucompositor = 0; int box64_malloc_hack = 0; int box64_dynarec_test = 0; +path_collection_t box64_addlibs = {0}; int box64_maxcpu = 0; int box64_maxcpu_immutable = 0; #if defined(SD845) || defined(SD888) || defined(SD8G2) || defined(TEGRAX1) @@ -1195,6 +1196,12 @@ int GatherEnv(char*** dest, char** env, char* prog) return 0; } +void AddNewLibs(const char* list) +{ + AppendList(&box64_addlibs, list, 0); + printf_log(LOG_INFO, "BOX64: Adding %s to the libs\n", list); +} + void PrintFlags() { printf("Environment Variables:\n"); printf(" BOX64_PATH is the box64 version of PATH (default is '.:bin')\n"); @@ -1369,6 +1376,9 @@ void LoadEnvVars(box64context_t *context) printf_log(LOG_INFO, "BOX64: Disabling handling of SigILL\n"); } } + if(getenv("BOX64_ADDLIBS")) { + AddNewLibs(getenv("BOX64_ADDLIBS")); + } // check BOX64_PATH and load it LoadEnvPath(&context->box64_path, ".:bin", "BOX64_PATH"); if(getenv("PATH")) @@ -1834,24 +1844,23 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf printf_log(LOG_INFO, "%s ", ld_preload.paths[i]); printf_log(LOG_INFO, "\n"); } - } else { - if(getenv("LD_PRELOAD")) { - char* p = getenv("LD_PRELOAD"); - if(strstr(p, "libtcmalloc_minimal.so.0")) - box64_tcmalloc_minimal = 1; - if(strstr(p, "libtcmalloc_minimal.so.4")) - box64_tcmalloc_minimal = 1; - if(strstr(p, "libtcmalloc_minimal_debug.so.4")) - box64_tcmalloc_minimal = 1; - if(strstr(p, "libasan.so")) - box64_tcmalloc_minimal = 1; // it seems Address Sanitizer doesn't handle dlsym'd malloc very well - ParseList(p, &ld_preload, 0); - if (ld_preload.size && box64_log) { - printf_log(LOG_INFO, "BOX64 trying to Preload "); - for (int i=0; inumDynamic; ++i) if(h->Dynamic[i].d_tag==DT_NEEDED) h->needed->names[j++] = h->DynStrTab+h->delta+h->Dynamic[i].d_un.d_val; - + if(h==my_context->elfs[0] && box64_addlibs.size) { + for(int i=0; iname); + add1lib_neededlib_name(h->needed, NULL, box64_addlibs.paths[i]); + } + } // TODO: Add LD_LIBRARY_PATH and RPATH handling if(AddNeededLib(maplib, local, bindnow, deepbind, h->needed, h, box64, emu)) { printf_log(LOG_INFO, "Error loading one of needed lib\n"); diff --git a/src/include/box64context.h b/src/include/box64context.h index c3493e7e7..19c45f904 100644 --- a/src/include/box64context.h +++ b/src/include/box64context.h @@ -69,6 +69,7 @@ needed_libs_t* new_neededlib(int n); needed_libs_t* copy_neededlib(needed_libs_t* needed); void add1_neededlib(needed_libs_t* needed); void add1lib_neededlib(needed_libs_t* needed, library_t* lib, const char* name); +void add1lib_neededlib_name(needed_libs_t* needed, library_t* lib, const char* name); void add1libref_neededlib(needed_libs_t* needed, library_t* lib); typedef struct base_segment_s { diff --git a/src/librarian/library.c b/src/librarian/library.c index 127339afd..14a1334ab 100644 --- a/src/librarian/library.c +++ b/src/librarian/library.c @@ -1180,6 +1180,25 @@ void add1lib_neededlib(needed_libs_t* needed, library_t* lib, const char* name) needed->size++; needed->init_size++; } +void add1lib_neededlib_name(needed_libs_t* needed, library_t* lib, const char* name) +{ + if(!needed || !name) + return; + // check if lib is already present + for (int i=0; isize; ++i) + if(!strcmp(needed->names[i], name)) + return; + // add it + if(needed->size==needed->cap) { + needed->cap = needed->size+1; + needed->libs = (library_t**)realloc(needed->libs, needed->cap*sizeof(library_t*)); + needed->names = (char**)realloc(needed->names, needed->cap*sizeof(char*)); + } + needed->libs[needed->size] = lib; + needed->names[needed->size] = (char*)name; + needed->size++; + needed->init_size++; +} void add1libref_neededlib(needed_libs_t* needed, library_t* lib) { if(!needed || !lib) diff --git a/src/tools/rcfile.c b/src/tools/rcfile.c index 34bf5cd4f..3fc9c8699 100644 --- a/src/tools/rcfile.c +++ b/src/tools/rcfile.c @@ -46,6 +46,9 @@ static const char default_rcfile[] = "[LotCG.x86_64]\n" "BOX64_DYNAREC_FASTROUND=0\n" "\n" +"[Mini Metro]\n" +"BOX64_ADDLIBS=stdc++.so.6\n" +"\n" "[pressure-vessel-wrap]\n" "BOX64_NOGTK=1\n" "\n" @@ -110,6 +113,7 @@ ENTRYBOOL(BOX64_JVM, box64_jvm) \ ENTRYBOOL(BOX64_SDL2_JGUID, box64_sdl2_jguid) \ ENTRYINT(BOX64_MALLOC_HACK, box64_malloc_hack, 0, 2, 2) \ ENTRYINTPOS(BOX64_MAXCPU, new_maxcpu) \ +ENTRYSTRING_(BOX64_ADDLIBS, new_addlibs) \ ENTRYSTRING_(BOX64_ENV, new_env) \ ENTRYSTRING_(BOX64_ENV1, new_env1) \ ENTRYSTRING_(BOX64_ENV2, new_env2) \ @@ -483,6 +487,7 @@ extern FILE* ftrace; extern char* ftrace_name; void openFTrace(const char* newtrace); void addNewEnvVar(const char* s); +void AddNewLibs(const char* libs); #ifdef DYNAREC void GatherDynarecExtensions(); #endif @@ -574,6 +579,9 @@ void ApplyParams(const char* name) AppendList(&my_context->box64_emulated_libs, param->emulated_libs, 0); printf_log(LOG_INFO, "Applying %s=%s\n", "BOX64_EMULATED_LIBS", param->emulated_libs); } + if(param->is_new_addlibs_present) { + AddNewLibs(param->new_addlibs); + } if(param->is_new_env_present) { addNewEnvVar(param->new_env); printf_log(LOG_INFO, "Applying %s=%s\n", "BOX64_ENV", param->new_env); diff --git a/src/wrapped/wrappedlibgl.c b/src/wrapped/wrappedlibgl.c index bf7a0b9ad..f7d7633ef 100644 --- a/src/wrapped/wrappedlibgl.c +++ b/src/wrapped/wrappedlibgl.c @@ -435,12 +435,6 @@ static void* find_glGetVkProcAddrNV_Fct(void* fct) s->resolved = 1; \ s->addr = (uintptr_t)find_glXSwapIntervalEXT_Fct(symb); \ } \ - if(!box64_wine && GetLibInternal("libgcc_s.so.1")) { \ - setNeededLibs(lib, 1, "libstdc++.so.6"); \ - } \ - -// This is a small hack to allow loading of libstdc++ as a dependancy for libGL as this is a the case with mesa. Some game, like Mini Metro on Steam don't have -// libstdc++.so.6 as a dependancy and yet needs it to run properly, rellying on other dependancies to work #include "wrappedlib_init.h" diff --git a/system/box64.box64rc b/system/box64.box64rc index f46795589..930a4f21a 100644 --- a/system/box64.box64rc +++ b/system/box64.box64rc @@ -113,6 +113,9 @@ BOX64_MAXCPU=4 [LotCG.x86_64] BOX64_DYNAREC_FASTROUND=0 +[Mini Metro] +BOX64_ADDLIBS=libstdc++.so.6 + [nacl_helper] BOX64_MALLOC_HACK=1