strip kernel modules more aggressively: make all global symbols local, rename all...
[openwrt/svn-archive/archive.git] / scripts / strip-kmod.sh
1 #!/usr/bin/env bash
2 [ -n "$CROSS" ] || {
3 echo "The variable CROSS must be set to point to the cross-compiler prefix"
4 exit 1
5 }
6
7 MODULE="$1"
8
9 [ "$#" -ne 1 ] && {
10 echo "Usage: $0 <module>"
11 exit 1
12 }
13
14 ${CROSS}objcopy \
15 --strip-unneeded \
16 -R .comment \
17 -R .pdr \
18 -R .mdebug.abi32 \
19 -R .note.gnu.build-id \
20 -R .gnu.attributes \
21 -R .reginfo \
22 -G __this_module \
23 -x "$MODULE" "$MODULE.tmp"
24
25 ${CROSS}nm "$MODULE.tmp" | awk '
26 BEGIN {
27 n = 0
28 }
29
30 $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ {
31 print "--redefine-sym "$3"=_"n;
32 n = n + 1
33 }
34 ' > "$MODULE.tmp1"
35
36 ${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
37 mv "${MODULE}.out" "${MODULE}"
38 rm -f "${MODULE}".t*