ELF シンボル テーブルを読み込もうとしています。
共有ライブラリで次の不一致に直面しており、その背後にある理由を理解できません。
libc の場合、readelf
i を使用すると次の出力が得られました。
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 ヘッダーを確認すると、両方のライブラリが同じタイプでした.