ELF搬迁 - 来自这些符号?

时间:2012-10-02 01:46:25

标签: linux gcc assembly ld binutils

在我的Debian x86 32位中,当我执行readelf -r /usr/lib/libstdc++.so.6时grep pthread,我得到了这个输出:

000eceac  00006206 R_386_GLOB_DAT    00000000   pthread_cancel
000ed058  00000807 R_386_JUMP_SLOT   00000000   pthread_cond_destroy
000ed148  00001207 R_386_JUMP_SLOT   00000000   pthread_cond_signal
000ed1e8  00001e07 R_386_JUMP_SLOT   00000000   pthread_key_create
000ed320  00002a07 R_386_JUMP_SLOT   00000000   pthread_once
000ed418  00003607 R_386_JUMP_SLOT   00000000   pthread_getspecific
000ed42c  00003a07 R_386_JUMP_SLOT   00000000   pthread_mutex_unlock
000ed4ec  00004607 R_386_JUMP_SLOT   00000000   pthread_create
000ed54c  00004b07 R_386_JUMP_SLOT   00000000   pthread_equal
000ed678  00005607 R_386_JUMP_SLOT   00000000   pthread_mutex_lock
000ed71c  00006007 R_386_JUMP_SLOT   00000000   pthread_cond_wait
000ed7b0  00006907 R_386_JUMP_SLOT   00000000   pthread_key_delete
000ed8b4  00007307 R_386_JUMP_SLOT   00000000   pthread_cond_broadcast
000ed8c0  00007507 R_386_JUMP_SLOT   00000000   pthread_detach
000ed8f0  00007a07 R_386_JUMP_SLOT   00000000   pthread_setspecific
000ed968  00007c07 R_386_JUMP_SLOT   00000000   pthread_join

但是,当我列出/usr/lib/libstdc++.so.6的依赖项时,未列出libpthread:

john@ThirdEarth:~$ ldd /usr/lib/libstdc++.so.6
linux-gate.so.1 =>  (0xb77df000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb76ad000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7566000)
/lib/ld-linux.so.2 (0xb77e0000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7547000)

那么动态加载器如何解决这些依赖关系呢?我在__gmon_start__中发现了类似的问题,粗略地说,这是这个符号的定义吗?

2 个答案:

答案 0 :(得分:4)

Linux中的pthread函数在libc中实现。

例如,在我不得不提供的系统上:

objdump -T /lib/libc-2.11.1.so | grep pthread

给出

00000000000f64a0 g    DF .text  0000000000000026  GLIBC_2.3.2 pthread_cond_signal
0000000000126100 g    DF .text  0000000000000026 (GLIBC_2.2.5) pthread_cond_signal
00000000000f6be0 g    DF .text  000000000000005a  GLIBC_PRIVATE __libc_pthread_init
00000000000f65f0 g    DF .text  0000000000000026  GLIBC_2.2.5 pthread_mutex_lock
00000000000f63e0 g    DF .text  0000000000000026  GLIBC_2.2.5 pthread_condattr_init
00000000000f6290 g    DF .text  0000000000000026  GLIBC_2.2.5 pthread_attr_getschedparam
...

答案 1 :(得分:0)

要回答问题的第二部分,__gmon_start__是其中的一部分 C运行时,在构建可执行文件时使用 gprof(1) - 样式分析。

在Ubuntu GNU / Linux上,相关的定义可以在/usr/lib/gcrt1.o中找到:

% nm /usr/lib/gcrt1.o| grep -C2 gmon_start
00000000 R _IO_stdin_used
00000000 D __data_start
00000030 T __gmon_start__
         U __libc_csu_fini
         U __libc_csu_init

对于正常的编译运行,/usr/lib/crti.o提供了一个“弱”定义:

% nm /usr/lib/crti.o| grep -C2 gmon_start
          U _GLOBAL_OFFSET_TABLE_
          w __gmon_start__
 00000000 T _fini
 00000000 T _init
相关问题