rand() may call malloc()
The solution isn't to stop using rand(). The solution is to stop using newlib.<p>If you're doing your own custom memory management like this, you shouldn't even <i>have</i> a malloc implementation at all. Even newlib is too bloated for your use case. At this point, chances are you're using a trivial subset of the C library and it'd be easy to roll your own. You can import bits and pieces from other projects (I personally sometimes copy and paste bits from PDClib for this). In such a tight embedded project, chances are you don't even have threads; why even pull in that reentrancy code?<p>Freestanding C code with no standard library isn't scary. If you need an example, look at what we do for m1n1:<p><a href="https://github.com/AsahiLinux/m1n1/tree/main/src" rel="nofollow">https://github.com/AsahiLinux/m1n1/tree/main/src</a><p>In particular, this is the libc subset we use (we do have malloc here, which is dlmalloc, but still not enough of libc to be worth depending on a full one):<p><a href="https://github.com/AsahiLinux/m1n1/tree/main/sysinc" rel="nofollow">https://github.com/AsahiLinux/m1n1/tree/main/sysinc</a>