-
Notifications
You must be signed in to change notification settings - Fork 135
Initial picolibc support #535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: preview
Are you sure you want to change the base?
Conversation
d660a22 to
e4ecd7d
Compare
|
|
vasnprintf is a newlib extension not even present in glibc; is there some reason vasprintf isn't sufficient for your use? |
|
There's no reason |
It's a hot code path though. We would have to change that to |
|
Makes sense. I think you could pretty easily build an implementation of the vasnprintf API using vsnprintf and vasprintf which did exactly that at modest cost in code space. It seems like using standard interfaces in your application would have some modest readability benefits at least. vasnprintf is not precisely documented in the newlib code, although the semantics seem fairly obvious. |
e4ecd7d to
32caa84
Compare
|
Rebased with the latest |
32caa84 to
f93520d
Compare
|
Rebased again. |
|
Just for you, I added picolibc/picolibc#885 |
|
Oh, I modified the PR not to require it months ago, but thank you! |
|
I figured the rest of the group would be happier to not have that regression :-) |
|
(also found that I wasn't testing asprintf at all (oops!)) |
|
After discussing on the Discord, we'll try to get the PR evaluated and merged in late December, after this year's N64 Jam is over. |
a166170 to
981a84b
Compare
|
Retested. The picolibc advantage is less significant now that libdragon is threaded, but removing |
dd27dbc to
2368351
Compare
54ce851 to
c13c11d
Compare
1e7140f to
b968dd9
Compare
44426d7 to
9b61739
Compare
3a09e4d to
79fe179
Compare
|
picolibc should be frozen at commit I am entertaining porting either a newer version of dlmalloc, or the TLSF allocator, on top. If you have any better ideas worth evaluating, let me know. |
Note that you can simply copy the newlib malloc code into your project directly and replace the picolibc malloc code that way. Picolibc cannot depend upon its own malloc implementation as many projects replace that with their own. |
|
Good to know that it's supported to do so - thank you! |
As of today, picolibc has dropped support for the newlib fork of dlmalloc[1]. While nano-malloc has code size advantages, it is noticeably slower for environments with more desktop-like, heavy allocation patterns. As such, this commit pulls the latest version of dlmalloc into libnds, which is formally supported by picolibc's maintainer[2]. This has a few other advantages; in particular, additional safety validations can now be included in the debug libnds build. Other, leaner allocators, such as tlsf, may be evaluated in the future, but this is the easiest way to unblock picolibc updates going forward. [1]: picolibc/picolibc#1155 [2]: DragonMinded/libdragon#535 (comment)
|
It turns out dlmalloc 2.8.6 slots right in. |
Yup, and this gets tested as a part of Zephyr integration on a regular basis. |
|
Thanks for the heads up. In N64 land, we would need a few extensions to dlmalloc, in particular we would need a way to hint what part of the heap (address range) try to fit some specific allocations, because there are performance issues when multiple hardware devices access memory areas that are too close together. This is not supported by dlmalloc as-is so I guess a fork is needed anyway |
|
If a 3-clause BSD license is not of concern to you, you can also try forking the tlsf allocator, which is held in high regard. Or you can try implementing your own allocator! Either way, the above dlmalloc implementation example should help with that. |
picolibc offers a number of advantages over newlib, some of which include:
iprintf/printfdual implementation problem (but this has problems, see below)This pull request provides initial support for picolibc, as an opt-in environment variable
N64_USE_PICOLIBC=truewhen building the toolchain. It also provides, separately, an environment variableN64_USE_PICOLIBC_TINYSTDIO=trueto enable the alternate stdio implementation. Without these environment variables, newlib is used as before, with no changes.TODO:
picolibc does not yet support theaddressed here: Add MIPS64 CPU family support. picolibc/picolibc#730mips64CPU familyfunopen(), which precludes supporting streaming compressed assets at this time. ~~ picolibc's tinystdio now implementsfunopen()!tinystdio does not implementpicolibc's tinystdio now implementsvasnprintf(), which precludes the stack/heap implementation ofrdpq_text_printf. However, this is not necessary; it's solely an optimization strategy, andvasprintf()works just fine.vasnprintf()!-Dnewlib-global-errno=truepassed. Is thread-local storage enabled early enough?