内核模块的strip以及依赖

打印 上一主题 下一主题

主题 970|帖子 970|积分 2910

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  由于目前使用的内核模块ko文件太大, 一个驱动ko大约11M;
  于是直接strip xx.ko;然后insmod xx.ko
但是报错了:module has no symbols (stripped?)
  1. Develop>insmod  /opt/bin/test.ko
  2. insmod: ERROR: could not insert module /opt/bin/test.ko: Invalid module format
  3. Develop>dmesg
  4. [132254.099352] test: module has no symbols (stripped?)
复制代码
 难道不能strip; 肯定不可能,于是strip --help 看下
  1. strip  -h
  2. Usage: strip <option(s)> in-file(s)
  3. Removes symbols and sections from files
  4. The options are:
  5.   -I --input-target=<bfdname>      Assume input file is in format <bfdname>
  6.   -O --output-target=<bfdname>     Create an output file in format <bfdname>
  7.   -F --target=<bfdname>            Set both input and output format to <bfdname>
  8.   -p --preserve-dates              Copy modified/access timestamps to the output
  9.   -D --enable-deterministic-archives
  10.                                    Produce deterministic output when stripping archives
  11.   -U --disable-deterministic-archives
  12.                                    Disable -D behavior (default)
  13.   -R --remove-section=<name>       Also remove section <name> from the output
  14.   -s --strip-all                   Remove all symbol and relocation information
  15.   -g -S -d --strip-debug           Remove all debugging symbols & sections
  16.      --strip-dwo                   Remove all DWO sections
  17.      --strip-unneeded              Remove all symbols not needed by relocations
  18.      --only-keep-debug             Strip everything but the debug information
  19.   -N --strip-symbol=<name>         Do not copy symbol <name>
  20.   -K --keep-symbol=<name>          Do not strip symbol <name>
  21.      --keep-file-symbols           Do not strip file symbol(s)
  22.   -w --wildcard                    Permit wildcard in symbol comparison
  23.   -x --discard-all                 Remove all non-global symbols
  24.   -X --discard-locals              Remove any compiler-generated symbols
  25.   -v --verbose                     List all object files modified
  26.   -V --version                     Display this program's version number
  27.   -h --help                        Display this output
  28.      --info                        List object formats & architectures supported
  29.   -o <file>                        Place stripped output into <file>
复制代码
   认为应该使用 -d or  --strip-debug 参数来strip 文件;在使用strip -d 后,insmod 加载成功;也就是 只能strip掉debug信息, 内核模块使用的信息较多, 不能瞎strip。
目前strip -d  xx 和 strip xx  两者执行后的文件大小也不是相差很大。但是都和源文件相差很大,所以以后使用strip -d 参数来strip吧, 然后以前使用的stip 是默认执行strip -d;
看样子不同版本 源码代码编译的strip 其默认参数是不一样的!!
  顺便说一个问题, 由于系统架构部那边提供的内核是带有netfiter的,但是由于业务需求,不需要netfilter,所以将netfilter编译成了ko模块;目前有业务人员想使用iptable 来查看丢包问题,于是问了一句这些netfilter中ko模块的依赖问题!----
  目前有个工具可以看到,就是modinfo;
  1. _COMPILE:~# modinfo  -h
  2. Usage:
  3.     modinfo [options] filename [args]
  4. Options:
  5.     -a, --author                Print only 'author'
  6.     -d, --description           Print only 'description'
  7.     -l, --license               Print only 'license'
  8.     -p, --parameters            Print only 'parm'
  9.     -n, --filename              Print only 'filename'
  10.     -0, --null                  Use \0 instead of \n
  11.     -F, --field=FIELD           Print only provided FIELD
  12.     -k, --set-version=VERSION   Use VERSION instead of `uname -r`
  13.     -b, --basedir=DIR           Use DIR as filesystem root for /lib/modules
  14.     -V, --version               Show version
  15.     -h, --help                  Show this help
复制代码
  1. root@COMPILE:~# lsmod  |grep nf_nat_ipv4
  2. nf_nat_ipv4            16384  1 iptable_nat
  3. nf_nat                 24576  3 nf_nat_ipv4,xt_nat,nf_nat_masquerade_ipv4
  4. nf_conntrack          106496  6 nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,nf_conntrack_ipv4
  5. root@COMPILE:~# modinfo -F depends /lib/modules/4.4.0-148-generic/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko
  6. nf_nat,nf_conntrack
复制代码
 
 
  可以看到 modinfo -F depends xx 就可以看出依赖的模块!lsmod 是查看已经成功加载后,这些模块依赖关系;同时
  常用参数为:

  • -a显示模块开发人员
  • -p显示模块所支持的参数
 
  1. modinfo /lib/modules/4.4.0-148-generic/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko
  2. filename:       /lib/modules/4.4.0-148-generic/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko
  3. alias:          nf-nat-2
  4. license:        GPL
  5. srcversion:     42CF3FCE9CB78E8B74CAB3D
  6. depends:        nf_nat,nf_conntrack
  7. retpoline:      Y
  8. intree:         Y
  9. vermagic:       4.4.0-148-generic SMP mod_unload modversions
复制代码
 
 这是直接查看模块的信息,包含了depends字段;这个modinfo -F depends 的原理其实直接读取查看modules.dep文件;
  1. root@_COMPILE:~# cat  /lib/modules/4.4.0-148-generic/modules.dep |grep nf_nat_ipv4
  2. kernel/net/ipv4/netfilter/nf_nat_ipv4.ko: kernel/net/netfilter/nf_nat.ko kernel/net/netfilter/nf_conntrack.ko
  3. kernel/net/ipv4/netfilter/nft_chain_nat_ipv4.ko: kernel/net/ipv4/netfilter/nf_nat_ipv4.ko kernel/net/netfilter/nf_tables.ko kernel/net/netfilter/nf_nat.ko kernel/net/netfilter/nfnetlink.ko kernel/net/netfilter/nf_conntrack.ko
  4. kernel/net/ipv4/netfilter/iptable_nat.ko: kernel/net/ipv4/netfilter/ip_tables.ko kernel/net/ipv4/netfilter/nf_nat_ipv4.ko kernel/net/netfilter/nf_nat.ko kernel/net/netfilter/nf_conntrack.ko kernel/net/netfilter/x_tables.ko
复制代码
可以看到 也可查看依赖关系
 

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

曹旭辉

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表