From: Rich Felker Date: Wed, 12 Apr 2017 02:10:52 +0000 (-0400) Subject: fix dl_iterate_phdr in static PIE binaries X-Git-Tag: v1.1.17~76 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b3751c3282e3fbae4b97cb4f29031df9bc6e0745;p=oweals%2Fmusl.git fix dl_iterate_phdr in static PIE binaries analogous to commit 5bf7eba213cacc4c1220627c91c28deff2ffecda, use of AT_PHDR/PT_PHDR does not actually work to find the program base, and the method with _DYNAMIC vs PT_DYNAMIC must be used as an alternative. patch by Shiz, along with testing to confirm that this fixes unwinding in static PIE. --- diff --git a/src/ldso/dl_iterate_phdr.c b/src/ldso/dl_iterate_phdr.c index e55cbf76..f3160ef4 100644 --- a/src/ldso/dl_iterate_phdr.c +++ b/src/ldso/dl_iterate_phdr.c @@ -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 @@ static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size 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; }