rstrip.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2006 OpenWrt.org
  4. #
  5. # This is free software, licensed under the GNU General Public License v2.
  6. # See /LICENSE for more information.
  7. #
  8. find_modparams() {
  9. FILE="$1"
  10. $NM "$FILE" | awk '
  11. BEGIN {
  12. FS=" "
  13. }
  14. ($3 ~ /^__module_parm_/) && ($3 !~ /^__module_parm_desc/) {
  15. gsub(/__module_parm_/, "", $3)
  16. printf "-K " $3 " "
  17. }
  18. ($2 ~ /r/) && ($3 ~ /__param_/) {
  19. gsub(/__param_/, "", $3)
  20. printf "-K " $3 " "
  21. }
  22. '
  23. }
  24. SELF=${0##*/}
  25. [ -z "$STRIP" ] && {
  26. echo "$SELF: strip command not defined (STRIP variable not set)"
  27. exit 1
  28. }
  29. TARGETS=$*
  30. [ -z "$TARGETS" ] && {
  31. echo "$SELF: no directories / files specified"
  32. echo "usage: $SELF [PATH...]"
  33. exit 1
  34. }
  35. find $TARGETS -type f -a -exec file {} \; | \
  36. sed -n -e 's/^\(.*\):.*ELF.*\(executable\|relocatable\|shared object\).*,.* stripped/\1:\2/p' | \
  37. (
  38. IFS=":"
  39. while read F S; do
  40. echo "$SELF: $F:$S"
  41. [ "${S}" = "relocatable" ] && {
  42. eval "$STRIP_KMOD -w -K '__param*' -K '__mod*' $(find_modparams "$F")$F"
  43. } || {
  44. b=$(stat -c '%a' $F)
  45. eval "$STRIP $F"
  46. a=$(stat -c '%a' $F)
  47. [ "$a" = "$b" ] || chmod $b $F
  48. }
  49. done
  50. true
  51. )