summaryrefslogtreecommitdiff
path: root/list-obj-sizes.awk
blob: 2c0f644cd9a898a6abab4da46498a0bb116443fd (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, i) {
  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 %6d   %6d   %6d\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|elf64/ {
  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 %6d   %6d   %6d\n", "TOTAL", text_total, data_total, rodata_total;
}