Xcode7.1 (7B91b): Linker errors when WMO is enabled

Originator:benchatelain
Number:rdar://23472326 Date Originated:09-Nov-2015 04:48 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode7.1 (7B91b)
Classification:Serious Bug Reproducible:Always
 
Summary:
Enabling Whole Module Optimization breaks the linker step of the build. See example project at the following URL for example project that clearly demonstrates this issue:
https://github.com/phatblat/SwiftGenWMO

The type in question (UIColor.Name) is an enum subtype added to UIColor through an extension.

Steps to Reproduce:
1. Clone the above repo
2. Build the “SwiftGenWMO (Release)” scheme

Expected Results:
The build will succeed

Actual Results:
The build fails with the following linker error message:

Ld /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/i386/SwiftGenWMO normal i386
    cd /Users/ben/dev/ios/SwiftGenWMO
    export IPHONEOS_DEPLOYMENT_TARGET=9.1
    export PATH="/Applications/Xcode7.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode7.1.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode7.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode7.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk -L/Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Products/Release-iphonesimulator -F/Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Products/Release-iphonesimulator -filelist /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/i386/SwiftGenWMO.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.1 -Xlinker -objc_abi_version -Xlinker 2 -L/Applications/Xcode7.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/i386/SwiftGenWMO.swiftmodule -Xlinker -dependency_info -Xlinker /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/i386/SwiftGenWMO_dependency_info.dat -o /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/i386/SwiftGenWMO

Undefined symbols for architecture i386:
  "direct type metadata for ext.SwiftGenWMO.__ObjC.UIColor.Name", referenced from:
      _globalinit_33_9DB38CA9AF8247CBBD097F938D9B20B4_func0 in ViewController.o
      generic specialization <ext.SwiftGenWMO.__ObjC.UIColor.Name with ext.SwiftGenWMO.__ObjC.UIColor.Name : Swift.Hashable in SwiftGenWMO, Swift.UInt32> of static Swift._VariantDictionaryStorage.maybeGetFromCocoaStorage <A, B where A: Swift.Hashable> (Swift._VariantDictionaryStorage<A, B>.Type)(Swift._CocoaDictionaryStorage, forKey : A) -> B? in ViewController.o
      function signature specialization <Arg[1] = Dead> of generic specialization <(ext.SwiftGenWMO.__ObjC.UIColor.Name, Swift.UInt32)> of static Swift.Array._allocateBufferUninitialized <A> ([A].Type)(Swift.Int) -> Swift._ArrayBuffer<A> in ViewController.o
      function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of generic specialization <ext.SwiftGenWMO.__ObjC.UIColor.Name with ext.SwiftGenWMO.__ObjC.UIColor.Name : Swift.Hashable in SwiftGenWMO, Swift.UInt32> of static Swift._NativeDictionaryStorage.fromArray <A, B where A: Swift.Hashable> (Swift._NativeDictionaryStorage<A, B>.Type)([(A, B)]) -> Swift._NativeDictionaryStorage<A, B> in ViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Ld /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/x86_64/SwiftGenWMO normal x86_64
    cd /Users/ben/dev/ios/SwiftGenWMO
    export IPHONEOS_DEPLOYMENT_TARGET=9.1
    export PATH="/Applications/Xcode7.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode7.1.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
    /Applications/Xcode7.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode7.1.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.1.sdk -L/Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Products/Release-iphonesimulator -F/Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Products/Release-iphonesimulator -filelist /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/x86_64/SwiftGenWMO.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -mios-simulator-version-min=9.1 -Xlinker -objc_abi_version -Xlinker 2 -L/Applications/Xcode7.1.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -Xlinker -add_ast_path -Xlinker /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/x86_64/SwiftGenWMO.swiftmodule -Xlinker -dependency_info -Xlinker /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/x86_64/SwiftGenWMO_dependency_info.dat -o /Users/ben/Library/Developer/Xcode/DerivedData/SwiftGenWMO-cpguaisqqgbnnhabwlwdrmjpjnmy/Build/Intermediates/SwiftGenWMO.build/Release-iphonesimulator/SwiftGenWMO.build/Objects-normal/x86_64/SwiftGenWMO

Undefined symbols for architecture x86_64:
  "direct type metadata for ext.SwiftGenWMO.__ObjC.UIColor.Name", referenced from:
      _globalinit_33_9DB38CA9AF8247CBBD097F938D9B20B4_func0 in ViewController.o
      generic specialization <ext.SwiftGenWMO.__ObjC.UIColor.Name with ext.SwiftGenWMO.__ObjC.UIColor.Name : Swift.Hashable in SwiftGenWMO, Swift.UInt32> of static Swift._VariantDictionaryStorage.maybeGetFromCocoaStorage <A, B where A: Swift.Hashable> (Swift._VariantDictionaryStorage<A, B>.Type)(Swift._CocoaDictionaryStorage, forKey : A) -> B? in ViewController.o
      function signature specialization <Arg[1] = Dead> of generic specialization <(ext.SwiftGenWMO.__ObjC.UIColor.Name, Swift.UInt32)> of static Swift.Array._allocateBufferUninitialized <A> ([A].Type)(Swift.Int) -> Swift._ArrayBuffer<A> in ViewController.o
      function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Dead> of generic specialization <ext.SwiftGenWMO.__ObjC.UIColor.Name with ext.SwiftGenWMO.__ObjC.UIColor.Name : Swift.Hashable in SwiftGenWMO, Swift.UInt32> of static Swift._NativeDictionaryStorage.fromArray <A, B where A: Swift.Hashable> (Swift._NativeDictionaryStorage<A, B>.Type)([(A, B)]) -> Swift._NativeDictionaryStorage<A, B> in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Regression:
Building the “SwiftGenWMO (Debug)” scheme succeeds with no changes to the code. Likewise, disabling WMO in the Release config and using the “Fast [-O]” value for the SWIFT_OPTIMIZATION_LEVEL build setting also works. It is only when WMO is enabled that these errors occur.

Comments

Affected Xcode versions

  • 7.1 (7B91b)
  • 7.1.1 (7B1005)
  • 7.2 beta 3 (7C62)
  • 7.3.1 (7D1014)
By benchatelain at Nov. 11, 2015, 4:44 a.m. (reply...)

Still observed in Xcode Version 7.2 (7C68)

By volodymyr.gorlov at Jan. 9, 2016, 4:40 p.m. (reply...)

Still reproduced Xcode 9.1 (9B55)


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!