通过objdump和objcopy修改符号名
 
#! /bin/bash
 
objdump -t $1 >objdump.out
 
filename=`basename $1`
file=${filename%.*}
 
cat objdump.out | while read LINE
do
        MODIFY=0
        TYPE=`echo ${LINE} | awk -F " " '{print $2}'`
        SEC_NAME=`echo ${LINE} | awk -F " " '{print $4}'`
        SYM_NAME=`echo ${LINE} | awk -F " " '{print $6}'`
        if [ "$TYPE" = "l" -a "$SEC_NAME" = ".data" -a "$SYM_NAME" != ".data" ];
        then
                MODIFY=1
        fi
        if [ "$TYPE" = "l" -a "$SEC_NAME" = ".bss" -a "$SYM_NAME" != ".bss" ];
        then
                MODIFY=1
        fi
        if [ "$TYPE" = 'l' -a "$SEC_NAME" = ".rodata" -a "$SYM_NAME" != ".rodata" ];
        then
                MODIFY=1
        fi
        if [ "$MODIFY" -eq 1 ];
        then
        objcopy "--redefine-sym" "${SYM_NAME}=${file}.${SYM_NAME}" $1
        fi
done
rm -rf objdump.out