newlib: move nano-malloc logic from build to source files

Simplify the build system logic a bit by moving the mallocr.c ->
nano-mallocr.c redirection from the Makefile to the source files.
This allows for consistent object name usage regardless of the
configuration options used in case a machine dir wants to define
its own override.
This commit is contained in:
Mike Frysinger 2022-02-28 23:46:52 -05:00
parent 5fca4e0f18
commit d7b16b0576
3 changed files with 67 additions and 116 deletions

View File

@ -83,34 +83,6 @@ GENERAL_SOURCES += \
wcstold.c
endif # HAVE_LONG_DOUBLE
if NEWLIB_NANO_MALLOC
MALIGNR=nano-malignr
MALLOPTR=nano-malloptr
PVALLOCR=nano-pvallocr
VALLOCR=nano-vallocr
FREER=nano-freer
REALLOCR=nano-reallocr
CALLOCR=nano-callocr
CFREER=nano-cfreer
MALLINFOR=nano-mallinfor
MALLSTATSR=nano-mallstatsr
MSIZER=nano-msizer
MALLOCR=nano-mallocr
else
MALIGNR=malignr
MALLOPTR=malloptr
PVALLOCR=pvallocr
VALLOCR=vallocr
FREER=freer
REALLOCR=reallocr
CALLOCR=callocr
CFREER=cfreer
MALLINFOR=mallinfor
MALLSTATSR=mallstatsr
MSIZER=msizer
MALLOCR=mallocr
endif
EXTENDED_SOURCES = \
arc4random.c \
arc4random_uniform.c \
@ -162,10 +134,10 @@ ELIX_2_SOURCES = \
wctob.c
ELIX_2_OBJS = \
$(lpfx)$(MALIGNR).o \
$(lpfx)$(MALLOPTR).o \
$(lpfx)$(PVALLOCR).o \
$(lpfx)$(VALLOCR).o
$(lpfx)malignr.o \
$(lpfx)malloptr.o \
$(lpfx)pvallocr.o \
$(lpfx)vallocr.o
ELIX_3_SOURCES = \
putenv.c \
@ -196,10 +168,10 @@ endif
endif
# Because of how libtool moves objects around, mallocr must be built last.
LIBADD_OBJS = $(lpfx)$(FREER).o $(lpfx)$(REALLOCR).o \
$(lpfx)$(CALLOCR).o $(lpfx)$(CFREER).o \
$(lpfx)$(MALLINFOR).o $(lpfx)$(MALLSTATSR).o \
$(lpfx)$(MSIZER).o $(lpfx)$(MALLOCR).o
LIBADD_OBJS = $(lpfx)freer.o $(lpfx)reallocr.o \
$(lpfx)callocr.o $(lpfx)cfreer.o \
$(lpfx)mallinfor.o $(lpfx)mallstatsr.o \
$(lpfx)msizer.o $(lpfx)mallocr.o
noinst_LIBRARIES = lib.a
lib_a_SOURCES = $(GENERAL_SOURCES) $(EXTENDED_SOURCES) $(ELIX_SOURCES)
@ -208,41 +180,41 @@ lib_a_CFLAGS = $(AM_CFLAGS)
lib_a_DEPENDENCIES = $(LIBADD_OBJS) $(ELIX_OBJS)
LIB_COMPILE = $(AM_V_CC)$(COMPILE)
$(lpfx)$(MALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)mallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOC -c $< -o $@
$(lpfx)$(FREER).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_FREE -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)freer.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_FREE -c $< -o $@
$(lpfx)$(REALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_REALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)reallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_REALLOC -c $< -o $@
$(lpfx)$(CALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_CALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)callocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_CALLOC -c $< -o $@
$(lpfx)$(CFREER).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_CFREE -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)cfreer.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_CFREE -c $< -o $@
$(lpfx)$(MALIGNR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)malignr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $< -o $@
$(lpfx)$(VALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_VALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)vallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_VALLOC -c $< -o $@
$(lpfx)$(PVALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_PVALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)pvallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_PVALLOC -c $< -o $@
$(lpfx)$(MALLINFOR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLINFO -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)mallinfor.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLINFO -c $< -o $@
$(lpfx)$(MALLSTATSR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOC_STATS -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)mallstatsr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOC_STATS -c $< -o $@
$(lpfx)$(MSIZER).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)msizer.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $< -o $@
$(lpfx)$(MALLOPTR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOPT -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)malloptr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOPT -c $< -o $@
$(lpfx)dtoa.o: dtoa.c mprec.h
$(lpfx)ldtoa.o: ldtoa.c mprec.h gdtoa.h

View File

