Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New V8 cannot be compiled on macOS <15 (or Xcode <16) #295

Open
targos opened this issue Dec 19, 2024 · 8 comments
Open

New V8 cannot be compiled on macOS <15 (or Xcode <16) #295

targos opened this issue Dec 19, 2024 · 8 comments

Comments

@targos
Copy link
Member

targos commented Dec 19, 2024

See https://github.com/nodejs/node-v8/actions/runs/12412846251/job/34653486549
I can cannot reproduce this error locally with macOS 15.2 (Xcode 16.2).

The code was introduced in https://chromium-review.googlesource.com/c/v8/v8/+/6105430.
Relevant lines: https://github.com/v8/v8/blob/da4e529cfddb93e7166666c447a94d173e1e682f/src/base/platform/mutex.cc#L118-L122

   sccache g++ -o /Users/runner/work/node-v8/node-v8/out/Release/obj.target/v8_libbase/deps/v8/src/base/platform/semaphore.o ../deps/v8/src/base/platform/semaphore.cc '-D_GLIBCXX_USE_CXX11_ABI=1' '-DNODE_OPENSSL_CONF_NAME=nodejs_conf' '-DNODE_OPENSSL_HAS_QUIC' '-DICU_NO_USER_DATA_OVERRIDE' '-DV8_GYP_BUILD' '-DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64' '-DBUILDING_V8_SHARED' '-D_DARWIN_USE_64_BIT_INODE=1' '-DOPENSSL_NO_PINSHARED' '-DOPENSSL_THREADS' '-DV8_TARGET_ARCH_ARM64' '-DV8_HAVE_TARGET_OS' '-DV8_TARGET_OS_MACOS' '-DV8_EMBEDDER_STRING="-node.7"' '-DENABLE_DISASSEMBLER' '-DV8_PROMISE_INTERNAL_FIELD_COUNT=1' '-DOBJECT_PRINT' '-DV8_INTL_SUPPORT' '-DV8_ATOMIC_OBJECT_FIELD_WRITES' '-DV8_ENABLE_LAZY_SOURCE_POSITIONS' '-DV8_USE_SIPHASH' '-DNDEBUG' '-DV8_WIN64_UNWINDING_INFO' '-DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH' '-DV8_USE_ZLIB' '-DV8_ENABLE_SPARKPLUG' '-DV8_ENABLE_MAGLEV' '-DV8_ENABLE_TURBOFAN' '-DV8_ENABLE_SYSTEM_INSTRUMENTATION' '-DV8_ENABLE_WEBASSEMBLY' '-DV8_ENABLE_JAVASCRIPT_PROMISE_HOOKS' '-DV8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA' '-DV8_ALLOCATION_FOLDING' '-DV8_ALLOCATION_SITE_TRACKING' '-DV8_ADVANCED_BIGINT_ALGORITHMS' '-DBUILDING_V8_BASE_SHARED' -I../deps/v8 -I../deps/v8/include -I../deps/v8/third_party/abseil-cpp  -O3 -gdwarf-2 -fno-strict-aliasing -fvisibility=hidden -mmacosx-version-min=11.0 -arch arm64 -Wall -Wendif-labels -W -Wno-unused-parameter -std=gnu++20 -stdlib=libc++ -fno-rtti -fno-exceptions -Wno-invalid-offsetof -MMD -MF /Users/runner/work/node-v8/node-v8/out/Release/.deps//Users/runner/work/node-v8/node-v8/out/Release/obj.target/v8_libbase/deps/v8/src/base/platform/semaphore.o.d.raw   -c
