获取.so文件中的符号

readelf -Ws <lib.so> | awk '{print $8}';

With these commands presented in this article at OpenGenus, you must have a complete idea of how to list the different symbols in a given .so file. You can use this information for debugging "symbol not found" error.

In this article, we have presented different commands which can be used to list all or specific symbols in a given shared object .so file. This involve different commands with nmobjdump and readelf.

Table of contents:

  1. 4 commands with nm
  2. objdump command
  3. readelf command

The different commands to list different symbols in a given shared object (.so) file are as follows:

4 commands with nm

  • To see all symbols in a given so file:
nm --demangle --dynamic <lib.so>

nm is a tool that comes with binutils. To install binutils, use the following steps.

  • To see only symbols that are defined in an .so file (skipping the undefined symbols), use:
  • nm --demangle --dynamic --defined-only <lib.so>
    
  • To see only symbols which are available for linking (internal linkage), use:
  • nm --demangle --dynamic --extern-only <lib.so>
    
  • To see symbols which are defined and available for linking, use:
  • nm --demangle --dynamic --defined-only --extern-only <lib.so>
    
  • To find a specific symbol in the above list, use grep with the command like:

    objdump command

    To get the list of symbols in a given .so file using objdump command, use the following:

    objdump -TC <lib.so>
    

    readelf command

    If the shared object .so file is in ELF format, one can use readelf command as follows to list the symbols:

    readelf -Ws <lib.so>
    

    This will list all symbols including the ones in shared objects referenced by the current .so file. To get the symbols in the current .so file, we need to check the information in the 7th column which can be extracted using awk command as follows:

  • nm --demangle --dynamic --defined-only --extern-only <lib.so> | grep <search>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值