#!/bin/sh
mkdir -p $2
rm -rf $2/*
readelf -Wr $1 \
  | gawk '
/^Relocation section.*\._ZTV/ {
  F = gensub (/^Relocation section.*\.(_ZTV[^'\'']*)'\''.*$/, "'$2'/\\1", "", $0);
  if (V[F]) F = "";
  V[F] = 1;
  next;
}
/^$/ {
  if (F) close (F);
  F = "";
  next;
}
($1 ~ /Offset/) {
  next
}
(F) {
  $2 = "";
  $4 = "";
  gsub (/^\.[^ ]*\./, "", $5);
  print >> F;
}
{
  next;
}'
