From 0341745519cb05ac7a48f313f3fb382f9a75afc3 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 3 Feb 2025 21:44:36 +0900 Subject: [PATCH 1/2] build: remove explicit linker call to libm on macOS /usr/lib/libm.tbd is available via libSystem.*.dylib and reexports sanitizer symbols. When building for asan this becomes an issue as the linker will resolve the symbols from the system library rather from libclang_rt.* For V8 that rely on specific version of these symbols that get bundled as part of clang, for ex: https://source.chromium.org/chromium/chromium/src/+/main:v8/src/heap/cppgc/platform.cc;l=93-97 accepting nullptr for shadow_offset in `asan_get_shadow_mapping`, linking to system version that doesn't support this will lead to a crash. Clang driver eventually links with `-lSystem` https://github.com/llvm/llvm-project/blob/e82f93890daefeb38fe2a22ee3db87a89948ec57/clang/lib/Driver/ToolChains/Darwin.cpp#L1628-L1631, this is done after linking the sanitizer libraries which ensures right order of resolution for the symbols. --- deps/brotli/unofficial.gni | 2 +- deps/uv/unofficial.gni | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/brotli/unofficial.gni b/deps/brotli/unofficial.gni index 5e07e106672a04..91001fa43ea480 100644 --- a/deps/brotli/unofficial.gni +++ b/deps/brotli/unofficial.gni @@ -25,7 +25,7 @@ template("brotli_gn_build") { } else if (target_os == "freebsd") { defines = [ "OS_FREEBSD" ] } - if (!is_win) { + if (is_linux) { libs = [ "m" ] } if (is_clang || !is_win) { diff --git a/deps/uv/unofficial.gni b/deps/uv/unofficial.gni index 348d2f0703e47c..864414475fa69c 100644 --- a/deps/uv/unofficial.gni +++ b/deps/uv/unofficial.gni @@ -87,11 +87,11 @@ template("uv_gn_build") { ] } if (is_posix) { - libs = [ "m" ] ldflags = [ "-pthread" ] } if (is_linux) { libs += [ + "m", "dl", "rt", ] From 5f41cb18974b09d26e5f962ee144f909f3378093 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 3 Feb 2025 23:53:09 +0900 Subject: [PATCH 2/2] build: gyp exclude libm linking on macOS --- deps/brotli/brotli.gyp | 7 ++++--- deps/uv/uv.gyp | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/deps/brotli/brotli.gyp b/deps/brotli/brotli.gyp index f82660d82c6cfa..f1f487945e5727 100644 --- a/deps/brotli/brotli.gyp +++ b/deps/brotli/brotli.gyp @@ -59,14 +59,15 @@ 'defines': [ 'OS_MACOSX' ] + }, { + 'libraries': [ + '-lm', + ], }], ], 'direct_dependent_settings': { 'include_dirs': [ 'c/include' ] }, - 'libraries': [ - '-lm', - ], 'sources': [ '<@(brotli_sources)', ] diff --git a/deps/uv/uv.gyp b/deps/uv/uv.gyp index fea86b4af7826e..8c8d7d00fd2913 100644 --- a/deps/uv/uv.gyp +++ b/deps/uv/uv.gyp @@ -220,7 +220,6 @@ '<@(uv_sources_posix)', ], 'link_settings': { - 'libraries': [ '-lm' ], 'conditions': [ ['OS=="solaris"', { 'ldflags': [ '-pthreads' ], @@ -231,6 +230,11 @@ ['OS != "solaris" and OS != "android" and OS != "zos"', { 'ldflags': [ '-pthread' ], }], + ['OS!="mac"', { + 'libraries': [ + '-lm' + ], + }], ], }, 'conditions': [