Skip to content

[Concurrency] Disable applying the -fswift-async-fp flag for Xcode builds until someone figures out the root cause #39561

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions stdlib/public/Concurrency/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,21 @@ if(NOT swift_concurrency_async_fp_mode)
set(swift_concurrency_async_fp_mode "always")
endif()

# Don't emit extended frame info on platforms other than darwin, system
# backtracer and system debugger are unlikely to support it.
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS
"-fswift-async-fp=${swift_concurrency_async_fp_mode}")
list(APPEND SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS
"-Xfrontend"
"-swift-async-frame-pointer=${swift_concurrency_async_fp_mode}")
if(XCODE)
message(WARNING "The -fswift-async-fp flag is being disabled because of an "
"issue with the Xcode build, see SR-15216 for info.")
else()
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS "-fswift-async-fp=never")
# Don't emit extended frame info on platforms other than darwin, system
# backtracer and system debugger are unlikely to support it.
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @buttaface
Does this works locally for you? I thought about testing that but because of this comment #39368 (comment), trying to compile the stdlib without this flag doesn't work so I'm not sure this will solve the issue.

Copy link
Member Author

Choose a reason for hiding this comment

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

As I mentioned a couple times on that earlier pull, I don't use macOS, so this pull has not been tested whatsoever.

My understanding of the problem from what you and others initially described is that the host clang at /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/ is being wrongly used by the Xcode generator to build the Swift stdlib, despite the Swift CMake config specifying that it use the just-built Swift-forked clang instead. This pull works around that by not passing the flag when the Xcode generator is used, because the host clang doesn't support this flag.

In your linked comment, you then claim that the Xcode generator was using the Swift-forked, freshly-built clang to build this Concurrency library, in which case this pull won't work, as you then have much deeper problems if the Xcode generator is randomly choosing which clang compiler to use.

I suggest you do a normal build without this pull, and paste the full error you get here. Then, apply this pull and rebuild without cleaning and see what difference it makes. If both runs show different compilers being used, I don't know what to tell you, there's something deeply wrong with your Xcode setup.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest you do a normal build without this pull, and paste the full error you get here. Then, apply this pull and rebuild without cleaning and see what difference it makes. If both runs show different compilers being used, I don't know what to tell you, there's something deeply wrong with your Xcode setup.

Thank you for the suggestion, I'll take a deeper look at it

Copy link
Member Author

Choose a reason for hiding this comment

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

Any luck?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @buttaface,
No, I tried this change and keep hitting that linker issue ... so I tried Doug's change locally from #39573 and it seems to be enough to unblock Xcode and build everything =]

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, can you provide the error messages I asked for before, ie the full error on a stock build and after applying this patch? You don't need to do a full rebuild because these patches only affect the stdlib, ie this should be pretty easy to do with an existing build just by changing the patch applied to this file.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, can you provide the error messages I asked for before,

Ah ok, I completely missed this sorry, but it is the same linker error as mentioned on the original PR

ld: warning: static initializer found in '${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/stdlib/public/Concurrency/Swift.build/Debug/swift_Concurrency-macosx-arm64.build/Objects-normal/arm64/Task.o'. Use -no_inits to make this an error.  Use -no_warn_inits to suppress warning
0  0x1023c4224  __assert_rtn + 128
1  0x1023c9304  ld::tool::OutputFile::makeSplitSegInfoV2(ld::Internal&) (.cold.7) + 0
2  0x1022ffc80  ld::tool::OutputFile::makeSplitSegInfoV2(ld::Internal&) + 1464
3  0x1022f9aa8  ld::tool::OutputFile::write(ld::Internal&) + 164
4  0x1022871d8  main + 584
A linker snapshot was created at:
	/tmp/libswift_Concurrency.dylib-2021-09-12-094110.ld-snapshot
ld: Assertion failed: (_machoSection != 0), function machoSection, file ld.hpp, line 1173.
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **


The following build commands failed:
	Ld ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64/libswift_Concurrency.dylib normal (in target 'swift_Concurrency-macosx-arm64' from project 'Swift')
(1 failure)
ERROR: command terminated with a non-zero exit status 65, aborting

Copy link
Member Author

Choose a reason for hiding this comment

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

Does Xcode not show the failing command? I don't care about the error as much as what particular command caused it.

Copy link
Contributor

Choose a reason for hiding this comment

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

It fails while linking libswift_Concurrency.dylib

Ld ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64/libswift_Concurrency.dylib normal (in target 'swift_Concurrency-macosx-arm64' from project 'Swift')
    cd ${SRC_DIR}/swift
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target arm64-apple-macos11.3 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64 -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/llvm-macosx-arm64/RelWithDebInfo/lib/Debug -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/llvm-macosx-arm64/RelWithDebInfo/lib -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64/Debug -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64 -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/bin/../lib/swift/macosx/arm64/Debug -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/bin/../lib/swift/macosx/arm64 -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/bin/../lib/swift/macosx/Debug -L${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/bin/../lib/swift/macosx -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/swift/Debug -L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/usr/lib/swift -F${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64 -filelist ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/stdlib/public/Concurrency/Swift.build/Debug/swift_Concurrency-macosx-arm64.build/Objects-normal/arm64/swift_Concurrency.LinkFileList -install_name /usr/lib/swift/libswift_Concurrency.dylib -Xlinker -object_path_lto -Xlinker ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/stdlib/public/Concurrency/Swift.build/Debug/swift_Concurrency-macosx-arm64.build/Objects-normal/arm64/swift_Concurrency_lto.o -stdlib\=libc++ -target arm64-apple-macosx10.9 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -arch arm64 -F/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/../../../Developer/Library/Frameworks -Wl,-sectcreate,__TEXT,__info_plist,${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/stdlib/public/Concurrency/Info.plist -Wl,-application_extension -Xlinker -compatibility_version -Xlinker 1 -dynamiclib -Wl,-headerpad_max_install_names ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64/libswiftCore.dylib -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/stdlib/public/Concurrency/Swift.build/Debug/swift_Concurrency-macosx-arm64.build/Objects-normal/arm64/swift_Concurrency_dependency_info.dat -o ${SRC_DIR}/build/Xcode-RelWithDebInfoAssert+swift-DebugAssert/swift-macosx-arm64/Debug/lib/swift/macosx/arm64/libswift_Concurrency.dylib

As for the build-script command I'm using SKIP_XCODE_VERSION_CHECK=1 ./swift/utils/build-script --xcode --release-debuginfo --debug-swift --skip-build-benchmarks --swift-darwin-supported-archs "$(uname -m)" --sccache --skip-ios --skip-tvos --skip-watchos

Copy link
Member Author

Choose a reason for hiding this comment

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

Huh, okay, I didn't know the macOS linker also requires that flag to be applied, I thought this was purely a compilation issue. This will require looking into the Xcode generator for CMake to see why it is building the stdlib with the host clang and not with Swift's fork of clang, as I mentioned before. Since I can't do that, I'll close this second attempt to work around that CMake bug.

list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS
"-fswift-async-fp=${swift_concurrency_async_fp_mode}")
list(APPEND SWIFT_RUNTIME_CONCURRENCY_SWIFT_FLAGS
"-Xfrontend"
"-swift-async-frame-pointer=${swift_concurrency_async_fp_mode}")
else()
list(APPEND SWIFT_RUNTIME_CONCURRENCY_C_FLAGS "-fswift-async-fp=never")
endif()
endif()

add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_STDLIB
Expand Down