Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Okay, here's the Linux syscalls(2) man page: https://man7.org/linux/man-pages/man2/syscalls.2.html

The second sentence is:

> System calls are generally not invoked directly, but rather via wrapper functions in glibc (or perhaps some other library).

Okay, so we can't avoid C that way, but what's the "invoked directly" way? Well, it's syscall(2): https://man7.org/linux/man-pages/man2/syscall.2.html

This man page actually reiterates what the other one, that you shouldn't be making syscalls directly! But in any case, what is `syscall()`?

...it's a C macro.

So yeah, Linux does require programs to use C. You've just been isolated from it.



It's true that the man pages assume C and the calling conventions are based on the C ABI, but it is possible to code the syscalls directly in assembly. In particular Go and Zig have such "bare-metal" syscalls.


You still have to follow the C ABI when interfacing with C. That's the exact problem being called out in the post.

Zig solves interoperability by incorporating an entire copy of LLVM. Go does do bare metal syscalls, but as mentioned elsewhere in these comments, this has caused breakage on Mac when the kernel was updated, because this interface isn't stable.


>So yeah, Linux does require programs to use C. You've just been isolated from it.

No, in the syscall man page it tells you how to call a syscall. For x86_64 you put the syscall into rax and then use the syscall instruction (syscall is the name of an actual instruction). That man page includes more information like what registers arguments should be in or where to find the return value.


I think that “generally” is targeting average programmers.

Programming language authors, writing their own stdglibbabbyscript, are exempt from that warning? That’s of course a big task nobody wants to do so many of them just piggyback on glibc with thin wrappers.


Well, yeah. Hence the rest of my comment. And if you don't go through glibc, then you still must follow the C ABI rules (since that's the only thing the kernel understands), and you are at risk of having your calls break when the kernel is updated (it's already been mentioned elsewhere in these comments that this actually happened to Go on Mac).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: