Some symbols missing for shared library relocations

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Some symbols missing for shared library relocations

Post by max »

Hey guys,

I have some missing symbols when I'm loading an executable with shared libraries, but I can't really figure out where they should come from. I have two major problems now, exception handling and global constructors.

When trying to relocate the shared objects I've loaded, my dynamic linker can't find these symbols:

Code: Select all

_ITM_deregisterTMCloneTable
_ITM_registerTMCloneTable
__deregister_frame_info
__register_frame_info
As far as I understood those are required to initialize exception handling, is this correct? Within the executable itself exception handling already works, but not when a shared library throws an exception.

So for example for __register_frame_info I looked at the ELF headers and the shared library has a relocation entry in .rel.dyn:

Code: Select all

0000639a  0000ee01 R_386_32          00000000   __deregister_frame_inf
000063ab  0000ee02 R_386_PC32        00000000   __deregister_frame_inf
000063d1  00024301 R_386_32          00000000   __register_frame_info
000063ea  00024302 R_386_PC32        00000000   __register_frame_info
000385f8  00000906 R_386_GLOB_DAT    00038d80   _stdin_buf
000385fc  00001f06 R_386_GLOB_DAT    00038a80   stdout
00038600  00004e23 R_386_TLS_DTPMOD3 00000000   errno
also the corresponding entry in .dyn.sym:

Code: Select all

   576: 0002adea    53 FUNC    GLOBAL DEFAULT    8 mkdir
   577: 0001f2a3   132 FUNC    GLOBAL DEFAULT    8 logbf
   578: 0000cdd9   185 FUNC    GLOBAL DEFAULT    8 posix_memalign
   579: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __register_frame_info
   580: 00026bf1    47 FUNC    GLOBAL DEFAULT    8 __stdio_impl_write
   581: 0002751e    49 FUNC    GLOBAL DEFAULT    8 klog
and .sym.tab also defines it:

Code: Select all

  1869: 0001f2a3   132 FUNC    GLOBAL DEFAULT    8 logbf
  1870: 0000cdd9   185 FUNC    GLOBAL DEFAULT    8 posix_memalign
  1871: 00000000     0 NOTYPE  WEAK   DEFAULT  UND __register_frame_info
  1872: 00026bf1    47 FUNC    GLOBAL DEFAULT    8 __stdio_impl_write
  1873: 0002751e    49 FUNC    GLOBAL DEFAULT    8 klog
The executable has definitions for those symbols I need in .symtab:

Code: Select all

   281: 0805f254     0 NOTYPE  LOCAL  DEFAULT   14 __preinit_array_end
   282: 0805f340     0 OBJECT  LOCAL  DEFAULT   20 _GLOBAL_OFFSET_TABLE_
   283: 0805f254     0 NOTYPE  LOCAL  DEFAULT   15 __init_array_start
   284: 0805f254     0 NOTYPE  LOCAL  DEFAULT   14 __preinit_array_start
   285: 080582e0    74 FUNC    LOCAL  DEFAULT    9 __register_frame_info
   286: 080570e6     0 FUNC    GLOBAL HIDDEN     9 __x86.get_pc_thunk.cx
   287: 08048e20    41 FUNC    GLOBAL DEFAULT    9 __cxa_free_exception
   288: 0804a0a0     3 FUNC    GLOBAL DEFAULT    9 _ZNKSt9type_info15__is_fu
   289: 08058c54    16 OBJECT  WEAK   DEFAULT   11 _ZTIPKDs
So I'm kind of lost finding out where those symbols should come from and where exactly I'm going wrong. The symbols I would need, namely __register_frame_info / __deregister_frame_info ... all occur in .symtab but not .dynsym of my executable. Should I load the whole .symtab from my executable to properly relocate them?

Thanks in advance!

Greets

EDIT: Okay, I checked the places where _ITM_registerTMCloneTable/_ITM_deregisterTMCloneTable should be relocated into, and it looks to me that this is only relevant if you link with libitm (by using -fgnu-tm), as they are weak references?
nullplan
Member
Member
Posts: 1794
Joined: Wed Aug 30, 2017 8:24 am

Re: Some symbols missing for shared library relocations

Post by nullplan »

It would appear you do not handle weak relocations correctly. If you do not find a symbol, but the undefined symbol is weak, you do not error, you leave the relocation as it is. That should solve your problems.

__register_frame_info sounds like a libgcc function.
Carpe diem!
User avatar
max
Member
Member
Posts: 616
Joined: Mon Mar 05, 2012 11:23 am
Libera.chat IRC: maxdev
Location: Germany
Contact:

Re: Some symbols missing for shared library relocations

Post by max »

nullplan wrote:It would appear you do not handle weak relocations correctly. If you do not find a symbol, but the undefined symbol is weak, you do not error, you leave the relocation as it is. That should solve your problems.

__register_frame_info sounds like a libgcc function.
Hey nullplan,

you are right. All those symbols seem to come from libitm and everything works as expected even when they are not relocated. Thanks!

Greets

EDIT: Just for the archive, those missing symbols come from libgcc.a which I was linking statically, this only works when linking with the shared libgcc_s.so, see this topic.
Post Reply