2

Say I write a non-sensical program that features a single system call, open:

#include <fcntl.h>

void main() { int hi = open("does not exist", 0); }

When I compile the program and issue an ldd command on the output, I get the following:

linux-vdso.so.1 (0x00007ffddd741000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f6835328000)
/lib64/ld-linux-x86-64.so.2 (0x00007f6835584000)

I only recognize the libc.so.6 link, but I don't recognize the others.

Does one of these other libraries contain kernel system calls? Or is it possible that system call functions are statically linked? (seems unlikely).

Kusalananda
  • 333,661
Izzo
  • 961
  • 2
    Hmm, the API is provided by libc itself, right? nm -D /lib/x86_64-linux-gnu/libc.so.6 | grep -w open. – Quasímodo Sep 09 '22 at 00:00
  • https://stackoverflow.com/questions/58657036/where-is-linux-vdso-so-1-present-on-the-file-system – gapsf Sep 09 '22 at 00:01
  • https://unix.stackexchange.com/questions/400621/what-is-lib64-ld-linux-x86-64-so-2-and-why-can-it-be-used-to-execute-file – gapsf Sep 09 '22 at 00:03
  • https://unix.stackexchange.com/questions/396987/is-the-vdso-shared-library-linux-vdso-so-the-library-that-contains-the-kernel/397014#397014 – gapsf Sep 09 '22 at 00:05
  • @Quasímodo you were right! I assumed libc.so only contained standard C library functions, not POSIX system calls. – Izzo Sep 10 '22 at 17:27

1 Answers1

5

System calls aren’t directly visible as functions, and they aren’t linked as such. Each architecture defines its own way of invoking system calls; on 64-bit x86, it involves a specific CPU instruction, SYSCALL.

The C library provides wrappers for most system calls (and a generic system call function for the few unwrapped system calls), and that’s what your program links to.

The other libraries linked in your program are the dynamic linker and the vDSO.

Stephen Kitt
  • 434,908