tools/squashfskit: fix version detection on non-linux system
[openwrt/staging/wigyori.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 -R .MIPS.abiflags \
32 -R .note.GNU-stack \
33 $ARGS \
34 "$MODULE" "$MODULE.tmp"
35
36 [ -n "$NO_RENAME" ] && {
37 mv "${MODULE}.tmp" "$MODULE"
38 exit 0
39 }
40
41 ${CROSS}nm "$MODULE.tmp" | awk '
42 BEGIN {
43 n = 0
44 }
45
46 $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
47 print "--redefine-sym "$3"=_"n;
48 n = n + 1
49 def[$3] = 1
50 }
51 ' > "$MODULE.tmp1"
52
53 ${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
54 mv "${MODULE}.out" "${MODULE}"
55 rm -f "${MODULE}".t*