Skip to content

Conversation

@ypsvlq
Copy link
Contributor

@ypsvlq ypsvlq commented Jun 30, 2023

fixes #9364, fixes #14727

Zig currently does not ship most of the mingw-w64 CRT, which is required for proper behaviour when linking system libraries. This patch updates mingw-w64 to the latest version and adds build logic for the missing/incomplete libraries.

This wiki diff implies the UCRT is intended to be the default libc, which has been changed here. As with a normal installation of mingw, different libc versions can be explicitly linked to.

@rohlem
Copy link
Contributor

rohlem commented Jun 30, 2023

Could / should this maybe be rebased onto #16109 (unless there's an intentional difference in approach?)

@ypsvlq
Copy link
Contributor Author

ypsvlq commented Jun 30, 2023

CI failures are due to the CI libs being compiled against msvcrt.

Could / should this maybe be rebased onto #16109 (unless there's an intentional difference in approach?)

I hadn't seen that PR, but the mingw commit here adds a lot of files not included there. I'm happy to rebase if that's preferable for maintainers though.

@andrewrk
Copy link
Member

andrewrk commented Jul 3, 2023

Yes, please rebase on top of the mingw-w64-v11.0.1 branch.

We will need to communicate on what files you would like to be added, because I must verify all files added by non- core team members. I hope you understand this is nothing personal, but it is standard security practice that our users expect from a programming language project.

@ypsvlq
Copy link
Contributor Author

ypsvlq commented Jul 3, 2023

Thanks, it should be much easier to review now (relatively at least).

All new files are unmodified from upstream mingw-w64 except .zri files which are preprocessed to simplify compiler logic. You can verify this by reading and running tools/update_mingw.sh locally which should produce identical output.

@andrewrk
Copy link
Member

andrewrk commented Jul 7, 2023

@ypsvlq can you please remove all mingw source files from this PR and just tell me the process that you followed to make the PR so that I can repeat your work?

@ypsvlq
Copy link
Contributor Author

ypsvlq commented Jul 8, 2023

@andrewrk What this PR does is recreate the logic from the mingw-w64-crt Makefile.am in mingw.zig and add the required source files.

The process looked like this:

  • copy the complete upstream mingw-w64-crt into lib/libc/mingw/
  • recreate build logic from Makefile.am in mingw.zig, with notable differences from mainline Zig being:
    • many libraries are built from both a def file and C sources, usually called libname_extra in the mingw build process
    • some libraries are built from MRI scripts, which specify a list of libraries to be linked into a single archive (in this PR, they are preprocessed to contain only the list of system libraries which should be added)
    • some files from the crt should be installed in the include folder (see Makefile.am line 2389)
  • add a shell script to install mingw into the Zig libc folder, preprocess MRI files, and remove unused files (I used this script to view the differences from the lists of sources in mingw.zig)

The mingw commits have been removed as requested, but are still needed for this branch to work.

@ypsvlq
Copy link
Contributor Author

ypsvlq commented Aug 3, 2023

This has been updated to compile post-#16058, but not yet extensively re-tested.

@andrewrk
Copy link
Member

andrewrk commented Jan 8, 2024

Closing in favor of #16109.

As for fixing those issues, this is too many files added. A more surgical approach is needed.

Also, there is a rule: all tools must be written in Zig. That means no Python, no Bash.

@andrewrk andrewrk closed this Jan 8, 2024
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.

Heap corruption crash during rawFree on x86_64-windows-msvc zig cc mingw libraries missing libws2_32.a

3 participants