Live data from Hacker News

Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

faultlore.com

171–180 of 279 posts

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#171
post #31

Dynamic linking is in my opinion not that useful anymore in this day and age where the few MB of RAM and disk space you save is not worth the hassle. The amount of dynamic linking issues I encountered on GNU/Linux was insane (fuck libstdc++). Not even glibc manages to keep forward compatibility working (breaking memcpy, breaking DT_HASH, ...)! It's much better to just statically link your binaries (unfortunately many…

This is a somewhat myopic take on the value of the dynamic linking.

One important aspect is that a dynamic library provides a host of implementations that have been tailored or optimised for specific subsets of CPU's or specific generational CPU features. Let's take «memcpy» as an example that is taken for granted. «memcpy» is defined as weak symbol in the libc.so or similar, and the dynamic linker will replace it with a version that has been optimised for the CPU flavour and CPU flavour's features that have been detected at the runtime or replace it with a less performant, default generic implementation if the dynamic linker does not recognise or support a particular CPU variety. Remember how «memcpy» got an instant manyfold speedup when the AVX-512 optimised version appeared? Yep, all dynamically linked binaries got an instant speedup without even noticing the change. The same will happen (likely, it has already happened) for aarch64 SVE2 vector instructions, and it will happen for RISC-V 64 bit once the vector extension is ratified etc. Doing away with the dynamic linking will slow the adoption of new CPU features down substantially.

If you do away with the dynamic linking, you will not be able to troubleshoot or debug a failing app by substituting the default «malloc» with a debug (or a more performant) implementation via LD_PRELOAD. The Boehm garbage collector was widely used this way (whilst it was being maintained) to overload «malloc» and «free» to successfully run leaky apps that would run out of memory without the GC.

Then there are linking times. Linking Chrome and KDE binaries has been reported to take over an hour and require vast amounts of disk space. We now have «sold» and «mold» so it might be less of an issue but they are not a mainstream linkers yet. Updating a single dynamic library is undisputably faster than relinking 100k binaries that use it. 99.999% of end users will never bother with the relinking anyway.

Naturally, you could claim that the same can be accomplished by fiddling with link maps supplied alongside of object files, but… the link maps are hostile to developers and require a large body of the low-level fringe knowledge that libc authors have taken the burden of. The link maps would have to be very detailed thus very large and also require every developer to have an advanced degree in witchcraft. That would hamper software development efforts for nearly everyone.

Which is not to mention that distributing object files has been tried before, and it has never caught on especially amongst commercial vendors for a number of mostly non-technical reasons. The amount of IP that can be extracted from an object file and the ease of extraction has made the vendors unwilling to distribute anything that is not a final binary product and balk at the idea of it.

You could make a stronger case with suggestion with the OS/400 style of the static binary translation (or AOT) which is functionally combines benefits of object files and some dynamic library features (with the exception of LD_PRELOAD that would have to be replaced with a separate AOT run to «re-link» the final binary product with whatever version of «malloc» / «memcpy» / etc is required), and LLVM has tried that with Bitcode, but for a reason unclear to me, Bitcode seems to have been fading away.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#172

Earlier quoted context omitted.

It's Apple-exclusive in the same way that C# is Windows-exclusive or Go is Linux-exclusive. You'll have a much better time programming C# on Windows or Swift on macOS, because that's where all the best tooling is. The tools and libraries are open-source, cross-platform, and mostly maintained by one company.

That's really not the case with C# or Go. C# has first class Linux support nowadays (minus GUI support) and using Go on windows is quite easy (I daily drive go on windows at work).

Not having GUI support is definitly not first class.

Secondly many libraries are missing as a large portion of the ecosystem is still focused on Windows, and VSCode is a tiny portion of Visual Studio features.

One needs to buy a Java based IDE (Rider) for good support doing C# development on Linux.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#173

[flagged]

I am honestly curious what kind of content you must be consuming to come to that sort of conclusion. Like, is there a secret “anti-dynamic linking league” somewhere who pushes people to think it’s the literal spawn of Satan?

