kernel: add missing symbol for 4.4
[openwrt/openwrt.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 ARGS=
15 if [ -n "$KEEP_SYMBOLS" ]; then
16 ARGS="-X --strip-debug"
17 else
18 ARGS="-x -G __this_module --strip-unneeded"
19 fi
20
21 if [ -z "$KEEP_BUILD_ID" ]; then
22 ARGS="$ARGS -R .note.gnu.build-id"
23 fi
24
25 ${CROSS}objcopy \
26 -R .comment \
27 -R .pdr \
28 -R .mdebug.abi32 \
29 -R .gnu.attributes \
30 -R .reginfo \
31 $ARGS \
32 "$MODULE" "$MODULE.tmp"
33
34 [ -n "$NO_RENAME" ] && {
35 mv "${MODULE}.tmp" "$MODULE"
36 exit 0
37 }
38
39 ${CROSS}nm "$MODULE.tmp" | awk '
40 BEGIN {
41 n = 0
42 }
43
44 $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
45 print "--redefine-sym "$3"=_"n;
46 n = n + 1
47 def[$3] = 1
48 }
49 ' > "$MODULE.tmp1"
50
51 ${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
52 mv "${MODULE}.out" "${MODULE}"
53 rm -f "${MODULE}".t*