195 points · by new4thaccount · 7y ago · 128 comments
You can find it at the old site version: https://prev.rust-lang.org/en-US/faq.html
A few weeks ago people pointed out that the internationalization also suffered due to this. Edit: by suffered, I mean "was removed entirely". I just checked and couldn't find a way to change the locale, nor could I manually set it e.g. by appending /de-DE, etc.
If the new design requires a link to the old design to access removed functionality, is it really ready to launch?
---
edit; these were the languages offered: Deutsch, English, Español, Français, Bahasa Indonesia, Italiano, 日本語, 한국어, Polski, Português, Русский, Svenska, Tiếng việt, 简体中文
Now if I want to refer to someone about Rust in Korean I have to link to prev.rust-lang.org, which is weird.
I always thought that for open source software, the more terrible the website the better it was. A site too slick may ruin Rust's reputation
Even if it is dated, I found the gist of it very helpful, so thanks!
I take a minor issue with the handwaving away (not just in this article but with others as well) of glibc and the suggestion that it can just be replaced with musl or another libc. There's a reason that glibc doesn't officially support static linking, and that is NSS, and PAM.
If all you need is a static executable for your Docker container or whatever that reads user/group information and authenticates out of flat files in /etc, then go for it. But in the "enterprise" space things like LDAP, Active Directory, 2FA etc. are real, and if your application needs to support those, then you're going to need glibc and its dependency on dlopen() and friends.
And this goes for every language which has a dependency on your chosen libc as well (which let's face it, is a large majority at least in the Linux world), if you want to use NSS and PAM modules.
> ...rightly points out that statically linked C/C++ executables are going to be large as well.
This is false, and both how a library is structured how linkers work, if you statically link parts of musl expect a somewhat tiny size increase.
> There's a reason that glibc doesn't officially support static linking, and that is NSS, and PAM.
That and the code isn't structured for static linking as there are dependency chains pulling in many symbols.
> ...most C and C++ programmers wouldn't ever perform perhaps outside of the most space constrained embedded projects.
This is because syscalls are os specific and depending on the os unstable. Also Linux has an interesting way of encoding errno into the ret val (maybe others too?) not to mention vdso 'syscalls'.
> ...glibc and its dependency on dlopen() and friends.
If $code doesn't work on musl 99.9% of the time its due to $code, also musl has dlopen and a dyn linker otherwise alpine wouldn't work.
So within my comment I thought it was implicitly clear I was referring to glibc based distributions, for example Redh^H^H IBM.
You CAN statically link binaries against glibc on these distributions, and in many cases it will work. However NSS and PAM will not work in my experience. Is it a generally a good idea to static link against glibc? No.
> If $code doesn't work on musl 99.9% of the time its due to $code, also musl has dlopen and a dyn linker otherwise alpine wouldn't work.
Is sssd officially supported on Alpine Linux? Does it just work out of the box? It seems to be in "testing" branch from what I can see with over 600 open bugs.
There is a reason that shareholders of large organizations want to pay a large, established Linux vendor for support, regardless of whether or not their engineers will ever use the support or not. They want to pay for stability/security updates. They are paying for a Linux distribution that 3rd party application providers have certified their application for.
They want LDAP/AD and other pluggable PAM modules to work out of the box without too much tinkering. Alpine Linux may fit that criteria for all I know. Doesn't matter. My employers wouldn't use it whether I wanted to or not.
Not saying that I like how things have turned out for Enterprise Linux necessarily, but it is what it is. Redhat and clones absolutely DOMINATE this particular space, at least in the USA, UK and Australia.
PAM works fine with musl even though the main implementation of PAM is horrible for security. Also PAM isn't tied to a libc so I don't understand why its mentioned, the glibc implementation of NSS tied to libc but there are other implementations of NSS.
If you're using a Docker image, then that's your statically-linked binary, for all intents and purposes. It won't change sizes much if you link libc statically or dynamically (esp. if you're running in an Alpine container with musl).
Thanks for pointing this out; I'd hit this problem in the past and it's annoying to see people keep promoting static linking as a silver bullet when there is a genuine purpose to dynamically linking the name services.
It would be good info for the rest of us, and it would be great if you could chronicle that stuff.
(Don't tell Life I said to kick it's ass, please. It will crush me.)
https://github.com/n64dev/cen64 is the emulator that I use
* C Hello World - 19K
* Rust Hello World - 1.6M (!)
The C gain is attributable to a change to ld: it puts read-only data and executable data in separate segments by default as a security hardening measure since ld 2.30. I don't see why this shouldn't produce three segments (R, RE, RW), but here I get four (R, RE, R, RW). (Anyone know why four?) If I pass -znoseparate-code to disable this the C goes back to the 8K shown in the article. (No effect on the Rust).
The Rust gain appears to be mostly in debug info. Stripped I get 187K, which is similar to 121K the article gives after stripping and removing jemalloc (which isn't in by default anymore).
Does anyone know why Rust has grown so much from 2016 to 2019?
You need to run `strip` on the executable :(
$ cargo --version && cargo init hello && cd hello && cat ./src/main.rs && cargo build --release && du -h ./target/release/hello
cargo 1.34.0 (6789d8a0a 2019-04-01)
Created binary (application) package
fn main() {
println!("Hello, world!");
}
Compiling hello v0.1.0 (/tmp/foo/hello)
Finished release [optimized] target(s) in 0.31s
1,6M ./target/release/hello
Edit: $ strip target/release/hello && du -h ./target/release/hello
192K ./target/release/helloYou also get the same size if you bypass the println machinery with io::stdout().write_all(b"Hello, world!").
Edit: 1.34.2
According to that thread, the size jump of the unstripped binary is probably from libstd being compiled with -C debuginfo=1 now.
If you compile C with libc statically linked in, it'll make executables as large as Rust's. If you compile Rust for dynamic linking, it'll give you hello world as small as you get from C.
$ cat test.c && musl-gcc -static -O2 test.c && echo && du -h a.out
#include <stdio.h>
int main(void) {
printf("Hello World\n");
}
20K a.out echo $(gcc --version) && cat test.c && gcc -static -O2 test.c && echo && du -h a.out
gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 ...
#include <stdio.h>
int main(void) {
printf("Hello World\n");
}
796K a.outNot in my experience.
Other languages do follow a similar pattern too. Free Pascal has its own runtime library which is linked statically to the executable, does not link against libc unless you want to use c library functions (or libraries that themselves may want to link against c), has a much richer library than libc and yet it can create executables around the same size as C (a simple hello world is a 40KB .exe file in FPC).
So, no, the reason for C having small executables is not that C has any head start (besides, with the exception of GCC and Clang, no other Windows C compiler in Windows relies on a C libraries that comes with Windows, although some - like MSVC and C++ Builder - can use it as a dynamic library which may or may not be installed system-wide).
The hairy part is finding the library on the system, and that's a mess that Rust merely inherited. The build scripts are there to run pkg-config, search system lib dirs, and compile a fallback if necessary (next everyone suggests to just have Cargo automatically figure it out, until they see how deep the rabbit hole goes for snowflake libraries like openssl and llvm).
I don't recommend this as it will increase the memory used by your program which is usually more important than how much disk space it takes up.
OSes only page in the bits of the executable that is actually run, however when upx decompresses the binary it has to load it all into RAM. That RAM can be swapped out but for a normal executable backed by a file the kernel would just drop pages from the file so no write IO needed.
In my tests with rclone, using upx made the binary 31% of the size, but made it use 42% more RAM. YMMV!
The real problem with upx is the invocation latency, which is a big blocker when your program starts a lot (common for CLIs). Executable compression has been much more common in Windows because the download size matters there and programs tend to last much longer.
Why do Rust programs have larger binary sizes than C programs?
[0] https://github.com/rust-lang/rust/blob/master/RELEASES.md#co...
Of course it is a toy example and I imagine in most real-world examples the size of the binary is a moot point.
#![feature(alloc_system)]
extern crate alloc_system;
As for the part that removes libstd it's how you'd generally do it for a bare metal program (i.e. bootloader/OS) since you can't really use it without an OS unless you manually reimplement all sorts of primitives (memory allocations being the most obvious one).Now if you do use libstd it's true that it's significantly larger that libc, but it's also vastly more powerful. You don't have anything like String, Vec or iterators in libc for instance, just a bunch of relatively low-level functions and wrappers around syscalls. It's also a fixed cost, so obviously for a simple Hello World there's a massive overhead but for a more complex application it should be less noticeable.
I mean when you think about it even the C Hello World is ridiculously bloated. If you were to write the equivalent program in assembly without any dependency on the libc you could probably get a binary that would be significantly smaller (and most of its size would really be the ELF metadata).
https://www.muppetlabs.com/~breadbox/software/tiny/teensy.ht...
Seeing that it's possible to make that more reasonable is enlightening!
The more RAM such applications take, the higher is probability that the system will get out of RAM and start swapping. And in this case the system will become so slow that it won't matter what kind of Internet connection you have.
The problem of non-shareable code is also actual for interpreted languages like Javascript, Python or Java. When running such applications, their code and byte-code generated from it often are not shareable. So if you run two copies of desktop JS application, that uses some JS library, you can get two copies of this library in memory. As I remember, Android uses some clever trick that allows sharing compiled Java code. Most other interpreted languages cannot do it.
Also, a fun fact: if you are using Gnome-shell on Wayland and the system starts swapping, computer can stop responding even to mouse movement, and you won't be able even to switch to other VT.
Like, I say this as someone who hates the electron-ification of the desktop.
Additionally there's some pretty good arguments when you're not in a dual interpreted/compiled world and can LTO fully like a pure Rust app is, that the benefits of having everything shared between processes are outweighed by stripping everything out that isn't necessary.
Binary size has less priority than important goals such as feature completeness, compiler speed, optimization performance, target platform coverage, performance tooling support, library coverage, and myriad others. Memory has become cheap enough that excess binary size is not typically the limiting factor preventing deployment, where that happens.
As the language matures, numerous impediments to industrial deployment will fall, one at a time. The language and its ecosystem are maturing with impressive, even stunning rapidity, but it will still be ten years before the language is an obviously safe choice for any random project -- if it gets there at all. Historically, odds are against that, but the only real risks for Rust are whether its adoption rate can be grown fast enough to retain relevance, and whether its development jumps some unforeseen shark not easily recovered from.
Are you talking about the SIGILL? That’s probably a ud2 inside of panic, which presumably tells LLVM it will not return and causes this instruction to be placed there.
Virgil is different, it only includes the stuff which is reachable from main(). In fact the entire compiler is organized around only compiling reachable code into the binary.
Even including the entire runtime and garbage collector, about (8KiB), there isn't much smaller you can get:
HelloWorld.v3: def main(a: Array<string>) {
System.puts("Hello World!\n");
}
-rwxr-xr-x 1 titzer wheel 80 May 16 13:59 HelloWorld-jar
-rwxr-xr-x 1 titzer wheel 9088 May 16 13:59 HelloWorld-x86-darwin
-rwxr-xr-x 1 titzer wheel 5744 May 16 13:58 HelloWorld-x86-darwin-nogc
-rwxr-xr-x 1 titzer wheel 4132 May 16 13:58 HelloWorld-x86-darwin-nort
-rwxr-xr-x 1 titzer wheel 4692 May 16 13:59 HelloWorld-x86-linux-nogc
-rwxr-xr-x 1 titzer wheel 340 May 16 13:59 HelloWorld-x86-linux-nort
-rw-r--r-- 1 titzer wheel 6309 May 16 13:59 HelloWorld.jar
-rw-r--r-- 1 titzer wheel 63 May 16 13:57 HelloWorld.v3
-rw-r--r-- 1 titzer wheel 3486 May 16 14:04 HelloWorld.wasm
-rw-r--r-- 1 titzer wheel 256 May 16 14:46 HelloWorld-nogc.wasm
(the executable files are, well, the executables). The Linux executable without runtime or GC is literally 340 bytes, the wasm executable without GC is 256 bytes. The x86-darwin-nort binary is large because apparently Mach-O executables don't work right unless they are at least one 4KiB page in size.