mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
build: fix AIX shared library exports generation
Signed-off-by: Stewart X Addison <sxa@ibm.com> Assisted-by: Cursor PR-URL: https://github.com/nodejs/node/pull/67359 Reviewed-By: Richard Lau <richard.lau@ibm.com>
This commit is contained in:
1 parent
9373f1f7df
commit
b3c164d592
6 files changed
+160
-58
No files matched your search
@@ -673,6 +673,12 @@
|
||||
},
|
||||
},
|
||||
}],
|
||||
['node_shared=="true" and OS in "aix os400"', {
|
||||
'dependencies': ['generate_node_exp'],
|
||||
'ldflags': [
|
||||
'-Wl,-bE:<(PRODUCT_DIR)/<(node_core_target_name).exp',
|
||||
],
|
||||
}],
|
||||
[ 'node_shared=="false"', {
|
||||
# Keep this whole-archive section in sync with the `node_lib` target below.
|
||||
'xcode_settings': {
|
||||
@@ -1171,6 +1177,23 @@
|
||||
'ldflags': [ '-Wl,-brtl' ],
|
||||
},
|
||||
}],
|
||||
['OS in "aix os400"', {
|
||||
'conditions': [
|
||||
['node_use_node_snapshot=="true"', {
|
||||
'variables': {
|
||||
'expfile_extra_inputs': [
|
||||
'<(obj_dir)/<(node_lib_target_name)/gen/node_snapshot.o',
|
||||
],
|
||||
},
|
||||
}, {
|
||||
'variables': {
|
||||
'expfile_extra_inputs': [
|
||||
'<(obj_dir)/<(node_lib_target_name)/src/node_snapshot_stub.o',
|
||||
],
|
||||
},
|
||||
}],
|
||||
],
|
||||
}],
|
||||
[ 'node_shared=="true" and OS=="win"', {
|
||||
'sources': [
|
||||
'src/res/node.rc',
|
||||
@@ -1718,6 +1741,33 @@
|
||||
], # end targets
|
||||
|
||||
'conditions': [
|
||||
['OS in "aix os400" and node_shared=="true"', {
|
||||
'targets': [
|
||||
{
|
||||
'target_name': 'generate_node_exp',
|
||||
'type': 'none',
|
||||
'dependencies': [
|
||||
'<(node_lib_target_name)',
|
||||
],
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'generate_node_exp_action',
|
||||
'inputs': [
|
||||
'<(PRODUCT_DIR)/<(node_lib_target_name).exp',
|
||||
],
|
||||
'outputs': [
|
||||
'<(PRODUCT_DIR)/<(node_core_target_name).exp',
|
||||
],
|
||||
'action': [
|
||||
'<(python)', 'tools/copyfile.py',
|
||||
'<@(_inputs)',
|
||||
'<@(_outputs)',
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}],
|
||||
['OS=="win" and node_shared=="true"', {
|
||||
'targets': [
|
||||
{
|
||||
|
||||
@@ -300,20 +300,24 @@
|
||||
[ 'force_load=="true"', {
|
||||
'variables': {
|
||||
'exp_filename': '<(PRODUCT_DIR)/<(_target_name).exp',
|
||||
'expfile_extra_inputs%': [],
|
||||
},
|
||||
'actions': [
|
||||
{
|
||||
'action_name': 'expfile',
|
||||
'inputs': [
|
||||
'<(obj_dir)',
|
||||
'<@(expfile_extra_inputs)',
|
||||
],
|
||||
'outputs': [
|
||||
'<(exp_filename)',
|
||||
],
|
||||
'action': [
|
||||
'sh', 'tools/create_expfile.sh',
|
||||
'<@(_inputs)',
|
||||
'<(obj_dir)',
|
||||
'<@(_outputs)',
|
||||
'<(_target_name)',
|
||||
'<@(expfile_extra_inputs)',
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
@@ -13,6 +13,7 @@ const char* dlopen_pong(void) {
|
||||
|
||||
namespace {
|
||||
|
||||
using v8::Exception;
|
||||
using v8::FunctionCallbackInfo;
|
||||
using v8::Isolate;
|
||||
using v8::Local;
|
||||
@@ -24,20 +25,43 @@ typedef const char* (*ping)(void);
|
||||
|
||||
static ping ping_func;
|
||||
|
||||
void ThrowError(Isolate* isolate, const char* message) {
|
||||
isolate->ThrowException(
|
||||
Exception::Error(String::NewFromUtf8(isolate, message).ToLocalChecked()));
|
||||
}
|
||||
|
||||
void LoadLibrary(const FunctionCallbackInfo<Value>& args) {
|
||||
const String::Utf8Value filename(args.GetIsolate(), args[0]);
|
||||
Isolate* isolate = args.GetIsolate();
|
||||
const String::Utf8Value filename(isolate, args[0]);
|
||||
char* dlerrormsg;
|
||||
void* handle = dlopen(*filename, RTLD_LAZY);
|
||||
if (handle == nullptr) fprintf(stderr, "%s\n", dlerror());
|
||||
assert(handle != nullptr);
|
||||
if (handle == nullptr) {
|
||||
dlerrormsg = dlerror();
|
||||
ThrowError(isolate, dlerrormsg != nullptr ? dlerrormsg : "dlopen failed");
|
||||
return;
|
||||
}
|
||||
ping_func = reinterpret_cast<ping>(dlsym(handle, "dlopen_ping"));
|
||||
assert(ping_func != nullptr);
|
||||
if (ping_func == nullptr) {
|
||||
if (dlclose(handle) != 0) {
|
||||
ThrowError(isolate, "dlclose failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Ping(const FunctionCallbackInfo<Value>& args) {
|
||||
Isolate* isolate = args.GetIsolate();
|
||||
assert(ping_func != nullptr);
|
||||
args.GetReturnValue().Set(String::NewFromUtf8(
|
||||
isolate, ping_func()).ToLocalChecked());
|
||||
if (ping_func == nullptr) {
|
||||
ThrowError(isolate, "ping library was not loaded");
|
||||
return;
|
||||
}
|
||||
const char* answer = ping_func();
|
||||
if (answer == nullptr) {
|
||||
ThrowError(isolate, "dlopen_pong could not be resolved (RTLD_GLOBAL)");
|
||||
return;
|
||||
}
|
||||
args.GetReturnValue().Set(
|
||||
String::NewFromUtf8(isolate, answer).ToLocalChecked());
|
||||
}
|
||||
|
||||
void init(Local<Object> exports) {
|
||||
|
||||
@@ -10,10 +10,12 @@
|
||||
'xcode_settings': {
|
||||
'OTHER_LDFLAGS': [ '-Wl,-undefined', '-Wl,dynamic_lookup' ]
|
||||
}}],
|
||||
# Enable the shared object to be linked by runtime linker
|
||||
['OS in "aix os400"', {
|
||||
# Deferred import of dlopen_pong (-Wl,-G) where ping.c links it directly.
|
||||
# AIX uses dlsym(RTLD_DEFAULT) in ping.c instead of a link-time import.
|
||||
['OS=="os400"', {
|
||||
'ldflags': [ '-Wl,-G' ]
|
||||
}]],
|
||||
}],
|
||||
],
|
||||
},
|
||||
{
|
||||
'target_name': 'binding',
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
#ifndef _WIN32
|
||||
|
||||
#if defined(_AIX)
|
||||
#include <stddef.h>
|
||||
#include <dlfcn.h>
|
||||
#else
|
||||
const char* dlopen_pong(void);
|
||||
#endif
|
||||
|
||||
__attribute__((visibility("default")))
|
||||
const char* dlopen_ping(void) {
|
||||
#if defined(_AIX)
|
||||
/* ping.so is built with -Wl,-G: link-time import of dlopen_pong is resolved
|
||||
* when ping.so is loaded. On --shared libnode builds that resolution can fail
|
||||
* even when dlopen_pong appears in binding's loader table (dump). Resolve
|
||||
* at call time via the global symbol set after process.dlopen(RTLD_GLOBAL). */
|
||||
typedef const char* (*pong_fn)(void);
|
||||
pong_fn pong =
|
||||
(pong_fn)dlsym(RTLD_DEFAULT, "dlopen_pong");
|
||||
return pong != NULL ? pong() : NULL;
|
||||
#else
|
||||
return dlopen_pong();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // _WIN32
|
||||
+53
-47
@@ -6,7 +6,7 @@
|
||||
# by native add-ons.
|
||||
#
|
||||
# The raw symbol data is obtained by using dump -tov on
|
||||
# the .a files which make up the node executable.
|
||||
# the .a and .o files which make up the node executable.
|
||||
#
|
||||
# dump -tov flags:
|
||||
# -t: Display symbol table entries
|
||||
@@ -29,12 +29,17 @@
|
||||
# Symbols for the gtest libraries are excluded as
|
||||
# they are not linked into the node executable.
|
||||
#
|
||||
echo "Searching $1 to write out expfile to $2"
|
||||
SEARCH_DIR="$1"
|
||||
OUTPUT="$2"
|
||||
TARGET_NAME="$3"
|
||||
shift 3 || true
|
||||
# Remaining arguments are explicit extra inputs for the build to order on.
|
||||
|
||||
# This special sequence must be at the start of the exp file.
|
||||
echo "#!." > "$2.tmp"
|
||||
echo "Searching $SEARCH_DIR to write out expfile to $OUTPUT"
|
||||
|
||||
SYMFILE="${OUTPUT}.syms"
|
||||
: > "$SYMFILE"
|
||||
|
||||
# Pull the symbols from the .a files.
|
||||
# Use dump -tov to get visibility information and exclude HIDDEN symbols.
|
||||
# This prevents AIX linker error 0711-407 when addons try to import symbols
|
||||
# with visibility attributes.
|
||||
@@ -42,46 +47,47 @@ echo "#!." > "$2.tmp"
|
||||
# IMPORTANT: AIX dump -tov output has a visibility column that contains either
|
||||
# a visibility keyword (HIDDEN/EXPORTED/PROTECTED) or blank spaces when no
|
||||
# visibility attribute is set. Since AWK splits fields on whitespace, this
|
||||
# results in different field counts:
|
||||
#
|
||||
# With visibility keyword (8 fields after AWK splits):
|
||||
# [137] m 0x00003290 .text 1 weak HIDDEN ._ZNKSt3__1...
|
||||
# $1 $2 $3 $4 $5 $6 $7 $8
|
||||
# | | └─ Symbol name
|
||||
# | └─ Visibility (HIDDEN/EXPORTED/PROTECTED)
|
||||
# └─ Linkage (weak/extern)
|
||||
#
|
||||
# Without visibility keyword (7 fields after AWK splits, spaces collapsed):
|
||||
# [77] m 0x00000000 .text 1 weak ._ZN8simdjson...
|
||||
# $1 $2 $3 $4 $5 $6 $7
|
||||
# | └─ Symbol name
|
||||
# └─ Linkage (weak/extern)
|
||||
#
|
||||
# The awk script handles both cases by using an associative array V[]
|
||||
# to map field values to their export suffixes. For fields that don't match
|
||||
# any key in V[], the lookup returns an empty string, which is perfect for
|
||||
# handling the variable field positions caused by the blank visibility column.
|
||||
#
|
||||
find "$1" -name "*.a" | grep -v gtest | while read -r f; do
|
||||
dump -tov -X 32_64 "$f" 2>/dev/null | \
|
||||
awk '
|
||||
BEGIN {
|
||||
V["EXPORTED"]=" export"
|
||||
V["PROTECTED"]=" protected"
|
||||
V["HIDDEN"]=" hidden"
|
||||
V["weak"]=" weak"
|
||||
}
|
||||
/^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|tdata|bss) +[^ ]+ +(extern|weak)( +(EXPORTED|PROTECTED|HIDDEN))?/ {
|
||||
# Exclude symbols starting with dot, __sinit, __sterm, __[0-9]+__
|
||||
# Also exclude HIDDEN symbols to avoid visibility attribute issues
|
||||
if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) {
|
||||
# Skip if HIDDEN visibility (can be at $(NF-1) or $(NF-2))
|
||||
if ($(NF-1) != "HIDDEN" && $(NF-2) != "HIDDEN") {
|
||||
print $NF V[$(NF-1)] V[$(NF-2)]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
done | sort -u >> "$2.tmp"
|
||||
# results in different field counts. The awk script handles both cases by using
|
||||
# an associative array V[] to map field values to their export suffixes.
|
||||
|
||||
mv -f "$2.tmp" "$2"
|
||||
# This is to bypass the lint-sh job from saying "Expressions don't expand in
|
||||
# single quotes, use double quotes for that." which is invalid for this case
|
||||
# shellcheck disable=SC2016
|
||||
DUMP_AWK='
|
||||
BEGIN {
|
||||
V["EXPORTED"]=" export"
|
||||
V["PROTECTED"]=" protected"
|
||||
V["HIDDEN"]=" hidden"
|
||||
V["weak"]=" weak"
|
||||
}
|
||||
/^\[[0-9]+\]\tm +[^ ]+ +\.(text|data|tdata|bss) +[^ ]+ +(extern|weak)( +(EXPORTED|PROTECTED|HIDDEN))?/ {
|
||||
if (!match($NF,/^(\.|__sinit|__sterm|__[0-9]+__)/)) {
|
||||
if ($(NF-1) != "HIDDEN" && $(NF-2) != "HIDDEN") {
|
||||
print $NF V[$(NF-1)] V[$(NF-2)]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
|
||||
find "$SEARCH_DIR" -name "*.a" | grep -v gtest | while read -r f; do
|
||||
dump -tov -X 32_64 "$f" 2>/dev/null | awk "$DUMP_AWK" >> "$SYMFILE"
|
||||
done
|
||||
|
||||
# Objects linked directly into the target (not archived), e.g. node_snapshot.o.
|
||||
if [ -n "$TARGET_NAME" ] && [ -d "$SEARCH_DIR/$TARGET_NAME" ]; then
|
||||
find "$SEARCH_DIR/$TARGET_NAME" -name "*.o" | while read -r f; do
|
||||
dump -tov -X 32_64 "$f" 2>/dev/null | awk "$DUMP_AWK" >> "$SYMFILE"
|
||||
done
|
||||
fi
|
||||
|
||||
for extra in "$@"; do
|
||||
if [ -f "$extra" ]; then
|
||||
dump -tov -X 32_64 "$extra" 2>/dev/null | awk "$DUMP_AWK" >> "$SYMFILE"
|
||||
fi
|
||||
done
|
||||
|
||||
{
|
||||
echo "#!."
|
||||
sort -u "$SYMFILE"
|
||||
} > "$OUTPUT"
|
||||
rm -f "$SYMFILE"
|
||||
Reference in new issue
Block a user