nodejs: Hardcode linker flags for shared libraries

We are passing flags to `configure.py` in order to tell the nodejs build
toolchain to use shared libraries. The toolchain seems to mistakenly
also try use shared libraries for host build, but it does not add
respective linker flags (For example `-lz` for zlib). This commit
hardcodes these flags to be always passed to linker by setting linker to
linker + LDFLAGS of shared libraries
This commit is contained in:
Yaksh Bariya 2021-09-10 11:08:48 +05:30
parent bc0f056a38
commit dddd5b0a9b
No known key found for this signature in database
GPG Key ID: F7486BA7D3D27581
21 changed files with 109 additions and 218 deletions

View File

@ -0,0 +1,10 @@
--- ./Makefile 2021-09-10 11:00:12.544728388 +0530
+++ ./Makefile.mod 2021-09-10 11:04:27.388422344 +0530
@@ -19,6 +19,7 @@
PWD = $(CURDIR)
BUILD_WITH ?= make
FIND ?= find
+V8_ARCH = $(DESTCPU)
ifdef JOBS
PARALLEL_ARGS = -j $(JOBS)

View File

@ -1,20 +1,20 @@
diff -uNr node-v13.0.0/deps/uv/src/unix/fs.c node-v13.0.0.mod/deps/uv/src/unix/fs.c
--- node-v13.0.0/deps/uv/src/unix/fs.c 2019-10-22 17:23:28.000000000 +0300
+++ node-v13.0.0.mod/deps/uv/src/unix/fs.c 2020-01-16 02:27:44.944603915 +0200
@@ -1048,6 +1048,7 @@
goto out;
diff -uNr ./deps/uv/src/unix/fs.c ./deps/uv/src/unix/fs.c.mod
--- ./deps/uv/src/unix/fs.c 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/uv/src/unix/fs.c.mod 2021-06-18 20:05:49.675642773 +0530
@@ -1247,6 +1247,7 @@
#endif /* !__linux__ */
}
+#ifndef __ANDROID__
#ifdef FICLONE
if (req->flags & UV_FS_COPYFILE_FICLONE ||
req->flags & UV_FS_COPYFILE_FICLONE_FORCE) {
@@ -1072,7 +1073,7 @@
@@ -1267,6 +1268,7 @@
goto out;
}
#endif
-
+#endif
bytes_to_send = src_statsbuf.st_size;
in_offset = 0;
while (bytes_to_send != 0) {

View File

@ -4,10 +4,9 @@ TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@termux"
# Note: package build may fail on Github Actions CI due to out-of-memory
# condition. It should be built locally instead.
TERMUX_PKG_VERSION=14.15.4
TERMUX_PKG_REVISION=2
TERMUX_PKG_VERSION=16.6.1
TERMUX_PKG_SRCURL=https://nodejs.org/dist/v${TERMUX_PKG_VERSION}/node-v${TERMUX_PKG_VERSION}.tar.xz
TERMUX_PKG_SHA256=adb7ecf66c74b52a14a08cc22bb0f9aedc157cac1ac93240f7f455e8c8edec9c
TERMUX_PKG_SHA256=79b1ea058cc67f2a69462cd5f2467a1efe08c64299c053da70384ce1a0e3e557
# Note that we do not use a shared libuv to avoid an issue with the Android
# linker, which does not use symbols of linked shared libraries when resolving
# symbols on dlopen(). See https://github.com/termux/termux-packages/issues/462.
@ -77,7 +76,9 @@ termux_step_configure() {
export GYP_DEFINES="host_os=linux"
export CC_host=gcc
export CXX_host=g++
export LINK_host=g++
export LINK_host="g++ -Wl,--no-as-needed -ldl -lz"
LDFLAGS+=" -Wl,--no-as-needed -ldl"
# See note above TERMUX_PKG_DEPENDS why we do not use a shared libuv.
./configure \

View File

@ -1,13 +1,11 @@
diff -uNr node-v8.4.0/deps/uv/src/unix/core.c node-v8.4.0.mod/deps/uv/src/unix/core.c
--- node-v8.4.0/deps/uv/src/unix/core.c 2017-08-15 19:42:28.000000000 +0300
+++ node-v8.4.0.mod/deps/uv/src/unix/core.c 2017-09-14 16:13:27.292856099 +0300
@@ -1112,7 +1112,9 @@
diff -uNr ./deps/uv/src/unix/core.c ./deps/uv/src/unix/core.c.mod
--- ./deps/uv/src/unix/core.c 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/uv/src/unix/core.c.mod 2021-06-18 20:10:13.705642672 +0530
@@ -1116,7 +1116,7 @@
/* No temp environment variables defined */
#if defined(__ANDROID__)
- buf = "/data/local/tmp";
+ // Don't use '/data/local/tmp' in Termux
+ //buf = "/data/local/tmp";
+ buf = "@TERMUX_PREFIX@/tmp";
#else
buf = "/tmp";

View File

@ -1,7 +1,6 @@
diff -uNr node-v12.10.0/deps/uv/src/unix/process.c node-v12.10.0.mod/deps/uv/src/unix/process.c
--- node-v12.10.0/deps/uv/src/unix/process.c 2019-09-04 18:36:23.000000000 +0300
+++ node-v12.10.0.mod/deps/uv/src/unix/process.c 2019-09-23 01:39:39.069030779 +0300
@@ -351,27 +351,6 @@
--- ./deps/uv/src/unix/process.c 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/uv/src/unix/process.c.mod 2021-06-18 20:15:54.095642543 +0530
@@ -281,27 +281,6 @@
_exit(127);
}

View File

@ -1,7 +1,6 @@
diff -u -r ../node-v9.7.1/deps/uv/uv.gyp ./deps/uv/uv.gyp
--- ../node-v9.7.1/deps/uv/uv.gyp 2018-03-02 01:58:02.000000000 +0000
+++ ./deps/uv/uv.gyp 2018-03-05 10:51:15.530165566 +0000
@@ -39,7 +39,7 @@
--- ./deps/uv/uv.gyp 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/uv/uv.gyp.mod 2021-06-18 20:21:23.955642417 +0530
@@ -40,7 +40,7 @@
{
'target_name': 'libuv',
'type': '<(uv_library)',
@ -10,7 +9,7 @@ diff -u -r ../node-v9.7.1/deps/uv/uv.gyp ./deps/uv/uv.gyp
'include',
'src/',
],
@@ -54,7 +54,7 @@
@@ -55,7 +55,7 @@
'<@(shared_unix_defines)',
'<@(shared_zos_defines)',
],

