Skip to content

Commit

Permalink
[libnode] Update to v18.12.1 (Latest LTS) and add scripts for win64 a…
Browse files Browse the repository at this point in the history
…nd mac builds. (#5859)

* Update for building NodeJS v18.12.1. Add scripts for w64 and mac.

* Try building with trap-handler on aarch64-linux.

* chmod +x

* Disable pointer authentication on arm 64. (nodejs/node#42888)

* Include a header to use `memalign`.
  • Loading branch information
sunoru committed Nov 15, 2022
1 parent 92c8559 commit 2fb1133
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 65 deletions.
67 changes: 55 additions & 12 deletions L/libnode/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,86 @@
using BinaryBuilder, Pkg

name = "libnode"
version = v"16.17.0"
version = v"18.12.1"

# Collection of sources required to complete build
sources = [
ArchiveSource("https://nodejs.org/dist/v$(version)/node-v$(version).tar.gz", "2a2e6262739741f98ab81648a50891861dbf66f12413b93f1a97b4c71570611e"),
ArchiveSource("https://nodejs.org/dist/v$(version)/node-v$(version).tar.gz", "ba8174dda00d5b90943f37c6a180a1d37c861d91e04a4cb38dc1c0c74981c186"),
ArchiveSource(
"https://github.com/sunoru/libnode/releases/download/v$(version)/libnode-v$(version)-Windows-x64.zip",
"675d4b4b335db8d1ab047ea55e09488e0b1c51008f42ee09e4ef7cbca978b2ff",
unpack_target = "x86_64-w64-mingw32"
),
ArchiveSource(
"https://github.com/sunoru/libnode/releases/download/v$(version)/libnode-v$(version)-macOS-x64.zip",
"a19cbfceaeae3e98f982e06dc232f8a228e021941a9ead79aef9bc1ca0fc2f50",
unpack_target = "x86_64-apple-darwin14"
),
DirectorySource("bundled")
]


# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir
w64_script = raw"""
cd ${target}/libnode-*
cd node-*
chmod +x *.cmd *.exe
mkdir -p ${bindir}
mv * ${bindir}/
mv ${bindir}/include ${prefix}
mv ${bindir}/LICENSE .
install_license ./LICENSE
"""

mac_script = raw"""
cd ${target}/libnode-*
chmod +x bin/*
mv * ${prefix}/
mv ${prefix}/LICENSE .
install_license ./LICENSE
"""

linux_script = raw"""
cd node-*
export CC_host=$HOSTCC
export CXX_host=$HOSTCXX
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/node_main.cc.patch"
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/trap-handler.h.patch"
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/configure.py.patch"
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/node.gypi.patch"
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/node_credentials.cc.patch"
atomic_patch -p1 "${WORKSPACE}/srcdir/patches/test_crypto_clienthello.cc.patch"
# Build & install libnode
if [[ $target == $MACHTYPE ]]
then
./configure --prefix=${prefix} --shared --no-cross-compiling
else
DEST_CPU=x86_64
if [[ $target == *aarch64* ]]; then DEST_CPU=arm64; fi
DEST_OS=linux
./configure --prefix=${prefix} --shared --cross-compiling --dest-cpu=$DEST_CPU --dest-os=$DEST_OS
./configure --prefix=${prefix} --shared --cross-compiling --dest-cpu=$DEST_CPU --dest-os=linux
fi
export LDFLAGS=-lrt
export CPPFLAGS=-D__STDC_FORMAT_MACROS
make -j`nproc`
make install
cp ./out/Release/node ${bindir}
install_license ./LICENSE
"""

# Bash recipe for building across all platforms
script = """
cd \$WORKSPACE/srcdir
if [[ \$target == *w64* ]]
then
$w64_script
elif [[ \$target == *apple* ]]
then
$mac_script
elif [[ \$target == *linux* ]]
then
$linux_script
fi
"""



# These are the platforms we will build for by default, unless further
# platforms are passed in on the command line
# Only 64-bit Linux platforms.
Expand All @@ -52,10 +95,10 @@ platforms = [
Platform("x86_64", "linux"; libc="musl"),
Platform("aarch64", "linux"; libc="musl"),

# Platform("x86_64", "macos"),
Platform("x86_64", "macos"),
# Platform("aarch64", "macos"),

# Platform("x86_64", "windows"),
Platform("x86_64", "windows"),
]
platforms = expand_cxxstring_abis(platforms)

Expand Down
17 changes: 17 additions & 0 deletions L/libnode/bundled/patches/configure.py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/configure.py b/configure.py
index a4e5723067..60ec604454 100755
--- a/configure.py
+++ b/configure.py
@@ -1245,9 +1245,9 @@ def configure_node(o):

o['variables']['want_separate_host_toolset'] = int(cross_compiling)

- # Enable branch protection for arm64
- if target_arch == 'arm64':
- o['cflags']+=['-msign-return-address=all']
+ # # Enable branch protection for arm64
+ # if target_arch == 'arm64':
+ # o['cflags']+=['-msign-return-address=all']

if options.node_snapshot_main is not None:
if options.shared:
13 changes: 13 additions & 0 deletions L/libnode/bundled/patches/node.gypi.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node.gypi b/node.gypi
index 0b0f05322e..25ce3e14c6 100644
--- a/node.gypi
+++ b/node.gypi
@@ -327,7 +327,7 @@
'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ],
}],
[ 'OS=="linux"', {
- 'libraries!': [
+ 'libraries': [
'-lrt'
],
}],
37 changes: 37 additions & 0 deletions L/libnode/bundled/patches/node_credentials.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
diff --git a/src/node_credentials.cc b/src/node_credentials.cc
index 115c2fc877..946f39f7b4 100644
--- a/src/node_credentials.cc
+++ b/src/node_credentials.cc
@@ -13,7 +13,13 @@
#endif
#ifdef __linux__
#include <linux/capability.h>
-#include <sys/auxv.h>
+#include <elf.h>
+#ifdef __LP64__
+#define Elf_auxv_t Elf64_auxv_t
+#else
+#define Elf_auxv_t Elf32_auxv_t
+#endif // __LP64__
+extern char** environ;
#include <sys/syscall.h>
#endif // __linux__

@@ -38,8 +44,15 @@ bool linux_at_secure() {
// and returns the correct value, e.g. even in static
// initialization code in other files.
#ifdef __linux__
- static const bool value = getauxval(AT_SECURE);
- return value;
+ char** envp = environ;
+ while (*envp++ != nullptr) {}
+ Elf_auxv_t* auxv = reinterpret_cast<Elf_auxv_t*>(envp);
+ for (; auxv->a_type != AT_NULL; auxv++) {
+ if (auxv->a_type == AT_SECURE) {
+ static const bool value = auxv->a_un.a_val;
+ return value;
+ }
+ }
#else
return false;
#endif
36 changes: 0 additions & 36 deletions L/libnode/bundled/patches/node_main.cc.patch

This file was deleted.

21 changes: 21 additions & 0 deletions L/libnode/bundled/patches/test_crypto_clienthello.cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff --git a/test/cctest/test_crypto_clienthello.cc b/test/cctest/test_crypto_clienthello.cc
index 60a8e294c8..e673073dc3 100644
--- a/test/cctest/test_crypto_clienthello.cc
+++ b/test/cctest/test_crypto_clienthello.cc
@@ -16,6 +16,7 @@
// safety is violated.
#if !defined(NO_GUARD_PAGE)
#ifdef __linux__
+#include <malloc.h>
#include <sys/mman.h>
#include <unistd.h>
#if defined(_SC_PAGE_SIZE) && defined(PROT_NONE) && defined(PROT_READ) && \
@@ -54,7 +55,7 @@ class OverrunGuardedBuffer {
#ifdef USE_MPROTECT
// Place the packet right before a guard page, which, when accessed, causes
// a segmentation fault.
- alloc_base = static_cast<uint8_t*>(aligned_alloc(page, 2 * page));
+ alloc_base = static_cast<uint8_t*>(memalign(page, 2 * page));
EXPECT_NE(alloc_base, nullptr);
uint8_t* second_page = alloc_base + page;
EXPECT_EQ(mprotect(second_page, page, PROT_NONE), 0);
17 changes: 0 additions & 17 deletions L/libnode/bundled/patches/trap-handler.h.patch

This file was deleted.

0 comments on commit 2fb1133

Please sign in to comment.