summaryrefslogtreecommitdiff
path: root/list-obj-sizes.awk
blob: 8a910f9de888d311ce6fe0418303c9487b6ae764 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#! /usr/bin/awk -f

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

function hex2int (hex) {
  n = 0;
  hex = tolower(hex);
  for (i = 1; i<=length(hex); i++)
    {
      n = n * 16 + index("0123456789abcdef", substr(hex,i,1)) - 1;
    }

  return n;
}

function output () {
  if (name)
    {
      printf "%25s %6x   %6x   %6x\n", name, text_size, data_size, rodata_size;
      text_total += text_size;
      data_total += data_size;
      rodata_total += rodata_size; 
    } 
  text_size = 0;
  data_size = 0;
  rodata_size = 0;
}

BEGIN {
    print "file                   text-size  data-size  rodata-size";
    text_total = 0;
    data_total = 0;
    rodata_total = 0;

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

    name = "";
    filter = ENVIRON["FILTER"];
    if (!filter)
      filter = ".*";
    else
      printf "Filter: %s\n", filter;
}

/elf32/ {
  output();
  if ($1 ~ filter)
    {
      name = $1; text_size = data_size = rodata_size = 0;
      sub(/^[^-]*_a-/, "", name);
    }
  else
    name = "";
}

/\.text/ { text_size += hex2int($3); }
/\.data/ { data_size += hex2int($3); }
/\.rodata/ { rodata_size += hex2int($3);}

END {
  output();
  printf "%25s %6x   %6x   %6x\n", "TOTAL", text_total, data_total, rodata_total;
}