Files
meta-openembedded/meta-oe/recipes-devtools/nodejs/nodejs/libatomic.patch
T
Gyorgy Sarvari bfbd962813 nodejs: extend libatomic patch to x86
This patch isn't intended to introduce new behavior, rather it
changes the order of some existing LDFLAGS to fix a workaround that
stopped working at some point in the past.

LDFLAGS:x86 contains libatomic, because linking with this library
is required for this platform.

However when gyp links, it invokes the following (pseudo-)command:
$LD $LDFLAGS $RESOURCES_TO_LINK $EXTRA_LIBS $EXTRA_LDFLAGS

The EXTRA* arguments are coming from the gyp config. Since
LDFLAGS appears very early in the command, libatomic also
appears early amongst the resources, and the linker couldn't
find the relevant symbols when compiled for x86 platform (as
it was processed the very last):

| [...] undefined reference to `__atomic_compare_exchange'

Using this patch the library appears at the end, along with
the other EXTRA_LIBS, after the list of linked resources,
allowing linking to succeed.

Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
2026-02-06 10:06:18 -08:00

97 lines
3.2 KiB
Diff

From 15e751e4b79475fb34e4b32a3ca54119b20c564a Mon Sep 17 00:00:00 2001
From: Hongxu Jia <hongxu.jia@windriver.com>
Date: Sat, 17 Aug 2024 21:33:18 +0800
Subject: [PATCH] link libatomic for clang conditionally
Clang emits atomic builtin, explicitly link libatomic conditionally:
- For target build, always link -latomic for clang as usual
- For host build, if host and target have same bit width, cross compiling
is enabled, and host toolchain is gcc which does not link -latomic;
if host and target have different bit width, no cross compiling,
host build is the same with target build that requires to link
-latomic;
Fix:
|tmp-glibc/work/core2-64-wrs-linux/nodejs/20.13.0/node-v20.13.0/out/Release/node_js2c: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory
Upstream-Status: Inappropriate [OE specific]
Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Added libatomic library explicitly to x86 targets.
Signed-off-by: Gyorgy Sarvari <skandigraun@gmail.com>
---
node.gyp | 13 ++++++++++++-
tools/v8_gypfiles/v8.gyp | 15 ++++++++++++---
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/node.gyp b/node.gyp
index b425f443..f296f35c 100644
--- a/node.gyp
+++ b/node.gyp
@@ -503,7 +503,18 @@
],
}],
['OS=="linux" and clang==1', {
- 'libraries': ['-latomic'],
+ 'target_conditions': [
+ ['_toolset=="host"', {
+ 'conditions': [
+ ['"<!(echo $HOST_AND_TARGET_SAME_WIDTH)"=="0"', {
+ 'libraries': ['-latomic'],
+ }],
+ ],
+ }],
+ ['_toolset=="target"', {
+ 'libraries': ['-latomic'],
+ }],
+ ],
}],
],
},
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
index b23263cf..dcabf4ca 100644
--- a/tools/v8_gypfiles/v8.gyp
+++ b/tools/v8_gypfiles/v8.gyp
@@ -1348,9 +1348,18 @@
# Platforms that don't have Compare-And-Swap (CAS) support need to link atomic library
# to implement atomic memory access
['v8_current_cpu in ["mips64", "mips64el", "ppc", "arm", "riscv64", "loong64"]', {
- 'link_settings': {
- 'libraries': ['-latomic', ],
- },
+ 'target_conditions': [
+ ['_toolset=="host"', {
+ 'conditions': [
+ ['"<!(echo $HOST_AND_TARGET_SAME_WIDTH)"=="0"', {
+ 'libraries': ['-latomic'],
+ }],
+ ],
+ }],
+ ['_toolset=="target"', {
+ 'libraries': ['-latomic', ],
+ }],
+ ],
}],
],
}, # v8_base_without_compiler
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
index cb82d4f15bc..65cb123b7bf 100644
--- a/tools/v8_gypfiles/v8.gyp
+++ b/tools/v8_gypfiles/v8.gyp
@@ -1820,6 +1820,13 @@
['enable_lto=="true"', {
'ldflags': [ '-fno-lto' ],
}],
+ # For future patch-rebases: this hunk is in mksnapshot target.
+ # ia32 includes x86 also
+ ['v8_target_arch=="ia32"', {
+ 'link_settings': {
+ 'libraries': ['-latomic']
+ }
+ }],
],
}, # mksnapshot
{