View File

@ -0,0 +1,11 @@
--- ./deps/v8/BUILD.gn 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/v8/BUILD.gn.mod 2021-07-17 17:32:54.134091233 +0530
@@ -17,6 +17,8 @@
import("gni/snapshot_toolchain.gni")
import("gni/v8.gni")
+v8_target_cpu = getenv("DEST_CPU")
+
# Specifies if the target build is a simulator build. Comparing target cpu
# with v8 target cpu to not affect simulator builds for making cross-compile
# snapshots.

View File

@ -1,7 +1,6 @@
diff -u -r ../node-v14.0.0/deps/v8/src/flags/flag-definitions.h ./deps/v8/src/flags/flag-definitions.h
--- ../node-v14.0.0/deps/v8/src/flags/flag-definitions.h 2020-04-21 11:38:50.000000000 +0000
+++ ./deps/v8/src/flags/flag-definitions.h 2020-04-28 23:22:24.894254000 +0000
@@ -1555,7 +1555,7 @@
--- ./deps/v8/src/flags/flag-definitions.h 2021-06-03 07:15:31.000000000 +0530
+++ ./deps/v8/src/flags/flag-definitions.h.mod 2021-06-18 20:24:38.915642342 +0530
@@ -1842,7 +1842,7 @@
#undef DEFINE_PERF_PROF_BOOL
#undef DEFINE_PERF_PROF_IMPLICATION

View File

