aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0032-fix-support-for-dl_iterate_phdr-in-static-pie-binaries.patch
blob: 5d1957e05973e640ec0953663191ccf542625f34 (plain)
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
From: Shiz <hi@shiz.me>
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