似乎答案是否定的,我只是想确保我没有做错任何事情。我找不到一种方法来告诉 Busybox.config
我想要构建musl
而不是构建glibc
,但现在 Busybox 代码库似乎需要 glibc 扩展,例如:
gnu_dev_minor
gnu_dev_major
mallopt
$ export CC=/usr/local/musl/bin/musl-gcc
$ export LDFLAGS=-L/usr/local/musl/lib
$ make
LINK busybox_unstripped
Static linking against glibc, can't use --gc-sections
Trying libraries: crypt m resolv rt
Failed: -Wl,--start-group -lcrypt -lm -lresolv -lrt -Wl,--end-group
Output of:
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 -finline-limit=0 -fno-builtin-strlen -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 -L/usr/local/musl/lib -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 -lcrypt -lm -lresolv -lrt -Wl,--end-group
==========
/usr/bin/ld: libbb/lib.a(appletlib.o): in function `main':
appletlib.c:(.text.main+0x18): undefined reference to `mallopt'
/usr/bin/ld: appletlib.c:(.text.main+0x24): undefined reference to `mallopt'
/usr/bin/ld: networking/lib.a(ping.o): in function `common_ping_main.isra.0':
ping.c:(.text.common_ping_main.isra.0+0x4dc): undefined reference to `__cmsg_nxthdr'
/usr/bin/ld: networking/udhcp/lib.a(dhcpc.o): in function `d4_recv_raw_packet':
dhcpc.c:(.text.d4_recv_raw_packet+0x1c4): undefined reference to `__cmsg_nxthdr'
/usr/bin/ld: util-linux/lib.a(mdev.o): in function `initial_scan':
mdev.c:(.text.initial_scan+0x2c): undefined reference to `gnu_dev_major'
/usr/bin/ld: mdev.c:(.text.initial_scan+0x38): undefined reference to `gnu_dev_minor'
/usr/bin/ld: util-linux/lib.a(mountpoint.o): in function `mountpoint_main':
mountpoint.c:(.text.mountpoint_main+0x64): undefined reference to `gnu_dev_major'
/usr/bin/ld: mountpoint.c:(.text.mountpoint_main+0x70): undefined reference to `gnu_dev_minor'
/usr/bin/ld: mountpoint.c:(.text.mountpoint_main+0x110): undefined reference to `gnu_dev_major'
/usr/bin/ld: mountpoint.c:(.text.mountpoint_main+0x11c): undefined reference to `gnu_dev_minor'
/usr/bin/ld: util-linux/volume_id/lib.a(get_devname.o): in function `uuidcache_check_device':
get_devname.c:(.text.uuidcache_check_device+0x24): undefined reference to `gnu_dev_major'
/usr/bin/ld: archival/lib.a(cpio.o): in function `cpio_o':
cpio.c:(.text.cpio_o+0x25c): undefined reference to `gnu_dev_major'
/usr/bin/ld: cpio.c:(.text.cpio_o+0x268): undefined reference to `gnu_dev_minor'
/usr/bin/ld: cpio.c:(.text.cpio_o+0x27c): undefined reference to `gnu_dev_major'
/usr/bin/ld: cpio.c:(.text.cpio_o+0x290): undefined reference to `gnu_dev_minor'
/usr/bin/ld: archival/lib.a(tar.o): in function `writeTarHeader':
tar.c:(.text.writeTarHeader+0x24c): undefined reference to `gnu_dev_major'
/usr/bin/ld: tar.c:(.text.writeTarHeader+0x264): undefined reference to `gnu_dev_minor'
/usr/bin/ld: coreutils/lib.a(ls.o): in function `my_stat':
ls.c:(.text.my_stat+0xe8): undefined reference to `gnu_dev_major'
/usr/bin/ld: ls.c:(.text.my_stat+0xf4): undefined reference to `gnu_dev_minor'
/usr/bin/ld: coreutils/lib.a(mknod.o): in function `mknod_main':
mknod.c:(.text.mknod_main+0x88): undefined reference to `gnu_dev_major'
/usr/bin/ld: mknod.c:(.text.mknod_main+0xa4): undefined reference to `gnu_dev_minor'
/usr/bin/ld: coreutils/lib.a(stat.o): in function `print_stat':
stat.c:(.text.print_stat+0x294): undefined reference to `gnu_dev_major'
/usr/bin/ld: stat.c:(.text.print_stat+0x2b4): undefined reference to `gnu_dev_minor'
/usr/bin/ld: klibc-utils/lib.a(resume.o): in function `resume_main':
resume.c:(.text.resume_main+0xf8): undefined reference to `gnu_dev_major'
/usr/bin/ld: resume.c:(.text.resume_main+0x1d4): undefined reference to `gnu_dev_minor'
/usr/bin/ld: libbb/lib.a(makedev.o): in function `bb_makedev':
makedev.c:(.text.bb_makedev+0x0): undefined reference to `gnu_dev_makedev'
/usr/bin/ld: libbb/lib.a(udp_io.o): in function `recv_from_to':
udp_io.c:(.text.recv_from_to+0xc8): undefined reference to `__cmsg_nxthdr'
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
另外,除非我关闭大文件系统支持,否则我会收到更多关于 musl 不提供这些的错误:
update_passwd.c:(.text.update_passwd+0xa8): undefined reference to `fopen64'
/usr/bin/ld: update_passwd.c:(.text.update_passwd+0xdc): undefined reference to `open64'
/usr/bin/ld: update_passwd.c:(.text.update_passwd+0xf8): undefined reference to `fstat64'
/usr/bin/ld: update_passwd.c:(.text.update_passwd+0x170): undefined reference to `fcntl64'
/usr/bin/ld: update_passwd.c:(.text.update_passwd+0x5a8): undefined reference to `fcntl64'
这是针对最新的musl libc
1.2.4 的2023-05-01
答案1
我刚刚在 Alpine linux(这是一个基于 MUSL-libc 的系统,没有安装 glibc)下静态构建了 busybox(来自 2023 年 9 月 19 日的提交 5dc9ece3b9e87af0dcb01449821ac827391ac116)。
构建完成,没有错误。
最终的二进制文件是:
/src/busybox # file busybox
busybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, stripped
如果您使用此 Dockerfile:
FROM docker.io/alpine:latest
RUN apk add git alpine-sdk ncurses-dev linux-headers
RUN mkdir /build
COPY busybox-config /build/
COPY build-busybox.sh /build/
CMD ["sh", "/build/build-busybox.sh"]
哪里build-busybox.sh
看起来像这样:
#!/bin/sh
set -e
cd /build
git clone --depth=1 git://busybox.net/busybox.git
cd busybox
cp /build/busybox-config .config
make oldconfig
make
mkdir -p /output
cp busybox /output
并且busybox-config
是.config
通过运行创建的make menuconfig
,那么你可以通过运行获得一个静态链接的busybox:
docker build -t busybuilder .
mkdir output
docker run --rm -v $PWD/output:/output busybuilder
这将创建静态链接的二进制文件output/busybox
。
我已将以上所有内容打包到存储库中这里;您只需克隆存储库并运行顶级build-image-and-busybox.sh
脚本即可。