../deps/v8/src/base/platform/mutex.cc:119:11: error: unknown type name 'os_unfair_lock_flags_t'
    const os_unfair_lock_flags_t options = static_cast<os_unfair_lock_flags_t>(
          ^
../deps/v8/src/base/platform/mutex.cc:119:56: error: unknown type name 'os_unfair_lock_flags_t'
    const os_unfair_lock_flags_t options = static_cast<os_unfair_lock_flags_t>(
                                                       ^
2 errors generated.
@targos
Copy link
Member Author

targos commented Dec 19, 2024

@verwaest
Copy link

As long as the deployment target is correctly set it should take the right path. I guess you're setting a deployment target >= 15 while building on a system with an older OS / SDK?

@targos
Copy link
Member Author

targos commented Dec 19, 2024

@targos
Copy link
Member Author

targos commented Dec 19, 2024

/cc @codebytere, @deepak1556 In case you run into issues for Electron.

@joyeecheung
Copy link
Member

I just tried building the V8 main branch on macOS 13 and it seems it doesn't build with MacOSX13.3.sdk either. Is there any document about macOS SDK requirements for building V8?

@joyeecheung
Copy link
Member

joyeecheung commented Dec 19, 2024

It seems in the V8 upstream, this args.gn:

is_component_build = true
is_debug = true
symbol_level = 2
target_cpu = "arm64"
v8_target_cpu = "arm64"
v8_enable_sandbox = true
v8_enable_backtrace = true
v8_enable_fast_mksnapshot = true
v8_enable_slow_dchecks = true
v8_optimized_debug = false

Generates this command on macOS 13 that fails to compile

../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/v8_libbase/mutex.o.d -DBUILDING_V8_BASE_SHARED -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__ARM_NEON__=1 -DCR_XCODE_VERSION=1431 -DCR_CLANG_REVISION=\"llvmorg-20-init-13894-g8cb44859-1\" -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE -DCOMPONENT_BUILD -D_LIBCPP_INSTRUMENTED_WITH_ASAN=0 -DCR_LIBCXX_REVISION=d0ddad5b79581e19d8e1aec627bb2ad86e1554cd -DTMP_REBUILD_HACK -D_DEBUG -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DV8_TYPED_ARRAY_MAX_SIZE_IN_HEAP=64 -DCPPGC_VERIFY_HEAP -DENABLE_DISASSEMBLER -DOBJECT_PRINT -DVERIFY_HEAP -DV8_TRACE_MAPS -DV8_ENABLE_ALLOCATION_TIMEOUT -DV8_ENABLE_FORCE_SLOW_PATH -DV8_ENABLE_DOUBLE_CONST_STORE_CHECK -DV8_INTL_SUPPORT -DENABLE_HANDLE_ZAPPING -DV8_CODE_COMMENTS -DV8_ENABLE_DEBUG_CODE -DV8_ENABLE_SLOW_DEBUG_CODE_BY_DEFAULT -DV8_ENABLE_HEAP_SNAPSHOT_VERIFY -DV8_SNAPSHOT_NATIVE_CODE_COUNTERS -DV8_USE_EXTERNAL_STARTUP_DATA -DV8_ATOMIC_OBJECT_FIELD_WRITES -DV8_ENABLE_LAZY_SOURCE_POSITIONS -DV8_WIN64_UNWINDING_INFO -DV8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH -DV8_ENABLE_FUZZTEST -DV8_SHORT_BUILTIN_CALLS -DV8_EXTERNAL_CODE_SPACE -DV8_ENABLE_SPARKPLUG -DV8_ENABLE_MAGLEV -DV8_ENABLE_TURBOFAN -DV8_ENABLE_SYSTEM_INSTRUMENTATION -DV8_ENABLE_WEBASSEMBLY -DV8_ENABLE_CONTINUATION_PRESERVED_EMBEDDER_DATA -DV8_ALLOCATION_FOLDING -DV8_ALLOCATION_SITE_TRACKING -DV8_ADVANCED_BIGINT_ALGORITHMS -DV8_STATIC_ROOTS -DV8_USE_ZLIB -DV8_USE_LIBM_TRIG_FUNCTIONS -DV8_ENABLE_MAGLEV_GRAPH_PRINTER -DV8_ENABLE_SLOW_TRACING -DV8_ENABLE_EXTENSIBLE_RO_SNAPSHOT -DV8_ENABLE_BLACK_ALLOCATED_PAGES -DV8_ENABLE_LEAPTIERING -DV8_WASM_RANDOM_FUZZERS -DV8_ARRAY_BUFFER_INTERNAL_FIELD_COUNT=0 -DV8_ARRAY_BUFFER_VIEW_INTERNAL_FIELD_COUNT=0 -DV8_PROMISE_INTERNAL_FIELD_COUNT=0 -DV8_ENABLE_CHECKS -DV8_ENABLE_MEMORY_ACCOUNTING_CHECKS -DV8_COMPRESS_POINTERS -DV8_COMPRESS_POINTERS_IN_SHARED_CAGE -DV8_31BIT_SMIS_ON_64BIT_ARCH -DV8_ENABLE_SANDBOX -DV8_DEPRECATION_WARNINGS -DV8_IMMINENT_DEPRECATION_WARNINGS -DV8_HAVE_TARGET_OS -DV8_TARGET_OS_MACOS -DCPPGC_ENABLE_API_CHECKS -DCPPGC_ENABLE_SLOW_API_CHECKS -DCPPGC_CAGED_HEAP -DCPPGC_YOUNG_GENERATION -DCPPGC_POINTER_COMPRESSION -DCPPGC_ENABLE_LARGER_CAGE -DCPPGC_SLIM_WRITE_BARRIER -DV8_TARGET_ARCH_ARM64 -DDEBUG -DENABLE_SLOW_DCHECKS -DV8_RUNTIME_CALL_STATS -DUSING_V8_BASE_SHARED -DABSL_ALLOCATOR_NOTHROW=1 -DABSL_CONSUME_DLL -DABSL_FLAGS_STRIP_NAMES=0 -I../.. -Igen -I../../buildtools/third_party/libc++ -I../../include -I../../third_party/abseil-cpp -Wall -Wextra -Wimplicit-fallthrough -Wextra-semi -Wunreachable-code-aggressive -Wthread-safety -Wgnu -Wno-gnu-anonymous-struct -Wno-gnu-conditional-omitted-operand -Wno-gnu-include-next -Wno-gnu-label-as-value -Wno-gnu-redeclared-enum -Wno-gnu-statement-expression -Wno-gnu-zero-variadic-macro-arguments -Wno-zero-length-array -Wunguarded-availability -Wno-missing-field-initializers -Wno-unused-parameter -Wno-psabi -Wloop-analysis -Wno-unneeded-internal-declaration -Wno-cast-function-type -Wno-thread-safety-reference-return -Wno-nontrivial-memcall -Wshadow -Werror -fno-delete-null-pointer-checks -fno-ident -fno-strict-aliasing -fstack-protector-strong -fcolor-diagnostics -fmerge-all-constants -fno-sized-deallocation -fcrash-diagnostics-dir=../../tools/clang/crashreports -mllvm -instcombine-lower-dbg-declare=0 -mllvm -split-threshold-for-reg-with-hint=0 -ffp-contract=off -fcomplete-member-pointers --target=arm64-apple-macos -mno-outline -Wno-builtin-macro-redefined -D__DATE__= -D__TIME__= -D__TIMESTAMP__= -ffile-compilation-dir=. -no-canonical-prefixes -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -g2 -gdwarf-aranges -Xclang -debug-info-kind=limited -isysroot ../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mmacos-version-min=11.0 -Wheader-hygiene -Wstring-conversion -Wtautological-overlap-compare -Wunreachable-code -Wno-shadow -Wctad-maybe-unsupported -Wno-invalid-offsetof -Wshorten-64-to-32 -Wmissing-field-initializers -O0 -fvisibility=default -Wno-invalid-offsetof -Wenum-compare-conditional -Wno-c++11-narrowing-const-reference -Wno-missing-template-arg-list-after-template-kw -Wno-dangling-assignment-gsl -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -std=c++20 -Wno-trigraphs -fno-exceptions -fno-rtti -nostdinc++ -isystem../../third_party/libc++/src/include -isystem../../third_party/libc++abi/src/include -c ../../src/base/platform/mutex.cc -o obj/v8_libbase/mutex.o

The important bits are

-isysroot ../../../../../../../Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -mmacos-version-min=11.0

So the upstream is also targetting 11.0, it seems

@joyeecheung
Copy link
Member

joyeecheung commented Dec 19, 2024

From what I can tell, neither os_unfair_lock_flags_t nor os_unfair_lock_lock_with_options is available in the macOS 13 SDK, these two gives me nothing

grep -r -F "os_unfair_lock_flags_t" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/
grep -r -F "os_unfair_lock_lock_with_options" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/

and os_unfair_lock_flags_t seems to come together with OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION? Locally this patch would make it build:

diff --git a/src/base/platform/mutex.cc b/src/base/platform/mutex.cc
index 6abe218185f..59014d7eb03 100644
--- a/src/base/platform/mutex.cc
+++ b/src/base/platform/mutex.cc
@@ -103,8 +103,8 @@ static V8_INLINE void InitializeNativeHandle(os_unfair_lock* lock) {

 // TODO(verwaest): We should use the constants from the header, but they aren't
 // exposed until macOS 15.
-#define OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION 0x00010000
-#define OS_UNFAIR_LOCK_ADAPTIVE_SPIN 0x00040000
+#define OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION_V8 0x00010000
+#define OS_UNFAIR_LOCK_ADAPTIVE_SPIN_V8 0x00040000

 typedef uint32_t os_unfair_lock_options_t;

@@ -115,18 +115,20 @@ os_unfair_lock_lock_with_options(os_unfair_lock* lock,
 }

 static V8_INLINE void LockNativeHandle(os_unfair_lock* lock) {
-  if (__builtin_available(macOS 15, *)) {
+#ifdef OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION
     const os_unfair_lock_flags_t options = static_cast<os_unfair_lock_flags_t>(
-        OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION | OS_UNFAIR_LOCK_ADAPTIVE_SPIN);
+        OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION_V8 | OS_UNFAIR_LOCK_ADAPTIVE_SPIN_V8);
     os_unfair_lock_lock_with_flags(lock, options);
-  } else if (os_unfair_lock_lock_with_options) {
+#else
+  if (os_unfair_lock_lock_with_options) {
     const os_unfair_lock_options_t options =
         static_cast<os_unfair_lock_options_t>(
-            OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION | OS_UNFAIR_LOCK_ADAPTIVE_SPIN);
+            OS_UNFAIR_LOCK_DATA_SYNCHRONIZATION_V8 | OS_UNFAIR_LOCK_ADAPTIVE_SPIN_V8);
     os_unfair_lock_lock_with_options(lock, options);
   } else {
     os_unfair_lock_lock(lock);
   }
+#endif
 }

 static V8_INLINE void UnlockNativeHandle(os_unfair_lock* lock) {

@deepak1556
Copy link

Thanks @targos

For electron we match the sdk version to mac_sdk_official_version from the branch we are building.

Is there any document about macOS SDK requirements for building V8?

When building with system xcode the minimum supported sdk version is picked from https://source.chromium.org/chromium/chromium/src/+/main:build/config/mac/mac_sdk_overrides.gni which I don't see being overriden by //v8, but based on the above seems like the requirements should be bumped ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants