File tree 3 files changed +16
-4
lines changed
3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change 8
8
#include < sys/stat.h>
9
9
#include < sys/time.h>
10
10
#include < sys/times.h>
11
+ #include < sys/reent.h>
11
12
#include < limits.h>
12
13
#include < nucleus.h>
13
14
#include < libndls.h>
@@ -24,6 +25,10 @@ extern int errno;
24
25
#include < syscall-list.h>
25
26
#include " syscall.h"
26
27
28
+ namespace __gnu_cxx {
29
+ extern __attribute__ ((weak)) void __freeres();
30
+ }
31
+
27
32
extern " C" {
28
33
29
34
// The only macro, I swear
@@ -197,6 +202,17 @@ void _exit(int ret)
197
202
nio_free (&csl);
198
203
#endif
199
204
205
+ // Free memory allocated by libstdc++
206
+ if (__gnu_cxx::__freeres)
207
+ __gnu_cxx::__freeres ();
208
+
209
+ // Newlib doesn't reclaim data from the statically allocated reent
210
+ // itself, so do it here. It needs a bit of "convincing".
211
+ // See https://sourceware.org/pipermail/newlib/2020/018173.html
212
+ struct _reent *global_reent = _impure_ptr;
213
+ _impure_ptr = nullptr ;
214
+ _reclaim_reent (global_reent);
215
+
200
216
__crt0_exit (ret);
201
217
202
218
__builtin_unreachable ();
Original file line number Diff line number Diff line change @@ -5,7 +5,6 @@ _start: .global _start
5
5
str sp, __crt0_savedsp
6
6
push {r0, r1}
7
7
bl initialise_monitor_handles /* Grab stdin, -out and -err, required for newlib */
8
- bl _init_signal /* Required for newlibs atexit */
9
8
bl __cpp_init /* C++ static initializers */
10
9
pop {r0, r1}
11
10
bl main
Original file line number Diff line number Diff line change 6
6
exit: .weak exit /* If linked without newlib, used by crt0. Can't be defined in crt0, as newlibs exit is also weak */
7
7
bl __crt0_exit
8
8
9
- _init_signal: .weak _init_signal /* Same here */
10
- bx lr
11
-
12
9
.section .init_array
13
10
.long -1 /* Terminating character for ctor list */
14
11
You can’t perform that action at this time.
0 commit comments