#!/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)+0,$NF }' | \
	sort -n | \
	awk '{
		if (last == "")
			last = $1
		curr = $1
		off = curr - last - size
		# ignore resolved weak funcs
		if (last == curr)
			next
		Off += off
		print $0 " +" off
		last = curr
		size = $2
	} END { print Off }'
