2
0
mirror of https://github.com/FWGS/xash3d-fwgs synced 2024-11-22 09:56:22 +01:00

nswitch: do not link libstdc++ into dynamic libraries

instead only link it to the main executable with --whole-archive, letting the dynamic libs import anything they want from it
This commit is contained in:
fgsfds 2023-02-08 00:52:48 +01:00
parent 4e87eb068a
commit 69607d7890
4 changed files with 41 additions and 45 deletions

View File

@ -28,18 +28,12 @@ static int nxlink_sock = -1;
/* HACKHACK: force-export stuff required by the dynamic libs */ /* HACKHACK: force-export stuff required by the dynamic libs */
// libunwind stuff for C++ exceptions, required by filesystem_stdio // this is required by some std::filesystem crap in libstdc++
extern void *_Unwind_GetIPInfo; // we don't have it defined in our libc
extern void *_Unwind_Resume_or_Rethrow; long pathconf( const char *path, int name ) { return -1; }
extern void *_Unwind_GetRegionStart;
// part of libunwind; required by any dynamic lib that uses C++ exceptions
extern void *_Unwind_Resume; extern void *_Unwind_Resume;
extern void *_Unwind_DeleteException;
extern void *_Unwind_RaiseException;
extern void *_Unwind_SetIP;
extern void *_Unwind_GetTextRelBase;
extern void *_Unwind_GetLanguageSpecificData;
extern void *_Unwind_SetGR;
extern void *_Unwind_GetDataRelBase;
// these are macros in our libc, so we need to wrap them // these are macros in our libc, so we need to wrap them
static int tolower_fn( int c ) { return tolower( c ); } static int tolower_fn( int c ) { return tolower( c ); }
@ -56,20 +50,11 @@ static const solder_export_t aux_exports[] =
SOLDER_EXPORT_SYMBOL( mkdir ), SOLDER_EXPORT_SYMBOL( mkdir ),
SOLDER_EXPORT_SYMBOL( remove ), SOLDER_EXPORT_SYMBOL( remove ),
SOLDER_EXPORT_SYMBOL( rename ), SOLDER_EXPORT_SYMBOL( rename ),
SOLDER_EXPORT_SYMBOL( pathconf ),
SOLDER_EXPORT_SYMBOL( fsync ), SOLDER_EXPORT_SYMBOL( fsync ),
SOLDER_EXPORT_SYMBOL( strchrnul ), SOLDER_EXPORT_SYMBOL( strchrnul ),
SOLDER_EXPORT_SYMBOL( stpcpy ), SOLDER_EXPORT_SYMBOL( stpcpy ),
SOLDER_EXPORT_SYMBOL(_Unwind_GetIPInfo),
SOLDER_EXPORT_SYMBOL(_Unwind_Resume_or_Rethrow),
SOLDER_EXPORT_SYMBOL(_Unwind_GetRegionStart),
SOLDER_EXPORT_SYMBOL( _Unwind_Resume ), SOLDER_EXPORT_SYMBOL( _Unwind_Resume ),
SOLDER_EXPORT_SYMBOL(_Unwind_DeleteException),
SOLDER_EXPORT_SYMBOL(_Unwind_RaiseException),
SOLDER_EXPORT_SYMBOL(_Unwind_SetIP),
SOLDER_EXPORT_SYMBOL(_Unwind_GetTextRelBase),
SOLDER_EXPORT_SYMBOL(_Unwind_GetLanguageSpecificData),
SOLDER_EXPORT_SYMBOL(_Unwind_SetGR),
SOLDER_EXPORT_SYMBOL(_Unwind_GetDataRelBase),
}; };
const solder_export_t *__solder_aux_exports = aux_exports; const solder_export_t *__solder_aux_exports = aux_exports;

View File

