Skip to content

Commit 70fca2a

Browse files
mhdawsonrvagg
authored andcommitted
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. PR-URL: #3114 Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 2974deb commit 70fca2a

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

configure

+4
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,10 @@ def configure_node(o):
675675
elif target_arch in ('mips', 'mipsel'):
676676
configure_mips(o)
677677

678+
if flavor == 'aix':
679+
o['variables']['node_core_target_name'] = 'node_base'
680+
o['variables']['node_target_type'] = 'static_library'
681+
678682
if flavor in ('solaris', 'mac', 'linux', 'freebsd'):
679683
use_dtrace = not options.without_dtrace
680684
# Don't enable by default on linux and freebsd

node.gyp

+51-2
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',
@@ -81,7 +82,7 @@
8182

8283
'targets': [
8384
{
84-
'target_name': 'node',
85+
'target_name': '<(node_core_target_name)',
8586
'type': '<(node_target_type)',
8687

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

tools/create_expfile.sh

+48
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

+4
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)