From f2cb42aa90ba3cc3b51242904021a6a7e735048f Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Wed, 23 Aug 2023 15:37:03 -0700 Subject: [PATCH] Roll clang with fix for ABI change (#44711) In the change here https://github.com/llvm/llvm-project/commit/b653a2823fe4b4c9c6d85cfe119f31d8e70c2fa0, an intentional ABI breaking change was introduced to the clang runtime library for macOS and iOS. That change caused a symbol requiring dynamic linkage to be exposed that triggers iOS App Store checks for usage of private API. This PR resolves that issue by rolling clang forward and introducing a definition of `_availability_version_check`. The declaration with weak linkage in the clang runtime library [here](https://github.com/llvm/llvm-project/blob/b653a2823fe4b4c9c6d85cfe119f31d8e70c2fa0/compiler-rt/lib/builtins/os_version_check.c#L89) will then be resolved against the definition introduced in this PR. Since the declaration in the clang runtime library will now be resolved by static linking, the Flutter dylib will no longer require it to be dynamically linked, and will therefore not trigger the App Store check for using private API. The definition of `_availability_version_check` is implemented using the `dlsym` strategy used by the old version of clang [here](https://github.com/llvm/llvm-project/blob/f9ac5575675e4117c2e097a71ad0f02cab92aa97/compiler-rt/lib/builtins/os_version_check.c#L97). Fixes https://github.com/flutter/flutter/issues/132130 --- DEPS | 2 +- ci/licenses_golden/licenses_flutter | 2 + shell/platform/darwin/common/BUILD.gn | 1 + .../common/availability_version_check.cc | 48 +++++++++++++++++++ .../Source/FlutterAppDelegateTest.mm | 8 +++- 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 shell/platform/darwin/common/availability_version_check.cc diff --git a/DEPS b/DEPS index db81b85eace10..ff32b859a088f 100644 --- a/DEPS +++ b/DEPS @@ -39,7 +39,7 @@ vars = { # The list of revisions for these tools comes from Fuchsia, here: # https://fuchsia.googlesource.com/integration/+/HEAD/toolchain # If there are problems with the toolchain, contact fuchsia-toolchain@. - 'clang_version': 'git_revision:6d667d4b261e81f325756fdfd5bb43b3b3d2451d', + 'clang_version': 'git_revision:020d2fb7711d70e296f19d83565f8d93d2cfda71', # The goma version and the clang version can be tightly coupled. If goma # stops working on a clang roll, this may need to be updated using the value diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 5721623184594..8598c28bb78ff 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -2582,6 +2582,7 @@ ORIGIN: ../../../flutter/shell/platform/common/text_editing_delta.h + ../../../f ORIGIN: ../../../flutter/shell/platform/common/text_input_model.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/text_input_model.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/common/text_range.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/darwin/common/availability_version_check.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/buffer_conversions.mm + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/darwin/common/command_line.h + ../../../flutter/LICENSE @@ -5336,6 +5337,7 @@ FILE: ../../../flutter/shell/platform/common/text_editing_delta.h FILE: ../../../flutter/shell/platform/common/text_input_model.cc FILE: ../../../flutter/shell/platform/common/text_input_model.h FILE: ../../../flutter/shell/platform/common/text_range.h +FILE: ../../../flutter/shell/platform/darwin/common/availability_version_check.cc FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.h FILE: ../../../flutter/shell/platform/darwin/common/buffer_conversions.mm FILE: ../../../flutter/shell/platform/darwin/common/command_line.h diff --git a/shell/platform/darwin/common/BUILD.gn b/shell/platform/darwin/common/BUILD.gn index 2a59b824c2d09..7d844b75b81de 100644 --- a/shell/platform/darwin/common/BUILD.gn +++ b/shell/platform/darwin/common/BUILD.gn @@ -13,6 +13,7 @@ source_set("common") { cflags_objcc = flutter_cflags_objcc sources = [ + "availability_version_check.cc", "buffer_conversions.h", "buffer_conversions.mm", "command_line.h", diff --git a/shell/platform/darwin/common/availability_version_check.cc b/shell/platform/darwin/common/availability_version_check.cc new file mode 100644 index 0000000000000..67514cbf5561f --- /dev/null +++ b/shell/platform/darwin/common/availability_version_check.cc @@ -0,0 +1,48 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include +#include +#include + +#include "flutter/fml/logging.h" + +// See context in https://github.com/flutter/flutter/issues/132130 and +// https://github.com/flutter/engine/pull/44711. + +// TODO(zanderso): Remove this after Clang 18 rolls into Xcode. +// https://github.com/flutter/flutter/issues/133203 + +namespace { + +typedef uint32_t dyld_platform_t; + +typedef struct { + dyld_platform_t platform; + uint32_t version; +} dyld_build_version_t; + +typedef bool (*AvailabilityVersionCheckFn)(uint32_t count, + dyld_build_version_t versions[]); + +AvailabilityVersionCheckFn AvailabilityVersionCheck; + +dispatch_once_t DispatchOnceCounter; + +void InitializeAvailabilityCheck(void* unused) { + if (AvailabilityVersionCheck) { + return; + } + AvailabilityVersionCheck = reinterpret_cast( + dlsym(RTLD_DEFAULT, "_availability_version_check")); + FML_CHECK(AvailabilityVersionCheck); +} + +extern "C" bool _availability_version_check(uint32_t count, + dyld_build_version_t versions[]) { + dispatch_once_f(&DispatchOnceCounter, NULL, InitializeAvailabilityCheck); + return AvailabilityVersionCheck(count, versions); +} + +} // namespace diff --git a/shell/platform/darwin/macos/framework/Source/FlutterAppDelegateTest.mm b/shell/platform/darwin/macos/framework/Source/FlutterAppDelegateTest.mm index b58e5e78f94f1..6b13959bde906 100644 --- a/shell/platform/darwin/macos/framework/Source/FlutterAppDelegateTest.mm +++ b/shell/platform/darwin/macos/framework/Source/FlutterAppDelegateTest.mm @@ -46,7 +46,9 @@ - (BOOL)handleOpenURLs:(NSArray*)urls { [[AppDelegateTestFlutterAppLifecycleDelegate alloc] init]; [appDelegate addApplicationLifecycleDelegate:delegate]; - NSArray* URLs = @[ [NSURL URLWithString:@"https://flutter.dev"] ]; + NSURL* URL = [NSURL URLWithString:@"https://flutter.dev"]; + EXPECT_NE(URL, nil); + NSArray* URLs = @[ URL ]; [appDelegate application:NSApplication.sharedApplication openURLs:URLs]; EXPECT_EQ([delegate receivedURLs], URLs); @@ -61,7 +63,9 @@ - (BOOL)handleOpenURLs:(NSArray*)urls { [appDelegate addApplicationLifecycleDelegate:firstDelegate]; [appDelegate addApplicationLifecycleDelegate:secondDelegate]; - NSArray* URLs = @[ [NSURL URLWithString:@"https://flutter.dev"] ]; + NSURL* URL = [NSURL URLWithString:@"https://flutter.dev"]; + EXPECT_NE(URL, nil); + NSArray* URLs = @[ URL ]; [appDelegate application:NSApplication.sharedApplication openURLs:URLs]; EXPECT_EQ([firstDelegate receivedURLs], URLs);