|
6 | 6 | # by native add-ons. |
7 | 7 | # |
8 | 8 | # The raw symbol data is obtained by using dump -tov on |
9 | | -# the .a files which make up the node executable. |
| 9 | +# the .a and .o files which make up the node executable. |
10 | 10 | # |
11 | 11 | # dump -tov flags: |
12 | 12 | # -t: Display symbol table entries |
|
29 | 29 | # Symbols for the gtest libraries are excluded as |
30 | 30 | # they are not linked into the node executable. |
31 | 31 | # |
32 | | -echo "Searching $1 to write out expfile to $2" |
| 32 | +SEARCH_DIR="$1" |
| 33 | +OUTPUT="$2" |
| 34 | +TARGET_NAME="$3" |
| 35 | +shift 3 || true |
| 36 | +# Remaining arguments are explicit extra inputs for the build to order on. |
33 | 37 |
|
34 | | -# This special sequence must be at the start of the exp file. |
35 | | -echo "#!." > "$2.tmp" |
| 38 | +echo "Searching $SEARCH_DIR to write out expfile to $OUTPUT" |
| 39 | + |
| 40 | +SYMFILE="${OUTPUT}.syms" |
| 41 | +: > "$SYMFILE" |
36 | 42 |
|
37 | | -# Pull the symbols from the .a files. |
38 | 43 | # Use dump -tov to get visibility information and exclude HIDDEN symbols. |
39 | 44 | # This prevents AIX linker error 0711-407 when addons try to import symbols |
40 | 45 | # with visibility attributes. |
41 | 46 | # |
42 | 47 | # IMPORTANT: AIX dump -tov output has a visibility column that contains either |
43 | 48 | # a visibility keyword (HIDDEN/EXPORTED/PROTECTED) or blank spaces when no |
44 | 49 | # visibility attribute is set. Since AWK splits fields on whitespace, this |
45 | | -# results in different field counts: |
46 | | -# |
47 | | -# With visibility keyword (8 fields after AWK splits): |
48 | | -# [137] m 0x00003290 .text 1 weak HIDDEN ._ZNKSt3__1... |
49 | | -# $1 $2 $3 $4 $5 $6 $7 $8 |
50 | | -# | | └─ Symbol name |
51 | | -# | └─ Visibility (HIDDEN/EXPORTED/PROTECTED) |
52 | | -# └─ Linkage (weak/extern) |
53 | | -# |
54 | | -# Without visibility keyword (7 fields after AWK splits, spaces collapsed): |
55 | | -# [77] m 0x00000000 .text 1 weak ._ZN8simdjson... |
56 | | -# $1 $2 $3 $4 $5 $6 $7 |
57 | | -# | └─ Symbol name |
58 | | -# └─ Linkage (weak/extern) |
59 | | -# |
60 | | -# The awk script handles both cases by using an associative array V[] |
61 | | -# to map field values to their export suffixes. For fields that don't match |
62 | | -# any key in V[], the lookup returns an empty string, which is perfect for |
63 | | -# handling the variable field positions caused by the blank visibility column. |
64 | | -# |
65 | | -find "$1" -name "*.a" | grep -v gtest | while read -r f; do |
66 | | - dump -tov -X 32_64 "$f" 2>/dev/null | \ |
67 | | - awk ' |
68 | | - BEGIN { |
69 | | - V["EXPORTED"]=" export" |
70 | | - V["PROTECTED"]=" protected" |
71 | | - V["HIDDEN"]=" hidden" |
72 | | - V["weak"]=" weak" |
73 | | - } |
74 | | - /^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|tdata|bss) +[^ ]+ +(extern|weak)( +(EXPORTED|PROTECTED|HIDDEN))?/ { |
75 | | - # Exclude symbols starting with dot, __sinit, __sterm, __[0-9]+__ |
76 | | - # Also exclude HIDDEN symbols to avoid visibility attribute issues |
77 | | - if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) { |
78 | | - # Skip if HIDDEN visibility (can be at $(NF-1) or $(NF-2)) |
79 | | - if ($(NF-1) != "HIDDEN" && $(NF-2) != "HIDDEN") { |
80 | | - print $NF V[$(NF-1)] V[$(NF-2)] |
81 | | - } |
82 | | - } |
| 50 | +# results in different field counts. The awk script handles both cases by using |
| 51 | +# an associative array V[] to map field values to their export suffixes. |
| 52 | + |
| 53 | +DUMP_AWK=' |
| 54 | +BEGIN { |
| 55 | + V["EXPORTED"]=" export" |
| 56 | + V["PROTECTED"]=" protected" |
| 57 | + V["HIDDEN"]=" hidden" |
| 58 | + V["weak"]=" weak" |
| 59 | +} |
| 60 | +/^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|tdata|bss) +[^ ]+ +(extern|weak)( +(EXPORTED|PROTECTED|HIDDEN))?/ { |
| 61 | + if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) { |
| 62 | + if ($(NF-1) != "HIDDEN" && $(NF-2) != "HIDDEN") { |
| 63 | + print $NF V[$(NF-1)] V[$(NF-2)] |
83 | 64 | } |
84 | | - ' |
85 | | -done | sort -u >> "$2.tmp" |
| 65 | + } |
| 66 | +} |
| 67 | +' |
| 68 | + |
| 69 | +find "$SEARCH_DIR" -name "*.a" | grep -v gtest | while read -r f; do |
| 70 | + dump -tov -X 32_64 "$f" 2>/dev/null | awk "$DUMP_AWK" >> "$SYMFILE" |
| 71 | +done |
| 72 | + |
| 73 | +# Objects linked directly into the target (not archived), e.g. node_snapshot.o. |
| 74 | +if [ -n "$TARGET_NAME" ] && [ -d "$SEARCH_DIR/$TARGET_NAME" ]; then |
| 75 | + find "$SEARCH_DIR/$TARGET_NAME" -name "*.o" | while read -r f; do |
| 76 | + dump -tov -X 32_64 "$f" 2>/dev/null | awk "$DUMP_AWK" >> "$SYMFILE" |
| 77 | + done |
| 78 | +fi |
| 79 | + |
| 80 | +for extra in "$@"; do |
| 81 | + if [ -f "$extra" ]; then |
| 82 | + dump -tov -X 32_64 "$extra" 2>/dev/null | awk "$DUMP_AWK" >> "$SYMFILE" |
| 83 | + fi |
| 84 | +done |
86 | 85 |
|
87 | | -mv -f "$2.tmp" "$2" |
| 86 | +{ |
| 87 | + echo "#!." |
| 88 | + sort -u "$SYMFILE" |
| 89 | +} > "$OUTPUT" |
| 90 | +rm -f "$SYMFILE" |
0 commit comments