Skip to content
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

[SR-14314] [Windows] Linker errors building libdispatch for x86 #606

Closed
triplef opened this issue Mar 8, 2021 · 5 comments
Closed

[SR-14314] [Windows] Linker errors building libdispatch for x86 #606

triplef opened this issue Mar 8, 2021 · 5 comments
Assignees

Comments

@triplef
Copy link
Contributor

triplef commented Mar 8, 2021

Previous ID SR-14314
Radar None
Original Reporter @triplef
Type Bug

Attachment: Download

Environment
  • Clang 11.0.1

  • Visual Studio 2019

  • Windows 10 1909

Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug
Assignee @compnerd
Priority Medium

md5: b4d8ba04a01d22ce72a059fa5b24e547

relates to:

  • SR-11873 [Windows] building the toolchain fails

Issue Description:

I'm trying to build libdispatch on Windows, which works fine for x64 (in a "x64 Native Tools Command Prompt for VS 2019").

However, building for x86 fails due to various linker errors for BlocksRuntime (full CMake invocation + CMake output + build output attached):

lld-link: error: <root>: undefined symbol: __DllMainCRTStartup@12
lld-link: error: undefined symbol: ___security_cookie
>>> referenced by C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdio.h:1781
>>>               src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(_sprintf)
...lld-link: error: undefined symbol: @__security_check_cookie@4
>>> referenced by C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdio.h:1792
>>>               src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(_sprintf)
...lld-link: error: undefined symbol: __declspec(dllimport) _malloc
>>> referenced by C:\libdispatch\src\BlocksRuntime\runtime.c:371
>>>               src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(__Block_copy_internal)
...lld-link: error: undefined symbol: _memmove
>>> referenced by C:\libdispatch\src\BlocksRuntime\runtime.c:373
>>>               src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(__Block_copy_internal)
...lld-link: error: undefined symbol: __declspec(dllimport) __wassert
>>> referenced by C:\libdispatch\src\BlocksRuntime\runtime.c:482
>>>               src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(__Block_byref_release)lld-link: error: undefined symbol: __declspec(dllimport) ___stdio_common_vsprintf
>>> referenced by C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\stdio.h:1390
>>>               src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(__vsnprintf_l)lld-link: error: undefined symbol: _free
>>> referenced by src\BlocksRuntime\CMakeFiles\BlocksRuntime.dir\runtime.c.obj:(__Block_deallocator)

I am building in a "x86 Native Tools Command Prompt for VS 2019". Even then I had to also specify CFLAGS/CXXFLAGS=-m32 for CMake to not try to target x64 to begin with.

SR-11873 is similar.

@typesanitizer
Copy link

cc @compnerd

@triplef
Copy link
Contributor Author

triplef commented Mar 15, 2021

The issue can also be reproduced using either vcvarsall.bat x86 or vcvarsall.bat x64_x86 instead of the Native Tools Command Prompt.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
@alexchandel
Copy link

What's the solution for <root>: undefined symbol: __DllMainCRTStartup? What lib was missing?

@triplef
Copy link
Contributor Author

triplef commented Jun 13, 2022

I haven’t found a solution for this issue so far.

@compnerd
Copy link
Collaborator

compnerd commented Oct 2, 2022

I'm going to close off this issue. https://dev.azure.com/compnerd/swift-build/_build/results?buildId=60189&view=logs&j=dd7b6b62-9f28-5f94-8c40-5f429eddf697&t=59165692-3d8b-580c-d072-b191af61d4c2 shows a valid build for x86. There was a time where the x86 build of libdispatch didn't work, but I believe all the issues have been resolved. Yes, this is a bit trickier to get right, but the following should give you a working build:
https://github.com/compnerd/swift-build/blob/master/build.cmd#L502
https://github.com/compnerd/swift-build/blob/master/build.cmd#L620-L639
with appropriate modifications of course.

FTR, the undefined symbol __DllMainCRTStartup is going to be fulfilled by msvcrt.lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants