Newlib build is broken if configured with nano-malloc and non-reentrant system calls

Non-reentrant system calls version implies both MISSING_SYSCALL_NAMES
and REENTRANT_SYSCALL_PROVIDED macros to be defined.
Being coupled with --enable-newlib-nano-malloc knob it breaks the build:

bash-4.3$ ../newlib-2.3.0.20160104/configure CC_FOR_TARGET=gcc
AR_FOR_TARGET=ar RANLIB_FOR_TARGET=ranlib CFLAGS_FOR_TARGET="-m32
-DMISSING_SYSCALL_NAMES -DREENTRANT_SYSCALLS_PROVIDED"
--target=i386-elf --enable-newlib-nano-malloc && make

<...omitted output...>

../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:
In function ‘_mallinfo_r’:
../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:489:35:
error: macro "_sbrk_r" requires 2 arguments, but only 1 given
         sbrk_now = _sbrk_r(RCALL 0);
                                   ^
../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:489:20:
error: ‘_sbrk_r’ undeclared (first use in this function)
         sbrk_now = _sbrk_r(RCALL 0);
                    ^
../../../../../../newlib-2.3.0.20160104/newlib/libc/stdlib/nano-mallocr.c:489:20:
note: each undeclared identifier is reported only once for each
function it appears in
Makefile:1512: recipe for target 'lib_a-nano-mallinfor.o' failed
make[8]: *** [lib_a-nano-mallinfor.o] Error 1

In case of non-reentrant system calls _sbrk_r became a macro with TWO
args (defined in reent.h):

#define _sbrk_r(__reent, __incr)  sbrk(__incr)

But in our case only one argument is present. (RCALL 0) is considered
as a single argument despite RCALL itself is a macro:)

So intermediate one-arg macro will be enough to expand args before
final _sbrk_r expansion:

#define _SBRK_R(X) _sbrk_r(X)

Here is a patch:
This commit is contained in:
Игорь Веневцев 2016-01-29 18:19:57 +03:00 committed by Corinna Vinschen
parent 7c9651e3cc
commit 352cdbb012
1 changed files with 6 additions and 4 deletions

View File

@ -46,6 +46,8 @@
#define MAX(a,b) ((a) >= (b) ? (a) : (b))
#endif
#define _SBRK_R(X) _sbrk_r(X)
#ifdef INTERNAL_NEWLIB
#include <sys/config.h>
@ -209,9 +211,9 @@ static void* sbrk_aligned(RARG malloc_size_t s)
{
char *p, *align_p;
if (sbrk_start == NULL) sbrk_start = _sbrk_r(RCALL 0);
if (sbrk_start == NULL) sbrk_start = _SBRK_R(RCALL 0);
p = _sbrk_r(RCALL s);
p = _SBRK_R(RCALL s);
/* sbrk returns -1 if fail to allocate */
if (p == (void *)-1)
@ -222,7 +224,7 @@ static void* sbrk_aligned(RARG malloc_size_t s)
{
/* p is not aligned, ask for a few more bytes so that we have s
* bytes reserved from align_p. */
p = _sbrk_r(RCALL align_p - p);
p = _SBRK_R(RCALL align_p - p);
if (p == (void *)-1)
return p;
}
@ -486,7 +488,7 @@ struct mallinfo nano_mallinfo(RONEARG)
if (sbrk_start == NULL) total_size = 0;
else {
sbrk_now = _sbrk_r(RCALL 0);
sbrk_now = _SBRK_R(RCALL 0);
if (sbrk_now == (void *)-1)
total_size = (size_t)-1;