Created
October 8, 2015 02:59
-
-
Save atotto/b9e1afe9f7079b896ba7 to your computer and use it in GitHub Desktop.
print go version from built binary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
# usage | |
# $0 path/to/go/built/binary | |
usage() { | |
echo "Usage" | |
echo " $0 path/to/go/built/binary" | |
exit 2 | |
} | |
obj=$1 | |
if [ -z $obj ] || [ ! -e $obj ];then | |
echo "No such file" | |
usage | |
fi | |
v=(`go tool nm -size $obj | grep 'runtime.buildVersion' | awk '{print $1,$2}'`) | |
addr=${v[0]} | |
size=${v[1]} | |
start=`objdump -s $obj | grep $addr | awk '{hex=$2; printf "0x%s%s%s%s\n",substr(hex,7,2),substr(hex,5,2),substr(hex,3,2),substr(hex,1,2);}'` | |
end=`printf "%d+%d\n" $start $size | bc` | |
objdump -s --start-address=$start --stop-address=$end $obj | grep go | sed -e 's/.*\(go.*\).*/\1/' -e 's/\.\.\+//g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment