unexpected reloc type问题分析
1.现象,程序在启动的时候报如下错误
error while loading shared libraries: /home/test/lib/libtest.so: unexpected reloc type 0x03
2.分析,可以通过readelf进行查看依赖的目标文件是否存在non-pic情况,对比新旧版本
readelf -d libtest.so
pic:position independent code.
有textrel说明该目标文件是non-pic, 没有则是pic的
non-pic在使用-fpic选项会出现问题
libtest.so.new
dynamic section at offset 0x19d928 contains 37 entries:
tag type name/value
0x00000003 (pltgot) 0x1a2280
0x00000002 (pltrelsz) 11936 (bytes)
0x00000017 (jmprel) 0x211b8
0x00000014 (pltrel) rel
0x00000011 (rel) 0x1e020
0x00000012 (relsz) 12696 (bytes)
0x00000013 (relent) 8 (bytes)
0x6ffffffa (relcount) 341
0x00000006 (symtab) 0x158
0x0000000b (syment) 16 (bytes)
0x00000005 (strtab) 0xa3a8
0x0000000a (strsz) 55275 (bytes)
0x6ffffef5 (gnu_hash) 0x17b94
0x00000001 (needed) shared library: [libpthread.so.0]
0x00000001 (needed) shared library: [libglib-2.0.so.0]
0x00000001 (needed) shared library: [librt.so.1]
0x00000001 (needed) shared library: [libstdc++.so.6]
0x00000001 (needed) shared library: [libm.so.6]
0x00000001 (needed) shared library: [libgcc_s.so.1]
0x00000001 (needed) shared library: [libc.so.6]
...
0x0000000c (init) 0x24058
0x0000000d (fini) 0xe2138
0x00000019 (init_array) 0x19f328
0x0000001b (init_arraysz) 16 (bytes)
0x0000001a (fini_array) 0x19f338
0x0000001c (fini_arraysz) 4 (bytes)
0x00000016 (textrel) 0x0
0x0000001e (flags) textrel
0x6ffffff0 (versym) 0x1caf8
0x6ffffffc (verdef) 0x1df44
0x6ffffffd (verdefnum) 1
0x6ffffffe (verneed) 0x1df60
0x6fffffff (verneednum) 5
0x00000000 (null) 0x0
libtest.so.old
dynamic section at offset 0x1915c0 contains 35 entries:
tag type name/value
0x00000003 (pltgot) 0x195f18
0x00000002 (pltrelsz) 11968 (bytes)
0x00000017 (jmprel) 0x20630
0x00000014 (pltrel) rel
0x00000011 (rel) 0x1d4b0
0x00000012 (relsz) 12672 (bytes)
0x00000013 (relent) 8 (bytes)
0x6ffffffa (relcount) 341
0x00000006 (symtab) 0x158
0x0000000b (syment) 16 (bytes)
0x00000005 (strtab) 0x9e38
0x0000000a (strsz) 54259 (bytes)
0x6ffffef5 (gnu_hash) 0x1722c
...
0x0000000c (init) 0x234f0
0x0000000d (fini) 0xd482c
0x00000019 (init_array) 0x192fb0
0x0000001b (init_arraysz) 16 (bytes)
0x0000001a (fini_array) 0x192fc0
0x0000001c (fini_arraysz) 4 (bytes)
0x6ffffff0 (versym) 0x1c038
0x6ffffffc (verdef) 0x1d3d4
0x6ffffffd (verdefnum) 1
0x6ffffffe (verneed) 0x1d3f0
0x6fffffff (verneednum) 5
0x00000000 (null) 0x0
执行如下命令查看目标文件的重定向类型,存在r_arm_rel32说明定向存在偏移,
如果存在该重定向类型,还可以看到涉及的function,从这个function判断该功能出自哪个库
readelf -r libtest.so|grep r_arm_rel32
如果使用-fpic,这个函数的重定向类型是r_arm_glob_dat
3.解决,用新的编译工具使用-fpic(-fpic -pie)选项重新编译相关依赖库文件,依赖库目标文件避免出现textrel标识。
上一篇: 李世民为什么会选择性格温和的李治?
下一篇: c/c++ lambda 表达式 剖析