Skip to content

Commit 1b406bf

Browse files
committed
aix: Add weak symbol detection ...
in create_expfile.sh AIX export files support the `weak` keyword to mark weak symbols. ref: https://www.ibm.com/docs/en/aix/7.2.0?topic=l-ld-command#ld__a3119106d This helps preserve C++ weak symbol semantics and preventing potential linker conflicts.
1 parent 6285b67 commit 1b406bf

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

β€Žtools/create_expfile.shβ€Ž

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,60 +5,79 @@
55
# specifically for export so that they can be used
66
# by native add-ons.
77
#
8-
# The raw symbol data is obtained by using nm on
8+
# The raw symbol data is obtained by using dump -tov on
99
# the .a files which make up the node executable.
1010
#
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
1316
#
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
1519
#
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)
3126
#
3227
# The final sort allows removal of any duplicates.
3328
#
3429
# Symbols for the gtest libraries are excluded as
3530
# they are not linked into the node executable.
3631
#
37-
set -x
3832
echo "Searching $1 to write out expfile to $2"
3933

4034
# This special sequence must be at the start of the exp file.
4135
echo "#!." > "$2.tmp"
4236

4337
# 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.
4539
# This prevents AIX linker error 0711-407 when addons try to import symbols
4640
# 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+
#
4765
find "$1" -name "*.a" | grep -v gtest | while read f; do
4866
dump -tov -X 32_64 "$f" 2>/dev/null | \
4967
awk '
5068
BEGIN {
5169
V["EXPORTED"]=" export"
5270
V["PROTECTED"]=" protected"
5371
V["HIDDEN"]=" hidden"
72+
V["weak"]=" weak"
5473
}
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))?/ {
5675
# Exclude symbols starting with dot, __sinit, __sterm, __[0-9]+__
5776
# Also exclude HIDDEN symbols to avoid visibility attribute issues
5877
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)]
6281
}
6382
}
6483
}

0 commit comments

Comments
Β (0)