@ -49,13 +49,21 @@ def configure(conf):
if not conf.check_cc( fragment='int main(){ int i = socket();}', lib = 'wattcpwl', mandatory=False ): if not conf.check_cc( fragment='int main(){ int i = socket();}', lib = 'wattcpwl', mandatory=False ):
conf.define('XASH_NO_NETWORK',1) conf.define('XASH_NO_NETWORK',1)
elif conf.env.DEST_OS == 'nswitch': elif conf.env.DEST_OS == 'nswitch':
# re-enable undefined reference errors
conf.env.CXXFLAGS += ['-Wl,--no-undefined']
conf.env.CFLAGS += ['-Wl,--no-undefined']
# allow the SDL2 sanity check to complete properly by linking in libstdc++ and lm normally
conf.env.LDFLAGS += ['-lstdc++', '-lm']
conf.load('sdl2') conf.load('sdl2')
if not conf.env.HAVE_SDL2: if not conf.env.HAVE_SDL2:
conf.fatal('SDL2 not availiable! Install switch-sdl2!') conf.fatal('SDL2 not availiable! Install switch-sdl2!')
conf.define('XASH_SDL', 2) conf.define('XASH_SDL', 2)
# disallow undefined symbols # HACK: now link in the entirety of libstdc++ so that dynamic libs could use all of it without manual exporting
conf.env.append_unique('CXXFLAGS', '-Wl,--no-undefined') # we can't do this right away because std::filesystem will complain about not having pathconf(),
conf.env.append_unique('CFLAGS', '-Wl,--no-undefined') # which we have defined in sys_nswitch.c
conf.env.LDFLAGS.remove('-lstdc++')
conf.env.LDFLAGS.remove('-lm')
conf.env.LDFLAGS += ['-Wl,--whole-archive', '-lstdc++', '-Wl,--no-whole-archive', '-lm']
elif conf.options.FBDEV_SW: elif conf.options.FBDEV_SW:
# unused, XASH_LINUX without XASH_SDL gives fbdev & alsa support # unused, XASH_LINUX without XASH_SDL gives fbdev & alsa support
# conf.define('XASH_FBDEV', 1) # conf.define('XASH_FBDEV', 1)

View File

@ -427,8 +427,9 @@ class NintendoSwitch:
return linkflags return linkflags
def ldflags(self): def ldflags(self):
# system libraries implicitly require math and C++ standard library # NOTE: shared libraries should be built without standard libs, so that they could import their contents from the NRO,
ldflags = ['-lm', '-lstdc++'] # but executables, including the SDL2 sanity check, will generally require libstdc++ and libm, which we will add manually
ldflags = [] # ['-lm', '-lstdc++']
return ldflags return ldflags
def options(opt): def options(opt):

View File

@ -246,8 +246,8 @@ def configure(conf):
cflags, linkflags = conf.get_optimization_flags() cflags, linkflags = conf.get_optimization_flags()
# on the Switch, allow undefined symbols by default, which is needed for libsolder to work # on the Switch, allow undefined symbols by default, which is needed for libsolder to work
# we'll specifically disallow for the engine executable # we'll specifically disallow them for the engine executable
# additionally, shared libs are linked without libc # additionally, shared libs are linked without standard libs, we'll add those back in the engine wscript
if conf.env.DEST_OS == 'nswitch': if conf.env.DEST_OS == 'nswitch':
linkflags.remove('-Wl,--no-undefined') linkflags.remove('-Wl,--no-undefined')
conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles']) conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles'])
@ -303,7 +303,9 @@ def configure(conf):
if conf.env.DEST_OS != 'win32': if conf.env.DEST_OS != 'win32':
if conf.env.DEST_OS == 'nswitch': if conf.env.DEST_OS == 'nswitch':
conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER') conf.check_cfg(package='solder', args='--cflags --libs', uselib_store='SOLDER', mandatory=True)
if conf.env.HAVE_SOLDER and conf.env.LIB_SOLDER and conf.options.BUILD_TYPE == 'debug':
conf.env.LIB_SOLDER[0] += 'd' # load libsolderd in debug mode
else: else:
conf.check_cc(lib='dl', mandatory=False) conf.check_cc(lib='dl', mandatory=False)