-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Don't get memcpy, memmove, memcmp, memset, and strlen from msvcrt.dll #29130
Comments
These functions are not shims as I have just disassembled and verified this. Also |
@retep998 At least on very old systems, msvcrt.dll did call into |
@alexchandel |
@retep998 I know it has all the syscalls, and that their syscalls are unstable, but I can't find any documentation at all on what symbols are in the current version. Which is uncharacteristic of MS. But that's too bad if we can't, because unless we provide our own implementations of them (alongside an allocator like jemalloc and a math lib like openlibm), we're still tied to MS's CRT> |
@alexchandel We don't rely on the CRT for the allocator, even without jemalloc. Replacing the |
(I don't think implementing our own libm-replacement is a great idea---using a preexisting one like openlibm seems better for various reasons---and, even then, SIMD isn't so useful for scalar functions like those in libm.) |
@huonw Can you elaborate on a few of these reasons? From what I understand, memcpy, memmove and memset have relatively trivial implementations. I realize there's probably loads of platform- and architecture-specific optimizations in the big libs but can't we still get reasonably fast with our own implementation? If it eliminates a problematic dependency I'm all for it. At the very least, it could be a viable alternative. |
@cybergeek94 I think he meant implementing math functions. @huonw you're working on SIMD stuff for memory? |
Why not just remove all uses of |
LLVM inserts calls to (some of) those functions during optimisation passes. |
Why not just turn off those optimizations in LLVM? That would be useful for some users of |
Because then you'd be harming performance for very little gain. |
This is my point. rlibc-based Rust should be made to be fast, and if it is made fast, then disabling the lowering to memcpy/memset/etc. wouldn't matter. I think it would be good to measure the performance impact. Also, Rust shouldn't be using |
It might lower the length-finding op of |
I have never personally seen llvm lower length finding ops to |
I guess I should have looked at the source for that method. I could have sworn I remembered it being implemented in Rust instead of shelling out to |
@briansmith rlibc is intended to be able to supply the implementations that llvm refers to in its loop recognition, memcpy (and others) insertion, etc. No reason to remove that optimization if it points to the pure rust code you wanted. [To improve ] It sounds like a cool project in the long term, but you should look into how huge the code bases for providing micro-architecture specific implementations to these functions are in some libc implementations, for a sense of the scale of it. (For example, there are 68 asm files for memcpy in glibc). |
So we could use rlibc instead when memcpy, memmove, memcmp, strlen, and memset symbols in msvcrt are not exist in ntdll.dll |
They always exist in ntdll.dll, and probably always will. This is slightly less of an issue once #30027 lands, since we could link against |
What about providing implementations in |
@DemiMarie high performance memcpy/memmove/etc implementations are extremely complex. Here is part of glibc's memcmp implementation: https://sourceware.org/git/gitweb.cgi?p=glibc.git;a=blob;f=sysdeps/x86_64/multiarch/memcmp-sse4.S;h=786f87282c08c521b579a15d306830f6263debfb;hb=HEAD. That's only used for x86_64 processors that support SSE4. There are two more completely separate implementations for other x86_64 generations alone. It does not seem to be a good use of resources to try to maintain our own versions when we can rely on implementations provided by the system. |
why not depends on the system msvcrt under system32 dir |
What about ntdll.dll? It is on all Windows systems, and provides such Another option is to use one from any of the permissively-licensed libc
|
Currently the options are:
Per #30027 none of these truly requires Rust to use a toolchain. And Rust code and C code statically linked with Rust can use different methods. |
@alexchandel Don't forget that we could just statically link the CRT which avoids the dependence on redistributables. rust-lang/libc#290 |
I would prefer for Rust to use the same implementation that the C compiler would use, so that when I link C and Rust code together, they are using a common implementation. |
@retep998 When you statically link against the UCRT in MSVC 14+, does the Rust-only executable have any dependence on the new And on a parallel note, if C object files are linked into this Rust binary as well, does linking |
By linking to |
I think we only need static link to libvcruntime.lib for memmove things |
@alexchandel: reviewing your last exchange with @retep998, I would like to ask whether you still wish to keep this issue open? |
Given that Rust provides the ability to statically link the CRT, and there are plans to provide a pure Rust Windows target in the future when #58713 is implemented, closing this issue. |
The
memcpy
,memmove
,memcmp
,strlen
, andmemset
symbols inmsvcrt
are just shims for implementations inntdll.dll
, which have existed since Windows 3.1.If possible, we should link against these directly, rather than going through
msvcrt
. This would have the effect of eliminating all of our dependencies onmsvcrt
except for math functions and the entry point.cc @retep998
The text was updated successfully, but these errors were encountered: