Skip to content

[iOS][macOS] Exported framework symbol verification disallows Swift extensions #186119

Description

@cbracken

In #185918, I added a Swift extension on an Obj-C type. Name-mangling for Swift extensions differs from name mangling on plain types, and causes verify_exported.dart to fail verification.

Example:

ERROR: /Volumes/Work/s/w/ir/cache/builder/engine/src/out/ci/ios_release_extension_safe/Flutter.framework/Flutter exports unexpected symbols:
     (__TEXT,__text) _$sSo14FlutterTracingC08InternalA11SwiftCommonE10beginScopeyAC05TraceG0CSSFZ
     (__TEXT,__text) _$sSo14FlutterTracingC08InternalA11SwiftCommonE9withTraceyxSS_xyKXEtKlFZ
ERROR: /Volumes/Work/s/w/ir/cache/builder/engine/src/out/ci/ios_release/Flutter.framework/Flutter exports unexpected symbols:
     (__TEXT,__text) _$sSo14FlutterTracingC08InternalA11SwiftCommonE10beginScopeyAC05TraceG0CSSFZ
     (__TEXT,__text) _$sSo14FlutterTracingC08InternalA11SwiftCommonE9withTraceyxSS_xyKXEtKlFZ
Failing checks: 2

Swift name mangling uses:

  • pair of symbol length + symbol: 14FlutterTracing (14 bytes long symbol "FlutterTracing"
  • substitutions: A (re-use stashed symbol from earlier "Flutter")

Taking a look at a demangled type above:

xcrun swift-demangle -expand '_$sSo14FlutterTracingC08InternalA11SwiftCommonE10beginScopeyAC05TraceG0CSSFZ'

I get:

Demangling for _$sSo14FlutterTracingC08InternalA11SwiftCommonE10beginScopeyAC05TraceG0CSSFZ
kind=Global
  kind=Static
    kind=Function
      kind=Extension
        kind=Module, text="InternalFlutterSwiftCommon"
        kind=Class
          kind=Module, text="__C"
          kind=Identifier, text="FlutterTracing"
      kind=Identifier, text="beginScope"
      kind=LabelList
      kind=Type
        kind=FunctionType
          kind=ArgumentTuple
            kind=Type
              kind=Structure
                kind=Module, text="Swift"
                kind=Identifier, text="String"
          kind=ReturnType
            kind=Type
              kind=Class
                kind=Module, text="InternalFlutterSwiftCommon"
                kind=Identifier, text="TraceScope"
_$sSo14FlutterTracingC08InternalA11SwiftCommonE10beginScopeyAC05TraceG0CSSFZ ---> static (extension in InternalFlutterSwiftCommon):__C.FlutterTracing.beginScope(Swift.String) -> InternalFlutterSwiftCommon.TraceScope

Swift has a stable ABI so these aren't at risk of changing and we should update our regexes to handle extensions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions