| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5b9f811 commit ecf8721
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,60 +5,79 @@ | |||
| 5 | 5 | # specifically for export so that they can be used | |
| 6 | 6 | # by native add-ons. | |
| 7 | 7 | # | |
| 8 | - # The raw symbol data is obtained by using nm on | ||
| 8 | + # The raw symbol data is obtained by using dump -tov on | ||
| 9 | 9 | # the .a files which make up the node executable. | |
| 10 | 10 | # | |
| 11 | - # -Xany processes symbols for both 32-bit and | ||
| 12 | - # 64-bit (the default is for 32-bit only). | ||
| 11 | + # dump -tov flags: | ||
| 12 | + # -t: Display symbol table entries | ||
| 13 | + # -o: Display object file headers | ||
| 14 | + # -v: Display visibility information (HIDDEN/EXPORTED/PROTECTED) | ||
| 15 | + # -X 32_64: Process both 32-bit and 64-bit symbols | ||
| 13 | 16 | # | |
| 14 | - # -g selects only exported symbols. | ||
| 17 | + # This approach is similar to CMake's ExportImportList module for AIX: | ||
| 18 | + # https://github.com/Kitware/CMake/blob/45f4742cbfe6c25c7c801e3806c8af04a2c4b09b/Modules/Platform/AIX/ExportImportList#L67-L80 | ||
| 15 | 19 | # | |
| 16 | - # -C, -B and -p ensure that the output is in a | ||
| 17 | - # format that can be easily parsed and converted | ||
| 18 | - # into the required symbol. | ||
| 19 | - # | ||
| 20 | - # -C suppresses the demangling of C++ names. | ||
| 21 | - # -B writes the output in BSD format. | ||
| 22 | - # -p displays the info in a standard portable | ||
| 23 | - # output format. | ||
| 24 | - # | ||
| 25 | - # Only include symbols if they are of the following | ||
| 26 | - # types and don't start with a dot. | ||
| 27 | - # | ||
| 28 | - # T - Global text symbol. | ||
| 29 | - # D - Global data symbol. | ||
| 30 | - # B - Global bss symbol. | ||
| 20 | + # We filter for symbols in .text, .data, .tdata, and .bss sections | ||
| 21 | + # with extern or weak linkage, excluding: | ||
| 22 | + # - Symbols starting with dot (internal/local symbols) | ||
| 23 | + # - __sinit/__sterm (static initialization/termination) | ||
| 24 | + # - __[0-9]+__ (compiler-generated symbols) | ||
| 25 | + # - HIDDEN visibility symbols (to avoid linker error 0711-407) | ||
| 31 | 26 | # | |
| 32 | 27 | # The final sort allows removal of any duplicates. | |
| 33 | 28 | # | |
| 34 | 29 | # Symbols for the gtest libraries are excluded as | |
| 35 | 30 | # they are not linked into the node executable. | |
| 36 | 31 | # | |
| 37 | - set -x | ||
| 38 | 32 | echo "Searching $1 to write out expfile to $2" | |
| 39 | 33 | ||
| 40 | 34 | # This special sequence must be at the start of the exp file. | |
| 41 | 35 | echo "#!." > "$2.tmp" | |
| 42 | 36 | ||
| 43 | 37 | # Pull the symbols from the .a files. | |
| 44 | - # Use dump -tov to get visibility information and exclude HIDDEN symbols | ||
| 38 | + # Use dump -tov to get visibility information and exclude HIDDEN symbols. | ||
| 45 | 39 | # This prevents AIX linker error 0711-407 when addons try to import symbols | |
| 46 | 40 | # with visibility attributes. | |
| 41 | + # | ||
| 42 | + # IMPORTANT: AIX dump -tov output has a visibility column that contains either | ||
| 43 | + # a visibility keyword (HIDDEN/EXPORTED/PROTECTED) or blank spaces when no | ||
| 44 | + # 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 | + # | ||
| 47 | 65 | find "$1" -name "*.a" | grep -v gtest | while read -r f; do | |
| 48 | 66 | dump -tov -X 32_64 "$f" 2>/dev/null | \ | |
| 49 | 67 | awk ' | |
| 50 | 68 | BEGIN { | |
| 51 | 69 | V["EXPORTED"]=" export" | |
| 52 | 70 | V["PROTECTED"]=" protected" | |
| 53 | 71 | V["HIDDEN"]=" hidden" | |
| 72 | + V["weak"]=" weak" | ||
| 54 | 73 | } | |
| 55 | - /^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|tdata|bss) +[^ ]+ +(extern|weak) +(EXPORTED|PROTECTED|HIDDEN| ) / { | ||
| 74 | + /^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|tdata|bss) +[^ ]+ +(extern|weak)( +(EXPORTED|PROTECTED|HIDDEN))?/ { | ||
| 56 | 75 | # Exclude symbols starting with dot, __sinit, __sterm, __[0-9]+__ | |
| 57 | 76 | # Also exclude HIDDEN symbols to avoid visibility attribute issues | |
| 58 | 77 | if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) { | |
| 59 | - visibility = $(NF-1) | ||
| 60 | - if (visibility != "HIDDEN") { | ||
| 61 | - print $NF | ||
| 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)] | ||
| 62 | 81 | } | |
| 63 | 82 | } | |
| 64 | 83 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments