Skip to content

Commit

Permalink
build: Don't add -latomic for clang
Browse files Browse the repository at this point in the history
compiler-rt supports `__atomic_is_lock_free` since LLVM 12[0]. Requiring
`-latomic` on clang builds introduces a dependency on libgcc, which is
often undesirable on LLVM-based build environments. This change makes
sure it's never added in clang builds, so it can use the compiler-rt's
implementation, making it possible to build Node.js on Linux systems
with LLVM as the main toolchain, without having to install GCC.

compiler-rt's `__atomic_is_lock_free` works on all architectures, so
there is no need to to link libatomic for mips64, ppc, arm, riscv etc.
as well, as long as clang is used.

Similar patch was already adopted or discussed in:

* Chimera Linux
  * https://github.com/chimera-linux/cports/blob/master/contrib/nodejs/patches/no-libatomic.patch
* Gentoo (LLVM profiles)
  * https://bugs.gentoo.org/869992
  * https://bugs.gentoo.org/911340
  * gentoo/gentoo#33141

[0] llvm/llvm-project@00530de
  • Loading branch information
vadorovsky committed Aug 10, 2024
1 parent 90d91ab commit e5b90cd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
3 changes: 0 additions & 3 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,6 @@
'-Wl,-bnoerrmsg',
],
}],
['OS=="linux" and clang==1', {
'libraries': ['-latomic'],
}],
],
},

Expand Down
2 changes: 1 addition & 1 deletion tools/v8_gypfiles/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@
}],
# 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"]', {
['clang==0 and v8_current_cpu in ["mips64", "mips64el", "ppc", "arm", "riscv64", "loong64"]', {
'link_settings': {
'libraries': ['-latomic', ],
},
Expand Down

0 comments on commit e5b90cd

Please sign in to comment.