Re:liblinux: Architecture-independent access to Linux system...
by GoblinSlayer on Tuesday November 09, 2021 @12:24PM
(#29164499)
An example of a relatively simple non-C interface is the linux kernel interface. It's so non-C you can't even cleanly interface with it from C.
Re:liblinux: Architecture-independent access to Linux system...
by matheusmoreira on Tuesday November 09, 2021 @02:05PM
(#29165960)
Yes. The Linux system call calling convention doesn't match the C ones at all. One needs inline assembly in order to interface with the Linux kernel from C.
The ideal solution is to have a system_call keyword built into the compiler that emits the proper instructions for the target platform.
So in order to have usable libraries people will wrap their C++ implementation in C interfaces. Rust faces the same problem. All those nice abstractions result in a complex ABI that will never touched by anything outside the Rust ecosystem. There is no escaping the extern "C".
Some languages are virtualized. Java, C#, Ruby, Python, Javascript all have virtual machines. There's no way to interface directly with code running in those languages. We must interface with the virtual machine instead: import it into our process and ask it to call the functions we want to use.
C binary interfaces are not language agnostic but they are quite simple. The result of compiling a C library is symbols pointing to functions with simple calling conventions. As a result, virtually any language can look up these symbols and call them.