Skip to content

Commit 71e6723

Browse files
committed
build: fix AIX shared library exports generation
Signed-off-by: Stewart X Addison <sxa@ibm.com> Assisted-by: Cursor
1 parent 9aa379e commit 71e6723

3 files changed

Lines changed: 104 additions & 47 deletions

File tree

‎node.gyp‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,12 @@
667667
},
668668
},
669669
}],
670+
['node_shared=="true" and OS in "aix os400"', {
671+
'dependencies': ['generate_node_exp'],
672+
'ldflags': [
673+
'-Wl,-bE:<(PRODUCT_DIR)/<(node_core_target_name).exp',
674+
],
675+
}],
670676
[ 'node_shared=="false"', {
671677
# Keep this whole-archive section in sync with the `node_lib` target below.
672678
'xcode_settings': {
@@ -1165,6 +1171,23 @@
11651171
'ldflags': [ '-Wl,-brtl' ],
11661172
},
11671173
}],
1174+
['OS in "aix os400"', {
1175+
'conditions': [
1176+
['node_use_node_snapshot=="true"', {
1177+
'variables': {
1178+
'expfile_extra_inputs': [
1179+
'<(obj_dir)/<(node_lib_target_name)/gen/node_snapshot.o',
1180+
],
1181+
},
1182+
}, {
1183+
'variables': {
1184+
'expfile_extra_inputs': [
1185+
'<(obj_dir)/<(node_lib_target_name)/src/node_snapshot_stub.o',
1186+
],
1187+
},
1188+
}],
1189+
],
1190+
}],
11681191
[ 'node_shared=="true" and OS=="win"', {
11691192
'sources': [
11701193
'src/res/node.rc',
@@ -1712,6 +1735,33 @@
17121735
], # end targets
17131736

17141737
'conditions': [
1738+
['OS in "aix os400" and node_shared=="true"', {
1739+
'targets': [
1740+
{
1741+
'target_name': 'generate_node_exp',
1742+
'type': 'none',
1743+
'dependencies': [
1744+
'<(node_lib_target_name)',
1745+
],
1746+
'actions': [
1747+
{
1748+
'action_name': 'generate_node_exp_action',
1749+
'inputs': [
1750+
'<(PRODUCT_DIR)/<(node_lib_target_name).exp',
1751+
],
1752+
'outputs': [
1753+
'<(PRODUCT_DIR)/<(node_core_target_name).exp',
1754+
],
1755+
'action': [
1756+
'<(python)', 'tools/copyfile.py',
1757+
'<@(_inputs)',
1758+
'<@(_outputs)',
1759+
],
1760+
},
1761+
],
1762+
},
1763+
],
1764+
}],
17151765
['OS=="win" and node_shared=="true"', {
17161766
'targets': [
17171767
{

‎node.gypi‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,24 @@
300300
[ 'force_load=="true"', {
301301
'variables': {
302302
'exp_filename': '<(PRODUCT_DIR)/<(_target_name).exp',
303+
'expfile_extra_inputs%': [],
303304
},
304305
'actions': [
305306
{
306307
'action_name': 'expfile',
307308
'inputs': [
308309
'<(obj_dir)',
310+
'<@(expfile_extra_inputs)',
309311
],
310312
'outputs': [
311313
'<(exp_filename)',
312314
],
313315
'action': [
314316
'sh', 'tools/create_expfile.sh',
315-
'<@(_inputs)',
317+
'<(obj_dir)',
316318
'<@(_outputs)',
319+
'<(_target_name)',
320+
'<@(expfile_extra_inputs)',
317321
],
318322
}
319323
],

‎tools/create_expfile.sh‎

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# by native add-ons.
77
#
88
# 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.
1010
#
1111
# dump -tov flags:
1212
# -t: Display symbol table entries
@@ -29,59 +29,62 @@
2929
# Symbols for the gtest libraries are excluded as
3030
# they are not linked into the node executable.
3131
#
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.
3337

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"
3642

37-
# Pull the symbols from the .a files.
3843
# Use dump -tov to get visibility information and exclude HIDDEN symbols.
3944
# This prevents AIX linker error 0711-407 when addons try to import symbols
4045
# with visibility attributes.
4146
#
4247
# IMPORTANT: AIX dump -tov output has a visibility column that contains either
4348
# a visibility keyword (HIDDEN/EXPORTED/PROTECTED) or blank spaces when no
4449
# 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)]
8364
}
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
8685

87-
mv -f "$2.tmp" "$2"
86+
{
87+
echo "#!."
88+
sort -u "$SYMFILE"
89+
} > "$OUTPUT"
90+
rm -f "$SYMFILE"

0 commit comments

Comments
 (0)