summaryrefslogtreecommitdiff
path: root/system/musl
diff options
context:
space:
mode:
Diffstat (limited to 'system/musl')
-rw-r--r--system/musl/APKBUILD22
-rw-r--r--system/musl/dcngettext-null-deref.patch82
-rw-r--r--system/musl/fix-file-locking-race.patch54
-rw-r--r--system/musl/getaddrinfo-regression.patch51
-rw-r--r--system/musl/ldconfig196
-rwxr-xr-xsystem/musl/musl-utils.trigger3
-rw-r--r--system/musl/ppc64-atomic.patch74
7 files changed, 463 insertions, 19 deletions
diff --git a/system/musl/APKBUILD b/system/musl/APKBUILD
index 0505e9ebd..08f4342dd 100644
--- a/system/musl/APKBUILD
+++ b/system/musl/APKBUILD
@@ -2,7 +2,7 @@
# Maintainer: A. Wilcox <awilfox@adelielinux.org>
pkgname=musl
pkgver=1.1.20
-pkgrel=0
+pkgrel=4
pkgdesc="System library (libc) implementation"
url="http://www.musl-libc.org/"
arch="all"
@@ -13,15 +13,25 @@ depends_dev="!uclibc-dev"
makedepends="$depends_dev"
subpackages="$pkgname-dev $pkgname-dbg"
case "$BOOTSTRAP" in
-nocc) pkgname="musl-dev"; subpackages=""; options="$options !dbg" builddir="$srcdir"/musl-$pkgver;;
+nocc) pkgname="musl-dev"
+ subpackages=""
+ options="$options !dbg"
+ builddir="$srcdir"/musl-$pkgver
+ ;;
nolibc) ;;
-*) subpackages="$subpackages $pkgname-utils";;
+*) subpackages="$subpackages $pkgname-utils"
+ triggers="$pkgname-utils.trigger=/etc/ld.so.conf.d"
+ ;;
esac
source="http://www.musl-libc.org/releases/musl-$pkgver.tar.gz
amalgamation.patch
2000-pthread-internals-increase-DEFAULT_GUARD_SIZE-to-2-p.patch
3001-make-real-lastlog-h.patch
handle-aux-at_base.patch
+ fix-file-locking-race.patch
+ dcngettext-null-deref.patch
+ getaddrinfo-regression.patch
+ ppc64-atomic.patch
ldconfig
getent.c
@@ -113,6 +123,10 @@ sha512sums="d3a7a30aa375ca50d7dcfbd618581d59e1aa5378417f50a0ca5510099336fd74cc9d
2c8e1dde1834238097b2ee8a7bfb53471a0d9cff4a5e38b55f048b567deff1cdd47c170d0578a67b1a039f95a6c5fbb8cff369c75b6a3e4d7ed171e8e86ebb8c 2000-pthread-internals-increase-DEFAULT_GUARD_SIZE-to-2-p.patch
88ae443dbb8e0a4368235bdc3a1c5c7b718495afa75e06deb8e01becc76cb1f0d6964589e2204fc749c9c1b3190b8b9ac1ae2c0099cab8e2ce3ec877103d4332 3001-make-real-lastlog-h.patch
6a7ff16d95b5d1be77e0a0fbb245491817db192176496a57b22ab037637d97a185ea0b0d19da687da66c2a2f5578e4343d230f399d49fe377d8f008410974238 handle-aux-at_base.patch
-8d3a2d5315fc56fee7da9abb8b89bb38c6046c33d154c10d168fb35bfde6b0cf9f13042a3bceee34daf091bc409d699223735dcf19f382eeee1f6be34154f26f ldconfig
+b967339d9048161583523e847be91779adb0e16cc225d6ff85ef51748269b2dab08a0b8e558ad01469135837a9df76a59bf9a31791dd4063d75bc5efe6e94861 fix-file-locking-race.patch
+a08d1b170356beea333ace1da12f8a8399ca80c5d9c32ff2fcd8562537a670214f566e4b1219a11b32129078e22fbf7009bb277b7de8550a89352a64b3b5090d dcngettext-null-deref.patch
+e3953a3a73ef11696dd3eb216e18b152ae35198d8bff686d157e27bc90fb558f9a0be518025a90534e9afd6ea1bf731ffdb6fcb202bb9368f2c8eec7ca886141 getaddrinfo-regression.patch
+aae9110eccb8cd7dcd3c957fcb01ed524598f79f7fa1a16b9993af40793545d1ec211e7e6aeabe7af7715d94cc26a473ea0acf6d6e66019bf65f03d4b8e24a4b ppc64-atomic.patch
+cce2f1eeb61e55674469c26871a573cce61d739c3defe9c8f56f2b774f6ba5435849ad542a6714120efddc98c297098e9c98a1a424ac593df2243d4aa479f9a9 ldconfig
378d70e65bcc65bb4e1415354cecfa54b0c1146dfb24474b69e418cdbf7ad730472cd09f6f103e1c99ba6c324c9560bccdf287f5889bbc3ef0bdf0e08da47413 getent.c
9d42d66fb1facce2b85dad919be5be819ee290bd26ca2db00982b2f8e055a0196290a008711cbe2b18ec9eee8d2270e3b3a4692c5a1b807013baa5c2b70a2bbf iconv.c"
diff --git a/system/musl/dcngettext-null-deref.patch b/system/musl/dcngettext-null-deref.patch
new file mode 100644
index 000000000..bcc385e86
--- /dev/null
+++ b/system/musl/dcngettext-null-deref.patch
@@ -0,0 +1,82 @@
+From 017e67ddde79fa2b6187a5e56b1e92bafc7c4cd2 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Fri, 14 Sep 2018 13:00:41 -0400
+Subject: drop lazy plural forms init in dcngettext
+
+there is no good reason to wait to find and process the plural rules
+for a translated message file until a gettext form requesting plural
+rule processing is used. it just imposes additional synchronization,
+here in the form of clunky use of atomics.
+
+it looks like there may also have been a race condition where nplurals
+could be seen without plural_rule being seen, possibly leading to null
+pointer dereference. if so, this commit fixes it.
+---
+ src/locale/dcngettext.c | 35 +++++++++++++++++------------------
+ 1 file changed, 17 insertions(+), 18 deletions(-)
+
+diff --git a/src/locale/dcngettext.c b/src/locale/dcngettext.c
+index 7fbe7196..8b891d00 100644
+--- a/src/locale/dcngettext.c
++++ b/src/locale/dcngettext.c
+@@ -100,8 +100,8 @@ struct msgcat {
+ struct msgcat *next;
+ const void *map;
+ size_t map_size;
+- void *volatile plural_rule;
+- volatile int nplurals;
++ const char *plural_rule;
++ int nplurals;
+ struct binding *binding;
+ const struct __locale_map *lm;
+ int cat;
+@@ -200,20 +200,7 @@ notrans:
+ p->lm = lm;
+ p->map = map;
+ p->map_size = map_size;
+- do {
+- old_cats = cats;
+- p->next = old_cats;
+- } while (a_cas_p(&cats, old_cats, p) != old_cats);
+- }
+-
+- const char *trans = __mo_lookup(p->map, p->map_size, msgid1);
+- if (!trans) goto notrans;
+-
+- /* Non-plural-processing gettext forms pass a null pointer as
+- * msgid2 to request that dcngettext suppress plural processing. */
+- if (!msgid2) return (char *)trans;
+
+- if (!p->plural_rule) {
+ const char *rule = "n!=1;";
+ unsigned long np = 2;
+ const char *r = __mo_lookup(p->map, p->map_size, "");
+@@ -237,10 +224,22 @@ notrans:
+ rule = r+7;
+ }
+ }
+- a_store(&p->nplurals, np);
+- a_cas_p(&p->plural_rule, 0, (void *)rule);
++ p->nplurals = np;
++ p->plural_rule = rule;
++
++ do {
++ old_cats = cats;
++ p->next = old_cats;
++ } while (a_cas_p(&cats, old_cats, p) != old_cats);
+ }
+- if (p->nplurals) {
++
++ const char *trans = __mo_lookup(p->map, p->map_size, msgid1);
++ if (!trans) goto notrans;
++
++ /* Non-plural-processing gettext forms pass a null pointer as
++ * msgid2 to request that dcngettext suppress plural processing. */
++
++ if (msgid2 && p->nplurals) {
+ unsigned long plural = __pleval(p->plural_rule, n);
+ if (plural > p->nplurals) goto notrans;
+ while (plural--) {
+--
+cgit v1.2.1
+
diff --git a/system/musl/fix-file-locking-race.patch b/system/musl/fix-file-locking-race.patch
new file mode 100644
index 000000000..2ef91390a
--- /dev/null
+++ b/system/musl/fix-file-locking-race.patch
@@ -0,0 +1,54 @@
+From 0db393d3a77bb9f300a356c6a5484fc2dddb161d Mon Sep 17 00:00:00 2001
+From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
+Date: Tue, 18 Sep 2018 10:03:27 +0300
+Subject: fix race condition in file locking
+
+The condition occurs when
+- thread #1 is holding the lock
+- thread #2 is waiting for it on __futexwait
+- thread #1 is about to release the lock and performs a_swap
+- thread #3 enters the __lockfile function and manages to grab the lock
+ before thread #1 calls __wake, resetting the MAYBE_WAITERS flag
+- thread #1 calls __wake
+- thread #2 wakes up but goes again to __futexwait as the lock is
+ held by thread #3
+- thread #3 releases the lock but does not call __wake as the
+ MAYBE_WAITERS flag is not set
+
+This condition results in thread #2 not being woken up. This patch fixes
+the problem by making the woken up thread ensure that the flag is
+properly set before going to sleep again.
+
+Mainainer's note: This fixes a regression introduced in commit
+c21f750727515602a9e84f2a190ee8a0a2aeb2a1.
+---
+ src/stdio/__lockfile.c | 12 ++++++------
+ 1 file changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/src/stdio/__lockfile.c b/src/stdio/__lockfile.c
+index 2ff75d8a..0dcb2a42 100644
+--- a/src/stdio/__lockfile.c
++++ b/src/stdio/__lockfile.c
+@@ -8,13 +8,13 @@ int __lockfile(FILE *f)
+ int owner = f->lock, tid = __pthread_self()->tid;
+ if ((owner & ~MAYBE_WAITERS) == tid)
+ return 0;
+- for (;;) {
+- owner = a_cas(&f->lock, 0, tid);
+- if (!owner) return 1;
+- if (a_cas(&f->lock, owner, owner|MAYBE_WAITERS)==owner) break;
++ owner = a_cas(&f->lock, 0, tid);
++ if (!owner) return 1;
++ while ((owner = a_cas(&f->lock, 0, tid|MAYBE_WAITERS))) {
++ if ((owner & MAYBE_WAITERS) ||
++ a_cas(&f->lock, owner, owner|MAYBE_WAITERS)==owner)
++ __futexwait(&f->lock, owner|MAYBE_WAITERS, 1);
+ }
+- while ((owner = a_cas(&f->lock, 0, tid|MAYBE_WAITERS)))
+- __futexwait(&f->lock, owner, 1);
+ return 1;
+ }
+
+--
+cgit v1.2.1
+
diff --git a/system/musl/getaddrinfo-regression.patch b/system/musl/getaddrinfo-regression.patch
new file mode 100644
index 000000000..28d4558b8
--- /dev/null
+++ b/system/musl/getaddrinfo-regression.patch
@@ -0,0 +1,51 @@
+From f381c118b2d4f7d914481d3cdc830ce41369b002 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Wed, 19 Sep 2018 18:03:22 -0400
+Subject: fix getaddrinfo regression with AI_ADDRCONFIG on some configurations
+
+despite not being documented to do so in the standard or Linux
+documentation, attempts to udp connect to 127.0.0.1 or ::1 generate
+EADDRNOTAVAIL when the loopback device is not configured and there is
+no default route for IPv6. this caused getaddrinfo with AI_ADDRCONFIG
+to fail with EAI_SYSTEM and EADDRNOTAVAIL on some no-IPv6
+configurations, rather than the intended behavior of detecting IPv6 as
+unsuppported and producing IPv4-only results.
+
+previously, only EAFNOSUPPORT was treated as unavailability of the
+address family being probed. instead, treat all errors related to
+inability to get an address or route as conclusive that the family
+being probed is unsupported, and only fail with EAI_SYSTEM on other
+errors.
+
+further improvements may be desirable, such as reporting EAI_AGAIN
+instead of EAI_SYSTEM for errors which are expected to be transient,
+but this patch should suffice to fix the serious regression.
+---
+ src/network/getaddrinfo.c | 11 ++++++++++-
+ 1 file changed, 10 insertions(+), 1 deletion(-)
+
+diff --git a/src/network/getaddrinfo.c b/src/network/getaddrinfo.c
+index ba26847a..e33bfa28 100644
+--- a/src/network/getaddrinfo.c
++++ b/src/network/getaddrinfo.c
+@@ -76,7 +76,16 @@ int getaddrinfo(const char *restrict host, const char *restrict serv, const stru
+ close(s);
+ if (!r) continue;
+ }
+- if (errno != EAFNOSUPPORT) return EAI_SYSTEM;
++ switch (errno) {
++ case EADDRNOTAVAIL:
++ case EAFNOSUPPORT:
++ case EHOSTUNREACH:
++ case ENETDOWN:
++ case ENETUNREACH:
++ break;
++ default:
++ return EAI_SYSTEM;
++ }
+ if (family == tf[i]) return EAI_NONAME;
+ family = tf[1-i];
+ }
+--
+cgit v1.2.1
+
diff --git a/system/musl/ldconfig b/system/musl/ldconfig
index ccf7c2aa4..7699c6722 100644
--- a/system/musl/ldconfig
+++ b/system/musl/ldconfig
@@ -1,18 +1,184 @@
-#!/bin/sh
-scan_dirs() {
- scanelf -qS "$@" | while read SONAME FILE; do
- TARGET="${FILE##*/}"
- LINK="${FILE%/*}/$SONAME"
- case "$FILE" in
- /lib/*|/usr/lib/*|/usr/local/lib/*) ;;
- *) [ -h "$LINK" -o ! -e "$LINK" ] && ln -sf "$TARGET" "$LINK"
- esac
+#!/bin/sh -eu
+# Copyright 2016-2018 Samuel Holland <samuel@sholland.org>
+# SPDX-License-Identifier: 0BSD
+
+ME=${0##*/}
+VERSION=0.2.0
+
+echo() {
+ printf '%s\n' "$*"
+}
+
+echo_lines() {
+ printf '%s\n' "$@"
+}
+
+msg() {
+ printf >&2 '%s: %s\n' "$ME" "$*"
+}
+
+musl_arch() {
+ $ROOT/usr/lib/libc.so |& sed -n 's/^musl libc (\(.*\))$/\1/p'
+}
+
+musl_version() {
+ $ROOT/usr/lib/libc.so |& sed -n 's/^Version //p'
+}
+
+read_ldso_conf() {
+ local conf="$*" d dir file glob line
+
+ # Start with the default "trusted" directories
+ set -- /lib /usr/lib
+ for file in $conf; do
+ test -r "$file" || continue
+ $VERBOSE && msg "Reading ${file}"
+ while read -r line; do
+ line=$(tokenize ${line%%#*})
+ if test "${line#include }" != "$line"; then
+ glob=${file%/*}/${line#include }
+ $VERBOSE && msg "Including ${glob}"
+ line=$(read_ldso_conf $glob)
+ fi
+ for dir in $line; do
+ # Ignore missing directories
+ test -d "$ROOT$dir" || continue
+ # Ignore duplicate directories
+ for d; do test "$d" = "$dir" && continue 2; done
+ set -- "$@" "$dir"
+ done
+ done < "$file"
done
- return 0
+
+ echo_lines "$@"
+}
+
+tokenize() {
+ echo "$*" | sed 's/=libc[456]//g;y/:,/ /' | xargs
}
-# eat ldconfig options
-while getopts "nNvXvf:C:r:" opt; do
- :
+
+LDSO_CACHE="/etc/ld.so.cache"
+LDSO_CONF="/etc/ld.so.conf"
+LIBRARY_MODE=false
+ONLYARG_MODE=false
+PRINT_CACHE=false
+PRINT_VERSION=false
+ROOT=
+UPDATE_CACHE=true
+UPDATE_LINKS=true
+VERBOSE=false
+
+while getopts ":c:C:Df:ilnNpr:vVX" OPTION; do
+ case "$OPTION" in
+ C)
+ LDSO_CACHE=$OPTARG
+ ;;
+ D)
+ UPDATE_CACHE=false
+ UPDATE_LINKS=false
+ ;;
+ f)
+ LDSO_CONF=$OPTARG
+ ;;
+ l)
+ LIBRARY_MODE=true
+ ;;
+ n)
+ ONLYARG_MODE=true
+ ;;
+ N)
+ UPDATE_CACHE=false
+ ;;
+ p)
+ PRINT_CACHE=true
+ ;;
+ r)
+ ROOT=$OPTARG
+ if ! test -x $ROOT/usr/lib/libc.so; then
+ msg "${ROOT} does not appear to be a valid root directory"
+ exit 1
+ fi
+ ;;
+ v)
+ VERBOSE=true
+ ;;
+ V)
+ PRINT_VERSION=true
+ ;;
+ X)
+ UPDATE_LINKS=false
+ ;;
+ c|i)
+ msg "Ignored option -${OPTION}"
+ ;;
+ \?)
+ msg "Invalid option -${OPTARG}"
+ cat >&2 <<- EOF
+ Usage: $ME [-DnNvX] [-C cache] [-f conf] [-r root] [dir...]
+ $ME [-v] -l lib...
+ $ME [-v] [-C cache] [-r root] -p
+ $ME -V
+ EOF
+ exit 1
+ ;;
+ esac
done
-shift $(( $OPTIND - 1 ))
-[ $# -gt 0 ] && scan_dirs "$@"
+shift $((OPTIND-1))
+
+BANNER="ldconfig ${VERSION} for musl $(musl_version)"
+LDSO_CACHE="$ROOT$LDSO_CACHE"
+LDSO_CONF="$ROOT$LDSO_CONF"
+LDSO_PATH="$ROOT/etc/ld-musl-$(musl_arch).path"
+LDSO_PATH_TMP="$LDSO_PATH.$$"
+
+if $PRINT_VERSION; then
+ echo "$BANNER"
+ exit 0
+elif $PRINT_CACHE; then
+ test -r "$LDSO_PATH" && cat "$LDSO_PATH"
+ exit 0
+fi
+
+$VERBOSE && echo "$BANNER"
+
+if $LIBRARY_MODE; then
+ for lib; do
+ soname=$(scanelf -qS "$ROOT$lib")
+ soname=${soname%% *}
+ done
+ exit 0
+fi
+
+# Update musl's list of library paths
+if ! test -w "${LDSO_PATH%/*}"; then
+ msg "You do not have permission to update ${LDSO_PATH}"
+ exit 0
+fi
+trap 'rm -f "$LDSO_PATH_TMP"' EXIT
+read_ldso_conf "$LDSO_CONF" > "$LDSO_PATH_TMP"
+$VERBOSE && msg "Writing ${LDSO_PATH}"
+mv "$LDSO_PATH_TMP" "$LDSO_PATH"
+trap - EXIT
+
+# Read the updated list of library paths
+$ONLYARG_MODE || set -- "$@" $(cat "$LDSO_PATH")
+
+if $UPDATE_LINKS; then
+ for dir; do
+ # Packages are responsible for libraries in these directories
+ if test "$dir" = /lib || test "$dir" = /usr/lib; then
+ continue
+ fi
+ $VERBOSE && msg "Scanning ${ROOT}${dir}"
+ scanelf -qS "$ROOT$dir" | while read soname file; do
+ link=${file%/*}/$soname
+ test -f "$link" && continue
+ $VERBOSE && msg "Creating link ${link}"
+ ln -fns "${file##*/}" "$link"
+ done
+ done
+fi
+
+if $UPDATE_CACHE && test $# -gt 0; then
+ touch "$ROOT$LDSO_CACHE"
+fi
diff --git a/system/musl/musl-utils.trigger b/system/musl/musl-utils.trigger
new file mode 100755
index 000000000..ee3a3c053
--- /dev/null
+++ b/system/musl/musl-utils.trigger
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+ldconfig -NX
diff --git a/system/musl/ppc64-atomic.patch b/system/musl/ppc64-atomic.patch
new file mode 100644
index 000000000..6e96a9048
--- /dev/null
+++ b/system/musl/ppc64-atomic.patch
@@ -0,0 +1,74 @@
+From 12817793301398241b6cb00c740f0d3ca41076e9 Mon Sep 17 00:00:00 2001
+From: Rich Felker <dalias@aerifal.cx>
+Date: Fri, 14 Sep 2018 10:47:16 -0400
+Subject: fix broken atomic store on powerpc[64]
+
+in our memory model, all atomics are supposed to be full barriers;
+stores are not release-only. this is important because store is used
+as an unlock operation in places where it needs to acquire the waiter
+count to determine if a futex wake is needed. at least in the
+malloc-internal locks, but possibly elsewhere, soft deadlocks from
+missing futex wake (breakable by poking the threads to restart the
+syscall, e.g. by attaching a tracer) were reported to occur.
+
+once the malloc lock is replaced with Jens Gustedt's new lock
+implementation (see commit 47d0bcd4762f223364e5b58d5a381aaa0cbd7c38),
+malloc will not be affected by the issue, but it's not clear that
+other uses won't be. reducing the strength of the ordering properties
+required from a_store would require a thorough analysis of how it's
+used.
+
+to fix the problem, I'm removing the powerpc[64]-specific a_store
+definition; now, the top-level atomic.h will implement a_store using
+a_barrier on both sides of the store.
+
+it's not clear to me yet whether there might be issues with the other
+atomics. it's possible that a_post_llsc needs to be replaced with a
+full barrier to guarantee the formal semanics we want, but either way
+I think the difference is unlikely to impact the way we use them.
+---
+ arch/powerpc/atomic_arch.h | 8 --------
+ arch/powerpc64/atomic_arch.h | 8 --------
+ 2 files changed, 16 deletions(-)
+
+diff --git a/arch/powerpc/atomic_arch.h b/arch/powerpc/atomic_arch.h
+index 5b65cde7..c2673919 100644
+--- a/arch/powerpc/atomic_arch.h
++++ b/arch/powerpc/atomic_arch.h
+@@ -30,14 +30,6 @@ static inline void a_post_llsc()
+ __asm__ __volatile__ ("isync" : : : "memory");
+ }
+
+-#define a_store a_store
+-static inline void a_store(volatile int *p, int v)
+-{
+- a_pre_llsc();
+- *p = v;
+- a_post_llsc();
+-}
+-
+ #define a_clz_32 a_clz_32
+ static inline int a_clz_32(uint32_t x)
+ {
+diff --git a/arch/powerpc64/atomic_arch.h b/arch/powerpc64/atomic_arch.h
+index 17cababd..2bed82be 100644
+--- a/arch/powerpc64/atomic_arch.h
++++ b/arch/powerpc64/atomic_arch.h
+@@ -48,14 +48,6 @@ static inline void a_post_llsc()
+ __asm__ __volatile__ ("isync" : : : "memory");
+ }
+
+-#define a_store a_store
+-static inline void a_store(volatile int *p, int v)
+-{
+- a_pre_llsc();
+- *p = v;
+- a_post_llsc();
+-}
+-
+ #define a_crash a_crash
+ static inline void a_crash()
+ {
+--
+cgit v1.2.1
+