From: Shiz Date: Wed, 12 Apr 2017 05:50:14 +0200 Subject: [PATCH] Fix support for dl_iterate_phdr in static PIE binaries Commit 5bf7eba213cacc4c1220627c91c28deff2ffecda in musl upstream fixes TLS initialisation for static PIE binaries, but a similar fix is needed for the dl_iterate_phdr function. This fixes, among others, exception unwinding breakage on static PIE binaries. --- src/ldso/dl_iterate_phdr.c 1 file changed, 5 insertions(+) diff --git a/src/ldso/dl_iterate_phdr.c b/src/ldso/dl_iterate_phdr.c --- a/src/ldso/dl_iterate_phdr.c 2017-01-01 04:27:17.000000000 +0100 +++ b/src/ldso/dl_iterate_phdr.c 2017-04-12 03:19:44.000000000 +0200 @@ -4,6 +4,9 @@ #define AUX_CNT 38 +__attribute__((__weak__, __visibility__("hidden"))) +extern const size_t _DYNAMIC[]; + static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data) { unsigned char *p; @@ -20,6 +23,8 @@ phdr = (void *)p; if (phdr->p_type == PT_PHDR) base = aux[AT_PHDR] - phdr->p_vaddr; + if (phdr->p_type == PT_DYNAMIC && _DYNAMIC) + base = (size_t)_DYNAMIC - phdr->p_vaddr; if (phdr->p_type == PT_TLS) tls_phdr = phdr; } --- 2.12.2