strip-kmod.sh 841 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. ${CROSS}objcopy \
  18. -R .comment \
  19. -R .pdr \
  20. -R .mdebug.abi32 \
  21. -R .note.gnu.build-id \
  22. -R .gnu.attributes \
  23. -R .reginfo \
  24. $ARGS \
  25. "$MODULE" "$MODULE.tmp"
  26. [ -n "$NO_RENAME" ] && {
  27. mv "${MODULE}.tmp" "$MODULE"
  28. exit 0
  29. }
  30. ${CROSS}nm "$MODULE.tmp" | awk '
  31. BEGIN {
  32. n = 0
  33. }
  34. $3 && $2 ~ /[brtd]/ && $3 !~ /\$LC/ && !def[$3] {
  35. print "--redefine-sym "$3"=_"n;
  36. n = n + 1
  37. def[$3] = 1
  38. }
  39. ' > "$MODULE.tmp1"
  40. ${CROSS}objcopy `cat ${MODULE}.tmp1` ${MODULE}.tmp ${MODULE}.out
  41. mv "${MODULE}.out" "${MODULE}"
  42. rm -f "${MODULE}".t*