Musl libc에 정적으로 연결된 Busybox를 구축하는 것이 가능합니까?

Musl libc에 정적으로 연결된 Busybox를 구축하는 것이 가능합니까?

대답은 '아니오'인 것 같습니다. 저는 단지 제가 잘못한 것이 없는지 확인하고 싶을 뿐입니다. build 대신 .configbuild 를 하고 싶다고 Busybox에 알리는 방법을 찾을 수 없지만 이제 Busybox 코드베이스에 glibc 확장이 필요한 것 같습니다. 예를 들면 다음과 같습니다.muslglibc

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 libc1.2.4 용입니다.2023-05-01

답변1

방금 Alpine Linux(glibc가 설치되지 않은 MUSL-libc 기반 시스템)에서 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다음 을 실행하여 정적으로 연결된 비지박스를 얻을 수 있습니다..configmake menuconfig

docker build -t busybuilder .
mkdir output
docker run --rm -v $PWD/output:/output busybuilder

그러면 정적으로 링크된 바이너리가 생성됩니다 output/busybox.

위의 모든 내용을 저장소에 패키지했습니다.여기;저장소를 복제하고 최상위 build-image-and-busybox.sh스크립트를 실행하면 됩니다.

관련 정보