diff options
-rw-r--r-- | meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch | 64 | ||||
-rw-r--r-- | meta-oe/recipes-devtools/nodejs/nodejs_22.15.0.bb | 1 |
2 files changed, 65 insertions, 0 deletions
diff --git a/meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch b/meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch new file mode 100644 index 0000000000..e372911193 --- /dev/null +++ b/meta-oe/recipes-devtools/nodejs/nodejs/zlib-fix-pointer-alignment.patch | |||
@@ -0,0 +1,64 @@ | |||
1 | From dc035bbc9b310ff8067bc0dad22230978489c061 Mon Sep 17 00:00:00 2001 | ||
2 | From: jhofstee <jeroen@myspectrum.nl> | ||
3 | Date: Wed, 9 Apr 2025 12:24:13 +0200 | ||
4 | Subject: [PATCH] zlib: fix pointer alignment | ||
5 | MIME-Version: 1.0 | ||
6 | Content-Type: text/plain; charset=UTF-8 | ||
7 | Content-Transfer-Encoding: 8bit | ||
8 | |||
9 | The function AllocForBrotli prefixes the allocated memory with its | ||
10 | size, and returns a pointer to the region after it. This pointer can | ||
11 | however no longer be suitably aligned. Correct this by allocating | ||
12 | the maximum of the the size of the size_t and the max alignment. | ||
13 | |||
14 | On Arm 32bits the size_t is 4 bytes long, but the alignment is 8 for | ||
15 | some NEON instructions. When Brotli is compiled with optimizations | ||
16 | enabled newer GCC versions will use the NEON instructions and trigger | ||
17 | a bus error killing node. | ||
18 | |||
19 | see https://github.com/google/brotli/issues/1159 | ||
20 | |||
21 | PR-URL: https://github.com/nodejs/node/pull/57727 | ||
22 | Reviewed-By: Shelley Vohr <shelley.vohr@gmail.com> | ||
23 | Reviewed-By: Tobias Nießen <tniessen@tnie.de> | ||
24 | Reviewed-By: Daniel Lemire <daniel@lemire.me> | ||
25 | Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> | ||
26 | |||
27 | Upstream-Status: Backport [https://github.com/nodejs/node/commit/dc035bbc9b310ff8067bc0dad22230978489c061] | ||
28 | --- | ||
29 | src/node_zlib.cc | 8 +++++--- | ||
30 | 1 file changed, 5 insertions(+), 3 deletions(-) | ||
31 | |||
32 | diff --git a/src/node_zlib.cc b/src/node_zlib.cc | ||
33 | index 0b7c47b326c7c5..7e6b38ecd1aa36 100644 | ||
34 | --- a/src/node_zlib.cc | ||
35 | +++ b/src/node_zlib.cc | ||
36 | @@ -608,7 +608,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { | ||
37 | } | ||
38 | |||
39 | static void* AllocForBrotli(void* data, size_t size) { | ||
40 | - size += sizeof(size_t); | ||
41 | + constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t)); | ||
42 | + size += offset; | ||
43 | CompressionStream* ctx = static_cast<CompressionStream*>(data); | ||
44 | char* memory = UncheckedMalloc(size); | ||
45 | if (memory == nullptr) [[unlikely]] { | ||
46 | @@ -617,7 +618,7 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { | ||
47 | *reinterpret_cast<size_t*>(memory) = size; | ||
48 | ctx->unreported_allocations_.fetch_add(size, | ||
49 | std::memory_order_relaxed); | ||
50 | - return memory + sizeof(size_t); | ||
51 | + return memory + offset; | ||
52 | } | ||
53 | |||
54 | static void FreeForZlib(void* data, void* pointer) { | ||
55 | @@ -625,7 +626,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork { | ||
56 | return; | ||
57 | } | ||
58 | CompressionStream* ctx = static_cast<CompressionStream*>(data); | ||
59 | - char* real_pointer = static_cast<char*>(pointer) - sizeof(size_t); | ||
60 | + constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t)); | ||
61 | + char* real_pointer = static_cast<char*>(pointer) - offset; | ||
62 | size_t real_size = *reinterpret_cast<size_t*>(real_pointer); | ||
63 | ctx->unreported_allocations_.fetch_sub(real_size, | ||
64 | std::memory_order_relaxed); | ||
diff --git a/meta-oe/recipes-devtools/nodejs/nodejs_22.15.0.bb b/meta-oe/recipes-devtools/nodejs/nodejs_22.15.0.bb index 07ea8c083d..68c96cc1fb 100644 --- a/meta-oe/recipes-devtools/nodejs/nodejs_22.15.0.bb +++ b/meta-oe/recipes-devtools/nodejs/nodejs_22.15.0.bb | |||
@@ -29,6 +29,7 @@ SRC_URI = "http://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz \ | |||
29 | file://0001-deps-disable-io_uring-support-in-libuv.patch \ | 29 | file://0001-deps-disable-io_uring-support-in-libuv.patch \ |
30 | file://0001-positional-args.patch \ | 30 | file://0001-positional-args.patch \ |
31 | file://0001-custom-env.patch \ | 31 | file://0001-custom-env.patch \ |
32 | file://zlib-fix-pointer-alignment.patch \ | ||
32 | file://run-ptest \ | 33 | file://run-ptest \ |
33 | " | 34 | " |
34 | SRC_URI:append:class-target = " \ | 35 | SRC_URI:append:class-target = " \ |