devkitPro / wut

Let's try to make a Wii U Toolchain / SDK for creating rpx/rpl.
zlib License
244 stars 52 forks source link

[elf2rpl] Using __DTOR_END__ causes "Could not find matching symbol for relocation" #60

Closed ashquarky closed 6 years ago

ashquarky commented 6 years ago

Heyo!

I'm working on RetroArch, which has its own little embedded toolchain. I recently rewrote some buggy __init/__fini shenanigans and have run into what appears to be a bug in elf2rpl. Here's the code:

__attribute__((weak))
void __fini(void)
{
   extern void (*const __DTOR_LIST__)(void);
   extern void (*const __DTOR_END__)(void);

   void (*const *dtor)(void) = &__DTOR_LIST__;
   while (dtor < &__DTOR_END__) {
      (*dtor++)();
   }
}

Calling __fini during application shutdown causes this message when building:

Could not find matching symbol for relocation
make: [Makefile.wiiu:258: retroarch_wiiu.rpx] Error 255

The exact same code works fine in our elf build; and gets through the linking stage of the rpx build without a warning. The ctor equivalent works fine in both builds. If I change &__DTOR_END__ to another random pointer (like init) then the code builds fine; though obviously `fini` wouldn't work right in the final rpx.

Some info (from the erroring input elf):

$ readrpl -s retroarch_wiiu.rpx.elf | grep DTOR
  5619 1001EE00      0 NOTYPE   GLOBAL     5 __DTOR_LIST__
  6788 1001EE08      0 NOTYPE   GLOBAL     5 __DTOR_END__
$ powerpc-eabi-readelf -r retroarch_wiiu.rpx.elf | grep 0211636
0211636a  00000106 R_PPC_ADDR16_HA   02000000   .text + 1001ee08
0211636e  00000104 R_PPC_ADDR16_LO   02000000   .text + 1001ee08

You can download that elf here.

Thanks in advance! Ash

exjam commented 6 years ago

Fixed in the rewrite branch.