5 ms·
This is one area where I feel that BSD approach (where the same team maintains both the kernel and the libc, and they're shipped in sync as part of the same rel
by int_19h 8y ago
This is one area where I feel that BSD approach (where the same team maintains both the kernel and the libc, and they're shipped in sync as part of the same release) makes a lot more sense.
In fact, come to think of it, Linux is the only OS where syscalls are the official public userspace API, is it not? On all other platforms, they're an implementation detail behind the system libraries.
- sanxiyn 8y agosyscall-as-API does have some advantages in that you can avoid libc if you want to. One example is Go's Linux target; on Linux, Go standard library calls syscalls directly without any help of libc.
- kayamon 8y agoYou can achieve that on other OSes too though, still without requiring libc. For instance, on Windows the syscall API is hidden and changes from release to release, but KERNEL32.DLL persists as the stable system API that you're supposed to call. Linux desperately needs to get past the notion that libc is the only gateway to the kernel, and instead start supplying a standardized "system/kernel" user-level wrapper library. One which wraps the syscalls nicely but doesn't try to add additional language-specific functionality like printf or memcpy.
- int_19h 8y agoOn Windows, kernel32.dll is basically the Windows equivalent of libc - it's still a userspace library that wraps syscalls, and you're not supposed to use them directly. But I don't see why it's a problem, either. What's the actual benefit of Go invoking syscalls directly on Linux? That it doesn't depend on glibc? But that is only an advantage because glibc is not guaranteed to be there on Linux, the way e.g. kernel32 is on Windows. If it were, there'd be no reason to not use it.
- IshKebab 8y ago> That it doesn't depend on glibc? But that is only an advantage because glibc is not guaranteed to be there on Linux, the way e.g. kernel32 is on Windows. If it were, there'd be no reason to not use it. Yes - but it's an advantage because glibc is a compatibility nightmare. One of Go's really nice features is that you can compile a binary and it will run pretty much anywhere. That would be pretty much impossible if it linked with glibc (even if you ignore the fact that glibc might not be present).
- 4ad 8y agoNot true. On Solaris (and Windows), and more recently in macOS as well we link with libc (or equivalent), and we can still cross compile from any system to these systems. It's not a free lunch of course, doing raw system calls would be preferable, for many reasons. I implemented support for this, for ELF, when I wrote the Solaris port. Other people have done it for PE and Mach-O. It is a fallacy to think that you need access to a shared library in order to link with it. That's only true for C toolchains that don't know better. For Go we have our own toolchain and it doesn't have such a restriction. This is one of the points lost to the "why didn't you just use LLVM?" crowds. Our own toolchain allows us flexibility that simply doesn't exist with traditional toolchains.
- matthewbauer 8y agoHow do you handle changes to the kernel? Can your binaries run on any macOS version or only the very latest? This sounds really cool but also super dangerous. Apple is not known for providing a stable ABI :)
- 4ad 8y agoYou got it backwards, Go used to do raw system calls on macOS, and binaries were occasionally broken by kernel updates. Now Go uses libc on macOS, and binaries are forward compatible with future macOS versions just like any other C/C++/ObjC/swift program. OS X 10.10 (Yosemite) is the current minimum supported version.
- vetinari 8y ago> Linux desperately needs to get past the notion that libc is the only gateway to the kernel, Are you sure about that? Linux doesn't have that notion, it keeps the syscal ABI stable, and anyone can use it directly, like Go does. There's no need to go through blessed syscall library, which on their respective systems are the only gateway to the kernel.
- masklinn 8y agoThe biggest advantage is that it lets other OS easily impersonate linux e.g. SmartOS or Windows can provide kernel-level "linux persona" and have an unmodified linux userland run on top.
- int0x80 8y agoThey can do right now. Both the API and ABI are very rarely (read never but very problematic bugs or similar) broken in a backwards way.
- masklinn 8y agoThat's my point. It's only possible with Linux because Linux provides a stable kernel ABI. You can't impersonate Windows or OSX the same way.
- btbuilder 8y agoAs the article eludes to it is not without its challenges, however. As an example see this issue: https://github.com/golang/go/issues/1435 https://github.com/golang/go/issues/1435 which goes into some of the details why implementing a call for setuid() is not straightforward without the knowledge built into glibc. Also the trickiness of having efficient process fork/exec based on vfork: http://ewontfix.com/7/ http://ewontfix.com/7/ and the considerations going into Go: https://go-review.googlesource.com/c/go/+/46173/ https://go-review.googlesource.com/c/go/+/46173/
- pm215 8y agoI think for setuid in particular the right fix is for the kernel to provide a new syscall that operates on the whole process. The current hoops that glibc has to jump through with signals are complicated (and maybe racy? it's been a while since I looked at the code) and tie up a signal for libc's private use; better support at the kernel layer would allow that to all be eventually dropped.
- carapace 8y ago( allude (elude means escape))
- saagarjha 8y agomacOS lists them all in /usr/include/sys/syscall.h, so I guess you can consider that public API?
- akvadrako 8y agoThat file doesn't even exist on my system, but in any case public means official, not in some header.
- saagarjha 8y agoIf you have the command line tools installed, it should also be under /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/syscall.h. macOS, by default, does not ship with these headers at all, and as of macOS Mojave they no longer provide them under /usr/include unless you install a certain package. With that being said, I disagree with your characterization of “some header”–anything that’s in Apple’s headers is public API, whether it has a fancy page on developer.apple.com or not. Apple has a very clear definition of what they consider to be “private”, and anything in /usr/include isn’t it.
- akvadrako 8y agoActually the path is: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/sys/syscall.h and you can clearly see that the file is wrapped with: #ifdef __APPLE_API_PRIVATE ... #endif /* __APPLE_API_PRIVATE */
- amaccuish 8y agoNope, on my system, without xcode, the previous poster's path is correct: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/sys/syscall.h
- saagarjha 8y agoAgain, if you have the Command Line Tools installed, it'll be under /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/. Xcode also has a copy, but I think fewer people have that installed.
- Annatar 8y agoOn all other platforms, they're an implementation detail behind the system libraries. Yes and this is by design, out of necessity, taught by experience. Commercial customers back in the day paid lots and lots of money, so solutions had to be found and they had to work.
- masklinn 8y ago> In fact, come to think of it, Linux is the only OS where syscalls are the official public userspace API, is it not? Although I never checked so I could be completely wrong, I would expect folks shipping just kernels like SeL4 to ship stable kernel ABI rather than a libc.