| 1 |
BEGIN {
|
| 2 |
split(ENVIRON["SYMBOLS"], SYMBOLS);
|
| 3 |
}
|
| 4 |
|
| 5 |
/^ OS\/ABI:/ {
|
| 6 |
ABI = $NF
|
| 7 |
}
|
| 8 |
|
| 9 |
{
|
| 10 |
# Unstripped libc's have '.symtab' section as well, and
|
| 11 |
# we should stop processing when we hit that
|
| 12 |
if ($0 ~ "^Symbol (.*)table '.symtab'")
|
| 13 |
nextfile;
|
| 14 |
|
| 15 |
for (x in SYMBOLS) {
|
| 16 |
sym_regex = "^" SYMBOLS[x] "(@|$)";
|
| 17 |
# On x86, x86_64 and others, $8 is the symbol name, but on
|
| 18 |
# alpha, its $10, so rather use $NF, as it should be the
|
| 19 |
# last field
|
| 20 |
if ($NF ~ sym_regex) {
|
| 21 |
split($NF, symbol_array, /@|@@/);
|
| 22 |
|
| 23 |
# Don't add local symbols of versioned libc's
|
| 24 |
if (VERSIONED_LIBC && !symbol_array[2])
|
| 25 |
continue;
|
| 26 |
|
| 27 |
# Handle non-versioned libc's like uClibc ...
|
| 28 |
if (!symbol_array[2])
|
| 29 |
symbol_array[2] = "";
|
| 30 |
|
| 31 |
# We have a versioned libc
|
| 32 |
if (symbol_array[2] && !VERSIONED_LIBC)
|
| 33 |
VERSIONED_LIBC = 1;
|
| 34 |
|
| 35 |
ADD = 1;
|
| 36 |
# Check that we do not add duplicates
|
| 37 |
for (y in PROCESSED_SYMBOLS) {
|
| 38 |
if (y == $NF) {
|
| 39 |
ADD = 0;
|
| 40 |
break;
|
| 41 |
}
|
| 42 |
}
|
| 43 |
|
| 44 |
if (ADD) {
|
| 45 |
SYMBOL_LIST[symbol_array[2]] = SYMBOL_LIST[symbol_array[2]] " " symbol_array[1];
|
| 46 |
PROCESSED_SYMBOLS[$NF] = $NF;
|
| 47 |
}
|
| 48 |
}
|
| 49 |
|
| 50 |
sym_regex = "^__" SYMBOLS[x] "(@@|$)";
|
| 51 |
if (($5 == "WEAK") && ($NF ~ sym_regex)) {
|
| 52 |
split($NF, symbol_array, /@@/);
|
| 53 |
|
| 54 |
# Don't add local symbols of versioned libc's
|
| 55 |
if (VERSIONED_LIBC && !symbol_array[2])
|
| 56 |
continue;
|
| 57 |
|
| 58 |
# Blacklist __getcwd on FreeBSD
|
| 59 |
# Unleashed - May 2006
|
| 60 |
if ((symbol_array[1] == "__getcwd") && (ABI == "FreeBSD"))
|
| 61 |
continue;
|
| 62 |
|
| 63 |
# Handle non-versioned libc's like uClibc ...
|
| 64 |
if (!symbol_array[2])
|
| 65 |
symbol_array[2] = "";
|
| 66 |
|
| 67 |
# We have a versioned libc
|
| 68 |
if (symbol_array[2] && !VERSIONED_LIBC)
|
| 69 |
VERSIONED_LIBC = 1;
|
| 70 |
|
| 71 |
ADD = 1;
|
| 72 |
# Check that we do not add duplicates
|
| 73 |
for (y in PROCESSED_SYMBOLS) {
|
| 74 |
if (y == $NF) {
|
| 75 |
ADD = 0;
|
| 76 |
break;
|
| 77 |
}
|
| 78 |
}
|
| 79 |
|
| 80 |
if (ADD) {
|
| 81 |
SYMBOL_LIST[symbol_array[2]] = SYMBOL_LIST[symbol_array[2]] " " symbol_array[1];
|
| 82 |
PROCESSED_SYMBOLS[$NF] = $NF;
|
| 83 |
}
|
| 84 |
}
|
| 85 |
}
|
| 86 |
}
|
| 87 |
|
| 88 |
END {
|
| 89 |
for (sym_version in SYMBOL_LIST) {
|
| 90 |
if (sym_version)
|
| 91 |
VERSIONS = VERSIONS " " sym_version;
|
| 92 |
}
|
| 93 |
|
| 94 |
# We need the symbol versions sorted alphabetically ...
|
| 95 |
if (VERSIONS) {
|
| 96 |
split(VERSIONS, VERSION_LIST);
|
| 97 |
COUNT = asort(VERSION_LIST);
|
| 98 |
} else {
|
| 99 |
# Handle non-versioned libc's like uClibc ...
|
| 100 |
COUNT = 1;
|
| 101 |
}
|
| 102 |
|
| 103 |
for (i = 1; i <= COUNT; i++) {
|
| 104 |
if (VERSION_LIST[i]) {
|
| 105 |
sym_version = VERSION_LIST[i];
|
| 106 |
printf("%s {\n", sym_version);
|
| 107 |
} else {
|
| 108 |
# Handle non-versioned libc's like uClibc ...
|
| 109 |
sym_version = "";
|
| 110 |
printf("{\n");
|
| 111 |
}
|
| 112 |
|
| 113 |
printf(" global:\n");
|
| 114 |
|
| 115 |
split(SYMBOL_LIST[sym_version], sym_names);
|
| 116 |
|
| 117 |
for (x in sym_names) {
|
| 118 |
printf(" %s;\n", sym_names[x]);
|
| 119 |
}
|
| 120 |
|
| 121 |
if (!old_sym_version) {
|
| 122 |
printf(" local:\n");
|
| 123 |
printf(" *;\n");
|
| 124 |
printf("};\n");
|
| 125 |
} else {
|
| 126 |
printf("} %s;\n", old_sym_version);
|
| 127 |
}
|
| 128 |
|
| 129 |
old_sym_version = sym_version;
|
| 130 |
}
|
| 131 |
}
|