Skip to content

Commit d38f659

Browse files
committed
Changed the workaround for MiniMetro/Steam, using rcfile now (for #1311)
1 parent 6d95a64 commit d38f659

7 files changed

Lines changed: 65 additions & 26 deletions

File tree

src/core.c

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ int box64_cefdisablegpu = 0;
5555
int box64_cefdisablegpucompositor = 0;
5656
int box64_malloc_hack = 0;
5757
int box64_dynarec_test = 0;
58+
path_collection_t box64_addlibs = {0};
5859
int box64_maxcpu = 0;
5960
int box64_maxcpu_immutable = 0;
6061
#if defined(SD845) || defined(SD888) || defined(SD8G2) || defined(TEGRAX1)
@@ -1195,6 +1196,12 @@ int GatherEnv(char*** dest, char** env, char* prog)
11951196
return 0;
11961197
}
11971198

1199+
void AddNewLibs(const char* list)
1200+
{
1201+
AppendList(&box64_addlibs, list, 0);
1202+
printf_log(LOG_INFO, "BOX64: Adding %s to the libs\n", list);
1203+
}
1204+
11981205
void PrintFlags() {
11991206
printf("Environment Variables:\n");
12001207
printf(" BOX64_PATH is the box64 version of PATH (default is '.:bin')\n");
@@ -1369,6 +1376,9 @@ void LoadEnvVars(box64context_t *context)
13691376
printf_log(LOG_INFO, "BOX64: Disabling handling of SigILL\n");
13701377
}
13711378
}
1379+
if(getenv("BOX64_ADDLIBS")) {
1380+
AddNewLibs(getenv("BOX64_ADDLIBS"));
1381+
}
13721382
// check BOX64_PATH and load it
13731383
LoadEnvPath(&context->box64_path, ".:bin", "BOX64_PATH");
13741384
if(getenv("PATH"))
@@ -1834,24 +1844,23 @@ int initialize(int argc, const char **argv, char** env, x64emu_t** emulator, elf
18341844
printf_log(LOG_INFO, "%s ", ld_preload.paths[i]);
18351845
printf_log(LOG_INFO, "\n");
18361846
}
1837-
} else {
1838-
if(getenv("LD_PRELOAD")) {
1839-
char* p = getenv("LD_PRELOAD");
1840-
if(strstr(p, "libtcmalloc_minimal.so.0"))
1841-
box64_tcmalloc_minimal = 1;
1842-
if(strstr(p, "libtcmalloc_minimal.so.4"))
1843-
box64_tcmalloc_minimal = 1;
1844-
if(strstr(p, "libtcmalloc_minimal_debug.so.4"))
1845-
box64_tcmalloc_minimal = 1;
1846-
if(strstr(p, "libasan.so"))
1847-
box64_tcmalloc_minimal = 1; // it seems Address Sanitizer doesn't handle dlsym'd malloc very well
1848-
ParseList(p, &ld_preload, 0);
1849-
if (ld_preload.size && box64_log) {
1850-
printf_log(LOG_INFO, "BOX64 trying to Preload ");
1851-
for (int i=0; i<ld_preload.size; ++i)
1852-
printf_log(LOG_INFO, "%s ", ld_preload.paths[i]);
1853-
printf_log(LOG_INFO, "\n");
1854-
}
1847+
}
1848+
if(getenv("LD_PRELOAD")) {
1849+
char* p = getenv("LD_PRELOAD");
1850+
if(strstr(p, "libtcmalloc_minimal.so.0"))
1851+
box64_tcmalloc_minimal = 1;
1852+
if(strstr(p, "libtcmalloc_minimal.so.4"))
1853+
box64_tcmalloc_minimal = 1;
1854+
if(strstr(p, "libtcmalloc_minimal_debug.so.4"))
1855+
box64_tcmalloc_minimal = 1;
1856+
if(strstr(p, "libasan.so"))
1857+
box64_tcmalloc_minimal = 1; // it seems Address Sanitizer doesn't handle dlsym'd malloc very well
1858+
AppendList(&ld_preload, p, 0);
1859+
if (ld_preload.size && box64_log) {
1860+
printf_log(LOG_INFO, "BOX64 trying to Preload ");
1861+
for (int i=0; i<ld_preload.size; ++i)
1862+
printf_log(LOG_INFO, "%s ", ld_preload.paths[i]);
1863+
printf_log(LOG_INFO, "\n");
18551864
}
18561865
}
18571866
// print PATH and LD_LIB used

src/elfs/elfloader.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ void AddSymbols(lib_t *maplib, elfheader_t* h)
928928
checkHookedSymbols(h);
929929
#endif
930930
}
931-
931+
extern path_collection_t box64_addlibs;
932932
/*
933933
$ORIGIN – Provides the directory the object was loaded from. This token is typical
934934
used for locating dependencies in unbundled packages. For more details of this
@@ -1021,7 +1021,12 @@ int LoadNeededLibs(elfheader_t* h, lib_t *maplib, int local, int bindnow, int de
10211021
for (size_t i=0; i<h->numDynamic; ++i)
10221022
if(h->Dynamic[i].d_tag==DT_NEEDED)
10231023
h->needed->names[j++] = h->DynStrTab+h->delta+h->Dynamic[i].d_un.d_val;
1024-
1024+
if(h==my_context->elfs[0] && box64_addlibs.size) {
1025+
for(int i=0; i<box64_addlibs.size; ++i) {
1026+
printf_log(LOG_INFO, "BOX64, Adding %s to needed libs of %s\n", box64_addlibs.paths[i], h->name);
1027+
add1lib_neededlib_name(h->needed, NULL, box64_addlibs.paths[i]);
1028+
}
1029+
}
10251030
// TODO: Add LD_LIBRARY_PATH and RPATH handling
10261031
if(AddNeededLib(maplib, local, bindnow, deepbind, h->needed, h, box64, emu)) {
10271032
printf_log(LOG_INFO, "Error loading one of needed lib\n");

src/include/box64context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ needed_libs_t* new_neededlib(int n);
6969
needed_libs_t* copy_neededlib(needed_libs_t* needed);
7070
void add1_neededlib(needed_libs_t* needed);
7171
void add1lib_neededlib(needed_libs_t* needed, library_t* lib, const char* name);
72+
void add1lib_neededlib_name(needed_libs_t* needed, library_t* lib, const char* name);
7273
void add1libref_neededlib(needed_libs_t* needed, library_t* lib);
7374

7475
typedef struct base_segment_s {

src/librarian/library.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,6 +1180,25 @@ void add1lib_neededlib(needed_libs_t* needed, library_t* lib, const char* name)
11801180
needed->size++;
11811181
needed->init_size++;
11821182
}
1183+
void add1lib_neededlib_name(needed_libs_t* needed, library_t* lib, const char* name)
1184+
{
1185+
if(!needed || !name)
1186+
return;
1187+
// check if lib is already present
1188+
for (int i=0; i<needed->size; ++i)
1189+
if(!strcmp(needed->names[i], name))
1190+
return;
1191+
// add it
1192+
if(needed->size==needed->cap) {
1193+
needed->cap = needed->size+1;
1194+
needed->libs = (library_t**)realloc(needed->libs, needed->cap*sizeof(library_t*));
1195+
needed->names = (char**)realloc(needed->names, needed->cap*sizeof(char*));
1196+
}
1197+
needed->libs[needed->size] = lib;
1198+
needed->names[needed->size] = (char*)name;
1199+
needed->size++;
1200+
needed->init_size++;
1201+
}
11831202
void add1libref_neededlib(needed_libs_t* needed, library_t* lib)
11841203
{
11851204
if(!needed || !lib)

src/tools/rcfile.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ static const char default_rcfile[] =
4646
"[LotCG.x86_64]\n"
4747
"BOX64_DYNAREC_FASTROUND=0\n"
4848
"\n"
49+
"[Mini Metro]\n"
50+
"BOX64_ADDLIBS=stdc++.so.6\n"
51+
"\n"
4952
"[pressure-vessel-wrap]\n"
5053
"BOX64_NOGTK=1\n"
5154
"\n"
@@ -110,6 +113,7 @@ ENTRYBOOL(BOX64_JVM, box64_jvm) \
110113
ENTRYBOOL(BOX64_SDL2_JGUID, box64_sdl2_jguid) \
111114
ENTRYINT(BOX64_MALLOC_HACK, box64_malloc_hack, 0, 2, 2) \
112115
ENTRYINTPOS(BOX64_MAXCPU, new_maxcpu) \
116+
ENTRYSTRING_(BOX64_ADDLIBS, new_addlibs) \
113117
ENTRYSTRING_(BOX64_ENV, new_env) \
114118
ENTRYSTRING_(BOX64_ENV1, new_env1) \
115119
ENTRYSTRING_(BOX64_ENV2, new_env2) \
@@ -483,6 +487,7 @@ extern FILE* ftrace;
483487
extern char* ftrace_name;
484488
void openFTrace(const char* newtrace);
485489
void addNewEnvVar(const char* s);
490+
void AddNewLibs(const char* libs);
486491
#ifdef DYNAREC
487492
void GatherDynarecExtensions();
488493
#endif
@@ -574,6 +579,9 @@ void ApplyParams(const char* name)
574579
AppendList(&my_context->box64_emulated_libs, param->emulated_libs, 0);
575580
printf_log(LOG_INFO, "Applying %s=%s\n", "BOX64_EMULATED_LIBS", param->emulated_libs);
576581
}
582+
if(param->is_new_addlibs_present) {
583+
AddNewLibs(param->new_addlibs);
584+
}
577585
if(param->is_new_env_present) {
578586
addNewEnvVar(param->new_env);
579587
printf_log(LOG_INFO, "Applying %s=%s\n", "BOX64_ENV", param->new_env);

src/wrapped/wrappedlibgl.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -435,12 +435,6 @@ static void* find_glGetVkProcAddrNV_Fct(void* fct)
435435
s->resolved = 1; \
436436
s->addr = (uintptr_t)find_glXSwapIntervalEXT_Fct(symb); \
437437
} \
438-
if(!box64_wine && GetLibInternal("libgcc_s.so.1")) { \
439-
setNeededLibs(lib, 1, "libstdc++.so.6"); \
440-
} \
441-
442-
// 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
443-
// libstdc++.so.6 as a dependancy and yet needs it to run properly, rellying on other dependancies to work
444438

445439
#include "wrappedlib_init.h"
446440

system/box64.box64rc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ BOX64_MAXCPU=4
113113
[LotCG.x86_64]
114114
BOX64_DYNAREC_FASTROUND=0
115115

116+
[Mini Metro]
117+
BOX64_ADDLIBS=libstdc++.so.6
118+
116119
[nacl_helper]
117120
BOX64_MALLOC_HACK=1
118121

0 commit comments

Comments
 (0)