2
0

strip-kmod.sh 935 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. MODULE="$1"
  7. [ "$#" -ne 1 ] && {
  8. echo "Usage: $0 <module>"
  9. exit 1
  10. }
  11. ARGS=
  12. if [ -n "$KEEP_SYMBOLS" ]; then
  13. ARGS="-X --strip-debug"
  14. else
  15. ARGS="-x -G __this_module --strip-unneeded"
  16. fi
  17. if [ -z "$KEEP_BUILD_ID" ]; then
  18. ARGS="$ARGS -R .note.gnu.build-id"
  19. fi
  20. ${CROSS}objcopy \
  21. -R .comment \
  22. -R .pdr \
  23. -R .mdebug.abi32 \
  24. -R .gnu.attributes \
  25. -R .reginfo \
  26. -R .MIPS.abiflags \
  27. -R .note.GNU-stack \
  28. $ARGS \
  29. "$MODULE" "$MODULE.tmp"
  30. [ -n "$NO_RENAME" ] && {
  31. mv "${MODULE}.tmp" "$MODULE"
  32. exit 0
  33. }
  34. ${CROSS}nm "$MODULE.tmp" | awk '
  35. BEGIN {
  36. n = 0
  37. }
  38. $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
  39. print "--redefine-sym "$3"=_"n;
  40. n = n + 1
  41. def[$3] = 1
  42. }
  43. ' > "$MODULE.tmp1"
  44. ${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
  45. mv "${MODULE}.out" "${MODULE}"
  46. rm -f "${MODULE}".t*