Linux内核中的64位time_t

时间:2015-03-16 19:15:27

标签: linux kernel time-t

我已经编译了内核3.19.1但是仍然有time_t的问题。只是简单的程序与cout<< sizeof(time_t);给出了4个字节的大小,而不是8个字节的大小。 我应该在make menuconfig期间打开特定选项吗?

3 个答案:

答案 0 :(得分:2)

目前time_t在内核中只是long:请参阅__kernel_time_t类型定义。因此,如果CPU上的long类型为32位长,time_t也是32位长。基本上,如果你有32位CPU - 系统上的long类型也是32位长。如果你有64位CPU - long类型将是64位长。

如果您需要自己的64位类型 - 只需使用long long即可。如果您希望内核时间API与64位长类型一起使用time_t - 它有点困难(意味着更改内核源代码)。例如,看看here。您也可能有兴趣阅读下一个链接:

[1] patchset: "Change time_t and clock_t to 64 bit"

[2] Is there any way to get 64-bit time_t in 32-bit program in Linux

[3] What is ultimately a time_t typedef to?


更新

在将__divdi3更改为time_t后,关于构建问题(使用long long等)。

现在您已将time_t大小更改为64位,使用time_t的任何代码都将尝试使用64位操作。 __divdi3表示: d is strong操作 d ouble i ntegers。 3 代表操作数的计数(如1 = 2 / 3)。有关详细信息,请参阅this。因此,此操作显然尚未针对您的平台实施。您应该自己实现它(在内核代码中)或者以某种方式使用gcc的实现。下一个链接可以帮助您:

[1] __udivdi3 undefined. Howto find code?

[2] divdi3 division used for long long by gcc on x86

[3] Where to find udivdi3 and umoddi3 in gcc?

答案 1 :(得分:1)

在32位Linux上,

64位时间支持为first introduced in the 5.1 kernel,因此,如果您年纪超过此年龄,请对不起。由于更改旧系统调用的返回类型会破坏旧应用程序,因此必须添加新的*time64 syscalls。选中this table,您会看到这些系统调用仅在32位平台上可用。

现在,如果您要为32位系统编写代码,则可以直接调用clock_gettime64(从内联汇编程序或使用带有syscall()函数的C语言)以获取当前时间。但是在那之后,您将完全依靠自己。要获得完整的 userspace 支持,您必须使用 Linux 5.6或更高版本以及musl 1.2+或glibc 2.32+。只需重建代码,time_t就会变成64位长

  • 所有用户空间都必须使用64位time_t进行编译,在即将发布的musl-1.2和glibc-2.32版本以及从linux-5.6或更高版本安装的内核头文件中都将支持该功能。

  • 需要直接移植使用系统调用接口的应用程序,以使用linux-5.1中添加的time64 syscall代替现有的系统调用。这会影响futex()seccomp()的大多数用户,以及具有自己的基于libc的运行时环境的编程语言。

https://lkml.org/lkml/2020/1/29/355?anz=web

有关更多信息,请阅读

答案 2 :(得分:0)

谢谢你的答案!我更改了include / uapi / asm-generic / posix_types.h(long long __kernel_time_t和__kernel_clock_t)

不幸的是内核没有正确构建,这是输出:

LD init / built-in.o kernel / built-in.o:在函数time_to_tm': /root/linux-3.19.1/kernel/time/timeconv.c:82: undefined reference to __ divdi3'中 /root/linux-3.19.1/kernel/time/timeconv.c:83:对__moddi3' security/built-in.o: In function tomoyo_convert_time'的未定义引用: /root/linux-3.19.1/security/tomoyo/util.c:99:对__moddi3' /root/linux-3.19.1/security/tomoyo/util.c:100: undefined reference to __ divdi3'的未定义引用 /root/linux-3.19.1/security/tomoyo/util.c:101:对__moddi3' /root/linux-3.19.1/security/tomoyo/util.c:102: undefined reference to __ divdi3'的未定义引用 /root/linux-3.19.1/security/tomoyo/util.c:103:对__moddi3' /root/linux-3.19.1/security/tomoyo/util.c:104: undefined reference to __ divdi3'的未定义引用 net / built-in.o:在函数ip_options_compile': /root/linux-3.19.1/net/ipv4/ip_options.c:421: undefined reference to __ moddi3'中 net / built-in.o:在函数ip_options_build': /root/linux-3.19.1/net/ipv4/ip_options.c:64: undefined reference to __ moddi3'中 net / built-in.o:在函数icmp_timestamp': /root/linux-3.19.1/net/ipv4/icmp.c:922: undefined reference to __ moddi3'中 make:*** [vmlinux]错误1