What are the __NR_-prefixed symbols in glibc?

1.3k views Asked by At

I'm trying to compile Box86 on Alpine Linux, a Linux distribution which uses the musl libc implementation rather than glibc. At 46% completion, the compilation halts with the following errors:

/home/newbyte/box86/src/emu/x86syscall.c:124:11: error: '__NR_gettimeofday' undeclared here (not in a function); did you mean 'gettimeofday'?
  124 |     { 78, __NR_gettimeofday, 2 },
      |           ^~~~~~~~~~~~~~~~~
      |           gettimeofday
/home/newbyte/box86/src/emu/x86syscall.c:210:12: error: '__NR_clock_gettime' undeclared here (not in a function); did you mean 'clock_gettime'?
  210 |     { 265, __NR_clock_gettime, 2 },
      |            ^~~~~~~~~~~~~~~~~~
      |            clock_gettime
/home/newbyte/box86/src/emu/x86syscall.c:211:12: error: '__NR_clock_getres' undeclared here (not in a function); did you mean 'clock_getres'?
  211 |     { 266, __NR_clock_getres, 2 },
      |            ^~~~~~~~~~~~~~~~~
      |            clock_getres

Naturally, my first instinct was to look these names up and figure out what they are for so that I can find a suitable replacement, but I had little luck doing so, which leads me to my question: What are these __NR_-prefixed symbols, and what do they do?

2

There are 2 answers

0
Florian Weimer On BEST ANSWER

You seem to be compiling using musl 1.2.0 or later, which has a 64-bit time_t even on 32-bit targets. This means that the 32-bit system calls (gettimeofday, clock_gettime, clock_getres) are not compatible with musl's definition of struct timeval and struct timespec. To protect from accidentally calling those system calls with the wrong types, the corresponding system call constants are not available in this environment.

2
zwol On

Identifiers starting with __NR_ are non-portable, Linux-kernel-specific names for the constants defining system call numbers. The portable names that user space programs should use, start with SYS_ instead.

GNU libc allows the non-portable names to pass through from the kernel's headers into <sys/syscall.h>; it sounds like musl libc doesn't. Try search-and-replace changing __NR_ to SYS_ throughout this file.