_REENT_CHECK_VERIFY calls __assert_func even if NDEBUG is defined

R. Diez rdiezmail-newlib@yahoo.de
Tue Apr 28 19:57:55 GMT 2020


Hallo again:

After some further research and testing, I wanted to share a couple of hints that may help other people too:

Point 1) Configuring with --disable-newlib-reent-small (which is actually the default) gets rid of the surprising malloc() on first touch from rand(), and probably many other places.

Note that sizeof( struct _reent  ) increases from 240 bytes to 1064 bytes (tested with Newlib version 3.3.0).

I think Newlib should document that option --enable-newlib-reent-small is risky. Unless you are really tight on RAM, I strongly advise against this unsafe optimisation.


Point 2) The documentation on this section is misleading:

  https://sourceware.org/newlib/libc.html#Reentrancy

That section states:

-----------8<-----------8<-----------8<-----------8<-----------
This means that you have two ways to achieve reentrancy. Both require that each thread of execution control initialize a unique global variable of type ‘struct _reent’:

Use the reentrant versions of the library functions, after initializing a global reentrancy structure for 1.  each process. Use the pointer to this structure as the extra argument for all library functions.
-----------8<-----------8<-----------8<-----------8<-----------

This section gives you the impression that you are free to choose. But if you have multithreading, you really need to implement _impure_ptr, mention in option (2). For example, the rand() function needs such a global state (that was my impression by looking at the convoluted macros).

Newlib does have a rand_r() counterpart, but it is not really equivalent (it is a much weaker pseudo-random generator), and Posix has declared it obsolete. So there is no real xxx_r() equivalent for rand() in Newlib (that I could see).

All the best,
  rdiez


More information about the Newlib mailing list