unexpected reloc type问题分析
Posted sciapex
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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_REL说明定向存在偏移,
如果存在该重定向类型,还可以看到涉及的function,从这个function判断该功能出自哪个库
readelf -r libtest.so|grep R_ARM_REL
如果使用-fPIC可能这个函数的重定向是R_ARM_GLOB_DAT
3.解决,用新的编译工具使用-fPIC(-fpic -pie)选项重新编译相关依赖库文件,依赖库目标文件避免出现TEXTREL标识。
以上是关于unexpected reloc type问题分析的主要内容,如果未能解决你的问题,请参考以下文章
POJ 2923 Relocation 装车问题 状态压缩DP+01背包
TypeError: index() got an unexpected keyword argument ‘doc_type‘
spring security There was an unexpected error (type=Forbidden, status=403).
Python libsvm: TypeError: __init__() got an unexpected keyword argument 'kernel_type'
There was an unexpected error (type=Forbidden, status=403). Forbidden
springboot 集成jsp问题: There was an unexpected error (type=Not Found, status=404). /WEB-INF/jsp/index.j