at master 1.4 kB view raw
1#!/usr/bin/env bash 2 3set -e 4 5target=$1 6deps_dir=$2 7 8if [ -z "$target" ] || [ -z "$deps_dir" ]; then 9 echo "Usage:\n\t./renamesyms.sh TARGET DEPS_DIR" 10 exit 1 11fi 12 13if [ ! -f "$target" ]; then 14 echo "Target file '$target' does not exist" 15 exit 1 16fi 17if [ ! -d "$deps_dir" ] ; then 18 echo "Deps dir '$deps_dir' does not exist or not a directory" 19 exit 1 20fi 21 22symbols_file=`mktemp` 23special_syms=( 24 __rdl_oom 25 __rg_alloc 26 __rg_alloc_zeroed 27 __rg_dealloc 28 __rg_oom 29 __rg_realloc 30 __rust_alloc 31 __rust_alloc_error_handler 32 __rust_alloc_error_handler_should_panic 33 __rust_alloc_zeroed 34 __rust_dealloc 35 __rust_no_alloc_shim_is_unstable 36 __rust_realloc 37 _RNvCsdRcTtHUCxqF_7___rustc12___rust_alloc 38 _RNvCsdRcTtHUCxqF_7___rustc19___rust_alloc_zeroed 39 _RNvCsdRcTtHUCxqF_7___rustc14___rust_dealloc 40 _RNvCsdRcTtHUCxqF_7___rustc14___rust_realloc 41 _RNvCsdRcTtHUCxqF_7___rustc8___rg_oom 42) 43 44for dep in `find $deps_dir -type f -name "*.rlib"`; do 45 "${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 46done 47 48for special_sym in "${special_syms[@]}"; do 49 echo "$special_sym __relibc_$special_sym" >> $symbols_file 50done 51 52sorted_file=`mktemp` 53sort -u "$symbols_file" > "$sorted_file" 54rm -f "$symbols_file" 55 56"${OBJCOPY}" --redefine-syms="$sorted_file" "$target" 57 58rm -f "$sorted_file"