rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
94.87k stars 12.23k forks source link

Indicate which version of MSVC Rust was built with #26258

Open retep998 opened 9 years ago

retep998 commented 9 years ago

When linking to the CRT on Windows, all code that is statically linked together needs to use the same version of the CRT. Different versions of the CRT (aka they have different DLL names) are not ABI compatible, so msvcrt120.dll and msvcrt110.dll are not ABI compatible. In particular, almost all Rust code links statically to libstd, so the version of the CRT that libstd uses needs to be same version of the CRT that Rust code using that libstd is using.

For the gnu version of Rust, it relies on msvcrt.dll and since all versions of MinGW will link to msvcrt.dll everything is fine and dandy.

However, for the MSVC version of Rust, it is linked against a specific versioned CRT such as msvcrt120.dll. Since the version of the CRT depends on which version of MSVC you build your code with, there is a possibility for you to use a different version of the CRT than libstd was built with, causing room for potential ABI issues. There's even separate debug/release versions of the CRT for each version, as well as static/dynamically linked versions of the CRT.

Therefore, to ensure that there is no ABI compatibility issues, distributions of the MSVC version of Rust should indicate exactly which version of MSVC and the CRT they were built with.

Note that this is purely an issue for developers using Rust to build their code with the msvc toolchain. End-users of binaries built by Rust merely need to have the appropriate redistributable installed and there's no ABI concerns there.

alexcrichton commented 9 years ago

It sounds like our best option will be to avoid the CRT entirely. I highly doubt there's a "correct" CRT to depend on and whatever we choose will likely cause pain for someone at some point, so not depending on one at all seems best.

Apart from the standard library we also need to worry about the small bits of C code we link into the standard library, any object compiled with cl.exe embeds which CRT it was linked against, so we need to be able to avoid that entirely.

cyplo commented 7 years ago

Hi ! Is this still an issue ?

retep998 commented 7 years ago

Rust still relies on things which are not guaranteed by Microsoft to remain stable across versions. Fortunately the stuff that Rust currently relies on hasn't changed between the versions of msvc that we currently support.

Mark-Simulacrum commented 7 years ago

So I seem to recall an RFC and implementation recently regarding CRTs, does that fix this issue? Or at least update it in some way?

steveklabnik commented 5 years ago

Triage: not aware of changes that fixes this.