list-obj-sizes.awk 1.26 KB
Newer Older
1
#! /usr/bin/awk -f
Niels Möller's avatar
Niels Möller committed
2 3 4 5 6

# Run this filter on the output of
#
#   objdump -h libnettle.a

7
function hex2int (hex, n, i) {
8 9 10 11 12 13 14 15 16 17
  n = 0;
  hex = tolower(hex);
  for (i = 1; i<=length(hex); i++)
    {
      n = n * 16 + index("0123456789abcdef", substr(hex,i,1)) - 1;
    }

  return n;
}

18 19 20
function output () {
  if (name)
    {
21
      printf "%25s %6d   %6d   %6d\n", name, text_size, data_size, rodata_size;
22 23 24 25 26 27 28 29 30
      text_total += text_size;
      data_total += data_size;
      rodata_total += rodata_size; 
    } 
  text_size = 0;
  data_size = 0;
  rodata_size = 0;
}

Niels Möller's avatar
Niels Möller committed
31
BEGIN {
32
    print "file                   text-size  data-size  rodata-size";
Niels Möller's avatar
Niels Möller committed
33 34 35
    text_total = 0;
    data_total = 0;
    rodata_total = 0;
36 37 38 39 40

    text_size = 0;
    data_size = 0;
    rodata_size = 0;

41 42 43 44 45 46
    name = "";
    filter = ENVIRON["FILTER"];
    if (!filter)
      filter = ".*";
    else
      printf "Filter: %s\n", filter;
Niels Möller's avatar
Niels Möller committed
47 48
}

49
/elf32|elf64/ {
50
  output();
51 52 53
  if ($1 ~ filter)
    {
      name = $1; text_size = data_size = rodata_size = 0;
54
      sub(/^[^-]*_a-/, "", name);
55 56
    }
  else
57
    name = "";
Niels Möller's avatar
Niels Möller committed
58
}
59 60 61 62

/\.text/ { text_size += hex2int($3); }
/\.data/ { data_size += hex2int($3); }
/\.rodata/ { rodata_size += hex2int($3);}
Niels Möller's avatar
Niels Möller committed
63 64

END {
65
  output();
66
  printf "%25s %6d   %6d   %6d\n", "TOTAL", text_total, data_total, rodata_total;
Niels Möller's avatar
Niels Möller committed
67
}