I have working in last few days on some interesting game, design of which are heavy based on sobjes/plugins.
The game splitted on objects, which loads on the running stage from the code by some "loadplugins()" function. Most of those .sobjes can be done statically (not like .so, but as .a) and linking to the binary, but one of the sobjs are not uses even if i linked it as static, because main binary want to load it only via "loadplugins()".
And so, as result, when i have everytihng builded static (but have one that sobj are as .so), then of course i can't use it, and loadplugins() itself failed just because that latest sobj, want all the others. And by all that crap, i just forced to use shared version.
So, added all that -use-dynld, -fPIC, --export-dynamic where is need it, and when game starts, its start to load sobjes via loadplugin() , and, i happyly crashes in the libstdc++.so, with such crash log. In brief, stack trace looks like this:
Quote:
Symbol info: Instruction pointer 0x7F5F5940 belongs to module "libstdc++.so" (PowerPC) Symbol: _ZNSs6assignERKSs + 0x240 in section 10 offset 0x0006E940
If i comment out that part of code inside, then, its going futher, but of course later crashes as well in the libstdc++.so
I can think about bad code of course, but the same code works fine if i build it as static (and i can run the binary, it works, just exits on the stage when want to load that .sobj which can be only as sobj).
query.Flags=ELF32_SQ_BYNAME;
query.Name="PluginFunction1";
IElf->SymbolQuery(filehandle,1,&query); // query.Value (uint32) has the result
PluginFunction1=(APTR)query.Value;
query.Flags=ELF32_SQ_BYNAME;
query.Name="PluginFunction2";
IElf->SymbolQuery(filehandle,1,&query); // query.Value (uint32) has the result
PluginFunction2=(APTR)query.Value;
Here's one way to load plugins into memory. But you have to query addresses of all functions one by one:
Its not my code as usuall, and there is all dependeces depend on other dependeces in code, and just putting to the begining of main() loading of that sobj, will not helps (imho). Because game later trying to register classes, which they parse by some resourcemanager.cpp , when its loaded via loadplugins().
And, in end of all, that .so also want others so (which in end will cause the same crash).
As i see there is 2 ways:
1. understand why it crashes (i remember someone saing back in times, that our sobjes cant catch exceptions normally, with all that catch() stuff, so maybe it is the same bug
2. trying to get code of that "really necessary" single sobjs, register somehow all the classes manually in the code, and put that code not to so, but to .a, and link it statically (i tryed it before, but what was a bit strange for me, its the with or without that .a , size of binary do not changes, what make me think, that no one single fucntion of that sobj, by some reassons not uses directly from the main binary.
Second way sounds prefferable for me, because with static version i even have something on screen already, just game can't register all the classes which are in that sobj. In end of all will try to contact with authors, maybe they will help to build it statically.
Btw, for now i remove all the stdc++.so from sdk, so, libstdc++.a are used, but what is interesting, is that i use libSDL_Mixer.so (latest from os4depot), which are compiled with libstd++.so.
And as result i have that:
No binary, no all my builded sobjs not reles on the libstdc++.so. But because libSDL_Mixer.so reles to libstdc++.so, looks like mixer automatically up libstdc++, and all the sobjs and main binary by some reassons start to use libstdc++ for all the other code as well, and as result , the same crash.
But for me its a bit strange, because i was in hope, that libstdc++ will be used _only_ for sdl_mixer.so (because only mixer want it now), but not like it now : just for all the code.
Anyway, i just use libSDL_Mixer as static, and , what is funny i again have the same crash ! but at this moment not in the libstd++.so, but in my own , game's, libsdlx.so:
Quote:
Symbol info: Instruction pointer 0x7F69F7F0 belongs to module "libsdlx.so" (PowerPC) Symbol: _ZNSs6assignERKSs + 0x10C in section 13 offset 0x000654FC
(and that code work in static version of cource, because i see how sdl window initialized, i can see first menu, etc). The only problem that it crashes there in shared version of code.
Edited by kas1e on 2011/5/10 11:47:52 Edited by kas1e on 2011/5/10 11:49:45
It was a pain, and one more time saying for me that heavy usage of sobjes together with all that c++ stuff on aos4 its still buggy.
How i fix the stuff in end:
I include all the code from that single sobj which are necessary for loadplugins(), and with some small modifications put in the main code, compile everything statically and remove loadplugins(); Then some more problems there and there, and in end of all: