-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function #79889
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
Conversation
7e88407
to
3dd9282
Compare
@swift-ci test |
Please test with following pull request: @swift-ci test |
Please test with following pull request: @swift-ci test |
@swift-ci test |
@swift-ci test |
…nst the runtime function This commit modifies IRGen to emit a stub function `__swift_coroFrameAllocStub` instead of the newly introduced swift-rt function `swift_coroFrameAlloc`. The stub checks whether the runtime has the symbol `swift_coroFrameAlloc` and dispatches to it if it exists, uses `malloc` otherwise. This ensures the ability to back deploy the feature to older OS targets. rdar://145239850
ef351da
to
27347f7
Compare
@swift-ci test |
lib/IRGen/GenFunc.h
Outdated
auto coroAllocPtr = IGF.IGM.getCoroFrameAllocFn(); | ||
auto coroAllocFn = dyn_cast<llvm::Function>(coroAllocPtr); | ||
if (!llvm::Triple(IGM.Triple).isOSWindows()) | ||
coroAllocFn->setLinkage(llvm::GlobalValue::ExternalWeakLinkage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes the symbol strong on windows and weak on everything else. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@t-rasmud saw errors of the form:
conflicting weak extern definition ... New default ... conflicts with old default
I think we have to answer first why we are getting this error message to decide that disabling weak linkage is the right thing to do here.
I am doubtful, without further information of why marking the declaration weak caused the failure.
Ideally, we can weakly link the symbol also on windows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the exact failure: https://ci-external.swift.org/job/swift-PR-windows/38338/consoleText
FAILED: lib/lib_FoundationCollections.lib
C:\Windows\system32\cmd.exe /C "cd . && T:\5\bin\swiftc.exe -target x86_64-unknown-windows-msvc -emit-library -static -o lib\lib_FoundationCollections.lib @CMakeFiles\_FoundationCollections.rsp && cd ."
Rope+_Node.swift.obj : fatal error LNK1227: conflicting weak extern definition for 'swift_coroFrameAlloc'. New default '.weak.swift_coroFrameAlloc.default.$s22_FoundationCollections4RopeV5_NodeV6objectyXlvs' conflicts with old default '.weak.swift_coroFrameAlloc.default.$s22_FoundationCollections4RopeV7isValidySbAC5IndexVyx_GF' in Rope+Collection.swift.obj
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@compnerd I don't know why a weak external reference would result in an error message like that. But it seems that others ran into a similar issue:
swift/lib/IRGen/IRGenModule.cpp
Line 1179 in 98fc0a9
// Windows does not allow multiple definitions of weak symbols. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm
Is the problem that entry in the stdlib runtime is not marked weak
?
swift/include/swift/Runtime/Heap.h
Line 44 in 98fc0a9
void *swift_coroFrameAlloc(size_t bytes, MallocTypeId typeId); |
What happens if we change that line to use SWIFT_RUNTIME_WEAK_IMPORT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using SWIFT_RUNTIME_WEAK_IMPORT
results in linker error: Undefined symbols for architecture x86_64: "_swift_coroFrameAlloc"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I only now realize that typed malloc is not available on windows (or any non apple platform for that matter).
You can disable coroFrameAlloc emission on windows.
swift/include/swift/Runtime/Config.h
Line 132 in ecc9093
#if defined(__APPLE__) && defined(__LP64__) && __has_include(<malloc_type_private.h>) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC |
#if defined(__APPLE__) && defined(__LP64__) && __has_include(<malloc_type_private.h>) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
# include <TargetConditionals.h>
# if TARGET_OS_IOS && !TARGET_OS_SIMULATOR ...
# define SWIFT_STDLIB_HAS_MALLOC_TYPE 1
# endif
#endif
#ifndef SWIFT_STDLIB_HAS_MALLOC_TYPE
# define SWIFT_STDLIB_HAS_MALLOC_TYPE 0
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would achieve that with something similar in spirit to the following change:
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -3766,6 +3766,10 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
Args.hasFlag(OPT_enable_async_frame_push_pop_metadata,
OPT_disable_async_frame_push_pop_metadata,
Opts.EmitAsyncFramePushPopMetadata);
+
+ if (Opts.EmitTypeMallocForCoroFrame && (Triple.isOSLinux() || Triple.isOSWindows())) {
+ Opts.EmitTypeMallocForCoroFrame = false;
+ }
Opts.EmitTypeMallocForCoroFrame =
Args.hasFlag(OPT_enable_emit_type_malloc_for_coro_frame,
OPT_disable_emit_type_malloc_for_coro_frame,
@swift-ci test |
@swift-ci test |
@swift-ci test |
You can restrict a test to run only on say
|
@swift-ci test |
1 similar comment
@swift-ci test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…nst the runtime function (#79889) * [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function This commit modifies IRGen to emit a stub function `__swift_coroFrameAllocStub` instead of the newly introduced swift-rt function `swift_coroFrameAlloc`. The stub checks whether the runtime has the symbol `swift_coroFrameAlloc` and dispatches to it if it exists, uses `malloc` otherwise. This ensures the ability to back deploy the feature to older OS targets. rdar://145239850 (cherry picked from commit 5e2f20b)
…nst the runtime function (#79889) (#80769) * [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function This commit modifies IRGen to emit a stub function `__swift_coroFrameAllocStub` instead of the newly introduced swift-rt function `swift_coroFrameAlloc`. The stub checks whether the runtime has the symbol `swift_coroFrameAlloc` and dispatches to it if it exists, uses `malloc` otherwise. This ensures the ability to back deploy the feature to older OS targets. rdar://145239850 (cherry picked from commit 5e2f20b)
This PR modifies IRGen to emit a stub function
__swift_coroFrameAllocStub
instead of thenewly introduced swift-rt function
swift_coroFrameAlloc
. The stub checks whether the runtime has the symbolswift_coroFrameAlloc
and dispatches to it if it exists, usesmalloc
otherwise. This ensures theability to back deploy the feature to older OS targets.
rdar://145239850