Skip to content

Commit

Permalink
Changed the workaround for MiniMetro/Steam, using rcfile now (for #1311)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitSeb committed May 9, 2024
1 parent 6d95a64 commit d38f659
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 26 deletions.
45 changes: 27 additions & 18 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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; i<ld_preload.size; ++i)
printf_log(LOG_INFO, "%s ", ld_preload.paths[i]);
printf_log(LOG_INFO, "\n");
}
}
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
AppendList(&ld_preload, p, 0);
if (ld_preload.size && box64_log) {
printf_log(LOG_INFO, "BOX64 trying to Preload ");
for (int i=0; i<ld_preload.size; ++i)
printf_log(LOG_INFO, "%s ", ld_preload.paths[i]);
printf_log(LOG_INFO, "\n");
}
}
// print PATH and LD_LIB used
Expand Down
9 changes: 7 additions & 2 deletions src/elfs/elfloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ void AddSymbols(lib_t *maplib, elfheader_t* h)
checkHookedSymbols(h);
#endif
}

extern path_collection_t box64_addlibs;
/*
$ORIGIN – Provides the directory the object was loaded from. This token is typical
used for locating dependencies in unbundled packages. For more details of this
Expand Down Expand Up @@ -1021,7 +1021,12 @@ int LoadNeededLibs(elfheader_t* h, lib_t *maplib, int local, int bindnow, int de
for (size_t i=0; i<h->numDynamic; ++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; i<box64_addlibs.size; ++i) {
printf_log(LOG_INFO, "BOX64, Adding %s to needed libs of %s\n", box64_addlibs.paths[i], h->name);
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");
Expand Down
1 change: 1 addition & 0 deletions src/include/box64context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 19 additions & 0 deletions src/librarian/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -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; i<needed->size; ++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)
Expand Down
8 changes: 8 additions & 0 deletions src/tools/rcfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions src/wrapped/wrappedlibgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 3 additions & 0 deletions system/box64.box64rc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d38f659

Please sign in to comment.