Weird link problems: game crash (pc jumps to 0)

RockinB

Established Member
Actually I just wanted to try out link time garbage collection (--gc-section), but...see yourself:

The gc only works if I compile stuff with -ffunction-sections and/or -fdata-sections and I also found out that it's better to KEEP() the SLSTART section :D in this case. Furthermore, the output format must be set to elf (why, because the linker even can producee binaries directly, without objcopy. anyways). But it turned out that the last step fucks up the binary, slightly, but effective.

When I link an ELF compiled project with gcc option -Xlinker --oformat=elf32-sh, then the binary will crash(in yabause).

Now comes the funny thing: the same project compiled with COFF "features" unused stuff, malloc and co. and I remembered that for COFF you have to define a dummy function __main() to prevent linking malloc. I did and now comes the funny thing: it crashes, just like the elf version.

Okay, I compared elf compiled versions, one with --oformat=elf32-sh and one without. The map files are almost perfectly identical(checked with WinMerge), every single object is in the same place for both binaries. Only sometimes the size of linked stuff is a little bit smaller, without effect to location.

Fine, then I compared the binaries with WinHex and I get 63 bytes different.

What can be the reason why the elf version crashs? All I want is to use some fancy compile and link flags, why do I have to get such a headache for this?
 
I found a very intersting fact about the 63 byte differences in the binary (with --oformat=elf32-sh and without):

They are all addresses in high work ram! It seems to be immediate data, holding the position of functions or variables. Since every single function and variable is in the same place for both binaries, I wonder why this can be. All of these adresses point to functions (or variables) of linked libraries like sgl or the cd lib. In the not working binary (--oformat=elf32-sh), these adresses point just somewhere else or even to a not used location in high work ram.

Let me point out that all files are compiled with elf toolchain, except the libraries(like sgl, cd, which) which where compiled with coff by SEGA long ago. For these files, I specify -Xlinker --format=coff-sh on the linker command line.

So obviously the problem is with the coff libraries. Why? How can I work around this?

I guess I can get it working for entirely self-compiled stuff, but what if I want to use extenal libs?
 
Back
Top