Skip to content

Conversation

@alvinhochun
Copy link
Contributor

Weak symbols on mingw-w64 target with GCC and the GNU linker is a bit broken for the intended use. When using the .weak + .set combo and the referenced symbol is undefined, LD does not produce an error but instead treat the referenced symbol like a weak symbol. This can happen if some of the link library flags is missing. The output executables will crash on run time, which can be very confusing.

This change makes the WINRT_IMPL_... Windows API declarations on GNUC use asm labels instead. This means we lose the ability to "hook" these functions when compiling for mingw-w64 target. But as mentioned in #475, developers should not be doing this anyway.

Weak symbols on mingw-w64 target with GCC and the GNU linker is a bit
broken for the intended use. When using the .weak + .set combo and the
referenced symbol is undefined, LD does not produce an error but instead
treat the referenced symbol like a weak symbol. This can happen if some
of the link library flags is missing. The output executables will crash
on run time, which can be very confusing.

This change makes the WINRT_IMPL_... Windows API declarations on GNUC
use asm labels instead. This means we lose the ability to "hook" these
functions when compiling for mingw-w64 target. But as mentioned in
[microsoft#475], developers should not be doing this anyway.

[microsoft#475]: microsoft#475
WINRT_IMPL_LINK(WaitForSingleObject, 8)
extern "C"
{
void* __stdcall WINRT_IMPL_LoadLibraryW(wchar_t const* name) noexcept WINRT_IMPL_LINK(LoadLibraryW, 4);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a little surprised this compiles, sticking the pragma before the semicolon in the function declaration on MSVC...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like it works in the same way as a #pragma directive on its own line, which you can also put anywhere.

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.

2 participants