-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Port swift/remote to Windows and MSVC #6025
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
@@ -756,6 +757,9 @@ class MetadataReader { | |||
return BuiltOpaque; | |||
} | |||
} | |||
|
|||
std::cerr << "fatal error: " << "Unhandled MetadataKind in switch." << "\n"; | |||
std::abort(); |
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.
Is this better handled with a covered switch and llvm_unreachable
?
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.
We get linker errors compiling swiftCore.dll if we use llvm_unreachable
. The errors are unresolved external llvm_unreachable_internal
. This is because we can't/don't link any LLVM libraries from the stdlib.
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.
Ah right. I think that having a swift_unreachable
is going to be cleaner. We could model it after llvm_unreachable
.
|
||
RemoteAddress InProcessMemoryReader::getSymbolAddress(const std::string &name) { | ||
#if defined(_WIN32) | ||
HMODULE module = GetModuleHandle(0); |
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.
Yes, 0
is equivalent, but please use NULL
as the documentation states.
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.
Right - fixed, thanks
@@ -175,6 +175,9 @@ swift_layout_kind_t getTypeInfoKind(const TypeInfo &TI) { | |||
} | |||
} | |||
} | |||
|
|||
std::cerr << "fatal error: " << "Unhandled TypeInfoKind in switch." << "\n"; | |||
std::abort(); |
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.
Covered switch + llvm_unreachable
?
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.
ditto
@@ -756,6 +757,9 @@ class MetadataReader { | |||
return BuiltOpaque; | |||
} | |||
} | |||
|
|||
std::cerr << "fatal error: " << "Unhandled MetadataKind in switch." << "\n"; | |||
std::abort(); |
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.
Ah right. I think that having a swift_unreachable
is going to be cleaner. We could model it after llvm_unreachable
.
#if defined(_WIN32) | ||
HMODULE module = GetModuleHandle(NULL); | ||
auto pointer = GetProcAddress(module, name.c_str()); | ||
FreeLibrary(module); |
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.
GetModuleHandle
does not increment reference count for the module. When you are invoking FreeLibrary
here, you are decrementing the refcount on the module. This can cause the main module to hit a reference count of 0, and be unloaded! Am I missing something?
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.
The GetModuleHandle function returns a handle to a mapped module without incrementing its reference count. However, if this handle is passed to the FreeLibrary function, the reference count of the mapped module will be decremented. Therefore, do not pass a handle returned by GetModuleHandle to the FreeLibrary function. Doing so can cause a DLL module to be unmapped prematurely.
According to the docs - my bad
Thanks @compnerd. I introduced a |
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
|
||
SWIFT_ATTRIBUTE_NORETURN | ||
inline static void swift_unreachable(const char* msg) { | ||
assert(false && msg); |
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.
Don't you get an unused variable warning when building release? (_NDEBUG).
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.
I think so, haven't done a release build - I've fixed this
RemoteAddress InProcessMemoryReader::getSymbolAddress(const std::string &name) { | ||
#if defined(_WIN32) | ||
HMODULE module = GetModuleHandle(NULL); | ||
auto pointer = GetProcAddress(module, name.c_str()); |
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.
Could've inlined the GetModuleHandle.
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.
Sure, fixed
|
||
#include <iostream> |
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.
Don't think that iostream
is needed any more.
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.
Correct, fixed thanks
@swift-ci please test and merge |
@compnerd sorry for the churn, tests passed but this didnt merge |
@swift-ci Please smoke test OS X platform |
@hughbe going to be a bit more paranoid and run the smoke tests on macOS before merging. |
#endif | ||
|
||
SWIFT_ATTRIBUTE_NORETURN | ||
inline static void swift_unreachable(const char* msg) { |
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.
Ah, please don't name this swift_unreachable
—we still want people to prefer llvm_unreachable
when possible. How about swift_runtime_unreachable
?
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.
…if there isn't already such a thing somewhere in the real runtime, in which case we should use that.
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.
Could we just use llvm_unreachable
with a runtime-local implementation of llvm_unreachable_internal
for debug builds? Unreachable branches should be optimized as really unreachable in release builds of the runtime.
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.
That could be even better. I'm honestly fairly unhappy about us having runtime things in include/swift/Basic/, but maybe I should be unhappy about having runtime libraries in lib/.
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.
I was thinking we'd just reimplement llvm_unreachable_internal
locally inside the runtime. We already have to provide a reimplementation of some LLVM hashing stuff to be able to use DenseMap
inside the runtime.
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.
Oh, I didn't realize we'd actually bitten the bullet and put DenseMap in. Should we just link llvmSupport and let the linker figure it out? ;-)
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.
@jrose-apple, while you propose that (probably) in jest, that would help with another issue that recently came up. The ABI breaking validation for LLVM uses a value in llvmSuppprt. We ended up having to add another build option to disable it and force disable for swift.
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.
It's worth a shot. If linking llvmSupport into the runtime doesn't affect the binary size too much, it'd certainly be preferable to cherry-picking certain definitions we need.
@@ -20,7 +21,7 @@ using namespace swift::reflection; | |||
using namespace swift::remote; | |||
|
|||
using NativeReflectionContext | |||
= ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>; | |||
= swift::reflection::ReflectionContext<External<RuntimeTarget<sizeof(uintptr_t)>>>; |
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.
dlfcn.h
, use Win32 APIs instead. This requires adding a CPP file to avoid importing<windows.h>
in a header.Error C2248 '
anonymous-namespace'::RemoteASTContextImpl::fail': cannot access private member declared in class 'anonymous-namespace'::RemoteASTContextImpl'
by making a private method protected.error C2872: 'ReflectionContext': ambiguous symbol
by qualifying the namespace ofReflectionContext
std::cerr
andstd::abort
as we get linker errors when we usellvm_unreachable