-
Notifications
You must be signed in to change notification settings - Fork 377
/
musl-symlink.sh
executable file
·57 lines (51 loc) · 1.56 KB
/
musl-symlink.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
# Create necessary symlinks for musl images to run
# dynamically-linked binaries.
# Just to be careful, we need this in a few locations,
# relative to the musl sysroot.
# /lib/ld-musl-armhf.so
# /lib/ld-musl-armhf.so.1
# /usr/lib/ld.so
# /usr/lib/ld.so.1
# /usr/lib/libc.so
# /usr/lib/libc.so.1
set -x
set -euo pipefail
main() {
local sysroot="${1}"
local arch="${2}"
local src
local dst
local dsts
# ignore any failures here
local ld_arch="${arch//_/-}"
mkdir -p "$sysroot/usr/lib"
src="$sysroot/lib/libc.so"
dsts=(
"/lib/ld-musl-${arch}.so"
"/lib/ld-musl-${arch}.so.1"
"$sysroot/lib/ld-musl-${arch}.so"
"$sysroot/lib/ld-musl-${arch}.so.1"
"$sysroot/usr/lib/ld.so"
"$sysroot/usr/lib/ld.so.1"
"$sysroot/usr/lib/libc.so"
"$sysroot/usr/lib/libc.so.1"
# this specifically is a workaround for ARM64, which
# for some reason links to `ld-linux-aarch64.so`, but
# it is a valid musl binary. trying to use `libc6-dev:arm64`
# shows it has an invalid ELF header.
"$sysroot/lib/ld-linux-${ld_arch}.so"
"$sysroot/lib/ld-linux-${ld_arch}.so.1"
)
for dst in "${dsts[@]}"; do
# force a link if the dst does not exist or is broken
if [[ -L "${dst}" ]] && [[ ! -a "${dst}" ]]; then
ln -sf "${src}" "${dst}"
elif [[ ! -f "${dst}" ]]; then
ln -s "${src}" "${dst}"
fi
done
echo "${sysroot}/lib" >> "/etc/ld-musl-${arch}.path"
rm -rf "${0}"
}
main "${@}"