我正试着读ELF符号表。
我面对的是共享库中的差异,我无法理解其背后的原因。
对于libc,使用readelf我得到了以下输出。
Num: Value Size Type Bind Vis Ndx Name
7: 00000033c32160b0 146 FUNC WEAK DEFAULT 11 realloc@@GLIBC_2.2.5
8: 00000033c3421000 4 OBJECT WEAK DEFAULT 21 _dl_starting_up@@GLIBC_PRIVATE
9: 00000033c32118f0 382 FUNC GLOBAL DEFAULT 11 _dl_allocate_tls@@GLIBC_PRIVATE
10: 00000033c3421280 40 OBJECT GLOBAL DEFAULT 21 _r_debug@@GLIBC_2.2.5
11: 00000033c341fdc8 8 OBJECT GLOBAL DEFAULT 17 __libc_stack_end@@GLIBC_2.2.5
12: 00000033c3215f30 252 FUNC WEAK DEFAULT 11 __libc_memalign@@GLIBC_2.2.5
13: 00000033c3211a70 140 FUNC GLOBAL DEFAULT 11 _dl_deallocate_tls@@GLIBC_PRIVATE
14: 00000033c3216040 52 FUNC WEAK DEFAULT 11 calloc@@GLIBC_2.2.5
15: 00000033c341fc88 8 OBJECT GLOBAL DEFAULT 17 _dl_argv@@GLIBC_PRIVATE
16: 00000033c3211000 599 FUNC GLOBAL DEFAULT 11 _dl_mcount@@GLIBC_2.2.5对于我自己的共享库构建,使用以下命令
gcc -rdynamic -Wint-to-pointer-cast -g -fPIC -lpthread -c probes.c -ldl -lelf
gcc -shared -lpthread -Wl,--no-as-needed,-soname,libprobes.so.1 -o libprobes.so.1 mutrace.o -ldl -lelf输出是
Num: Value Size Type Bind Vis Ndx Name
.
.
.
34: 00000000000040d0 66 FUNC GLOBAL DEFAULT 11 pthread_create
35: 0000000000001d72 109 FUNC GLOBAL DEFAULT 11 thread_local_init
36: 0000000000002b21 481 FUNC GLOBAL DEFAULT 11 trylock_ret_event
37: 00000000000030c4 652 FUNC GLOBAL DEFAULT 11 lock_init_event
38: 0000000000003e4d 130 FUNC GLOBAL DEFAULT 11 pthread_mutex_init
39: 0000000000004668 0 FUNC GLOBAL DEFAULT 12 _fini
40: 0000000000003dd0 125 FUNC GLOBAL DEFAULT 11 pthread_cond_timedwait
41: 0000000000001b03 92 FUNC GLOBAL DEFAULT 11 backtrace
42: 0000000000001b5f 94 FUNC GLOBAL DEFAULT 11 backtrace_symbols
43: 0000000000002ee3 481 FUNC GLOBAL DEFAULT 11 unlock_ret_event
44: 0000000000004026 95 FUNC GLOBAL DEFAULT 11 pthread_mutex_trylock
45: 0000000000003531 476 FUNC GLOBAL DEFAULT 11 lock_destroy_event
46: 0000000000004112 1012 FUNC GLOBAL DEFAULT 11 print_symtable对于libc,符号值是绝对的(虚拟地址),但是在我的库中,这些值是相对的。是什么决定了这种行为?
我尝试跟踪来自http://docs.oracle.com/cd/E19082-01/819-0690/chapter6-35166/index.html的信息,但是当我检查ELF头时,这两个库的类型是相同的。
发布于 2013-04-16 02:33:47
对于我自己的共享库构建,请使用以下命令 gcc -rdynamic -对位投篮- -g -fPIC -lpthread -c probes.c .c -ldl -lelf gcc -shared -lpthread -Wl,--无所需,-soname,libproes.so.1 -o libproes.so.1
这些命令是不正确的。第一个是编译命令(因为有-c标志)。链接器选项(-rdynamic、-lpthread等)不属于它。
第二个命令是link命令,并有错误的库顺序。此外,您忘了实际使用您编译的probes.o。这样做会更好:
gcc -shared -o libprobes.so.1 -Wl,-soname=libprobes.so.1 probes.o -lpthread对于libc,符号值是绝对的。
不,他们不是。您的libc显然是在address 0x33c3210000 (或类似的)上预先链接的。这并不意味着符号是绝对的。您可以撤消预链接(读取man prelink),您将在libc.so.6中看到类似的“相对”地址。
https://stackoverflow.com/questions/16010396
复制相似问题