经常在使用第三方SDK的时候会莫名其妙报错,其中最常见的一种就是SO符号冲突,比如libA.so静态链接了libC.a,而libB.so动态链接了libC.so。这样便会导致符号冲突。又或者在使用不同版本的动态库,也会造成符号冲突。
DEBUG : Abort message: 'terminating with unexpected exception of type std::bad_cast: std::bad_cast'
A/DEBUG: Softversion: PD1911C_A_1.9.7
A/DEBUG: Time: 2020-06-12 15:30:46
A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
A/DEBUG: Build fingerprint: 'vivo/PD1911/PD1911:9/PKQ1.181030.001/compiler02261735:user/release-keys'
A/DEBUG: Revision: '0'
A/DEBUG: ABI: 'arm'
A/DEBUG: pid: 18115, tid: 19792, name: Thread-158 >>> com.renderer.app <<<
A/DEBUG: signal 11 (SIGSEGV), code 0 (SI_USER), fault addr --------
A/DEBUG: r0 c3f7e350 r1 ffffffff r2 c3f7e31c r3 00000014
A/DEBUG: r4 c3f7e25c r5 c3f7e308 r6 f2deed8c r7 c3f7e250
A/DEBUG: r8 c3f7e350 r9 c204a028 r10 00000000 r11 00000001
A/DEBUG: ip d1011f04 sp c3f7e248 lr d0ff766f pc d0ff7856
A/DEBUG: backtrace:
A/DEBUG: #00 pc 0006e856 /data/app/com.renderer.app-Ibeyey3dw8tSdgPla9iLpg==/lib/arm/libc++_shared.so
A/DEBUG: #01 pc 0006e66b /data/app/com.renderer.app-Ibeyey3dw8tSdgPla9iLpg==/lib/arm/libc++_shared.so
A/DEBUG: #02 pc 0006bffd /data/app/com.renderer.app-Ibeyey3dw8tSdgPla9iLpg==/lib/arm/libc++_shared.so
A/DEBUG: #03 pc 0006beaf /data/app/com.renderer.app-Ibeyey3dw8tSdgPla9iLpg==/lib/arm/libc++_shared.so (__gxx_personality_v0+78)
A/DEBUG: #04 pc 000e4bfc /data/app/com.renderer.app-Ibeyey3dw8tSdgPla9iLpg==/lib/arm/libpg_sdk.so
A/DEBUG: #05 pc 000e5740 /data/app/com.renderer.app-Ibeyey3dw8tSdgPla9iLpg==/lib/arm/libpg_sdk.so
基于以上背景,可能存在一下几种解决方案
解决跟libc++_shared.so
符号冲突的so重命名
import lief
import sys
if __name__ == '__main__':
cpp_shared_so_path = "libc++_shared.so"
cpp_shared_so = lief.parse(cpp_shared_so_path)
cpp_shared_so_exported_symbols = cpp_shared_so.exported_symbols
cpp_shared_so_exported_symbols_list = [sym.name for sym in cpp_shared_so_exported_symbols]
targetElf = sys.argv[1]
elf = lief.parse(targetElf)
exported_symbols = elf.exported_symbols #dynamic_symbols
for symbol in exported_symbols:
if symbol.name in cpp_shared_so_exported_symbols_list:
sym_export = elf.get_symbol(symbol.name)
sym_export.name = symbol.name.replace("_Z","_M")
elf.write(targetElf.replace(".so","_out.so"))