[lld] [lld-macho] Add swift support to ObjC category merger (PR #95124)

Zhaoxuan Jiang via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 17 05:17:45 PDT 2026


nocchijiang wrote:

I ran into the "Protocol list does not match expected size" assert when I was testing category merging. The minimal repro:

ModA.swift:
```swift
import Foundation

@objc public protocol P {
    func p()
}

@objc open class Foo: NSObject {}
```

ModB.swift:
```swift
import Foundation
import ModA

extension Foo: P {
    public func p() {}
}
```

extras.m:
```objc
#import <Foundation/Foundation.h>
#import "ModA.h"

@interface Foo (CExt)
- (void)cf;
@end

@implementation Foo (CExt)
- (void)cf {}
@end
```

Build and link:
```bash
xcrun swiftc -target arm64-apple-macosx13.0 -module-name ModA \
    -emit-module ModA.swift
xcrun swiftc -target arm64-apple-macosx13.0 -module-name ModA \
    -emit-objc-header-path ModA.h -c ModA.swift -o ModA.o

xcrun swiftc -target arm64-apple-macosx13.0 -module-name ModB \
    -I. -L. -lModA -c ModB.swift -o ModB.o

xcrun clang -target arm64-apple-macosx13.0 -c extras.m -o extras.o

ld64.lld -arch arm64 -platform_version macos 13.0 13.0 -dylib \
    -o out.dylib ModA.o ModB.o extras.o -objc_category_merging \
    -syslibroot "$(xcrun --show-sdk-path)" -lSystem \
    -undefined dynamic_lookup
```

https://github.com/llvm/llvm-project/pull/95124


More information about the llvm-commits mailing list