由于目前使用的核心子產品ko檔案太大, 一個驅動ko大約11M;
于是直接strip xx.ko;然後insmod xx.ko
但是報錯了:module has no symbols (stripped?)
Develop>insmod /opt/bin/test.ko
insmod: ERROR: could not insert module /opt/bin/test.ko: Invalid module format
Develop>dmesg
[132254.099352] test: module has no symbols (stripped?)
難道不能strip; 肯定不可能,于是strip --help 看下
strip -h
Usage: strip <option(s)> in-file(s)
Removes symbols and sections from files
The options are:
-I --input-target=<bfdname> Assume input file is in format <bfdname>
-O --output-target=<bfdname> Create an output file in format <bfdname>
-F --target=<bfdname> Set both input and output format to <bfdname>
-p --preserve-dates Copy modified/access timestamps to the output
-D --enable-deterministic-archives
Produce deterministic output when stripping archives
-U --disable-deterministic-archives
Disable -D behavior (default)
-R --remove-section=<name> Also remove section <name> from the output
-s --strip-all Remove all symbol and relocation information
-g -S -d --strip-debug Remove all debugging symbols & sections
--strip-dwo Remove all DWO sections
--strip-unneeded Remove all symbols not needed by relocations
--only-keep-debug Strip everything but the debug information
-N --strip-symbol=<name> Do not copy symbol <name>
-K --keep-symbol=<name> Do not strip symbol <name>
--keep-file-symbols Do not strip file symbol(s)
-w --wildcard Permit wildcard in symbol comparison
-x --discard-all Remove all non-global symbols
-X --discard-locals Remove any compiler-generated symbols
-v --verbose List all object files modified
-V --version Display this program's version number
-h --help Display this output
--info List object formats & architectures supported
-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;
_COMPILE:~# modinfo -h
Usage:
modinfo [options] filename [args]
Options:
-a, --author Print only 'author'
-d, --description Print only 'description'
-l, --license Print only 'license'
-p, --parameters Print only 'parm'
-n, --filename Print only 'filename'
-0, --null Use \0 instead of \n
-F, --field=FIELD Print only provided FIELD
-k, --set-version=VERSION Use VERSION instead of `uname -r`
-b, --basedir=DIR Use DIR as filesystem root for /lib/modules
-V, --version Show version
-h, --help Show this help
root@COMPILE:~# lsmod |grep nf_nat_ipv4
nf_nat_ipv4 16384 1 iptable_nat
nf_nat 24576 3 nf_nat_ipv4,xt_nat,nf_nat_masquerade_ipv4
nf_conntrack 106496 6 nf_nat,nf_nat_ipv4,xt_conntrack,nf_nat_masquerade_ipv4,nf_conntrack_netlink,nf_conntrack_ipv4
root@COMPILE:~# modinfo -F depends /lib/modules/4.4.0-148-generic/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko
nf_nat,nf_conntrack
可以看到 modinfo -F depends xx 就可以看出依賴的子產品!lsmod 是檢視已經成功加載後,這些子產品依賴關系;同時
常用參數為:
- -a顯示子產品開發人員
- -p顯示子產品所支援的參數
modinfo /lib/modules/4.4.0-148-generic/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko
filename: /lib/modules/4.4.0-148-generic/kernel/net/ipv4/netfilter/nf_nat_ipv4.ko
alias: nf-nat-2
license: GPL
srcversion: 42CF3FCE9CB78E8B74CAB3D
depends: nf_nat,nf_conntrack
retpoline: Y
intree: Y
vermagic: 4.4.0-148-generic SMP mod_unload modversions
這是直接檢視子產品的資訊,包含了depends字段;這個modinfo -F depends 的原理其實直接讀取檢視modules.dep檔案;
root@_COMPILE:~# cat /lib/modules/4.4.0-148-generic/modules.dep |grep nf_nat_ipv4
kernel/net/ipv4/netfilter/nf_nat_ipv4.ko: kernel/net/netfilter/nf_nat.ko kernel/net/netfilter/nf_conntrack.ko
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
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