I never got the anti-dynamic linking crowd, being old enough that static linking was the only option (minus hacks like overlays), I don't miss those days.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#174
post #166
post #159

Earlier quoted context omitted.

Component object model. It’s a windows thing from the 90’s that still permeates the lower levels of windows programming.

Nope, it is the way modern Windows APIs are done since Vista.

That doesn’t negate anything I said.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#175

Earlier quoted context omitted.

It's a common argument of computers getting powerful so we don't need to care that much for performance and/or efficiency regarding to cpu/memory/storage etc. In some limited cases the argument is valid but most of the time it's not. First of all while maybe desktops and mobile phones are more powerful now, but we're getting more and more lower spec devices, like smart watches. Even when smart watches will be powerfu…

So are you saying use Rust, more efficient at the expense of maybe using more memory? Or swift which may save some memory by being dynamically linked but perhaps is a little slower. Honestly a ton of code is utility code, not run that often and nobody wants to take the time or expense to rewrite that Perl/python/bash script. Some code efficiency is much more important than others.

This thread[0] might answer your questions

[0] https://news.ycombinator.com/item?id=34575561

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#176
post #117

Earlier quoted context omitted.

What do you mean about rust being too specific for most things? It seems like a fairly obvious choic for c++ replacement in a new project, the issue is large c++ codebases already exist, and that migration is painful in my experience. Autocxx type support is still largely missing or in work, diplomat seems reasonable, but I haven't had an opportunity to use it for something real yet.

Rust will not replace C++. Everything is thrown out the window, including developer productivity in order to provide the 'zero overhead runtime guarantee' feature. The code ends up quite laborious, and it's just not suitable for many things, and it doesn't play so easily with C. Most projects do not require what Rust provides at the cost it provides it at. C++ people really wants a C++ that is clean, modern, parsable…

> Most projects do not require what Rust provides at the cost it provides it at.

If this is true, it's because most projects should use a GC'd, memory safe language, not because most projects should use memory unsafe languages. There is little to no place for memory unsafe languages such as C++ for new projects in 2023.

> Also I think that Rust is a 'V1' version of a borrow checker and I can't wait for newer iterations which I think will be better.

This is the literal definition of vaporware, without a specific plan for how "newer iterations" will do it better. People have been searching for silver bullets for years in this space and nobody has really found a way to improve on the balance Rust has found without introducing garbage collection of some kind. I personally don't believe a "better borrow checker" can exist without GC (which is not such a bad thing, by the way--in my experience, C++ and Rust developers tend to be unfairly dismissive of garbage collection).

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#177
post #174
post #166

Earlier quoted context omitted.

Nope, it is the way modern Windows APIs are done since Vista.

That doesn’t negate anything I said.

The way you phrased it kind of implies it being legacy and we still need to deal with it.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#178
this post makes me realize why swift is starting to look more and more bloated from an end-user pov. It was designed to be right from the beginning. instead of carefully backing off complex problems and slashing features to keep the design elegant, they just "went for it" at full speed.

History will tell if that was a good thing.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#179
post #33

Earlier quoted context omitted.

Security updates, though? I mean, you aren't wrong. But there were other advantages to dynamic linking.

You are going to see more security improvement by using Rust than the unlikely but possible chance of having your C library incidentally updated.

Not convinced at all. Say a big exploit gets published for a very popular library: you probably want to patch it as fast as possible. Whereas Rust will help you have fewer security issues in your own code, which is likely not as popular as some of your critical deps.

Re: Swift Achieved Dynamic Linking Where Rust Couldn't (2019)

#180
post #33

Earlier quoted context omitted.

Security updates, though? I mean, you aren't wrong. But there were other advantages to dynamic linking.

There is obviously a trade off here, but categorically speaking, new releases introduce new bugs and security exploits too.

But they do patch the known security exploits that are likely to be actively used. I'm happier with a security exploit (almost) nobody knows than with a published one that appears in hacking tutorials from 10 years ago.
Post reply on HN