diff options
Diffstat (limited to 'scripts/gen_symbol_header.awk')
-rw-r--r-- | scripts/gen_symbol_header.awk | 145 |
1 files changed, 79 insertions, 66 deletions
diff --git a/scripts/gen_symbol_header.awk b/scripts/gen_symbol_header.awk index c9af7f9..0180f6c 100644 --- a/scripts/gen_symbol_header.awk +++ b/scripts/gen_symbol_header.awk @@ -1,5 +1,21 @@ +# Read the symbols list and create regexs to use for processing readelf output. BEGIN { - COUNT = split(" " SYMBOLS_LIST, SYMBOLS); + COUNT = 0; + + sym_regex = ""; + while ((getline line < SYMBOLS_FILE) > 0) { + if (line ~ /^ *#/ || line ~ /^$/) + continue; + split(line, fields); + symbol = fields[1]; + + SYMBOLS[++COUNT] = symbol; + if (sym_regex) + sym_regex = sym_regex "|"; + sym_regex = sym_regex symbol; + } + SYMBOL_REGEX = "^(" sym_regex ")(@|$)"; + WEAK_SYMBOL_REGEX = "^__(" sym_regx ")(@@|$)"; } /^ OS\/ABI:/ { @@ -12,73 +28,69 @@ BEGIN { if ($0 ~ "^Symbol (.*)table '.symtab'") nextfile; - for (x in SYMBOLS) { - sym_regex = "^" SYMBOLS[x] "(@|$)"; - # On x86, x86_64 and others, $8 is the symbol name, but on - # alpha, its $10, so rather use $NF, as it should be the - # last field - if ($NF ~ sym_regex) { - split($NF, symbol_array, /@|@@/); - - # Don't add local symbols of versioned libc's - if (VERSIONED_LIBC && !symbol_array[2]) - continue; - - # We have a versioned libc - if (symbol_array[2] && !VERSIONED_LIBC) - VERSIONED_LIBC = 1; - - ADD = 1; - # Check that we do not add duplicates - for (y in PROCESSED_SYMBOLS) { - if (y == $NF) { - ADD = 0; - break; - } + # On x86, x86_64 and others, $8 is the symbol name, but on + # alpha, its $10, so rather use $NF, as it should be the + # last field + if ($NF ~ SYMBOL_REGEX) { + split($NF, symbol_array, /@|@@/); + + # Don't add local symbols of versioned libc's + if (VERSIONED_LIBC && !symbol_array[2]) + next; + + # We have a versioned libc + if (symbol_array[2] && !VERSIONED_LIBC) + VERSIONED_LIBC = 1; + + ADD = 1; + # Check that we do not add duplicates + for (y in PROCESSED_SYMBOLS) { + if (y == $NF) { + ADD = 0; + break; } + } - if (ADD) { - SYMBOL_LIST[symbol_array[1]] = SYMBOL_LIST[symbol_array[1]] " " $NF; - PROCESSED_SYMBOLS[$NF] = $NF; - } + if (ADD) { + SYMBOL_LIST[symbol_array[1]] = SYMBOL_LIST[symbol_array[1]] " " $NF; + PROCESSED_SYMBOLS[$NF] = $NF; } + } - # No apparent need to handle weak __XXX symbols ... so disable - # until we have documentation on why ... - # If we do re-add this, need to update the `readelf` call in - # libsandbox/ to include the -h flag again. - continue; - - sym_regex = "^__" SYMBOLS[x] "(@@|$)"; - if (($5 == "WEAK") && ($NF ~ sym_regex)) { - split($NF, symbol_array, /@@/); - - # Don't add local symbols of versioned libc's - if (VERSIONED_LIBC && !symbol_array[2]) - continue; - - # Blacklist __getcwd on FreeBSD - # Unleashed - May 2006 - if ((symbol_array[1] == "__getcwd") && (ABI == "FreeBSD")) - continue; - - # We have a versioned libc - if (symbol_array[2] && !VERSIONED_LIBC) - VERSIONED_LIBC = 1; - - ADD = 1; - # Check that we do not add duplicates - for (y in PROCESSED_SYMBOLS) { - if (y == $NF) { - ADD = 0; - break; - } + # No apparent need to handle weak __XXX symbols ... so disable + # until we have documentation on why ... + # If we do re-add this, need to update the `readelf` call in + # libsandbox/ to include the -h flag again. + next; + + if (($5 == "WEAK") && ($NF ~ WEAK_SYMBOL_REGEX)) { + split($NF, symbol_array, /@@/); + + # Don't add local symbols of versioned libc's + if (VERSIONED_LIBC && !symbol_array[2]) + next; + + # Blacklist __getcwd on FreeBSD + # Unleashed - May 2006 + if ((symbol_array[1] == "__getcwd") && (ABI == "FreeBSD")) + next; + + # We have a versioned libc + if (symbol_array[2] && !VERSIONED_LIBC) + VERSIONED_LIBC = 1; + + ADD = 1; + # Check that we do not add duplicates + for (y in PROCESSED_SYMBOLS) { + if (y == $NF) { + ADD = 0; + break; } + } - if (ADD) { - WEAK_SYMBOLS[SYMBOLS[x]] = WEAK_SYMBOLS[SYMBOLS[x]] " " $NF; - PROCESSED_SYMBOLS[$NF] = $NF; - } + if (ADD) { + WEAK_SYMBOLS[SYMBOLS[x]] = WEAK_SYMBOLS[SYMBOLS[x]] " " $NF; + PROCESSED_SYMBOLS[$NF] = $NF; } } } @@ -86,7 +98,6 @@ BEGIN { END { printf("#ifndef __symbols_h\n"); printf("#define __symbols_h\n\n"); - printf("#define SB_NR_UNDEF -99999\n\n"); SB_MAX_STRING_LEN = 0 @@ -99,7 +110,7 @@ END { SB_MAX_STRING_LEN = length(sym_index); if (full_count == 0) - printf("#define SB_NR_%s SB_NR_UNDEF\n", toupper(sym_index)); + printf("#define SB_NR_%s (SB_NR_UNDEF - %i)\n", toupper(sym_index), i); for (x in sym_full_names) { split(sym_full_names[x], symbol_array, /@|@@/); @@ -117,6 +128,10 @@ END { gsub(/@|\./, "_", sym_real_name); } + # Avoid libc's symbol rename via #define. musl defines aliases as: + # #define mkstemp64 mkstemp + # #define mkstemps64 mkstemps + printf("#undef %s\n", sym_index); printf("#define symname_%s \"%s\"\n", sym_real_name, sym_index); # We handle non-versioned libc's by setting symver_* @@ -186,8 +201,6 @@ END { } } - printf("#include \"wrapper-funcs/__pre_check.c\"\n"); - printf("#define SB_MAX_STRING_LEN %i\n\n", SB_MAX_STRING_LEN); printf("#endif /* __symbols_h */\n"); |