aboutsummaryrefslogtreecommitdiff
path: root/scripts/abilist.awk
blob: 6cc7af6ac8e1dd1d4cfb84f60949ee8f9b34ad33 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# This awk script processes the output of objdump --dynamic-syms
# into a simple format that should not change when the ABI is not changing.

BEGIN {
  if (combine_fullname)
    combine = 1;
  if (combine)
    parse_names = 1;
}

# Per-file header.
/[^ :]+\.so\.[0-9.]+:[ 	]+.file format .*$/ {
  emit(0);

  seen_opd = 0;

  sofullname = $1;
  sub(/:$/, "", sofullname);
  soname = sofullname;
  sub(/^.*\//, "", soname);
  sub(/\.so\.[0-9.]+$/, "", soname);

  suppress = ((filename_regexp != "" && sofullname !~ filename_regexp) \
	      || (libname_regexp != "" && soname !~ libname_regexp));

  next
}

suppress { next }

# Normalize columns.
/^[0-9a-fA-F]+      / { sub(/      /, "  -   ") }

# Skip undefineds.
$4 == "*UND*" { next }

# Skip locals.
$2 == "l" { next }

# If the target uses ST_OTHER, it will be output before the symbol name.
$2 == "g" || $2 == "w" && (NF == 7 || NF == 8) {
  type = $3;
  size = $5;
  sub(/^0*/, "", size);
  if (size == "") {
      size = " 0x0";
  } else {
      size = " 0x" size;
  }
  version = $6;
  symbol = $NF;
  gsub(/[()]/, "", version);

  # binutils versions up through at least 2.23 have some bugs that
  # caused STV_HIDDEN symbols to appear in .dynsym, though that is useless.
  if (NF > 7 && $7 == ".hidden") next;

  if (version ~ /^GLIBC_ABI_/ && !include_abi_version) next;

  if (version == "GLIBC_PRIVATE" && !include_private) next;

  desc = "";
  if (type == "D" && ($4 == ".tbss" || $4 == ".tdata")) {
    type = "T";
  }
  else if (type == "D" && $4 == ".opd") {
    type = "F";
    size = "";
    if (seen_opd < 0)
      type = "O";
    seen_opd = 1;
  }
  else if (type == "D" && NF == 8 && $7 == "0x80") {
    # Alpha functions avoiding plt entry in users
    type = "F";
    size = "";
    seen_opd = -1;
  }
  else if ($4 == "*ABS*") {
    next;
  }
  else if (type == "D") {
    # Accept unchanged.
  }
  else if (type == "DO") {
    type = "D";
  }
  else if (type == "DF") {
    if (symbol ~ /^\./ && seen_opd >= 0)
      next;
    seen_opd = -1;
    type = "F";
    size = "";
  }
  else if (type == "iD" && ($4 == ".text" || $4 == ".opd")) {
    # Indirect functions.
    type = "F";
    size = "";
  }
  else {
    print "ERROR: Unable to handle this type of symbol:", $0
    exit 1
  }

  if (desc == "")
    desc = symbol " " type size;

  if (combine)
    version = soname " " version (combine_fullname ? " " sofullname : "");

  # Append to the string which collects the results.
  descs = descs version " " desc "\n";
  next;
}

# Header crapola.
NF == 0 || /DYNAMIC SYMBOL TABLE/ || /file format/ { next }

{
  print "ERROR: Unable to interpret this line:", $0
  exit 1
}

function emit(end) {
  if (!end && (combine || ! parse_names || soname == ""))
    return;
  tofile = parse_names && !combine;

  if (tofile) {
    out = prefix soname ".symlist";
    if (soname in outfiles)
      out = out "." ++outfiles[soname];
    else
      outfiles[soname] = 1;
    outpipe = "LC_ALL=C sort -u > " out;
  } else {
    outpipe = "LC_ALL=C sort -u";
  }

  printf "%s", descs | outpipe;

  descs = "";

  if (tofile)
    print "wrote", out, "for", sofullname;
}

END {
  emit(1);
}