admin 管理员组

文章数量: 887021

busybox

问题

1、问题环境

编译环境:Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-122-generic x86_64)
GCC版本gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
busybox下载地址:.29.0.tar.bz2

出现步骤

修改Makefile之后make defconfig;make menuconfig修改对应的选项:

 Location: -> Settings -> Build static binary (no shared libs)	//编译为静态库-> vi-style line editing commands		//选中-> Linux Module Utilities-> Simplified modutils		//取消选中

之后执行make -j8,出现了如下报错:

Static linking against glibc, can't use --gc-sections
Trying libraries: m resolv
Failed: -Wl,--start-group  -lm -lresolv  -Wl,--end-group
Output of:
arm-linux-gnueabi-gcc -Wall -Wshadow -Wwrite-strings -Wundef -Wstrict-prototypes -Wunused -Wunused-parameter -Wunused-function -Wunused-value -Wmissing-prototypes -Wmissing-declarations -Wno-format-security -Wdeclaration-after-statement -Wold-style-definition -fno-builtin-strlen -finline-limit=0 -fomit-frame-pointer -ffunction-sections -fdata-sections -fno-guess-branch-probability -funsigned-char -static-libgcc -falign-functions=1 -falign-jumps=1 -falign-labels=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-builtin-printf -Os -static -o busybox_unstripped -Wl,--sort-common -Wl,--sort-section,alignment -Wl,--start-group applets/built-in.o archival/lib.a archival/libarchive/lib.a console-tools/lib.a coreutils/lib.a coreutils/libcoreutils/lib.a debianutils/lib.a klibc-utils/lib.a e2fsprogs/lib.a editors/lib.a findutils/lib.a init/lib.a libbb/lib.a libpwdgrp/lib.a loginutils/lib.a mailutils/lib.a miscutils/lib.a modutils/lib.a networking/lib.a networking/libiproute/lib.a networking/udhcp/lib.a printutils/lib.a procps/lib.a runit/lib.a selinux/lib.a shell/lib.a sysklogd/lib.a util-linux/lib.a util-linux/volume_id/lib.a archival/built-in.o archival/libarchive/built-in.o console-tools/built-in.o coreutils/built-in.o coreutils/libcoreutils/built-in.o debianutils/built-in.o klibc-utils/built-in.o e2fsprogs/built-in.o editors/built-in.o findutils/built-in.o init/built-in.o libbb/built-in.o libpwdgrp/built-in.o loginutils/built-in.o mailutils/built-in.o miscutils/built-in.o modutils/built-in.o networking/built-in.o networking/libiproute/built-in.o networking/udhcp/built-in.o printutils/built-in.o procps/built-in.o runit/built-in.o selinux/built-in.o shell/built-in.o sysklogd/built-in.o util-linux/built-in.o util-linux/volume_id/built-in.o -Wl,--end-group -Wl,--start-group -lm -lresolv -Wl,--end-group
==========
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: libbb/lib.a(inet_common.o): in function `INET6_resolve':
inet_common.c:(.text.INET6_resolve+0x50): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: coreutils/lib.a(mktemp.o): in function `mktemp_main':
mktemp.c:(.text.mktemp_main+0x9c): warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: networking/lib.a(ipcalc.o): in function `ipcalc_main':
ipcalc.c:(.text.ipcalc_main+0x238): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: libbb/lib.a(inet_common.o): in function `INET_resolve':
inet_common.c:(.text.INET_resolve+0x50): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: networking/lib.a(inetd.o): in function `reread_config_file':
inetd.c:(.text.reread_config_file+0x3b0): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: networking/lib.a(netstat.o): in function `ip_port_str':
netstat.c:(.text.ip_port_str+0x50): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: util-linux/lib.a(rdate.o): in function `rdate_main':
rdate.c:(.text.rdate_main+0xf0): undefined reference to `stime'
/usr/lib/gcc-cross/arm-linux-gnueabi/9/../../../../arm-linux-gnueabi/bin/ld: coreutils/lib.a(date.o): in function `date_main':
date.c:(.text.date_main+0x248): undefined reference to `stime'
collect2: error: ld returned 1 exit status
Note: if build needs additional libraries, put them in CONFIG_EXTRA_LDLIBS.
Example: CONFIG_EXTRA_LDLIBS="pthread dl tirpc audit pam"
make: *** [Makefile:719: busybox_unstripped] Error 1

问题的原因是rdata.c调用的stime函数并没有定义.

rdate.c:(.text.rdate_main+0xf0): undefined reference to `stime'

解决

在busybox的提交记录中搜索stime的提交可以发现有移除stime相关的信息.

/


可以看到修改的原因是glibc2.31中使用clock_settime()替代了stime().

stime() has been deprecated in glibc 2.31 and replaced with
clock_settime(). Let's replace the stime() function calls with
clock_settime() in preperation.

将修改记录同步到本地的代码重新进行编译,可以编译通过.

diff --git a/coreutils/date.c b/coreutils/date.c
index f7e9a8d0e..b9b7fd2cb 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -276,6 +276,9 @@ int date_main(int argc UNUSED_PARAM, char **argv)time(&ts.tv_sec);#endif}
+#if !ENABLE_FEATURE_DATE_NANO
+	ts.tv_nsec = 0;
+#endiflocaltime_r(&ts.tv_sec, &tm_time);/* If date string is given, update tm_time, and maybe set date */
@@ -298,9 +301,10 @@ int date_main(int argc UNUSED_PARAM, char **argv)if (date_str[0] != '@')tm_time.tm_isdst = -1;ts.tv_sec = validate_tm_time(date_str, &tm_time);
+		ts.tv_nsec = 0;/* if setting time, set it */
-		if ((opt & OPT_SET) && stime(&ts.tv_sec) < 0) {
+		if ((opt & OPT_SET) && clock_settime(CLOCK_REALTIME, &ts) < 0) {bb_simple_perror_msg("can't set date");}}
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
index 87cf59b3d..dc40d9155 100644
--- a/libbb/missing_syscalls.c
+++ b/libbb/missing_syscalls.c
@@ -15,14 +15,6 @@ pid_t getsid(pid_t pid)return syscall(__NR_getsid, pid);}-int stime(const time_t *t)
-{
-	struct timeval tv;
-	tv.tv_sec = *t;
-	tv.tv_usec = 0;
-	return settimeofday(&tv, NULL);
-}
-int sethostname(const char *name, size_t len){return syscall(__NR_sethostname, name, len);
diff --git a/util-linux/rdate.c b/util-linux/rdate.c
index 41aade5ea..bb1dc519a 100644
--- a/util-linux/rdate.c
+++ b/util-linux/rdate.c
@@ -95,9 +95,13 @@ int rdate_main(int argc UNUSED_PARAM, char **argv)if (!(flags & 2)) { /* no -p (-s may be present) */if (time(NULL) == remote_time)bb_simple_error_msg("current time matches remote time");
-		else
-			if (stime(&remote_time) < 0)
+		else {
+			struct timespec ts;
+			ts.tv_sec = remote_time;
+			ts.tv_nsec = 0;
+			if (clock_settime(CLOCK_REALTIME, &ts) < 0)bb_simple_perror_msg_and_die("can't set time of day");
+		}}if (flags != 1) /* not lone -s */

参考:

本文标签: busybox