2
0

renamesyms.sh 748 B

123456789101112131415161718192021222324252627
  1. #!/bin/sh
  2. target=$1
  3. deps_dir=$2
  4. if [ -z "$target" ] || [ -z "$deps_dir" ]; then
  5. echo "Usage:\n\t./renamesyms.sh TARGET DEPS_DIR"
  6. exit 1
  7. fi
  8. symbols_file=`mktemp`
  9. special_syms="__rg_alloc __rg_dealloc __rg_realloc __rg_alloc_zeroed __rg_oom"
  10. for dep in `find $deps_dir -type f -name "*.rlib"`; do
  11. "${TARGET}-nm" --format=posix -g "$dep" 2>/dev/null | sed 's/.*:.*//g' | awk '{if ($2 == "T") print $1}' | sed 's/^\(.*\)$/\1 __relibc_\1/g' >> $symbols_file
  12. done
  13. for special_sym in $special_syms; do
  14. echo "$special_sym __relibc_$special_sym" >> $symbols_file
  15. done
  16. sorted_file=`mktemp`
  17. sort -u "$symbols_file" > "$sorted_file"
  18. rm -f "$symbols_file"
  19. "${TARGET}-objcopy" --redefine-syms="$sorted_file" "$target"
  20. rm -f "$sorted_file"