list-obj-sizes.awk 1.04 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
8
9
10
11
12
13
14
15
16
17
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;
}

Niels Möller's avatar
Niels Möller committed
18
19
20
21
22
BEGIN {
    print "file            text-size  data-size  rodata-size";
    text_total = 0;
    data_total = 0;
    rodata_total = 0;
23
24
25
26
27
28
    name = "";
    filter = ENVIRON["FILTER"];
    if (!filter)
      filter = ".*";
    else
      printf "Filter: %s\n", filter;
Niels Möller's avatar
Niels Möller committed
29
30
}

31
32
33
34
35
36
37
38
39
40
41
42
43
44
/elf32/ {
  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; 
    }
  if ($1 ~ filter)
    {
      name = $1; text_size = data_size = rodata_size = 0;
    }
  else
    name = ""
Niels Möller's avatar
Niels Möller committed
45
}
46
47
48
/\.text/ { text_size = hex2int($3) }
/\.data/ { data_size = hex2int($3); }
/\.rodata/ { rodata_size = hex2int($3); }
Niels Möller's avatar
Niels Möller committed
49
50

END {
51
  printf "%25s %6x   %6x   %6x\n", "TOTAL", text_total, data_total, rodata_total;
Niels Möller's avatar
Niels Möller committed
52
}