#!/bin/bash
[[ $# -ne 2 ]] && echo "Usage: $0 <file> <section name>" && exit 1
f=$1
s=$2
n=$(readelf -S "$f" | grep " $s " | sed -e 's:\[::' -e 's:\]::' | awk '{print $1}')
readelf -s -W "$f" | \
	awk --non-decimal-data 'NF == 8 && $7 == "'$n'" { print ("0x" $2)+0,$3,$NF }' | \
	sort -n | \
	awk '{ if (l == "") { l=$1 } c=$1; o=c-l-s; O+=o; print $0 " +" o; l=c; s=$2 } END { print O }'
