求助:MachO剥离bitcode的处理

各位好:

我求助的问题是这样的,现在有个IPA进来,macho是带bitcode,我需要把bitcode去掉。在处理第三方库的时候,纯OC的倒是能成功,但是有Swift的库就不成功了。拿里面Kingfisher.framework举例我的操作步骤是这样的:

1 通过以下几步,汇出xml,提取bitcode

segedit -extract __LLVM __bundle bundle Kingfisher.framework/Kingfisher

xar -d toc.xml -f bundle

mkdir bundle.extract

xar -x -C bundle.extract -f bundle

2 通过xml中的编译参数将各个bitcode编译成.o

OC的操作:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -cc1 -triple arm64-apple-ios12.0.0 -emit-obj --mrelax-relocations -target-sdk-version=15.5 -fvisibility-inlines-hidden-static-local-var -fno-rounding-math -target-abi darwinpcs -Os bundle.extract/01 -o bundle.extract/01.o -x ir

Swift的操作,将bitcode文件先改成.bc格式:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -emit-object -target arm64-apple-ios12.0.0 -Xllvm -aarch64-use-tbi -O -disable-llvm-optzns -module-name Kingfisher bundle.extract/03.bc -o bundle.extract/03.o

3 链接.o文件, xml 中列出了 libswiftsimd.tbd等库但在本地没有,我就拼了系统的路径,这一步走不下去了:

/usr/bin/ld -arch arm64 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Accelerate.framework/Accelerate /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CFNetwork.framework/CFNetwork /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Foundation /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libobjc.A.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libSystem.B.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AVFoundation.framework/AVFoundation /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CarPlay.framework/CarPlay /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreImage.framework/CoreImage /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreServices.framework/CoreServices /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/ImageIO.framework/ImageIO /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/UIKit.framework/UIKit /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCarPlay.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreMIDI.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftDataDetection.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftFileProvider.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftUniformTypeIdentifiers.dylib -dylib -compatibility_version 1.0 -current_version 1.0.0.0.0 -install_name @rpath/Kingfisher.framework/Kingfisher -platform_version ios 12.0 15.5 -rpath /usr/lib/swift -rpath @executable_path/Frameworks -rpath @loader_path/Frameworks -dead_strip /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftAVFoundation.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftAccelerate.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCore.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreAudio.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreData.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreFoundation.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreGraphics.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreImage.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreLocation.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftCoreMedia.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftDarwin.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftDispatch.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftFoundation.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftMapKit.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftMetal.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftObjectiveC.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftQuartzCore.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftUIKit.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftos.tbd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftsimd.tbd -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -o bundle.extract/Kingfisher bundle.extract/01.o bundle.extract/02.o bundle.extract/03.o bundle.extract/04.o bundle.extract/05.o bundle.extract/06.o bundle.extract/07.o bundle.extract/08.o bundle.extract/09.o bundle.extract/10.o bundle.extract/11.o bundle.extract/12.o bundle.extract/13.o bundle.extract/14.o bundle.extract/15.o bundle.extract/16.o bundle.extract/17.o bundle.extract/18.o bundle.extract/19.o bundle.extract/20.o bundle.extract/21.o bundle.extract/22.o bundle.extract/23.o bundle.extract/24.o bundle.extract/25.o bundle.extract/26.o bundle.extract/27.o bundle.extract/28.o bundle.extract/29.o bundle.extract/30.o bundle.extract/31.o bundle.extract/32.o bundle.extract/33.o bundle.extract/34.o bundle.extract/35.o bundle.extract/36.o bundle.extract/37.o bundle.extract/38.o bundle.extract/39.o bundle.extract/40.o bundle.extract/41.o bundle.extract/42.o bundle.extract/43.o bundle.extract/44.o bundle.extract/45.o bundle.extract/46.o bundle.extract/47.o bundle.extract/48.o bundle.extract/49.o bundle.extract/50.o bundle.extract/51.o bundle.extract/52.o bundle.extract/53.o bundle.extract/54.o bundle.extract/55.o bundle.extract/56.o bundle.extract/57.o bundle.extract/58.o bundle.extract/59.o bundle.extract/60.o bundle.extract/61.o bundle.extract/62.o bundle.extract/63.o bundle.extract/64.o bundle.extract/65.o bundle.extract/66.o bundle.extract/67.o bundle.extract/68.o bundle.extract/69.o

报错:

ld: warning: Could not find or use auto-linked library 'swift_Concurrency'

ld: warning: Could not find or use auto-linked library 'swiftDispatch'

ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'

ld: warning: Could not find or use auto-linked library 'swiftos'

ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'

ld: warning: Could not find or use auto-linked library 'swiftUIKit'

ld: warning: Could not find or use auto-linked library 'swiftCompatibilityConcurrency'

ld: warning: Could not find or use auto-linked library 'swiftDarwin'

ld: warning: Could not find or use auto-linked library 'swiftMetal'

ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'

ld: warning: Could not find or use auto-linked library 'swiftDataDetection'

ld: warning: Could not find or use auto-linked library 'swiftCoreLocation'

ld: warning: Could not find or use auto-linked library 'swiftAccelerate'

ld: warning: Could not find or use auto-linked library 'swiftAVFoundation'

ld: warning: Could not find or use auto-linked library 'swiftCore'

ld: warning: Could not find or use auto-linked library 'swiftFoundation'

ld: warning: Could not find or use auto-linked library 'swiftCoreMedia'

ld: warning: Could not find or use auto-linked library 'swiftCoreData'

ld: warning: Could not find or use auto-linked library 'swiftFileProvider'

ld: warning: Could not find or use auto-linked library 'swiftMapKit'

ld: warning: Could not find or use auto-linked library 'swiftCoreAudio'

ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'

ld: warning: Could not find or use auto-linked library 'swiftCompatibility51'

ld: warning: Could not find or use auto-linked library 'swiftsimd'

ld: warning: Could not find or use auto-linked library 'swiftUniformTypeIdentifiers'

ld: warning: Could not find or use auto-linked library 'swiftCoreMIDI'

ld: warning: Could not find or use auto-linked library 'swiftCarPlay'

ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'

ld: warning: Could not find or use auto-linked library 'swiftCoreImage'

ld: warning: Could not find or use auto-linked library 'swiftCompatibilityDynamicReplacements'

Undefined symbols for architecture arm64:

"___isPlatformVersionAtLeast", referenced from:

_$s10Kingfisher15ImageDownloaderC21createDownloadContext33_1CBBE1CEF600480D48F123F40F117AB5LL4with7options4doney10Foundation3URLV_AA0A17ParsedOptionsInfoVys6ResultOyAC011DownloadingF0VAA0A5ErrorOGctF in 23.o

_$s10Kingfisher0A7WrapperVAASo11UIImageViewCRbzlE13indicatorTypeAA09IndicatorF0Ovs in 32.o

__hidden#7229_ in 42.o

ld: symbol(s) not found for architecture arm64

请问各位是在第3步链接阶段我搞错了什么吗?或者大家有什么方法可以把Kingfisher MachO里面的bitcode直接剥离掉吗?
相关的文件放这里:阿里云盘分享

xcrun bitcode_strip mach-o -r -o mach-o-nobitcode 试一试这个。

2 个赞

好棒啊,谢谢了 :grinning: