Search code examples
clinuxglibc

Where are syscalls located in glibc source


So I was looking through the linux glibc source and I don't see where it actually does anything. The following is from io/chdir.c but it is indicative of many of the source files. What's going on here? Obviously I am missing something. What's the secret, where does it make a system call or actually do something?

stub_warning is some legacy craziness. __set_errno seems to be a simple macro that sets errno. And while I find a million usages of weak_alias I don't see it defined anywhere.

Is there a helpful guide to understanding how glibc works somewhere?

#include <errno.h>
#include <stddef.h>
#include <unistd.h>

/* Change the current directory to PATH.  */
int
__chdir (path)
     const char *path;
{
  if (path == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  __set_errno (ENOSYS);
  return -1;
}
stub_warning (chdir)

weak_alias (__chdir, chdir)
#include <stub-tag.h> 

Solution

  • What you've found is a stub function for systems it's not implemented on. You need to look under the sysdeps tree for the actual implementation. The following may be of interest:

    • sysdeps/unix/sysv/linux
    • sysdeps/posix
    • sysdeps/i386 (or x86_64 or whatever your cpu arch is)