Skip to content

Commit 3565bb5

Browse files
committed
build: Updates for AIX npm support - part 1
This PR is the first step enabling support for native modules for AIX. The main issue is that unlike linux where all symbols within the Node executable are available to the shared library for a native module (npm), on AIX the symbols must be explicitly exported. In addition, when the shared library is built it must be linked using a list of the available symbols. This patch covers the changes need to: 1) Export the symbols when building the node executable 2) Generate the file listing the symbols that can be used when building the shared library. For AIX, it breaks the build process into 2 steps. The first builds a static library and then generates a node.exp file which contains the symbols from that library. The second builds the node executable and uses the node.exp file to specify which symbols should be exported. In addition, it save the node.exp file so that it can later be used in the creation of the shared library when building a native module. The following additional steps will be required in dependent projects to fully enable AIX for native modules and are being worked separately: - Updates to node-gyp to use node.exp when creating the shared library for a native module - Fixes to gyp related to copying files as covered in https://codereview.chromium.org/1368133002/patch/1/10001 - Pulling in updated gyp versions to Node and node-gyp - Pulling latest libuv These changes were done to minimize the change to other platforms by working within the existing structure to add the 2 step process for AIX without changing the process for other platforms.
1 parent 30b8bb0 commit 3565bb5

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

configure

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,10 @@ def configure_node(o):
657657
elif target_arch in ('mips', 'mipsel'):
658658
configure_mips(o)
659659

660+
if flavor == 'aix':
661+
o['variables']['node_core_target_name'] = 'node_base'
662+
o['variables']['node_target_type'] = 'static_library'
663+
660664
if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
661665
use_dtrace = not options.without_dtrace
662666
# Don't enable by default on linux and freebsd

node.gyp

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'node_shared_openssl%': 'false',
1414
'node_v8_options%': '',
1515
'node_target_type%': 'executable',
16+
'node_core_target_name%': 'node',
1617
'library_files': [
1718
'src/node.js',
1819
'lib/_debug_agent.js',
@@ -79,7 +80,7 @@
7980

8081
'targets': [
8182
{
82-
'target_name': 'node',
83+
'target_name': '<(node_core_target_name)',
8384
'type': '<(node_target_type)',
8485

8586
'dependencies': [
@@ -666,5 +667,53 @@
666667
'test/cctest/util.cc',
667668
],
668669
}
669-
] # end targets
670+
], # end targets
671+
672+
'conditions': [
673+
['OS=="aix"', {
674+
'targets': [
675+
{
676+
'target_name': 'node',
677+
'type': 'executable',
678+
'dependencies': ['<(node_core_target_name)', 'node_exp'],
679+
680+
'include_dirs': [
681+
'src',
682+
'deps/v8/include',
683+
],
684+
685+
'sources': [
686+
'src/node_main.cc',
687+
'<@(library_files)',
688+
# node.gyp is added to the project by default.
689+
'common.gypi',
690+
],
691+
692+
'ldflags': ['-Wl,-bbigtoc,-bE:<(PRODUCT_DIR)/node.exp'],
693+
},
694+
{
695+
'target_name': 'node_exp',
696+
'type': 'none',
697+
'dependencies': [
698+
'<(node_core_target_name)',
699+
],
700+
'actions': [
701+
{
702+
'action_name': 'expfile',
703+
'inputs': [
704+
'<(OBJ_DIR)'
705+
],
706+
'outputs': [
707+
'<(PRODUCT_DIR)/node.exp'
708+
],
709+
'action': [
710+
'sh', 'tools/create_expfile.sh',
711+
'<@(_inputs)', '<@(_outputs)'
712+
],
713+
}
714+
]
715+
}
716+
], # end targets
717+
}], # end aix section
718+
], # end conditions block
670719
}

tools/create_expfile.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/sh
2+
# This script writes out all the exported symbols to a file
3+
# AIX needs this as sybmols are not exported by an
4+
# executable by default and we need to list
5+
# them specifically in order to export them
6+
# so that they can be used by native add-ons
7+
#
8+
# The raw symbol data is objtained by using nm on
9+
# the .a files which make up the node executable
10+
#
11+
# -Xany makes sure we get symbols on both
12+
# 32 bit and 64 bit as by default we'd only get those
13+
# for 32 bit
14+
#
15+
# -g selects only exported symbols
16+
#
17+
# -C, -B and -p ensure the output is in a format we
18+
# can easily parse and convert into the symbol we need
19+
#
20+
# -C suppresses the demangling of C++ names
21+
# -B gives us output in BSD format
22+
# -p displays the info in a standard portable output format
23+
#
24+
# We only include symbols if they are of the
25+
# following types and don't start with a dot.
26+
#
27+
# T - Global text symbol
28+
# D - Global data symbol
29+
# B - Gobal bss symbol.
30+
#
31+
# the final sort allows us to remove any duplicates
32+
#
33+
# We need to exclude gtest libraries as they are not
34+
# linked into the node executable
35+
#
36+
echo "Searching $1 to write out expfile to $2"
37+
38+
# this special sequence must be at the start of the exp file
39+
echo "#!." > $2
40+
41+
# pull the symbols from the .a files
42+
find $1 -name "*.a" | grep -v gtest \
43+
| xargs nm -Xany -BCpg \
44+
| awk '{
45+
if ((($2 == "T") || ($2 == "D") || ($2 == "B")) &&
46+
(substr($3,1,1) != ".")) { print $3 }
47+
}' \
48+
| sort -u >> $2

tools/install.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def headers(action):
160160
'src/node_version.h',
161161
], 'include/node/')
162162

163+
# Add the expfile that is created on AIX
164+
if sys.platform.startswith('aix'):
165+
action(['out/Release/node.exp'], 'include/node/')
166+
163167
subdir_files('deps/cares/include', 'include/node/', action)
164168
subdir_files('deps/v8/include', 'include/node/', action)
165169

0 commit comments

Comments
 (0)