News for hackers. Stuff that matters.
Re:Making Rust as Fast as Go by ekidd on Sunday May 03, 2020 @10:08AM (#23059072)
As far as I know, the official system interface on Windows and several Unix systems is via the standard library, not via direct syscalls. I don't know about the MacOS. But in general, you may be required to dynamically link the standard library on many platforms.

Linux guarantees syscalls are stable. And on Linux, you have the option of telling Rust to cross-compile using a statically-linked musl-libc. (If you also need to statically link OpenSSL or a few other common libraries, I maintain https://github.com/emk/rust-musl-builder, and there's at least one similar image out there.)

Re:Making Rust as Fast as Go by majewsky on Sunday May 03, 2020 @10:15AM (#23059108)
macOS requires you to make syscalls through libSystem if you want a stable interface. Go binaries used to make direct syscalls until 1.10. Since this caused major breakage on most new macOS releases, they have since switched to using libSystem as well in 1.11:

> On macOS and iOS, the runtime now uses libSystem.dylib instead of calling the kernel directly. This should make Go binaries more compatible with future versions of macOS and iOS. The syscall package still makes direct system calls; fixing this is planned for a future release.

Source: https://golang.org/doc/go1.11

Re:Making Rust as Fast as Go by masklinn on Sunday May 03, 2020 @11:42AM (#23059665)
> I don't know about the MacOS.

MacOS literally forbids statically linking to libSystem.

Go finally had to bow down and accept that they just could not perform raw syscalls on MacOS after gettimeofday (IIRC) changed ABI multiple times during the Sierra beta.

Re:Making Rust as Fast as Go by pansa2 on Sunday May 03, 2020 @10:31AM (#23059212)
AFAIK on Windows, the hierarchy is:

C library => kernel32.dll => ntdll.dll => system calls

You don’t have to go via the C library - calling kernel32 directly is fine (I believe this is what Go does). However, it’s very rare to call ntdll or to make system calls directly.

Re:Making Rust as Fast as Go by ChrisSD on Sunday May 03, 2020 @11:26AM (#23059536)
To expand on that, on Windows it's best to use kernel32 (or WindowsApp) unless you really need the cross-platform convenience of the C lib. The exception being architecture dependent functions like memcmp, memcpy and memset which will most likely have efficient assembly implementations.

ntdll is lower level and technically unstable but core functions have been pretty stable for a long time. They could of course have breaking changes but it risks breaking things like cygwin. Microsoft tends to take compatibility seriously, although perhaps not as much as they used to.

Direct system calls are completely unstable. They can and do change a lot between releases. You'd need to use a lookup table for every build of Windows.

Re:Making Rust as Fast as Go by codeflo on Sunday May 03, 2020 @10:38AM (#23059263)
Basically yes. ntdll is an implementation detail that shouldn’t be relied upon. kernel32/user32 and friends are considered the “proper” interface to the system and have been stable for decades.
Re:Making Rust as Fast as Go by vardump on Sunday May 03, 2020 @04:57PM (#23061799)
There are some ntdll calls that are officially documented and ok to use. Of course there are also a lot of calls you shouldn't use.

When necessary, it's fine to use even undocumented ones to support Windows 7 and older. It's not like those are going to change anymore.

Re:Making Rust as Fast as Go by vardump on Sunday May 03, 2020 @10:52AM (#23059339)
> it’s very rare to call ntdll or to make system calls directly

Until you need to do something that's not possible through kernel32.dll. Sometimes I've called ntdll.dll directly to support older Windows versions.

Re:Making Rust as Fast as Go by ludamad on Sunday May 03, 2020 @11:14AM (#23059461)
I'm guessing the performance benefits are negligible anyway?
Re:Making Rust as Fast as Go by ludamad on Tuesday May 05, 2020 @11:53AM (#23081386)
Not sure why I was downvoted for curiousity
Re:Making Rust as Fast as Go by codeflo on Sunday May 03, 2020 @10:25AM (#23059177)
That’s partly true, but the stable interface on Windows is not the libc, but the kernel32/user32 functions like VirtualAlloc, CreateFileW etc. Those are stable since the NT days. The libc functions like malloc and fopen are a compatibility layer above that and unfortunately switch places every few years. Currently they are delivered by a combination of a Windows update and a redistributable package, which makes it a nightmare to ship (on pre-Windows 10 even more so).
Re:Making Rust as Fast as Go by jfkebwjsbx on Sunday May 03, 2020 @05:32PM (#23062030)
Do you really need to ship them? I thought libc (CRT?) in Windows was a given, and what used to be redistributed was only the C++ ones. Is not that the case?
Re:Making Rust as Fast as Go by codeflo on Monday May 04, 2020 @12:28AM (#23064554)
Thanks for the correction, Microsoft calls it the C Runtime/CRT. It‘s unfortunately complicated, and I’ll completely ignore static linking, which is possible, but not supported in many scenarios involving DLLs.

It used to be the case that the CRT shipped with Windows (msvcrt.dll). That file is now considered legacy/deprecated and is no longer supported by current compilers. For several years after that, you always had to redistribute the CRT (msvcrtXXX.dll), even for pure C support.

The current state of affairs is that the CRT is split into several files, some of which come with Windows update (the so-called UCRT) and some of which are compiler-specific and have to be redistributed. C++ std support requires yet more files.

This document gives an overview: https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-l...

Re:Making Rust as Fast as Go by jfkebwjsbx on Monday May 04, 2020 @06:23AM (#23066366)
Thanks a lot! It indeed seems complicated...

I understand standards evolve and that they want to modularize stuff, but in the case of C the majority programs will only use the basics of the C library.