• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2#
3# Generate private_symbols[_jet].awk.
4#
5# Usage: private_symbols.sh <sym_prefix> <sym>*
6#
7# <sym_prefix> is typically "" or "_".
8
9sym_prefix=$1
10shift
11
12cat <<EOF
13#!/usr/bin/env awk -f
14
15BEGIN {
16  sym_prefix = "${sym_prefix}"
17  split("\\
18EOF
19
20for public_sym in "$@" ; do
21  cat <<EOF
22        ${sym_prefix}${public_sym} \\
23EOF
24done
25
26cat <<"EOF"
27        ", exported_symbol_names)
28  # Store exported symbol names as keys in exported_symbols.
29  for (i in exported_symbol_names) {
30    exported_symbols[exported_symbol_names[i]] = 1
31  }
32}
33
34# Process 'nm -a <c_source.o>' output.
35#
36# Handle lines like:
37#   0000000000000008 D opt_junk
38#   0000000000007574 T malloc_initialized
39(NF == 3 && $2 ~ /^[ABCDGRSTVW]$/ && !($3 in exported_symbols) && $3 ~ /^[A-Za-z0-9_]+$/) {
40  print substr($3, 1+length(sym_prefix), length($3)-length(sym_prefix))
41}
42
43# Process 'dumpbin /SYMBOLS <c_source.obj>' output.
44#
45# Handle lines like:
46#   353 00008098 SECT4  notype       External     | opt_junk
47#   3F1 00000000 SECT7  notype ()    External     | malloc_initialized
48($3 ~ /^SECT[0-9]+/ && $(NF-2) == "External" && !($NF in exported_symbols)) {
49  print $NF
50}
51EOF
52