From 9bf9453e269dff2ba869acc308be59c32c5c494f Mon Sep 17 00:00:00 2001 From: Chris Bracken Date: Thu, 31 Aug 2023 11:41:00 -0700 Subject: [PATCH] [macOS] Link __availability_version_check (flutter/engine#45333) Links in an implementation of _availability_version_check on macOS. This is required due to an upstream compiler builtin (runtime) change that marked this function as weakly-linked via `__attribute__((weak import))` As such, no linking failure occurs when the function is unavailable at link time. By providing an implementation, the linker picks up our implementation, which looks up symbol in question at runtime (via dlsym) on the first invocation, caches it for later invocations, then invokes it. This is, in fact, precisely what the original clang builtin implementation did. Upstream clang change: https://reviews.llvm.org/D150397 Issue: https://github.com/flutter/flutter/issues/133777 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style --- .../shell/platform/darwin/common/BUILD.gn | 27 ++++++++++++++++++- .../shell/platform/darwin/macos/BUILD.gn | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/shell/platform/darwin/common/BUILD.gn b/engine/src/flutter/shell/platform/darwin/common/BUILD.gn index 7d844b75b8..0d29be6c70 100644 --- a/engine/src/flutter/shell/platform/darwin/common/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/common/BUILD.gn @@ -13,13 +13,38 @@ source_set("common") { cflags_objcc = flutter_cflags_objcc sources = [ - "availability_version_check.cc", "buffer_conversions.h", "buffer_conversions.mm", "command_line.h", "command_line.mm", ] + deps = [ + ":availability_version_check", + "//flutter/fml", + ] + + public_configs = [ "//flutter:config" ] +} + +# Provides an implementation for _availability_version_check. +# +# This is required due to an upstream compiler builtin (runtime) change +# that marked this function as weakly-linked via __attribute__((weak import)) +# As such, no linking failure occurs when the function is unavailable at +# link time. Since the symbol is no longer linked in, App Store review blocks +# publishing due to relying on a private symbol. Instead we link in our own +# implementation, which provides the exact implementation used in clang prior +# to the upstream change. +# +# See: Upstream clang change: https://reviews.llvm.org/D150397 +# See: https://github.com/flutter/flutter/issues/133777 +source_set("availability_version_check") { + cflags_objc = flutter_cflags_objc + cflags_objcc = flutter_cflags_objcc + + sources = [ "availability_version_check.cc" ] + deps = [ "//flutter/fml" ] public_configs = [ "//flutter:config" ] diff --git a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn index 4bef2c68b1..d36e9b1486 100644 --- a/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn +++ b/engine/src/flutter/shell/platform/darwin/macos/BUILD.gn @@ -121,6 +121,7 @@ source_set("flutter_framework_source") { "//flutter/shell/platform/common:common_cpp_enums", "//flutter/shell/platform/common:common_cpp_input", "//flutter/shell/platform/common:common_cpp_switches", + "//flutter/shell/platform/darwin/common:availability_version_check", "//flutter/shell/platform/darwin/common:framework_common", "//flutter/shell/platform/darwin/graphics:graphics", "//flutter/shell/platform/embedder:embedder_as_internal_library",