Skip to content

Commit 5922b57

Browse files
committed
build: add arg to disable linking against -latomic
building using `clang` with `compiler-rt` fails with an error due to `-latomic` being added even when it is not needed: ``` ld.lld: error: unable to find library -latomic ``` Ideally, the build would run a link test to determine if `-latomic` is needed and does not add `-latomic`, when the compiler runtime provides atomic builtin. This workaround adds `--without_libatomic` to manually disable `-latomic`. Bug: #65900 Signed-off-by: Pepper Gray <hello@peppergray.xyz>
1 parent 0de4fcc commit 5922b57

5 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎BUILDING.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ may reduce build time. For more information, see the
380380
The above requires that `python` resolves to a supported version of
381381
Python. See [Prerequisites](#prerequisites).
382382

383+
> Note: When the compiler runtime provides atomic builtins, such as with compiler-rt (llvm),
384+
> passing `--without-libatomic` disables linking against `libatomic` (`-latomic`).
385+
383386
After building, setting up [firewall rules](tools/macos-firewall.sh) can avoid
384387
popups asking to accept incoming network connections when running tests.
385388

‎common.gypi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
'force_dynamic_crt%': 0,
2323
'node_use_v8_platform%': 'true',
2424
'node_use_bundled_v8%': 'true',
25+
'node_use_libatomic%': 'true',
2526
'node_module_version%': '',
2627
'node_with_ltcg%': '',
2728
'node_shared_openssl%': 'false',

‎configure.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,13 @@
11201120
default=None,
11211121
help='build without FFI (Foreign Function Interface) support')
11221122

1123+
parser.add_argument('--without-libatomic', '--without_libatomic',
1124+
action='store_true',
1125+
dest='without_libatomic',
1126+
default=None,
1127+
help='do not link against libatomic when the compiler runtime ' +
1128+
'provides atomic builtins (e.g. compiler-rt)')
1129+
11231130
parser.add_argument('--experimental-quic',
11241131
action='store_true',
11251132
dest='experimental_quic',
@@ -1907,6 +1914,7 @@ def configure_node(o):
19071914
o['variables']['node_install_corepack'] = b(options.with_corepack)
19081915
o['variables']['control_flow_guard'] = b(options.enable_cfg)
19091916
o['variables']['node_use_amaro'] = b(not options.without_amaro)
1917+
o['variables']['node_use_libatomic'] = b(not options.without_libatomic)
19101918
o['variables']['debug_node'] = b(options.debug_node)
19111919
o['variables']['debug_symbols'] = b(options.debug_symbols)
19121920
if options.debug_symbols:

‎node.gyp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@
578578
'-Wl,-bnoerrmsg',
579579
],
580580
}],
581-
['OS=="linux" and clang==1', {
581+
['OS=="linux" and clang==1 and node_use_libatomic=="true"', {
582582
'libraries': ['-latomic'],
583583
}],
584584
],

‎tools/v8_gypfiles/v8.gyp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@
14041404
# Platforms that don't have Compare-And-Swap (CAS) support need to link atomic library
14051405
# to implement atomic memory access.
14061406
# Clang needs it for some atomic operations (https://clang.llvm.org/docs/Toolchain.html#atomics-library).
1407-
['(OS=="linux" and clang==1) or (v8_current_cpu in ["mips64", "mips64el", "arm", "riscv64", "loong64"])', {
1407+
['((OS=="linux" and clang==1) or (v8_current_cpu in ["mips64", "mips64el", "arm", "riscv64", "loong64"])) and node_use_libatomic=="true"', {
14081408
'link_settings': {
14091409
'libraries': ['-latomic', ],
14101410
},

0 commit comments

Comments
 (0)