@ -1,7 +1,6 @@
diff -u -r ../node-v12.9.0/deps/v8/src/logging/log.cc ./deps/v8/src/logging/log.cc
--- ../node-v12.9.0/deps/v8/src/logging/log.cc 2019-08-20 17:14:50.000000000 +0000
+++ ./deps/v8/src/logging/log.cc 2019-08-24 22:39:52.426124955 +0000
@@ -280,7 +280,7 @@
--- ./deps/v8/src/logging/log.cc 2021-06-03 07:15:31.000000000 +0530
+++ ./deps/v8/src/logging/log.cc.mod 2021-06-18 20:27:34.605642275 +0530
@@ -291,7 +291,7 @@
FILE* perf_output_handle_;
};

View File

@ -1,6 +1,5 @@
diff -uNr node-v12.3.1/deps/uv/src/unix/sysinfo-memory.c node-v12.3.1.mod/deps/uv/src/unix/sysinfo-memory.c
--- node-v12.3.1/deps/uv/src/unix/sysinfo-memory.c 2019-05-22 15:21:52.000000000 +0300
+++ node-v12.3.1.mod/deps/uv/src/unix/sysinfo-memory.c 2019-05-28 15:37:28.698418026 +0300
--- ./deps/uv/src/unix/sysinfo-memory.c 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/uv/src/unix/sysinfo-memory.c.mod 2021-06-18 20:31:00.255642197 +0530
@@ -25,6 +25,7 @@
#include <stdint.h>
#include <sys/sysinfo.h>
@ -9,8 +8,11 @@ diff -uNr node-v12.3.1/deps/uv/src/unix/sysinfo-memory.c node-v12.3.1.mod/deps/u
uint64_t uv_get_free_memory(void) {
struct sysinfo info;
@@ -40,3 +41,4 @@
return (uint64_t) info.totalram * info.mem_unit;
@@ -32,6 +33,7 @@
return (uint64_t) info.freeram * info.mem_unit;
return 0;
}
+#endif
uint64_t uv_get_total_memory(void) {
struct sysinfo info;

View File

@ -1,7 +1,6 @@
diff -u -r ../node-v6.2.0/lib/child_process.js ./lib/child_process.js
--- ../node-v6.2.0/lib/child_process.js 2016-05-17 15:53:06.000000000 -0400
+++ ./lib/child_process.js 2016-05-18 16:31:45.574685443 -0400
@@ -335,7 +335,7 @@
--- ./lib/child_process.js 2021-06-03 07:15:32.000000000 +0530
+++ ./lib/child_process.js.mod 2021-06-18 20:32:47.215642156 +0530
@@ -520,7 +520,7 @@
if (typeof options.shell === 'string')
file = options.shell;
else if (process.platform === 'android')

View File

@ -1,12 +1,11 @@
diff -u -r ../node-v10.9.0/lib/os.js ./lib/os.js
--- ../node-v10.9.0/lib/os.js 2018-08-15 13:53:34.000000000 +0000
+++ ./lib/os.js 2018-08-23 20:42:39.611186774 +0000
@@ -130,7 +130,7 @@
--- ./lib/os.js 2021-06-03 07:15:32.000000000 +0530
+++ ./lib/os.js.mod 2021-06-18 20:34:28.215642118 +0530
@@ -183,7 +183,7 @@
path = safeGetenv('TMPDIR') ||
safeGetenv('TMP') ||
safeGetenv('TEMP') ||
- '/tmp';
+ '@TERMUX_PREFIX@/tmp';
if (path.length > 1 && path.endsWith('/'))
path = path.slice(0, -1);
if (path.length > 1 && StringPrototypeEndsWith(path, '/'))
path = StringPrototypeSlice(path, 0, -1);
}

View File

