Skip to content

Enable building TestFoundation for profiling in Xcode #1180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2017

Conversation

spevans
Copy link
Contributor

@spevans spevans commented Aug 16, 2017

This change enables building the TestFoundation executable in Release mode so that it can be profiled in Instruments.

Some symbols have been changed to public as they need to be exported to CoreFoundation and used for ObjCBridging.

To profile, the TestFoundation scheme needs to be edited and the 'Profile(Release)' scheme set to 'Ask on Launch' for the executable. The Xcode project has not been updated as Xcode adds the full path to the executable and the path it adds in TestFoundation.xcscheme is an absolute path including my homedir so it would not be applicable to anyone else.

@spevans
Copy link
Contributor Author

spevans commented Aug 16, 2017

@parkera @phausler Can you comment as to whether its ok to make these symbols public? I couldn't find any other way to make it work.

@@ -790,7 +790,7 @@ public final class _DataStorage {
}
}

internal class _NSSwiftData : NSData {
public class _NSSwiftData : NSData {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is quite unfortunate since Data.swift is shared tween swift-corelibs-foundation and the overlay

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a possible #if we could wrap around it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEPLOYMENT_RUNTIME_SWIFT is defined for swift-corelibs-foundation and is not for the overlay since it's runtime is objc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but if you #if guard it please provide a comment explaining why this is needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we mark this public then others will come to depend upon it, making us unable to improve it in the future.

Supposedly the 'testable' feature is what we need for this, but I don't know what the support for testable is like on Linux.

return unsafeBitCast(__NSCFType.self, to:UnsafeRawPointer.self)
}

@_cdecl("__CFInitializeSwift")
internal func __CFInitializeSwift() {
public func __CFInitializeSwift() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed? can you attach the errors from the instruments attach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The errors I get when building for profiling are:

Undefined symbols for architecture x86_64:
  "___CFInitializeSwift", referenced from:
      ___CFInitialize in libCoreFoundation.a(CFRuntime.o)
  "___CFSwiftGetBaseClass", referenced from:
      ___CFInitialize in libCoreFoundation.a(CFRuntime.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the workflow you use to get there?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guessed and just selected the test bundle as the profile target for instruments -

the linker invocation is wrong btw I think... It probably is attempting to link the real CoreFoundation instead of the libCoreFoundation.a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The link command is

/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -dynamiclib -isysroot /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -L/Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Products/Release -F/Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Products/Release -filelist /Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation.LinkFileList -init ___CFInitialize -install_name @rpath/SwiftFoundation.framework/Versions/A/SwiftFoundation -Xlinker -rpath -Xlinker @executable_path/../Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -mmacosx-version-min=10.11 -Xlinker -object_path_lto -Xlinker /Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation_lto.o -fobjc-link-runtime -L/Users/spse/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-08-14-a.xctoolchain/usr/lib/swift/macosx -Xlinker -add_ast_path -Xlinker /Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation.swiftmodule -twolevel_namespace -Wl,-alias_list,CoreFoundation/Base.subproj/SymbolAliases -sectcreate __UNICODE __csbitmaps CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap -sectcreate __UNICODE __properties CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data -sectcreate __UNICODE __data CoreFoundation/CharacterSets/CFUnicodeData-L.mapping -segprot __UNICODE r r -lcurl.3 -lxml2 -lCoreFoundation -lz -licucore -single_module -compatibility_version 150 -current_version 1303 -Xlinker -dependency_info -Xlinker /Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation_dependency_info.dat -o /Users/spse/Files/src/swift/swift-corelibs-foundation/DerivedData/Foundation/Build/Products/Release/SwiftFoundation.framework/Versions/A/SwiftFoundation

There is a -lCoreFoundation in there, so I think you are correct, I will see if I can fix up the linker command.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tossed a -v -Wl,-v on the clang linker command and it seems to be the right CF

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang \
> -arch x86_64 \
> -dynamiclib \
> -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk \
> -L/Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release \
> -F/Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release \
> -filelist /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation.LinkFileList \
> -init ___CFInitialize \
> -install_name @rpath/SwiftFoundation.framework/Versions/A/SwiftFoundation \
> -Xlinker -rpath -Xlinker @executable_path/../Frameworks \
> -Xlinker -rpath -Xlinker @loader_path/Frameworks \
> -mmacosx-version-min=10.11 \
> -Xlinker -object_path_lto -Xlinker /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation_lto.o \
> -fobjc-link-runtime \
> -L/Library/Developer/Toolchains/swift-LOCAL-2017-08-15-a.xctoolchain/usr/lib/swift/macosx \
> -Xlinker -add_ast_path -Xlinker /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation.swiftmodule \
> -twolevel_namespace \
> -Wl,-alias_list,CoreFoundation/Base.subproj/SymbolAliases \
> -sectcreate __UNICODE __csbitmaps CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap \
> -sectcreate __UNICODE __properties CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data \
> -sectcreate __UNICODE __data CoreFoundation/CharacterSets/CFUnicodeData-L.mapping \
> -segprot __UNICODE r r \
> -Wl,-all_load \
> -lcurl.3 \
> -lxml2 \
> -lCoreFoundation \
> -lz \
> -licucore \
> -single_module \
> -compatibility_version 150 \
> -current_version 1303 \
> -Xlinker -dependency_info -Xlinker /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation_dependency_info.dat \
> -o /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release/SwiftFoundation.framework/Versions/A/SwiftFoundation -v -Wl,-v
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin17.0.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -dylib -dylib_compatibility_version 150 -dylib_current_version 1303 -arch x86_64 -dylib_install_name @rpath/SwiftFoundation.framework/Versions/A/SwiftFoundation -init ___CFInitialize -macosx_version_min 10.11.0 -single_module -sectcreate __UNICODE __csbitmaps CoreFoundation/CharacterSets/CFCharacterSetBitmaps.bitmap -sectcreate __UNICODE __properties CoreFoundation/CharacterSets/CFUniCharPropertyDatabase.data -sectcreate __UNICODE __data CoreFoundation/CharacterSets/CFUnicodeData-L.mapping -segprot __UNICODE r r -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -twolevel_namespace -o /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release/SwiftFoundation.framework/Versions/A/SwiftFoundation -L/Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release -L/Library/Developer/Toolchains/swift-LOCAL-2017-08-15-a.xctoolchain/usr/lib/swift/macosx -filelist /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation.LinkFileList -rpath @executable_path/../Frameworks -rpath @loader_path/Frameworks -object_path_lto /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation_lto.o -add_ast_path /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation.swiftmodule -alias_list CoreFoundation/Base.subproj/SymbolAliases -all_load -lcurl.3 -lxml2 -lCoreFoundation -lz -licucore -dependency_info /Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Intermediates.noindex/Foundation.build/Release/SwiftFoundation.build/Objects-normal/x86_64/SwiftFoundation_dependency_info.dat -v -framework Foundation -lobjc -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a -F/Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release
@(#)PROGRAM:ld  PROJECT:ld64-302.3
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em (tvOS)
Library search paths:
	/Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release
	/Library/Developer/Toolchains/swift-LOCAL-2017-08-15-a.xctoolchain/usr/lib/swift/macosx
	/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/lib
Framework search paths:
	/Users/phausler/Library/Developer/Xcode/DerivedData/Foundation-gmfgumwkdqjdvbazoebxtjjmneiy/Build/Products/Release
	/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
  "___CFInitializeSwift", referenced from:
      ___CFInitialize in libCoreFoundation.a(CFRuntime.o)
  "___CFSwiftGetBaseClass", referenced from:
      ___CFInitialize in libCoreFoundation.a(CFRuntime.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

So the problem is likely the flag -fobjc-link-runtime

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So why would the debug build always use the correct one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However we set in the project scope variable (with no override) CLANG_LINK_OBJC_RUNTIME to NO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be an Xcode bug? (very skeptical of claiming that without a very clear reduced case). I will investigate more and let you know.

@spevans
Copy link
Contributor Author

spevans commented Aug 16, 2017

Updated with fixes from @phausler

Copy link
Contributor

@phausler phausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, works as you would expect now in release mode

@phausler
Copy link
Contributor

@swift-ci please test and merge

@swift-ci swift-ci merged commit 2c5d0af into swiftlang:master Aug 17, 2017
@spevans spevans deleted the pr_xcode_release branch September 19, 2017 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants