blob: e5b2868f5d5f54233c5f0db1d54982a773f40143 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001#!/bin/sh
2[ -n "$CROSS" ] || {
3 echo "The variable CROSS must be set to point to the cross-compiler prefix"
4 exit 1
5}
6
7MODULE="$1"
8
9[ "$#" -ne 1 ] && {
10 echo "Usage: $0 <module>"
11 exit 1
12}
13
14ARGS=
15if [ -n "$KEEP_SYMBOLS" ]; then
16 ARGS="-X --strip-debug"
17else
18 ARGS="-x -G __this_module --strip-unneeded"
19fi
20
21if [ -z "$KEEP_BUILD_ID" ]; then
22 ARGS="$ARGS -R .note.gnu.build-id"
23fi
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 '
42BEGIN {
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
54mv "${MODULE}.out" "${MODULE}"
55rm -f "${MODULE}".t*