News for hackers. Stuff that matters.
Re:Practical Libc-free threading on Linux by dataflow on Thursday March 23, 2023 @09:10PM (#35283782)
To make it explicit, #4 is basically making the case for why the Linux setting the syscall interface as the stable API boundary is a poor approach.
Re:Practical Libc-free threading on Linux by nine_k on Thursday March 23, 2023 @10:12PM (#35284210)
What approach would be better?
Re:Practical Libc-free threading on Linux by ben0x539 on Thursday March 23, 2023 @10:43PM (#35284417)
I think competing products define their interface in terms of calling a provided C library, and leave the entirely of the system call mechanics as an implementation detail.
Re:Practical Libc-free threading on Linux by jmillikin on Thursday March 23, 2023 @11:59PM (#35284934)
For context, this is how it worked in old-school UNIX. If you look at (for example) SunOS, the kernel ABI is undocumented and everything in userspace depends on libc. The OSes and userspace languages of the day were deeply coupled -- C was the language of UNIX.

You can still see the remnants of this design in macOS, except instead of libc it's libSystem. Apple has decoupled their OS from C (in favor of Objective C, then Swift) but the idea of a userspace entry point to system functionality survived.

Linux is different from traditional UNIX because it's a kernel-only OS. There's no "Linux libc", and third parties have written multiple implementations of the C standard library that run on Linux. The only way this structure can work is for the kernel itself to provide stable ABI, and the standard approach at the time (mid 90s) was numeric syscall codes with positional parameters.

Re:Practical Libc-free threading on Linux by __turbobrew__ on Friday March 24, 2023 @02:16AM (#35285639)
OpenBSD does (did?) require all syscalls to originate from libc as well.
Re:Practical Libc-free threading on Linux by ben0x539 on Friday March 24, 2023 @11:11PM (#35298908)
Yeah, and the particular old-school UNIX I had in mind was Win32. :)
Re:Practical Libc-free threading on Linux by jmillikin on Thursday March 23, 2023 @10:59PM (#35284516)
What alternative is there? Linux is a more minimalist OS than old-school UNIX, and libc as a userspace construct allows more evolution in that space (see glibc vs musl vs uclibc).

I could see an argument for small shims injected by a vDSO (AIUI this is what Fuchsia does), but clearly the 80s-style "libc is the OS boundary" is obsolete.

Re:Practical Libc-free threading on Linux by dataflow on Thursday March 23, 2023 @11:02PM (#35284532)
A user-mode library bundled with the kernel (like libc) is the alternative to the syscall boundary. You maintain the library as the stable interface for the user, and let the syscalls change as you please.
Re:Practical Libc-free threading on Linux by jmillikin on Thursday March 23, 2023 @11:48PM (#35284878)
Yes, I understand the mechanism, but why would you want to structure your OS like that?

You either have to maintain a stable syscall ABI, or a stable userspace function ABI, and it's not like one is materially more difficult than the other. If anything, the Linux approach has proven to be superior -- glibc has had multiple breaking changes over the years and to this day users will resort to Docker to run binaries that depend on "old" glibc, but programs written against the Linux syscall ABI twenty years ago will run fine to this day.

Even if you decide to have a userspace trampoline/shim, it doesn't make sense for that to be libc. The C standard library is huge and requiring userspace programs to link it regardless of implementation language does nothing except add forty years of bad ideas into your process's address space.

Re:Practical Libc-free threading on Linux by userbinator on Friday March 24, 2023 @12:00AM (#35284938)
If anything, the Linux approach has proven to be superior -- glibc has had multiple breaking changes over the years and to this day users will resort to Docker to run binaries that depend on "old" glibc, but programs written against the Linux syscall ABI twenty years ago will run fine to this day.

Windows takes the opposite approach (except that the libraries are gdi32/kernel32/ntdll/user32/etc.), and it's definitely an example of backwards-compatibility done well.

Re:Practical Libc-free threading on Linux by jmillikin on Friday March 24, 2023 @12:14AM (#35285003)
I think the case of Windows is slightly different. Its architecture has the same backwards compatibility challenges of GNU libc, but where GNU took a user-hostile approach ("just recompile"), Microsoft invested thousands of person-years to mitigate and resolve issues as they were discovered.

Most folks reading this are likely familiar with Raymond Chen's blog posts about compatibility shims for older binaries, or stories like the Windows 95 work around for memory-management bugs in SimCity. That's the kind of thing that happens when you design an OS ABI with problems, but are committed to bearing the cost of those problems yourself rather than passing them along to users.

I'm sure if you asked today's Windows team if they'd have a different approach, they'd rattle off a half-dozen great ideas for backwards-compatible syscall ABIs. There's been lots of research in that area since the foundations of our current OS ecosystem were laid down 30 years ago.

Re:Practical Libc-free threading on Linux by fweimer on Friday March 24, 2023 @06:21AM (#35287175)
Multiple organizations ship Linux kernels which do not support the original x86-64 system call ABI at all. Old applications only keep running because these applications are dynamically linked against glibc, and the system glibc version is new enough to use the new system call ABI. Some Linux subsystems are curiously exempt from the ABI stability, or different ABIs can be provided through compile-time or system configuration. Either way, as an application developer, you cannot be sure which ABI will be available.

On the glibc side, it's challenging for us upstream developers because a lot of people assume that we do not aim to provide backwards-compatibility, so they do not bother reporting compatibility issues. I suspect this perception is there because one of the backwards compatibility mechanisms we use prevents running binaries built on newer systems on older systems. (New programs use a new symbol with a backwards-incompatible change, old programs get the old implementation.) But that is not actually about backwards compatibility, it's requesting forward compatibility.

The goal is to require recompilation only in limited scenarios: static libraries and object files not yet fully linked, deliberate dependencies on undocumented internals (e.g., internal struct offsets), and dependency on behavior that is not standards-conforming (e.g., non-sticky EOF on stdio streams). And in the latter case, it's often possible to add a kludge to maintain backwards compatibility.