1From 3690dc5f567906c45f057509305fbaa021b33adb Mon Sep 17 00:00:00 2001
2From: Yichao Yu <yyc1992@gmail.com>
3Date: Tue, 15 Sep 2020 12:35:46 -0700
4Subject: [PATCH] Fix compilation with -fno-common.
5
6Making all other archs consistent with IA64 which should not have this problem.
7Also move the FIXME to the correct place.
8
9Also add some minimum comments about this...
10
11Upstream-Status: Backport [https://github.com/libunwind/libunwind/pull/166/commits/29e17d8d2ccbca07c423e3089a6d5ae8a1c9cb6e]
12Signed-off-by: Khem Raj <raj.khem@gmail.com>
13---
14 src/third_party/unwind/dist/src/aarch64/Ginit.c   | 15 +++++++--------
15 src/third_party/unwind/dist/src/arm/Ginit.c       | 15 +++++++--------
16 .../src/coredump/_UPT_get_dyn_info_list_addr.c    |  5 +++++
17 src/third_party/unwind/dist/src/hppa/Ginit.c      | 15 +++++++--------
18 src/third_party/unwind/dist/src/ia64/Ginit.c      |  1 +
19 .../unwind/dist/src/mi/Gfind_dynamic_proc_info.c  |  1 +
20 src/third_party/unwind/dist/src/mips/Ginit.c      | 15 +++++++--------
21 src/third_party/unwind/dist/src/ppc32/Ginit.c     | 11 +++++++----
22 src/third_party/unwind/dist/src/ppc64/Ginit.c     | 11 +++++++----
23 .../dist/src/ptrace/_UPT_get_dyn_info_list_addr.c |  5 +++++
24 src/third_party/unwind/dist/src/s390x/Ginit.c     | 15 +++++++--------
25 src/third_party/unwind/dist/src/sh/Ginit.c        | 15 +++++++--------
26 src/third_party/unwind/dist/src/tilegx/Ginit.c    | 15 +++++++--------
27 src/third_party/unwind/dist/src/x86/Ginit.c       | 15 +++++++--------
28 src/third_party/unwind/dist/src/x86_64/Ginit.c    | 15 +++++++--------
29 15 files changed, 89 insertions(+), 80 deletions(-)
30
31diff --git a/src/third_party/unwind/dist/src/aarch64/Ginit.c b/src/third_party/unwind/dist/src/aarch64/Ginit.c
32index dec235c829..35389762f2 100644
33--- a/src/third_party/unwind/dist/src/aarch64/Ginit.c
34+++ b/src/third_party/unwind/dist/src/aarch64/Ginit.c
35@@ -61,13 +61,6 @@ tdep_uc_addr (unw_tdep_context_t *uc, int reg)
36
37 # endif /* UNW_LOCAL_ONLY */
38
39-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
40-
41-/* XXX fix me: there is currently no way to locate the dyn-info list
42-       by a remote unwinder.  On ia64, this is done via a special
43-       unwind-table entry.  Perhaps something similar can be done with
44-       DWARF2 unwind info.  */
45-
46 static void
47 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
48 {
49@@ -78,7 +71,13 @@ static int
50 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
51                         void *arg)
52 {
53-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
54+#ifndef UNW_LOCAL_ONLY
55+# pragma weak _U_dyn_info_list_addr
56+  if (!_U_dyn_info_list_addr)
57+    return -UNW_ENOINFO;
58+#endif
59+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
60+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
61   return 0;
62 }
63
64diff --git a/src/third_party/unwind/dist/src/arm/Ginit.c b/src/third_party/unwind/dist/src/arm/Ginit.c
65index 2720d063a2..0bac0d72da 100644
66--- a/src/third_party/unwind/dist/src/arm/Ginit.c
67+++ b/src/third_party/unwind/dist/src/arm/Ginit.c
68@@ -57,18 +57,17 @@ tdep_uc_addr (unw_tdep_context_t *uc, int reg)
69
70 # endif /* UNW_LOCAL_ONLY */
71
72-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
73-
74-/* XXX fix me: there is currently no way to locate the dyn-info list
75-       by a remote unwinder.  On ia64, this is done via a special
76-       unwind-table entry.  Perhaps something similar can be done with
77-       DWARF2 unwind info.  */
78-
79 static int
80 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
81                         void *arg)
82 {
83-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
84+#ifndef UNW_LOCAL_ONLY
85+# pragma weak _U_dyn_info_list_addr
86+  if (!_U_dyn_info_list_addr)
87+    return -UNW_ENOINFO;
88+#endif
89+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
90+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
91   return 0;
92 }
93
94diff --git a/src/third_party/unwind/dist/src/coredump/_UPT_get_dyn_info_list_addr.c b/src/third_party/unwind/dist/src/coredump/_UPT_get_dyn_info_list_addr.c
95index 0d11905566..739ed0569b 100644
96--- a/src/third_party/unwind/dist/src/coredump/_UPT_get_dyn_info_list_addr.c
97+++ b/src/third_party/unwind/dist/src/coredump/_UPT_get_dyn_info_list_addr.c
98@@ -74,6 +74,11 @@ get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
99
100 #else
101
102+/* XXX fix me: there is currently no way to locate the dyn-info list
103+       by a remote unwinder.  On ia64, this is done via a special
104+       unwind-table entry.  Perhaps something similar can be done with
105+       DWARF2 unwind info.  */
106+
107 static inline int
108 get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
109                int *countp)
110diff --git a/src/third_party/unwind/dist/src/hppa/Ginit.c b/src/third_party/unwind/dist/src/hppa/Ginit.c
111index 461e4b93da..265455a68c 100644
112--- a/src/third_party/unwind/dist/src/hppa/Ginit.c
113+++ b/src/third_party/unwind/dist/src/hppa/Ginit.c
114@@ -64,13 +64,6 @@ _Uhppa_uc_addr (ucontext_t *uc, int reg)
115
116 # endif /* UNW_LOCAL_ONLY */
117
118-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
119-
120-/* XXX fix me: there is currently no way to locate the dyn-info list
121-       by a remote unwinder.  On ia64, this is done via a special
122-       unwind-table entry.  Perhaps something similar can be done with
123-       DWARF2 unwind info.  */
124-
125 static void
126 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
127 {
128@@ -81,7 +74,13 @@ static int
129 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
130                         void *arg)
131 {
132-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
133+#ifndef UNW_LOCAL_ONLY
134+# pragma weak _U_dyn_info_list_addr
135+  if (!_U_dyn_info_list_addr)
136+    return -UNW_ENOINFO;
137+#endif
138+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
139+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
140   return 0;
141 }
142
143diff --git a/src/third_party/unwind/dist/src/ia64/Ginit.c b/src/third_party/unwind/dist/src/ia64/Ginit.c
144index b09a2ad57c..8601bb3ca8 100644
145--- a/src/third_party/unwind/dist/src/ia64/Ginit.c
146+++ b/src/third_party/unwind/dist/src/ia64/Ginit.c
147@@ -68,6 +68,7 @@ get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
148   if (!_U_dyn_info_list_addr)
149     return -UNW_ENOINFO;
150 #endif
151+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
152   *dyn_info_list_addr = _U_dyn_info_list_addr ();
153   return 0;
154 }
155diff --git a/src/third_party/unwind/dist/src/mi/Gfind_dynamic_proc_info.c b/src/third_party/unwind/dist/src/mi/Gfind_dynamic_proc_info.c
156index 98d3501286..2e7c62e5e8 100644
157--- a/src/third_party/unwind/dist/src/mi/Gfind_dynamic_proc_info.c
158+++ b/src/third_party/unwind/dist/src/mi/Gfind_dynamic_proc_info.c
159@@ -49,6 +49,7 @@ local_find_proc_info (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
160     return -UNW_ENOINFO;
161 #endif
162
163+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
164   list = (unw_dyn_info_list_t *) (uintptr_t) _U_dyn_info_list_addr ();
165   for (di = list->first; di; di = di->next)
166     if (ip >= di->start_ip && ip < di->end_ip)
167diff --git a/src/third_party/unwind/dist/src/mips/Ginit.c b/src/third_party/unwind/dist/src/mips/Ginit.c
168index 3df170c754..bf7a8f5a8f 100644
169--- a/src/third_party/unwind/dist/src/mips/Ginit.c
170+++ b/src/third_party/unwind/dist/src/mips/Ginit.c
171@@ -69,13 +69,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
172
173 # endif /* UNW_LOCAL_ONLY */
174
175-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
176-
177-/* XXX fix me: there is currently no way to locate the dyn-info list
178-       by a remote unwinder.  On ia64, this is done via a special
179-       unwind-table entry.  Perhaps something similar can be done with
180-       DWARF2 unwind info.  */
181-
182 static void
183 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
184 {
185@@ -86,7 +79,13 @@ static int
186 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
187                         void *arg)
188 {
189-  *dyn_info_list_addr = (unw_word_t) (intptr_t) &_U_dyn_info_list;
190+#ifndef UNW_LOCAL_ONLY
191+# pragma weak _U_dyn_info_list_addr
192+  if (!_U_dyn_info_list_addr)
193+    return -UNW_ENOINFO;
194+#endif
195+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
196+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
197   return 0;
198 }
199
200diff --git a/src/third_party/unwind/dist/src/ppc32/Ginit.c b/src/third_party/unwind/dist/src/ppc32/Ginit.c
201index ba302448a3..7b45455807 100644
202--- a/src/third_party/unwind/dist/src/ppc32/Ginit.c
203+++ b/src/third_party/unwind/dist/src/ppc32/Ginit.c
204@@ -91,9 +91,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
205
206 # endif /* UNW_LOCAL_ONLY */
207
208-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
209-
210-
211 static void
212 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
213 {
214@@ -104,7 +101,13 @@ static int
215 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
216                         void *arg)
217 {
218-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
219+#ifndef UNW_LOCAL_ONLY
220+# pragma weak _U_dyn_info_list_addr
221+  if (!_U_dyn_info_list_addr)
222+    return -UNW_ENOINFO;
223+#endif
224+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
225+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
226   return 0;
227 }
228
229diff --git a/src/third_party/unwind/dist/src/ppc64/Ginit.c b/src/third_party/unwind/dist/src/ppc64/Ginit.c
230index 4c88cd6e77..7bfb395a79 100644
231--- a/src/third_party/unwind/dist/src/ppc64/Ginit.c
232+++ b/src/third_party/unwind/dist/src/ppc64/Ginit.c
233@@ -95,9 +95,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
234
235 # endif /* UNW_LOCAL_ONLY */
236
237-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
238-
239-
240 static void
241 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
242 {
243@@ -108,7 +105,13 @@ static int
244 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
245                         void *arg)
246 {
247-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
248+#ifndef UNW_LOCAL_ONLY
249+# pragma weak _U_dyn_info_list_addr
250+  if (!_U_dyn_info_list_addr)
251+    return -UNW_ENOINFO;
252+#endif
253+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
254+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
255   return 0;
256 }
257
258diff --git a/src/third_party/unwind/dist/src/ptrace/_UPT_get_dyn_info_list_addr.c b/src/third_party/unwind/dist/src/ptrace/_UPT_get_dyn_info_list_addr.c
259index cc5ed04418..16671d453e 100644
260--- a/src/third_party/unwind/dist/src/ptrace/_UPT_get_dyn_info_list_addr.c
261+++ b/src/third_party/unwind/dist/src/ptrace/_UPT_get_dyn_info_list_addr.c
262@@ -71,6 +71,11 @@ get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
263
264 #else
265
266+/* XXX fix me: there is currently no way to locate the dyn-info list
267+       by a remote unwinder.  On ia64, this is done via a special
268+       unwind-table entry.  Perhaps something similar can be done with
269+       DWARF2 unwind info.  */
270+
271 static inline int
272 get_list_addr (unw_addr_space_t as, unw_word_t *dil_addr, void *arg,
273                int *countp)
274diff --git a/src/third_party/unwind/dist/src/s390x/Ginit.c b/src/third_party/unwind/dist/src/s390x/Ginit.c
275index f0886ac933..db01743c06 100644
276--- a/src/third_party/unwind/dist/src/s390x/Ginit.c
277+++ b/src/third_party/unwind/dist/src/s390x/Ginit.c
278@@ -50,8 +50,6 @@ static struct unw_addr_space local_addr_space;
279
280 unw_addr_space_t unw_local_addr_space = &local_addr_space;
281
282-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
283-
284 static inline void *
285 uc_addr (ucontext_t *uc, int reg)
286 {
287@@ -75,11 +73,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
288
289 # endif /* UNW_LOCAL_ONLY */
290
291-/* XXX fix me: there is currently no way to locate the dyn-info list
292-       by a remote unwinder.  On ia64, this is done via a special
293-       unwind-table entry.  Perhaps something similar can be done with
294-       DWARF2 unwind info.  */
295-
296 static void
297 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
298 {
299@@ -90,7 +83,13 @@ static int
300 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
301                         void *arg)
302 {
303-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
304+#ifndef UNW_LOCAL_ONLY
305+# pragma weak _U_dyn_info_list_addr
306+  if (!_U_dyn_info_list_addr)
307+    return -UNW_ENOINFO;
308+#endif
309+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
310+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
311   return 0;
312 }
313
314diff --git a/src/third_party/unwind/dist/src/sh/Ginit.c b/src/third_party/unwind/dist/src/sh/Ginit.c
315index 52988a721e..9fe96d2bd4 100644
316--- a/src/third_party/unwind/dist/src/sh/Ginit.c
317+++ b/src/third_party/unwind/dist/src/sh/Ginit.c
318@@ -58,13 +58,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
319
320 # endif /* UNW_LOCAL_ONLY */
321
322-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
323-
324-/* XXX fix me: there is currently no way to locate the dyn-info list
325-       by a remote unwinder.  On ia64, this is done via a special
326-       unwind-table entry.  Perhaps something similar can be done with
327-       DWARF2 unwind info.  */
328-
329 static void
330 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
331 {
332@@ -75,7 +68,13 @@ static int
333 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
334                         void *arg)
335 {
336-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
337+#ifndef UNW_LOCAL_ONLY
338+# pragma weak _U_dyn_info_list_addr
339+  if (!_U_dyn_info_list_addr)
340+    return -UNW_ENOINFO;
341+#endif
342+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
343+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
344   return 0;
345 }
346
347diff --git a/src/third_party/unwind/dist/src/tilegx/Ginit.c b/src/third_party/unwind/dist/src/tilegx/Ginit.c
348index 7564a558be..925e641324 100644
349--- a/src/third_party/unwind/dist/src/tilegx/Ginit.c
350+++ b/src/third_party/unwind/dist/src/tilegx/Ginit.c
351@@ -64,13 +64,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
352
353 # endif /* UNW_LOCAL_ONLY */
354
355-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
356-
357-/* XXX fix me: there is currently no way to locate the dyn-info list
358-       by a remote unwinder.  On ia64, this is done via a special
359-       unwind-table entry.  Perhaps something similar can be done with
360-       DWARF2 unwind info.  */
361-
362 static void
363 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
364 {
365@@ -81,7 +74,13 @@ static int
366 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
367                         void *arg)
368 {
369-  *dyn_info_list_addr = (unw_word_t) (intptr_t) &_U_dyn_info_list;
370+#ifndef UNW_LOCAL_ONLY
371+# pragma weak _U_dyn_info_list_addr
372+  if (!_U_dyn_info_list_addr)
373+    return -UNW_ENOINFO;
374+#endif
375+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
376+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
377   return 0;
378 }
379
380diff --git a/src/third_party/unwind/dist/src/x86/Ginit.c b/src/third_party/unwind/dist/src/x86/Ginit.c
381index f6b8dc27d4..3cec74a216 100644
382--- a/src/third_party/unwind/dist/src/x86/Ginit.c
383+++ b/src/third_party/unwind/dist/src/x86/Ginit.c
384@@ -54,13 +54,6 @@ tdep_uc_addr (ucontext_t *uc, int reg)
385
386 # endif /* UNW_LOCAL_ONLY */
387
388-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
389-
390-/* XXX fix me: there is currently no way to locate the dyn-info list
391-       by a remote unwinder.  On ia64, this is done via a special
392-       unwind-table entry.  Perhaps something similar can be done with
393-       DWARF2 unwind info.  */
394-
395 static void
396 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
397 {
398@@ -71,7 +64,13 @@ static int
399 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
400                         void *arg)
401 {
402-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
403+#ifndef UNW_LOCAL_ONLY
404+# pragma weak _U_dyn_info_list_addr
405+  if (!_U_dyn_info_list_addr)
406+    return -UNW_ENOINFO;
407+#endif
408+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
409+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
410   return 0;
411 }
412
413diff --git a/src/third_party/unwind/dist/src/x86_64/Ginit.c b/src/third_party/unwind/dist/src/x86_64/Ginit.c
414index 6161da6401..5c4e4269a6 100644
415--- a/src/third_party/unwind/dist/src/x86_64/Ginit.c
416+++ b/src/third_party/unwind/dist/src/x86_64/Ginit.c
417@@ -49,13 +49,6 @@ static struct unw_addr_space local_addr_space;
418
419 unw_addr_space_t unw_local_addr_space = &local_addr_space;
420
421-HIDDEN unw_dyn_info_list_t _U_dyn_info_list;
422-
423-/* XXX fix me: there is currently no way to locate the dyn-info list
424-       by a remote unwinder.  On ia64, this is done via a special
425-       unwind-table entry.  Perhaps something similar can be done with
426-       DWARF2 unwind info.  */
427-
428 static void
429 put_unwind_info (unw_addr_space_t as, unw_proc_info_t *proc_info, void *arg)
430 {
431@@ -66,7 +59,13 @@ static int
432 get_dyn_info_list_addr (unw_addr_space_t as, unw_word_t *dyn_info_list_addr,
433                         void *arg)
434 {
435-  *dyn_info_list_addr = (unw_word_t) &_U_dyn_info_list;
436+#ifndef UNW_LOCAL_ONLY
437+# pragma weak _U_dyn_info_list_addr
438+  if (!_U_dyn_info_list_addr)
439+    return -UNW_ENOINFO;
440+#endif
441+  // Access the `_U_dyn_info_list` from `LOCAL_ONLY` library, i.e. libunwind.so.
442+  *dyn_info_list_addr = _U_dyn_info_list_addr ();
443   return 0;
444 }
445
446--
4472.28.0
448
449