c-glibc中以__NR_为前缀的符号是什么



我正试图在Alpine Linux上编译Box86,这是一个使用musl-libc实现而不是glibc的Linux发行版。在完成46%时,编译因以下错误而停止:

/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

当然,我的第一本能是查找这些名称,弄清楚它们的用途,这样我就可以找到合适的替代品,但我在这样做时运气不佳,这让我产生了一个问题:这些前缀为__NR_的符号是什么,它们做什么?

您似乎在使用musl 1.2.0或更高版本进行编译,即使在32位目标上也有64位time_t。这意味着32位系统调用(gettimeofdayclock_gettimeclock_getres(与musl对struct timevalstruct timespec的定义不兼容。为了防止意外调用那些类型错误的系统调用,相应的系统调用常量在此环境中不可用。

__NR_开头的标识符是定义系统调用号的常量的不可移植的Linux内核特定名称。用户空间程序应该使用的可移植名称以SYS_开头。

GNU libc允许不可移植的名称从内核的头部传递到<sys/syscall.h>;听起来musl-libc没有。尝试在整个文件中搜索并替换将__NR_更改为SYS_

最新更新