undefined reference to `__umoddi3'解决办法

来源:互联网 发布:数据安全管理指引 编辑:程序博客网 时间:2024/05/16 12:49

主机配置:ubuntu 11.10下利用交叉编译工具arm-linux-gcc编译内核;

目标板:AT91SAM9260

内核版本:linux-2.6.24


在编译内核linux-2.6.24的过程中遇到错误:

kernel/built-in.o: In function `getnstimeofday':
utsname_sysctl.c:(.text+0x23c64): undefined reference to `__umoddi3'
kernel/built-in.o: In function `do_gettimeofday':
utsname_sysctl.c:(.text+0x23d18): undefined reference to `__udivdi3'
utsname_sysctl.c:(.text+0x23d34): undefined reference to `__umoddi3'
kernel/built-in.o: In function `timekeeping_resume':
utsname_sysctl.c:(.text+0x23ec0): undefined reference to `__udivdi3'
utsname_sysctl.c:(.text+0x23ee0): undefined reference to `__umoddi3'
kernel/built-in.o: In function `update_wall_time':
utsname_sysctl.c:(.text+0x24640): undefined reference to `__udivdi3'
utsname_sysctl.c:(.text+0x24660): undefined reference to `__umoddi3'
utsname_sysctl.c:(.text+0x246f4): undefined reference to `__udivdi3'
utsname_sysctl.c:(.text+0x24714): undefined reference to `__umoddi3'
make: *** [.tmp_vmlinux1] Error 1

网上查阅了,说是include/linux/time.h文件中函数timespec_add_ns()的loop循环在编译过程中被优化掉了。

static inline void timespec_add_ns(struct timespec *a, u64 ns){ns += a->tv_nsec;while(unlikely(ns >= NSEC_PER_SEC)) {ns -= NSEC_PER_SEC;a->tv_sec++;}a->tv_nsec = ns;}
利用https://lkml.org/lkml/2008/2/22/464的patch,可以解决这个问题。打上patch之后的函数是:

static inline void timespec_add_ns(struct timespec *a, u64 ns){ns += a->tv_nsec;while(unlikely(ns >= NSEC_PER_SEC)) {/* The following asm() prevents the compiler from * optimising this loop into a modulo operation.  */asm("" : "+r"(ns));ns -= NSEC_PER_SEC;a->tv_sec++;}a->tv_nsec = ns;}
更改之后编译顺利通过。