From: "katei (Yuta Saito)" Date: 2022-09-23T18:53:19+00:00 Subject: [ruby-core:110051] [Ruby master Bug#18912] Build failure with Xcode 14 and macOS 13 (Ventura) Beta Issue #18912 has been updated by katei (Yuta Saito). From my further debugging, I found that CoreFoundation internally creates NSTaggedPointerString for small strings since macOS 13. This C code can check a string is represented by tagged pointer in CoreFoundation. ```c // $ clang -g main.c -framework CoreFoundation // $ ./a.out # on macOS ~12 // CFStringCreateWithBytesNoCopy("/") = 0x600003d94780 (tagged = NO) // $ ./a.out # on macOS 13 // CFStringCreateWithBytesNoCopy("/") = 0xab98bd5bc57e5fed (tagged = YES) #include #include // Ref: https://github.com/apple-oss-distributions/objc4/blob/8701d5672d3fd3cd817aeb84db1077aafe1a1604/runtime/objc-internal.h#L446-L482 #if (TARGET_OS_OSX || TARGET_OS_MACCATALYST) && __x86_64__ # define _OBJC_TAG_MASK 1ULL #else # define _OBJC_TAG_MASK 0x8000000000000000ULL #endif #define _objc_isTaggedPointer(x) (((uintptr_t)(x)&_OBJC_TAG_MASK) != 0) int main(void) { long len = 1; const char *ptr = "/"; CFStringRef s = CFStringCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8 *)ptr, len, kCFStringEncodingUTF8, FALSE, kCFAllocatorNull); printf("CFStringCreateWithBytesNoCopy(\"%s\") = %18p (tagged = %s)\n", ptr, s, _objc_isTaggedPointer(s) ? "YES" : "NO"); return 0; } ``` In the above reproducible case in #note-12, 1. `Process.daemon(false, true)` performs `chdir("/")` 2. `Dir.pwd` calls `CFStringCreateWithBytesNoCopy` API with `"/"` 3. `CFStringCreateWithBytesNoCopy` returns `NSTaggedPointerString` because `"/"` is small enough to fit in the tagged string. 4. `CFStringCreateMutableCopy` calls `NSMutableString`'s methods based on the tagged string. So a reduced minimum repro can be: ```ruby pid = fork { p File.realpath "/" } Process.waitpid(pid) ``` To avoid Objective-C runtime crash, we need to warm up Objective-C classes internally used in CFString family API by passing small string before `fork()`. Here is a patch to address it https://github.com/ruby/ruby/pull/6426 ---------------------------------------- Bug #18912: Build failure with Xcode 14 and macOS 13 (Ventura) Beta https://bugs.ruby-lang.org/issues/18912#change-99302 * Author: hsbt (Hiroshi SHIBATA) * Status: Assigned * Priority: Normal * Assignee: hsbt (Hiroshi SHIBATA) * Backport: 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED ---------------------------------------- Today, I tried to build ruby master with macOS 13 (Ventura) Beta. It breaks the build status caused by Xcode 14 beta changes. TL;DR: We should add `--without=+,bigdecimal --enable-shared` to the `configure` option. 1. Build failed without `--enable-shared`. I build ruby master without `--enable-shared` option. I got the following error. ``` (snip) linking shared-object -test-/arith_seq/extract.bundle Undefined symbols for architecture arm64: "_rb_arithmetic_sequence_extract", referenced from: _arith_seq_s_extract in extract.o "_rb_ary_new_capa", referenced from: _arith_seq_s_extract in extract.o "_rb_ary_store", referenced from: _arith_seq_s_extract in extract.o "_rb_define_singleton_method", referenced from: _Init_extract in extract.o "_rb_path2class", referenced from: _Init_extract in extract.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` @katei says this error affects with `-undefined dynamic_lookup` flags. 2. Build error with bigdecimal With `--enabled-shared` resolved the first error. But I got the another build failure. ``` compiling bigdecimal.c In file included from bigdecimal.c:13: In file included from ./bigdecimal.h:14: ./missing.h:127:1: error: static declaration of 'rb_rational_num' follows non-static declaration rb_rational_num(VALUE rat) ^ ../.././include/ruby/internal/intern/rational.h:128:7: note: previous declaration is here VALUE rb_rational_num(VALUE rat); ^ In file included from bigdecimal.c:13: In file included from ./bigdecimal.h:14: (snip) ``` It's affected with `static inline` declaration in missing.h of bigdecimal. 3. test failure with mjit I could build with `--with-out-ext=+,bigdecimal --enable-share` option. But I also got the test failure with mjit. ``` [215/402] TestMJIT#test_lambda_longjmp = 0.19 s 192) Failure: TestMJIT#test_lambda_longjmp [/Users/hsbt/Documents/github.com/ruby/ruby/test/ruby/test_mjit.rb:1045]: Expected 1 times of JIT success, but succeeded 0 times. script: """ fib = lambda do |x| return x if x == 0 || x == 1 fib.call(x-1) + fib.call(x-2) end print fib.call(5) """ stderr: """ Undefined symbols for architecture arm64: "_mjit_call_p", referenced from: __mjit0 in _ruby_mjit_p39885u0-643ab5.o _vm_sendish in _ruby_mjit_p39885u0-643ab5.o ``` I already shared this to @k0kubun . macOS 13 beta is still development status. I will track this until the official release date. -- https://bugs.ruby-lang.org/ Unsubscribe: