by zasdffaa · 4y ago · 0 comments
Could someone explain this. I'm not familiar with low level linux stuff. Why would you choose not to use libc, what are the implications?
1. libc is considered hazard - security, comfort, runtime. It needs to maintain support for so many flows and setups so it's hard to make things better. For example, having `errno` as a global is quite weird (instead of just returning it, which is a whole discussion of it's own)
2. Golang devs like to re-invent the wheel, in a kind of Apple-ish way - all other are doing it wrong, we're going to do it better. ofc it's debatable whether they're correct with their approach.
3. Given they use Plan 9 system design, doing FFI from Go is very expensive (need to switch stack, save context, etc on each call)
It was quite weird before we wrote concurrent software. Once you're writing concurrent software it's very weird because as originally documented this single error location is shared by all threads, so it necessarily gets concurrently modified while being read, a Data Race.
Your 2022 C library typically defines it as Thread Local instead, so when you call some_c_function() and then check errno, you aren't confused by the fact meanwhile another thread tried to open("nonexistent.file") and so their thread set errno to report that the file doesn't exist.
Given that none of this fuss is how the actual system calls work, it's understandable that people might want to sidestep it.
I'm very happy with these tradeoffs. Not only is it a pleasure not to have to deal with libc (truly static binaries on Linux, 2mb docker images, etc), but because interop is tedious/expensive, the ecosystem is largely pure-Go. This means that we rarely (if ever) have to deal with C's abysmal build tooling and (lack of) package managers and stuff like cross compilation is trivial. Everything builds consistently on every system, every time, and irrespective of target platform (provided there are no C dependencies).
Easy interop has only ever been an illusion (we forget about the difficulties of integrating distinct build systems and memory management systems or the runtime costs of marshaling data between memory layouts). Rather than paying significant costs to preserve that illusion, Go doubled down in order to realize some pretty considerable gains: easy compilation even on niche distros, even when cross compiling, truly static binaries, etc.