servo / mozjs

Servo's SpiderMonkey fork
253 stars 118 forks source link

__builtin_available is intermittently not available on macOS #504

Open jdm opened 1 month ago

jdm commented 1 month ago

When building mozjs on macOS arm64, I intermittently receive linker errors like this:

          Undefined symbols for architecture arm64:
            "___isPlatformVersionAtLeast", referenced from:
                js::jit::AutoMarkJitCodeWritableForThread::markExecutable(bool) in libmozjs_sys-13c131082aca4d88.rlib[85](Unified_cpp_js_src_jit9.o)
          ld: symbol(s) not found for architecture arm64
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

There is one use of this function in mozjs: https://github.com/servo/mozjs/blob/10fb074ab11756444e8b0f69e4cbed8d6462e3ae/mozjs-sys/mozjs/js/src/jit/ProcessExecutableMemory.cpp#L1010

The most recent spidermonkey upgrade removed a patch that removed a previous use of __builtinAvailable: https://github.com/servo/mozjs/commit/bf41ed080ec3c2fb84a53928c7db7691b0a0b161#diff-5c427df1c88acdb6a3478df156bdd162ecf6bc6abd7231cfdec3b4ccb5a35138L1

https://github.com/curl/curl/issues/4314 suggests that the issue here is that __builtinAvailable is only available in dynamic libraries, but we're building a static library. I have no idea why I would only hit this intermittently, or why CI never appears to run into this problem.

jdm commented 1 month ago

Just removing the __builtin_available check results in:

  In file included from Unified_cpp_js_src_jit9.cpp:29:
  /Users/jdm/src/mozjs/mozjs-sys/mozjs/js/src/jit/ProcessExecutableMemory.cpp:1010:3: error: 'pthread_jit_write_protect_np' is only available on macOS 11.0 or newer [-Werror,-Wunguarded-availability-new]
    pthread_jit_write_protect_np(executable);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/include/pthread.h:588:6: note: 'pthread_jit_write_protect_np' has been marked as being introduced in macOS 11.0 here, but the deployment target is macOS 10.10.0
  void pthread_jit_write_protect_np(int enabled);
       ^
  /Users/jdm/src/mozjs/mozjs-sys/mozjs/js/src/jit/ProcessExecutableMemory.cpp:1010:3: note: enclose 'pthread_jit_write_protect_np' in a __builtin_available check to silence this warning
    pthread_jit_write_protect_np(executable);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
jdm commented 1 month ago

Strangely, https://github.com/servo/mozjs/blob/10fb074ab11756444e8b0f69e4cbed8d6462e3ae/mozjs-sys/mozjs/build/moz.configure/toolchain.configure#L54-L66 looks like it should be setting a 11.0 deployment target in this case, and I have no idea where the 10.10 value comes from.

jdm commented 1 month ago

I am able to build after removing the __builtin_available check with ./mach clean and MACOSX_DEPLOYMENT_TARGET=11.0.

mrobinson commented 1 month ago

Servo is setting the MACOSX_DEPLOYMENT_TARGET to 10.10 in .cargo/config.toml. I believe this was previously set in the environment by mach.

sagudev commented 1 month ago

Then we should probably set MACOSX_DEPLOYMENT_TARGET in mozjs-sys and remove __builtin_available check.

jschwe commented 1 month ago

Shouldn't we just bump MACOSX_DEPLOYMENT_TARGET in servo? The oldest available version in github CI is macOS-12, so I don't think we can even test at all if servo can actually run on 10.10.