@ -1,6 +1,5 @@
diff -uNr node-v14.0.0/deps/v8/BUILD.gn node-v14.0.0.mod/deps/v8/BUILD.gn
--- node-v14.0.0/deps/v8/BUILD.gn 2020-04-21 11:38:50.000000000 +0000
+++ node-v14.0.0.mod/deps/v8/BUILD.gn 2020-05-07 14:11:12.247429516 +0000
--- ./deps/v8/BUILD.gn 2021-06-03 07:15:30.000000000 +0530
+++ ./deps/v8/BUILD.gn.mod 2021-06-18 20:42:14.845641940 +0530
@@ -28,7 +28,7 @@
declare_args() {
@ -10,27 +9,3 @@ diff -uNr node-v14.0.0/deps/v8/BUILD.gn node-v14.0.0.mod/deps/v8/BUILD.gn
# Dynamically set an additional dependency from v8/custom_deps.
v8_custom_deps = ""
diff -uNr node-v14.0.0/deps/v8/infra/mb/mb_config.pyl node-v14.0.0.mod/deps/v8/infra/mb/mb_config.pyl
--- node-v14.0.0/deps/v8/infra/mb/mb_config.pyl 2020-04-21 11:38:50.000000000 +0000
+++ node-v14.0.0.mod/deps/v8/infra/mb/mb_config.pyl 2020-05-07 14:12:44.653746359 +0000
@@ -565,7 +565,7 @@
'mixins': {
'android': {
- 'gn_args': 'target_os="android" v8_android_log_stdout=true',
+ 'gn_args': 'target_os="android" v8_android_log_stdout=false',
},
'android_strip_outputs': {
diff -uNr node-v14.0.0/src/debug_utils.cc node-v14.0.0.mod/src/debug_utils.cc
--- node-v14.0.0/src/debug_utils.cc 2020-04-21 11:38:51.000000000 +0000
+++ node-v14.0.0.mod/src/debug_utils.cc 2020-05-07 14:12:00.694741330 +0000
@@ -500,7 +500,7 @@
WriteConsoleW(handle, wbuf.data(), n, nullptr, nullptr);
return;
-#elif defined(__ANDROID__)
+#elif defined(__ANDROID__) && !defined(__TERMUX__)
if (file == stderr) {
__android_log_print(ANDROID_LOG_ERROR, "nodejs", "%s", str.data());
return;

View File

@ -1,15 +1,17 @@
--- ./node.gyp.orig 2020-10-17 18:07:04.114992036 +0000
+++ ./node.gyp 2020-10-17 18:30:04.575629963 +0000
@@ -1201,101 +1201,6 @@
}],
diff -uNr node-v16.6.1/node.gyp node-v16.6.1.mod/node.gyp
--- node-v16.6.1/node.gyp 2021-08-03 05:54:26.000000000 +0000
+++ node-v16.6.1.mod/node.gyp 2021-08-07 05:43:34.342341704 +0000
@@ -1062,107 +1062,6 @@
],
}, # fuzz_env
- {
{
- 'target_name': 'cctest',
- 'type': 'executable',
-
- 'dependencies': [
- '<(node_lib_target_name)',
- 'deps/googletest/googletest.gyp:gtest',
- 'deps/googletest/googletest.gyp:gtest_main',
- 'deps/histogram/histogram.gyp:histogram',
- 'deps/uvwasi/uvwasi.gyp:uvwasi',
- 'node_dtrace_header',
@ -40,8 +42,6 @@
- 'sources': [
- 'src/node_snapshot_stub.cc',
- 'src/node_code_cache_stub.cc',
- 'test/cctest/gtest/gtest-all.cc',
- 'test/cctest/gtest/gtest_main.cc',
- 'test/cctest/node_test_fixture.cc',
- 'test/cctest/node_test_fixture.h',
- 'test/cctest/test_aliased_buffer.cc',
@ -49,7 +49,9 @@
- 'test/cctest/test_base_object_ptr.cc',
- 'test/cctest/test_node_postmortem_metadata.cc',
- 'test/cctest/test_environment.cc',
- 'test/cctest/test_js_native_api_v8.cc',
- 'test/cctest/test_linked_binding.cc',
- 'test/cctest/test_node_api.cc',
- 'test/cctest/test_per_process.cc',
- 'test/cctest/test_platform.cc',
- 'test/cctest/test_json_utils.cc',
@ -64,6 +66,9 @@
- 'defines': [
- 'HAVE_OPENSSL=1',
- ],
- 'sources': [
- 'test/cctest/test_node_crypto.cc',
- ]
- }],
- ['v8_enable_inspector==1', {
- 'sources': [
@ -99,6 +104,8 @@
- }],
- ],
- }, # cctest
{
-
- {
'target_name': 'embedtest',
'type': 'executable',

View File

@ -1,29 +0,0 @@
--- ../node/deps/npm/node_modules/cacache/lib/util/move-file.js 2017-10-22 19:30:25.778456404 +0200
+++ ./deps/npm/node_modules/cacache/lib/util/move-file.js 2017-10-22 20:41:18.021337095 +0200
@@ -4,6 +4,7 @@
const BB = require('bluebird')
const chmod = BB.promisify(fs.chmod)
const unlink = BB.promisify(fs.unlink)
+const access = BB.promisify(fs.access)
let move
let pinflight
@@ -18,6 +19,18 @@
// content their own way.
//
// Note that, as the name suggests, this strictly only supports file moves.
+
+
+ // Calling link() on android is not allowed, we get a SELinux security exception
+ if(process.platform === 'android') {
+ return access(dest, fs.constants.F_OK)
+ .catch(err => {
+ if (!move) { move = require('move-concurrently') }
+ return move(src, dest, { BB, fs })
+ .then(() => chmod(dest, '0444'))
+ })
+ }
+
return BB.fromNode(cb => {
fs.link(src, dest, err => {
if (err) {

View File

@ -1,12 +0,0 @@
diff -u -r ../node-v6.0.0/src/cares_wrap.cc ./src/cares_wrap.cc
--- ../node-v6.0.0/src/cares_wrap.cc 2016-04-26 15:50:22.000000000 -0400
+++ ./src/cares_wrap.cc 2016-05-02 00:24:26.349502775 -0400
@@ -15,8 +15,7 @@
#include <stdlib.h>
#include <string.h>
-#if defined(__ANDROID__) || \
- defined(__MINGW32__) || \
+#if defined(__MINGW32__) || \
defined(__OpenBSD__) || \
defined(_MSC_VER)

View File

@ -0,0 +1,12 @@
--- ./src/cares_wrap.h 2021-06-03 07:15:32.000000000 +0530
+++ ./src/cares_wrap.h.mod 2021-06-19 08:34:10.153760365 +0530
@@ -22,8 +22,7 @@
# include <netdb.h>
#endif // __POSIX__
-#if defined(__ANDROID__) || \
- defined(__MINGW32__) || \
+#if defined(__MINGW32__) || \
defined(__OpenBSD__) || \
defined(_MSC_VER)

View File

@ -1,7 +1,6 @@
diff -u -r ../node-v11.7.0/src/node_internals.h ./src/node_internals.h
--- ../node-v11.7.0/src/node_internals.h 2019-01-17 21:27:16.000000000 +0000
+++ ./src/node_internals.h 2019-01-18 22:44:06.207542176 +0000
@@ -358,7 +358,7 @@
--- ./src/node_internals.h 2021-06-03 07:15:32.000000000 +0530
+++ ./src/node_internals.h.mod 2021-06-18 20:49:41.375641769 +0530
@@ -286,7 +286,7 @@
// Functions defined in node.cc that are exposed via the bootstrapper object

View File

@ -1,11 +1,10 @@
diff -u -r ../node-v6.3.1/src/node_main.cc ./src/node_main.cc
--- ../node-v6.3.1/src/node_main.cc 2016-07-21 16:44:43.000000000 -0400
+++ ./src/node_main.cc 2016-07-23 13:53:57.530095071 -0400
@@ -54,6 +54,10 @@
--- ./src/node_main.cc 2021-06-03 07:15:32.000000000 +0530
+++ ./src/node_main.cc.mod 2021-06-18 21:13:57.512327727 +0530
@@ -124,6 +124,10 @@
// calls elsewhere in the program (e.g., any logging from V8.)
setvbuf(stdout, nullptr, _IONBF, 0);
setvbuf(stderr, nullptr, _IONBF, 0);
+ if (getenv("TMPDIR") == NULL) {
+ if(getenv("TMPDIR") == NULL) {
+ // Give javascript programs (such as updated versions of npm) a working tmpdir.
+ putenv("TMPDIR=@TERMUX_PREFIX@/tmp");
+ }

View File

@ -1,11 +1,10 @@
diff -u -r ../node-v12.9.0/tools/v8_gypfiles/v8.gyp ./tools/v8_gypfiles/v8.gyp
--- ../node-v12.9.0/tools/v8_gypfiles/v8.gyp 2019-08-20 17:14:53.000000000 +0000
+++ ./tools/v8_gypfiles/v8.gyp 2019-08-24 22:02:57.943558855 +0000
@@ -1010,6 +1010,7 @@
--- ./tools/v8_gypfiles/v8.gyp 2021-06-03 07:15:33.000000000 +0530
+++ ./tools/v8_gypfiles/v8.gyp.mod 2021-06-18 21:18:09.722327631 +0530
@@ -928,6 +928,7 @@
'<(V8_ROOT)/src/base/platform/platform-posix.h',
'<(V8_ROOT)/src/base/platform/platform-posix-time.cc',
'<(V8_ROOT)/src/base/platform/platform-posix-time.h',
+ '<(V8_ROOT)/src/base/platform/platform-linux.cc',
+ '<(V8_ROOT)/src/base/platform/platform-linux.h',
],
'conditions': [
['_toolset=="host"', {
'link_settings': {
'target_conditions': [

View File

@ -1,75 +0,0 @@
diff -uNr ./deps/v8/src/objects/js-list-format.cc ./deps/v8/src/objects/js-list-format.cc.mod
--- ./deps/v8/src/objects/js-list-format.cc 2021-06-16 14:17:02.740441957 +0530
+++ ./deps/v8/src/objects/js-list-format.cc.mod 2021-06-16 14:14:03.766819789 +0530
@@ -29,46 +29,27 @@
namespace internal {
namespace {
-const char* kStandard = "standard";
-const char* kOr = "or";
-const char* kUnit = "unit";
-const char* kStandardShort = "standard-short";
-const char* kOrShort = "or-short";
-const char* kUnitShort = "unit-short";
-const char* kStandardNarrow = "standard-narrow";
-const char* kOrNarrow = "or-narrow";
-const char* kUnitNarrow = "unit-narrow";
-const char* GetIcuStyleString(JSListFormat::Style style,
- JSListFormat::Type type) {
+UListFormatterWidth GetIcuWidth(JSListFormat::Style style) {
+ switch (style) {
+ case JSListFormat::Style::LONG:
+ return ULISTFMT_WIDTH_WIDE;
+ case JSListFormat::Style::SHORT:
+ return ULISTFMT_WIDTH_SHORT;
+ case JSListFormat::Style::NARROW:
+ return ULISTFMT_WIDTH_NARROW;
+ }
+ UNREACHABLE();
+}
+
+UListFormatterType GetIcuType(JSListFormat::Type type) {
switch (type) {
case JSListFormat::Type::CONJUNCTION:
- switch (style) {
- case JSListFormat::Style::LONG:
- return kStandard;
- case JSListFormat::Style::SHORT:
- return kStandardShort;
- case JSListFormat::Style::NARROW:
- return kStandardNarrow;
- }
+ return ULISTFMT_TYPE_AND;
case JSListFormat::Type::DISJUNCTION:
- switch (style) {
- case JSListFormat::Style::LONG:
- return kOr;
- case JSListFormat::Style::SHORT:
- return kOrShort;
- case JSListFormat::Style::NARROW:
- return kOrNarrow;
- }
+ return ULISTFMT_TYPE_OR;
case JSListFormat::Type::UNIT:
- switch (style) {
- case JSListFormat::Style::LONG:
- return kUnit;
- case JSListFormat::Style::SHORT:
- return kUnitShort;
- case JSListFormat::Style::NARROW:
- return kUnitNarrow;
- }
+ return ULISTFMT_TYPE_UNITS;
}
UNREACHABLE();
}
@@ -143,7 +124,7 @@
icu::Locale icu_locale = r.icu_locale;
UErrorCode status = U_ZERO_ERROR;
icu::ListFormatter* formatter = icu::ListFormatter::createInstance(
- icu_locale, GetIcuStyleString(style_enum, type_enum), status);
+ icu_locale, GetIcuType(type_enum), GetIcuWidth(style_enum), status);
if (U_FAILURE(status) || formatter == nullptr) {
delete formatter;
THROW_NEW_ERROR(isolate, NewRangeError(MessageTemplate::kIcuError),