Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ database:

$ ./get # List categories
$ ./get ubuntu debian # Download Ubuntu's and Debian's libc, old default behavior
$ ./get ubuntu-arm # Download Ubuntu's arm64/armhf libc from ports.ubuntu.com
$ ./get all # Download all categories. Can take a while!

You can also add a custom libc to your database.
Expand Down
19 changes: 15 additions & 4 deletions common/libc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ die() {
}

dump_symbols() {
readelf -Ws $1 | perl -n -e '/: (\w+)\s+\w+\s+(?:FUNC|OBJECT)\s+(?:\w+\s+){3}(\w+)\b(?:@@GLIBC)?/ && print "$2 $1\n"' | sort -u
# Force byte-order (C locale) sorting: under locale-aware collation (e.g.
# en_US.UTF-8), `sort -u` can treat symbols differing only by leading
# underscores as equal (e.g. "__dup2" and "dup2"), silently dropping one.
readelf -Ws $1 | perl -n -e '/: (\w+)\s+\w+\s+(?:FUNC|OBJECT)\s+(?:\w+\s+){3}(\w+)\b(?:@@GLIBC)?/ && print "$2 $1\n"' | LC_ALL=C sort -u
}

extract_label() {
perl -n -e '/(\w+)/ && print $1'
}

dump_libc_start_main_ret() {
# Match the "call" instruction on the relevant architecture: x86 uses
# "call"; ARM/AArch64 use "bl" (direct branch-with-link), "blr" (AArch64
# register-indirect branch-with-link) or "blx" (ARM/Thumb register-indirect
# branch-with-link, used to call the app-specific main()).
local call_main=`objdump -D $1 \
| grep -EA 100 '<__libc_start_main.*>:' \
| grep call \
| grep -E '\b(call|bl|blr|blx)\b' \
| grep -EB 1 '<exit.*>' \
| head -n 1 \
| extract_label`
Expand All @@ -27,7 +34,7 @@ dump_libc_start_main_ret() {
if [[ "$call_main" == "" ]]; then
local call_main=`objdump -D $1 \
| grep -EB 100 '<__libc_start_main.*>:' \
| grep call \
| grep -E '\b(call|bl|blr|blx)\b' \
| grep -EB 1 '<exit.*>' \
| head -n 1 \
| extract_label`
Expand Down Expand Up @@ -136,7 +143,11 @@ get_all_debian() {
local info=$1
local url=$2
local pkgname=$3
for f in `wget $url/ -O - 2>/dev/null | grep -Eoh "$pkgname"'(-i386|-amd64|-x32)?_[^"]*(amd64|i386)\.deb' |grep -v "</a>"`; do
# arch is a grep -E alternation of Debian architecture names to match in the
# .deb filename, e.g. "amd64|i386" or "arm64|armhf". Defaults to the
# traditional x86 architectures for backwards compatibility.
local arch="${4:-amd64|i386}"
for f in `wget $url/ -O - 2>/dev/null | grep -Eoh "$pkgname"'(-i386|-amd64|-x32|-armel|-armhf|-arm64)?_[^"]*('"$arch"')\.deb' |grep -v "</a>"`; do
get_debian "$url/$f" "$info" "$pkgname"
done
return 0
Expand Down
12 changes: 10 additions & 2 deletions download
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ download_single() {
popd 1>/dev/null

mkdir libs/$id
cp $tmp/lib/*/* libs/$id 2>/dev/null || cp $tmp/lib32/* libs/$id 2>/dev/null \
|| die "Failed to save. Check it manually $tmp"
# Depending on the distro/architecture and whether merged-/usr is in use,
# the shared libraries can live under lib/<triplet>, usr/lib/<triplet>
# (e.g. modern amd64/arm64 packages), lib32 (i386 multiarch on amd64), or
# lib64/usr/lib64 (amd64 multiarch on i386, e.g. libc6-amd64).
# Only copy regular files (not subdirs like gconv/, audit/), and rely on
# find succeeding rather than cp's exit code, since cp exits non-zero
# whenever a directory is among its arguments even if all files copied.
find $tmp/lib/*/ $tmp/usr/lib/*/ $tmp/lib32/ $tmp/lib64/ $tmp/usr/lib64/ \
-maxdepth 1 -type f -exec cp -t libs/$id {} + 2>/dev/null
[ "$(ls -A libs/$id 2>/dev/null)" ] || die "Failed to save. Check it manually $tmp"
echo " -> Package saved to libs/$id"

rm -rf $tmp
Expand Down
13 changes: 13 additions & 0 deletions get
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ ubuntu() {
get_all_debian ubuntu-old-dietlibc http://old-releases.ubuntu.com/ubuntu/pool/universe/d/dietlibc/ dietlibc
}

categories[cntr_category]="ubuntu-arm"
requirements["ubuntu-arm"]="requirements_debian"
cntr_category=$((cntr_category + 1))
ubuntu_arm_archs="arm64|armhf"
ubuntu-arm() {
# Ubuntu ports archive hosts arm64/armhf (and other non-x86) builds,
# including security updates, all under the same pool directory.
get_all_debian ubuntu-arm-eglibc http://ports.ubuntu.com/ubuntu-ports/pool/main/e/eglibc/ libc6 "$ubuntu_arm_archs"
get_all_debian ubuntu-arm-glibc http://ports.ubuntu.com/ubuntu-ports/pool/main/g/glibc/ libc6 "$ubuntu_arm_archs"
get_all_debian ubuntu-arm-musl http://ports.ubuntu.com/ubuntu-ports/pool/universe/m/musl/ musl "$ubuntu_arm_archs"
get_all_debian ubuntu-arm-dietlibc http://ports.ubuntu.com/ubuntu-ports/pool/universe/d/dietlibc/ dietlibc "$ubuntu_arm_archs"
}

categories[cntr_category]="debian"
requirements["debian"]="requirements_debian"
cntr_category=$((cntr_category + 1))
Expand Down