@ -402,30 +402,6 @@ GENERAL_SOURCES = __adjust.c __atexit.c __call_atexit.c __exp10.c \
strtoimax.c strtol.c strtoul.c strtoumax.c utoa.c wcstod.c \
wcstoimax.c wcstol.c wcstoul.c wcstoumax.c wcstombs.c \
wcstombs_r.c wctomb.c wctomb_r.c $(am__append_1)
@NEWLIB_NANO_MALLOC_FALSE@MALIGNR = malignr
@NEWLIB_NANO_MALLOC_TRUE@MALIGNR = nano-malignr
@NEWLIB_NANO_MALLOC_FALSE@MALLOPTR = malloptr
@NEWLIB_NANO_MALLOC_TRUE@MALLOPTR = nano-malloptr
@NEWLIB_NANO_MALLOC_FALSE@PVALLOCR = pvallocr
@NEWLIB_NANO_MALLOC_TRUE@PVALLOCR = nano-pvallocr
@NEWLIB_NANO_MALLOC_FALSE@VALLOCR = vallocr
@NEWLIB_NANO_MALLOC_TRUE@VALLOCR = nano-vallocr
@NEWLIB_NANO_MALLOC_FALSE@FREER = freer
@NEWLIB_NANO_MALLOC_TRUE@FREER = nano-freer
@NEWLIB_NANO_MALLOC_FALSE@REALLOCR = reallocr
@NEWLIB_NANO_MALLOC_TRUE@REALLOCR = nano-reallocr
@NEWLIB_NANO_MALLOC_FALSE@CALLOCR = callocr
@NEWLIB_NANO_MALLOC_TRUE@CALLOCR = nano-callocr
@NEWLIB_NANO_MALLOC_FALSE@CFREER = cfreer
@NEWLIB_NANO_MALLOC_TRUE@CFREER = nano-cfreer
@NEWLIB_NANO_MALLOC_FALSE@MALLINFOR = mallinfor
@NEWLIB_NANO_MALLOC_TRUE@MALLINFOR = nano-mallinfor
@NEWLIB_NANO_MALLOC_FALSE@MALLSTATSR = mallstatsr
@NEWLIB_NANO_MALLOC_TRUE@MALLSTATSR = nano-mallstatsr
@NEWLIB_NANO_MALLOC_FALSE@MSIZER = msizer
@NEWLIB_NANO_MALLOC_TRUE@MSIZER = nano-msizer
@NEWLIB_NANO_MALLOC_FALSE@MALLOCR = mallocr
@NEWLIB_NANO_MALLOC_TRUE@MALLOCR = nano-mallocr
EXTENDED_SOURCES = \
arc4random.c \
arc4random_uniform.c \
@ -477,10 +453,10 @@ ELIX_2_SOURCES = \
wctob.c
ELIX_2_OBJS = \
$(lpfx)$(MALIGNR).o \
$(lpfx)$(MALLOPTR).o \
$(lpfx)$(PVALLOCR).o \
$(lpfx)$(VALLOCR).o
$(lpfx)malignr.o \
$(lpfx)malloptr.o \
$(lpfx)pvallocr.o \
$(lpfx)vallocr.o
ELIX_3_SOURCES = \
putenv.c \
@ -502,10 +478,10 @@ ELIX_4_SOURCES = \
@ELIX_LEVEL_1_TRUE@ELIX_OBJS =
# Because of how libtool moves objects around, mallocr must be built last.
LIBADD_OBJS = $(lpfx)$(FREER).o $(lpfx)$(REALLOCR).o \
$(lpfx)$(CALLOCR).o $(lpfx)$(CFREER).o \
$(lpfx)$(MALLINFOR).o $(lpfx)$(MALLSTATSR).o \
$(lpfx)$(MSIZER).o $(lpfx)$(MALLOCR).o
LIBADD_OBJS = $(lpfx)freer.o $(lpfx)reallocr.o \
$(lpfx)callocr.o $(lpfx)cfreer.o \
$(lpfx)mallinfor.o $(lpfx)mallstatsr.o \
$(lpfx)msizer.o $(lpfx)mallocr.o
noinst_LIBRARIES = lib.a
lib_a_SOURCES = $(GENERAL_SOURCES) $(EXTENDED_SOURCES) $(ELIX_SOURCES)
@ -1499,41 +1475,41 @@ uninstall-am:
.PRECIOUS: Makefile
$(lpfx)$(MALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)mallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOC -c $< -o $@
$(lpfx)$(FREER).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_FREE -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)freer.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_FREE -c $< -o $@
$(lpfx)$(REALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_REALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)reallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_REALLOC -c $< -o $@
$(lpfx)$(CALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_CALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)callocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_CALLOC -c $< -o $@
$(lpfx)$(CFREER).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_CFREE -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)cfreer.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_CFREE -c $< -o $@
$(lpfx)$(MALIGNR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)malignr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $< -o $@
$(lpfx)$(VALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_VALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)vallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_VALLOC -c $< -o $@
$(lpfx)$(PVALLOCR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_PVALLOC -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)pvallocr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_PVALLOC -c $< -o $@
$(lpfx)$(MALLINFOR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLINFO -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)mallinfor.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLINFO -c $< -o $@
$(lpfx)$(MALLSTATSR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOC_STATS -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)mallstatsr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOC_STATS -c $< -o $@
$(lpfx)$(MSIZER).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)msizer.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $< -o $@
$(lpfx)$(MALLOPTR).o: $(MALLOCR).c
$(LIB_COMPILE) -DDEFINE_MALLOPT -c $(srcdir)/$(MALLOCR).c -o $@
$(lpfx)malloptr.o: mallocr.c
$(LIB_COMPILE) -DDEFINE_MALLOPT -c $< -o $@
$(lpfx)dtoa.o: dtoa.c mprec.h
$(lpfx)ldtoa.o: ldtoa.c mprec.h gdtoa.h

View File

@ -1,5 +1,8 @@
#include <newlib.h>
#ifdef MALLOC_PROVIDED
int _dummy_mallocr = 1;
#elif defined(_NANO_MALLOC)
# include "nano-mallocr.c"
#else
/* ---------- To make a malloc.h, start cutting here ------------ */