diff options
-rw-r--r-- | meta/recipes-support/libunwind/libunwind/malloc.patch | 255 | ||||
-rw-r--r-- | meta/recipes-support/libunwind/libunwind_1.8.1.bb | 1 |
2 files changed, 256 insertions, 0 deletions
diff --git a/meta/recipes-support/libunwind/libunwind/malloc.patch b/meta/recipes-support/libunwind/libunwind/malloc.patch new file mode 100644 index 0000000000..026a56f155 --- /dev/null +++ b/meta/recipes-support/libunwind/libunwind/malloc.patch | |||
@@ -0,0 +1,255 @@ | |||
1 | From b67d508a93bf1ba231c18dce3894cfee25c16e0d Mon Sep 17 00:00:00 2001 | ||
2 | From: Stephen Webb <swebb@blackberry.com> | ||
3 | Date: Wed, 12 Feb 2025 12:08:07 -0500 | ||
4 | Subject: [PATCH] Fix bad prototype for malloc() in test | ||
5 | |||
6 | The unit test Gtest-nomalloc.c had an incorrect prototype for malloc() | ||
7 | which caused newer compilers to fail compiling for newer C editions. | ||
8 | |||
9 | Corrected the prototype and corrected a few other errors. The unit now | ||
10 | compiles using GCC with `CFLAGS=-Wall -Wextra -pedantic -C11` with no | ||
11 | warnings, which is the minimum requirement. | ||
12 | |||
13 | Added the tests/unw_test.h header as a first step to cleaning up some | ||
14 | unit tests further. | ||
15 | |||
16 | Upstream-Status: Backport [https://github.com/libunwind/libunwind/commit/b67d508]] | ||
17 | Signed-off-by: Ross Burton <ross.burton@arm.com> | ||
18 | --- | ||
19 | tests/Gtest-nomalloc.c | 124 +++++++++++++++++++++++------------------ | ||
20 | tests/Makefile.am | 2 +- | ||
21 | tests/unw_test.h | 47 ++++++++++++++++ | ||
22 | 3 files changed, 117 insertions(+), 56 deletions(-) | ||
23 | create mode 100644 tests/unw_test.h | ||
24 | |||
25 | diff --git a/tests/Gtest-nomalloc.c b/tests/Gtest-nomalloc.c | ||
26 | index 5b97fc709..e770ff614 100644 | ||
27 | --- a/tests/Gtest-nomalloc.c | ||
28 | +++ b/tests/Gtest-nomalloc.c | ||
29 | @@ -1,78 +1,92 @@ | ||
30 | -/* libunwind - a platform-independent unwind library | ||
31 | - Copyright (C) 2009 Google, Inc | ||
32 | - Contributed by Arun Sharma <arun.sharma@google.com> | ||
33 | +/** | ||
34 | + * @file tests/Gtest-nomalloc.c | ||
35 | + * | ||
36 | + * Verify that @c malloc() is not called during an unwinding operation. | ||
37 | + */ | ||
38 | +/* | ||
39 | + * This file is part of libunwind. | ||
40 | + * Copyright 2025 Stephen M. Webb <stephen.webb@bregmasoft.ca> | ||
41 | + * Copyright (C) 2009 Google, Inc | ||
42 | + * Contributed by Arun Sharma <arun.sharma@google.com> | ||
43 | + * | ||
44 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
45 | + * of this software and associated documentation files (the "Software"), to | ||
46 | + * deal in the Software without restriction, including without limitation the | ||
47 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
48 | + * sell copies of the Software, and to permit persons to whom the Software is | ||
49 | + * furnished to do so, subject to the following conditions: | ||
50 | + * | ||
51 | + * The above copyright notice and this permission notice shall be included in | ||
52 | + * all copies or substantial portions of the Software. | ||
53 | + * | ||
54 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
55 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
56 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
57 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
58 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
59 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
60 | + * IN THE SOFTWARE. | ||
61 | + */ | ||
62 | |||
63 | -Permission is hereby granted, free of charge, to any person obtaining | ||
64 | -a copy of this software and associated documentation files (the | ||
65 | -"Software"), to deal in the Software without restriction, including | ||
66 | -without limitation the rights to use, copy, modify, merge, publish, | ||
67 | -distribute, sublicense, and/or sell copies of the Software, and to | ||
68 | -permit persons to whom the Software is furnished to do so, subject to | ||
69 | -the following conditions: | ||
70 | - | ||
71 | -The above copyright notice and this permission notice shall be | ||
72 | -included in all copies or substantial portions of the Software. | ||
73 | - | ||
74 | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
75 | -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
76 | -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
77 | -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
78 | -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
79 | -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
80 | -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ | ||
81 | - | ||
82 | -#include <unistd.h> | ||
83 | -#include <stdio.h> | ||
84 | -#include <stdlib.h> | ||
85 | #include <dlfcn.h> | ||
86 | #include <libunwind.h> | ||
87 | +#include <stdio.h> | ||
88 | +#include <stdlib.h> | ||
89 | +#include <unistd.h> | ||
90 | |||
91 | -#define panic(args...) \ | ||
92 | - { fprintf (stderr, args); exit (-1); } | ||
93 | +#include "unw_test.h" | ||
94 | |||
95 | -int verbose; | ||
96 | -int num_errors; | ||
97 | +int malloc_call_count; | ||
98 | int in_unwind; | ||
99 | |||
100 | +/** | ||
101 | + * Intercepted malloc() call. | ||
102 | + * | ||
103 | + * If invoked during unwinding this call will increment the test error count | ||
104 | + * and indicate a failure by returning NULL. Otherwise it just calls the real | ||
105 | + * malloc(). | ||
106 | + */ | ||
107 | void * | ||
108 | -malloc(size_t s) | ||
109 | +malloc (size_t sz) | ||
110 | { | ||
111 | - static void * (*func)(); | ||
112 | + typedef void *(*malloc_t) (size_t); | ||
113 | |||
114 | - if(!func) | ||
115 | - func = (void *(*)()) dlsym(RTLD_NEXT, "malloc"); | ||
116 | + static malloc_t real_malloc = NULL; | ||
117 | + if (real_malloc == NULL) | ||
118 | + { | ||
119 | + real_malloc = (malloc_t)(intptr_t)dlsym (RTLD_NEXT, "malloc"); | ||
120 | + if (real_malloc == NULL) | ||
121 | + { | ||
122 | + fprintf (stderr, "no malloc() found\n"); | ||
123 | + exit (UNW_TEST_EXIT_HARD_ERROR); \ | ||
124 | + } | ||
125 | + } | ||
126 | |||
127 | - if (in_unwind) { | ||
128 | - num_errors++; | ||
129 | - return NULL; | ||
130 | - } else { | ||
131 | - return func(s); | ||
132 | - } | ||
133 | + if (in_unwind) | ||
134 | + { | ||
135 | + malloc_call_count++; | ||
136 | + } | ||
137 | + return real_malloc (sz); | ||
138 | } | ||
139 | |||
140 | static void | ||
141 | do_backtrace (void) | ||
142 | { | ||
143 | - unw_word_t ip, sp; | ||
144 | - unw_cursor_t cursor; | ||
145 | + unw_cursor_t cursor; | ||
146 | unw_context_t uc; | ||
147 | - int ret; | ||
148 | + int ret; | ||
149 | |||
150 | in_unwind = 1; | ||
151 | unw_getcontext (&uc); | ||
152 | if (unw_init_local (&cursor, &uc) < 0) | ||
153 | - panic ("unw_init_local failed!\n"); | ||
154 | + { | ||
155 | + fprintf (stderr, "unw_init_local failed!\n"); | ||
156 | + exit (UNW_TEST_EXIT_HARD_ERROR); \ | ||
157 | + } | ||
158 | |||
159 | do | ||
160 | { | ||
161 | - unw_get_reg (&cursor, UNW_REG_IP, &ip); | ||
162 | - unw_get_reg (&cursor, UNW_REG_SP, &sp); | ||
163 | - | ||
164 | ret = unw_step (&cursor); | ||
165 | - if (ret < 0) | ||
166 | - { | ||
167 | - ++num_errors; | ||
168 | - } | ||
169 | } | ||
170 | while (ret > 0); | ||
171 | in_unwind = 0; | ||
172 | @@ -99,12 +113,12 @@ foo1 (void) | ||
173 | int | ||
174 | main (void) | ||
175 | { | ||
176 | - foo1(); | ||
177 | + foo1 (); | ||
178 | |||
179 | - if (num_errors > 0) | ||
180 | + if (malloc_call_count > 0) | ||
181 | { | ||
182 | - fprintf (stderr, "FAILURE: detected %d errors\n", num_errors); | ||
183 | - exit (-1); | ||
184 | + fprintf (stderr, "FAILURE: malloc called %d times, expected 0\n", malloc_call_count); | ||
185 | + exit (UNW_TEST_EXIT_FAIL); | ||
186 | } | ||
187 | - return 0; | ||
188 | + exit (UNW_TEST_EXIT_PASS); | ||
189 | } | ||
190 | diff --git a/tests/Makefile.am b/tests/Makefile.am | ||
191 | index adc34ac63..60f3f3adc 100644 | ||
192 | --- a/tests/Makefile.am | ||
193 | +++ b/tests/Makefile.am | ||
194 | @@ -214,7 +214,7 @@ endif | ||
195 | |||
196 | noinst_PROGRAMS = $(noinst_PROGRAMS_common) $(noinst_PROGRAMS_cdep) \ | ||
197 | $(noinst_PROGRAMS_arch) | ||
198 | -noinst_HEADERS = ident.h | ||
199 | +noinst_HEADERS = ident.h unw_test.h | ||
200 | |||
201 | do_test_subst = sed -e 's,[@]TESTS[@],$(TESTS),g' \ | ||
202 | -e 's,[@]XFAIL_TESTS[@],$(XFAIL_TESTS),g' \ | ||
203 | diff --git a/tests/unw_test.h b/tests/unw_test.h | ||
204 | new file mode 100644 | ||
205 | index 000000000..9ae86dce1 | ||
206 | --- /dev/null | ||
207 | +++ b/tests/unw_test.h | ||
208 | @@ -0,0 +1,47 @@ | ||
209 | +/** | ||
210 | + * @file tests/unw_test.h | ||
211 | + * | ||
212 | + * Common unit test API for libunwind. | ||
213 | + */ | ||
214 | +/* | ||
215 | + * This file is part of libunwind. | ||
216 | + * Copyright 2025 Stephen M. Webb <stephen.webb@bregmasoft.ca> | ||
217 | + * | ||
218 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
219 | + * of this software and associated documentation files (the "Software"), to | ||
220 | + * deal in the Software without restriction, including without limitation the | ||
221 | + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
222 | + * sell copies of the Software, and to permit persons to whom the Software is | ||
223 | + * furnished to do so, subject to the following conditions: | ||
224 | + * | ||
225 | + * The above copyright notice and this permission notice shall be included in | ||
226 | + * all copies or substantial portions of the Software. | ||
227 | + * | ||
228 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
229 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
230 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
231 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
232 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
233 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
234 | + * IN THE SOFTWARE. | ||
235 | + */ | ||
236 | +#ifndef LIBUNWIND_UNW_TEST_H | ||
237 | +#define LIBUNWIND_UNW_TEST_H 1 | ||
238 | + | ||
239 | +/** | ||
240 | + * Exit values for test programs. | ||
241 | + * Based on https://www.gnu.org/software/automake/manual/html_node/Scripts_002dbased-Testsuites.html | ||
242 | + * | ||
243 | + * These are used to interact with the test harness (eg. a TAP-based harness, | ||
244 | + * CTest, or automake). | ||
245 | + */ | ||
246 | +enum { | ||
247 | + UNW_TEST_EXIT_PASS = 0, /* Item under test is a PASS */ | ||
248 | + UNW_TEST_EXIT_FAIL = 1, /* Item under test is a FAIL */ | ||
249 | + UNW_TEST_EXIT_BAD_COMMAND = 2, /* Test program is invoked with invalid arguments */ | ||
250 | + UNW_TEST_EXIT_SKIP = 77, /* Test should be skipped */ | ||
251 | + UNW_TEST_EXIT_HARD_ERROR = 99 /* Test program itself has failed */ | ||
252 | +}; | ||
253 | + | ||
254 | +#endif /* LIBUNWIND_UNW_TEST_H */ | ||
255 | + | ||
diff --git a/meta/recipes-support/libunwind/libunwind_1.8.1.bb b/meta/recipes-support/libunwind/libunwind_1.8.1.bb index da87f3e3ee..68d7a98ee4 100644 --- a/meta/recipes-support/libunwind/libunwind_1.8.1.bb +++ b/meta/recipes-support/libunwind/libunwind_1.8.1.bb | |||
@@ -14,6 +14,7 @@ SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/${BP}.tar.gz \ | |||
14 | file://0004-Rework-inline-aarch64-as-for-setcontext.patch \ | 14 | file://0004-Rework-inline-aarch64-as-for-setcontext.patch \ |
15 | file://0005-Handle-musl-on-PPC32.patch \ | 15 | file://0005-Handle-musl-on-PPC32.patch \ |
16 | file://libatomic.patch \ | 16 | file://libatomic.patch \ |
17 | file://malloc.patch \ | ||
17 | " | 18 | " |
18 | 19 | ||
19 | SRC_URI[sha256sum] = "ddf0e32dd5fafe5283198d37e4bf9decf7ba1770b6e7e006c33e6df79e6a6157" | 20 | SRC_URI[sha256sum] = "ddf0e32dd5fafe5283198d37e4bf9decf7ba1770b6e7e006c33e6df79e6a6157" |