public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/6] rework malloc logic from build rules to source files
@ 2022-03-02  1:36 Mike Frysinger
  2022-03-02  1:36 ` [PATCH 1/6] newlib: move nano-malloc logic from build " Mike Frysinger
                   ` (6 more replies)
  0 siblings, 7 replies; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

I broke these out into separate changes to make it easier to review.
The goal is to kill off all the custom build rules in stdlib/ so we
only rely on Automake to compile so we can convert the libc build to
a non-recursive one like we've done with libm.a.  This is the last
series needed to unblock that.

There's also some real bugfixes in here independent of the build
system rework, but I kept them separate for bisection purposes.

Mike Frysinger (6):
  newlib: move nano-malloc logic from build to source files
  newlib: rename mallocr.c to _mallocr.c
  newlib: xstormy16: fix mallopt definition & mstats handling
  newlib: xstormy16: break up mallocr stubs
  newlib: xstormy16: move malloc multiplex logic from build to source
    files
  newlib: libc: move stdlib multiplex logic from build to source files

 newlib/libc/machine/xstormy16/Makefile.am |   83 +-
 newlib/libc/machine/xstormy16/Makefile.in |  175 +-
 newlib/libc/machine/xstormy16/calloc.c    |    2 +
 newlib/libc/machine/xstormy16/callocr.c   |    7 +
 newlib/libc/machine/xstormy16/cfree.c     |    2 +
 newlib/libc/machine/xstormy16/freer.c     |    7 +
 newlib/libc/machine/xstormy16/malign.c    |    2 +
 newlib/libc/machine/xstormy16/malloc.c    |    4 +
 newlib/libc/machine/xstormy16/mallocr.c   |   26 -
 newlib/libc/machine/xstormy16/msize.c     |    2 +
 newlib/libc/machine/xstormy16/mstats.c    |    6 +
 newlib/libc/machine/xstormy16/realloc.c   |    2 +
 newlib/libc/machine/xstormy16/reallocr.c  |    7 +
 newlib/libc/machine/xstormy16/valloc.c    |    4 +
 newlib/libc/stdlib/Makefile.am            |  120 +-
 newlib/libc/stdlib/Makefile.in            |  254 +-
 newlib/libc/stdlib/_mallocr.c             | 3719 +++++++++++++++++++++
 newlib/libc/stdlib/callocr.c              |    2 +
 newlib/libc/stdlib/cfreer.c               |    2 +
 newlib/libc/stdlib/freer.c                |    2 +
 newlib/libc/stdlib/malignr.c              |    2 +
 newlib/libc/stdlib/mallinfor.c            |    2 +
 newlib/libc/stdlib/mallocr.c              | 3716 +-------------------
 newlib/libc/stdlib/malloptr.c             |    2 +
 newlib/libc/stdlib/mallstatsr.c           |    2 +
 newlib/libc/stdlib/msizer.c               |    2 +
 newlib/libc/stdlib/pvallocr.c             |    2 +
 newlib/libc/stdlib/reallocr.c             |    2 +
 newlib/libc/stdlib/vallocr.c              |    2 +
 29 files changed, 4034 insertions(+), 4126 deletions(-)
 create mode 100644 newlib/libc/machine/xstormy16/calloc.c
 create mode 100644 newlib/libc/machine/xstormy16/callocr.c
 create mode 100644 newlib/libc/machine/xstormy16/cfree.c
 create mode 100644 newlib/libc/machine/xstormy16/freer.c
 create mode 100644 newlib/libc/machine/xstormy16/malign.c
 create mode 100644 newlib/libc/machine/xstormy16/malloc.c
 create mode 100644 newlib/libc/machine/xstormy16/msize.c
 create mode 100644 newlib/libc/machine/xstormy16/mstats.c
 create mode 100644 newlib/libc/machine/xstormy16/realloc.c
 create mode 100644 newlib/libc/machine/xstormy16/reallocr.c
 create mode 100644 newlib/libc/machine/xstormy16/valloc.c
 create mode 100644 newlib/libc/stdlib/_mallocr.c
 create mode 100644 newlib/libc/stdlib/callocr.c
 create mode 100644 newlib/libc/stdlib/cfreer.c
 create mode 100644 newlib/libc/stdlib/freer.c
 create mode 100644 newlib/libc/stdlib/malignr.c
 create mode 100644 newlib/libc/stdlib/mallinfor.c
 create mode 100644 newlib/libc/stdlib/malloptr.c
 create mode 100644 newlib/libc/stdlib/mallstatsr.c
 create mode 100644 newlib/libc/stdlib/msizer.c
 create mode 100644 newlib/libc/stdlib/pvallocr.c
 create mode 100644 newlib/libc/stdlib/reallocr.c
 create mode 100644 newlib/libc/stdlib/vallocr.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/6] newlib: move nano-malloc logic from build to source files
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
@ 2022-03-02  1:36 ` Mike Frysinger
  2022-03-02  1:36 ` [PATCH 2/6] newlib: rename mallocr.c to _mallocr.c Mike Frysinger
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

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.
---
 newlib/libc/stdlib/Makefile.am | 92 ++++++++++++----------------------
 newlib/libc/stdlib/Makefile.in | 88 ++++++++++++--------------------
 newlib/libc/stdlib/mallocr.c   |  3 ++
 3 files changed, 67 insertions(+), 116 deletions(-)

diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 50e22d90c0e0..950ad98ac134 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -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
diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
index 6167433c8e2c..4b53997a34b0 100644
--- a/newlib/libc/stdlib/mallocr.c
+++ b/newlib/libc/stdlib/mallocr.c
@@ -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 ------------ */
 
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 2/6] newlib: rename mallocr.c to _mallocr.c
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
  2022-03-02  1:36 ` [PATCH 1/6] newlib: move nano-malloc logic from build " Mike Frysinger
@ 2022-03-02  1:36 ` Mike Frysinger
  2022-03-02  1:36 ` [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling Mike Frysinger
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

This file is a little confusing: it provides all of the mallocr logic,
but is compiled multiple times to produce a unique symbol each time.
For example, building mallocr.c with -DDEFINE_FREER produces freer.o
that only defines _free_r().  This is fine for most symbols, but it's
a little confusing when defining mallocr itself -- we produce a file
with the same symbol name, but we still need -DDEFINE_MALLOCR.  In
order to move the logic from the build rules to source files, using
mallocr.c both as a multiplexer and for defining a single symbol is a
bit tricky.  It's possible (if we add a lot of redundant preprocessor
checks to mallocr.c, or we add complicated build flags just for this
one files), but it's easier if we simply rename this to a dedicated
file.  So let's do that.

We do this as a dedicated commit because the next one will create a
new mallocr.c file and git's automatic diff algorithms can handle
trivial renames, but it can't handle renames+creates in the same
commit.
---
 newlib/libc/stdlib/Makefile.am               | 24 ++++++++++----------
 newlib/libc/stdlib/Makefile.in               | 24 ++++++++++----------
 newlib/libc/stdlib/{mallocr.c => _mallocr.c} |  0
 3 files changed, 24 insertions(+), 24 deletions(-)
 rename newlib/libc/stdlib/{mallocr.c => _mallocr.c} (100%)

diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index 950ad98ac134..cb2fbe850b85 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -180,40 +180,40 @@ lib_a_CFLAGS = $(AM_CFLAGS)
 lib_a_DEPENDENCIES = $(LIBADD_OBJS) $(ELIX_OBJS)
 LIB_COMPILE = $(AM_V_CC)$(COMPILE)
 
-$(lpfx)mallocr.o: mallocr.c
+$(lpfx)mallocr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_MALLOC -c $< -o $@
 
-$(lpfx)freer.o: mallocr.c
+$(lpfx)freer.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_FREE -c $< -o $@
 
-$(lpfx)reallocr.o: mallocr.c
+$(lpfx)reallocr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_REALLOC -c $< -o $@
 
-$(lpfx)callocr.o: mallocr.c
+$(lpfx)callocr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_CALLOC -c $< -o $@
 
-$(lpfx)cfreer.o: mallocr.c
+$(lpfx)cfreer.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_CFREE -c $< -o $@
 
-$(lpfx)malignr.o: mallocr.c
+$(lpfx)malignr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $< -o $@
 
-$(lpfx)vallocr.o: mallocr.c
+$(lpfx)vallocr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_VALLOC -c $< -o $@
 
-$(lpfx)pvallocr.o: mallocr.c
+$(lpfx)pvallocr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_PVALLOC -c $< -o $@
 
-$(lpfx)mallinfor.o: mallocr.c
+$(lpfx)mallinfor.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_MALLINFO -c $< -o $@
 
-$(lpfx)mallstatsr.o: mallocr.c
+$(lpfx)mallstatsr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_MALLOC_STATS -c $< -o $@
 
-$(lpfx)msizer.o: mallocr.c
+$(lpfx)msizer.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $< -o $@
 
-$(lpfx)malloptr.o: mallocr.c
+$(lpfx)malloptr.o: _mallocr.c
 	$(LIB_COMPILE) -DDEFINE_MALLOPT -c $< -o $@
 
 $(lpfx)dtoa.o: dtoa.c mprec.h
diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/_mallocr.c
similarity index 100%
rename from newlib/libc/stdlib/mallocr.c
rename to newlib/libc/stdlib/_mallocr.c
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
  2022-03-02  1:36 ` [PATCH 1/6] newlib: move nano-malloc logic from build " Mike Frysinger
  2022-03-02  1:36 ` [PATCH 2/6] newlib: rename mallocr.c to _mallocr.c Mike Frysinger
@ 2022-03-02  1:36 ` Mike Frysinger
  2022-03-02  9:46   ` Corinna Vinschen
  2022-03-02  1:36 ` [PATCH 4/6] newlib: xstormy16: break up mallocr stubs Mike Frysinger
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

The mallopt symbol is defined in tiny-malloc.c, not mallocr.c, but
the Makefile in here tries to compile it out of the latter.  This
leads to mallopt never being defined.

The build also creates mallinfo.o & mallopt.o & mallstats.o objects
to override common ones, but the common dir doesn't use these names.
Instead, it places these all in mstats.o.

So move the build define logic to a dedicated file and compile it
directly to make things a bit simpler while fixing the missing func
and aligning objects with the cmomon code.
---
 newlib/libc/machine/xstormy16/Makefile.am | 15 ++--------
 newlib/libc/machine/xstormy16/Makefile.in | 36 +++++++++++++----------
 newlib/libc/machine/xstormy16/mstats.c    |  6 ++++
 3 files changed, 29 insertions(+), 28 deletions(-)
 create mode 100644 newlib/libc/machine/xstormy16/mstats.c

diff --git a/newlib/libc/machine/xstormy16/Makefile.am b/newlib/libc/machine/xstormy16/Makefile.am
index faaac89413ed..f5237dce3880 100644
--- a/newlib/libc/machine/xstormy16/Makefile.am
+++ b/newlib/libc/machine/xstormy16/Makefile.am
@@ -6,7 +6,8 @@ AM_CCASFLAGS = $(AM_CPPFLAGS)
 
 noinst_LIBRARIES = lib.a
 
-lib_a_SOURCES = setjmp.S
+lib_a_SOURCES = setjmp.S \
+	mstats.c
 lib_a_CFLAGS = $(AM_CFLAGS)
 
 lib_a_LIBADD = $(lpfx)malloc.o \
@@ -17,10 +18,7 @@ lib_a_LIBADD = $(lpfx)malloc.o \
 	$(lpfx)malign.o \
 	$(lpfx)valloc.o \
 	$(lpfx)pvalloc.o \
-	$(lpfx)mallinfo.o \
-	$(lpfx)mallstats.o \
 	$(lpfx)msize.o \
-	$(lpfx)mallopt.o \
 	$(lpfx)mallocr.o \
 	$(lpfx)freer.o \
 	$(lpfx)reallocr.o \
@@ -54,18 +52,9 @@ $(lpfx)valloc.o: tiny-malloc.c
 $(lpfx)pvalloc.o: tiny-malloc.c
 	$(MALLOC_COMPILE) -DDEFINE_PVALLOC -c $(srcdir)/tiny-malloc.c -o $@
 
-$(lpfx)mallinfo.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_MALLINFO -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)mallstats.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_MALLOC_STATS -c $(srcdir)/tiny-malloc.c -o $@
-
 $(lpfx)msize.o: tiny-malloc.c
 	$(MALLOC_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/tiny-malloc.c -o $@
 
-$(lpfx)mallopt.o: mallocr.c
-	$(MALLOC_COMPILE) -DDEFINE_MALLOPT -c $(srcdir)/mallocr.c -o $@
-
 $(lpfx)mallocr.o: mallocr.c
 	$(MALLOC_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/mallocr.c -o $@
 
diff --git a/newlib/libc/machine/xstormy16/mstats.c b/newlib/libc/machine/xstormy16/mstats.c
new file mode 100644
index 000000000000..1bd24da555f1
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/mstats.c
@@ -0,0 +1,6 @@
+/* stdlib/mstats.c defines all these symbols in this file.
+   TODO: Missing mstats function.  */
+#define DEFINE_MALLINFO
+#define DEFINE_MALLOC_STATS
+#define DEFINE_MALLOPT
+#include "tiny-malloc.c"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 4/6] newlib: xstormy16: break up mallocr stubs
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
                   ` (2 preceding siblings ...)
  2022-03-02  1:36 ` [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling Mike Frysinger
@ 2022-03-02  1:36 ` Mike Frysinger
  2022-03-02  1:36 ` [PATCH 5/6] newlib: xstormy16: move malloc multiplex logic from build to source files Mike Frysinger
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

Move the multiplex logic out of the build and into source files to
make the build rules a lot simpler.
---
 newlib/libc/machine/xstormy16/Makefile.am | 24 +++--------
 newlib/libc/machine/xstormy16/Makefile.in | 52 ++++++++++++++---------
 newlib/libc/machine/xstormy16/callocr.c   |  7 +++
 newlib/libc/machine/xstormy16/freer.c     |  7 +++
 newlib/libc/machine/xstormy16/mallocr.c   | 26 ------------
 newlib/libc/machine/xstormy16/reallocr.c  |  7 +++
 6 files changed, 60 insertions(+), 63 deletions(-)
 create mode 100644 newlib/libc/machine/xstormy16/callocr.c
 create mode 100644 newlib/libc/machine/xstormy16/freer.c
 create mode 100644 newlib/libc/machine/xstormy16/reallocr.c

diff --git a/newlib/libc/machine/xstormy16/Makefile.am b/newlib/libc/machine/xstormy16/Makefile.am
index f5237dce3880..842bab9b04ff 100644
--- a/newlib/libc/machine/xstormy16/Makefile.am
+++ b/newlib/libc/machine/xstormy16/Makefile.am
@@ -7,7 +7,11 @@ AM_CCASFLAGS = $(AM_CPPFLAGS)
 noinst_LIBRARIES = lib.a
 
 lib_a_SOURCES = setjmp.S \
-	mstats.c
+	callocr.c \
+	freer.c \
+	mallocr.c \
+	mstats.c \
+	reallocr.c
 lib_a_CFLAGS = $(AM_CFLAGS)
 
 lib_a_LIBADD = $(lpfx)malloc.o \
@@ -18,11 +22,7 @@ lib_a_LIBADD = $(lpfx)malloc.o \
 	$(lpfx)malign.o \
 	$(lpfx)valloc.o \
 	$(lpfx)pvalloc.o \
-	$(lpfx)msize.o \
-	$(lpfx)mallocr.o \
-	$(lpfx)freer.o \
-	$(lpfx)reallocr.o \
-	$(lpfx)callocr.o
+	$(lpfx)msize.o
 
 lib_a_DEPENDENCIES = $(lib_a_LIBADD)
 
@@ -54,15 +54,3 @@ $(lpfx)pvalloc.o: tiny-malloc.c
 
 $(lpfx)msize.o: tiny-malloc.c
 	$(MALLOC_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)mallocr.o: mallocr.c
-	$(MALLOC_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/mallocr.c -o $@
-
-$(lpfx)freer.o: mallocr.c
-	$(MALLOC_COMPILE) -DDEFINE_FREE -c $(srcdir)/mallocr.c -o $@
-
-$(lpfx)reallocr.o: mallocr.c
-	$(MALLOC_COMPILE) -DDEFINE_REALLOC -c $(srcdir)/mallocr.c -o $@
-
-$(lpfx)callocr.o: mallocr.c
-	$(MALLOC_COMPILE) -DDEFINE_CALLOC -c $(srcdir)/mallocr.c -o $@
diff --git a/newlib/libc/machine/xstormy16/callocr.c b/newlib/libc/machine/xstormy16/callocr.c
new file mode 100644
index 000000000000..3e5053c67650
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/callocr.c
@@ -0,0 +1,7 @@
+#include <malloc.h>
+
+void *
+_calloc_r (struct _reent *r, size_t a, size_t b)
+{
+  return calloc (a, b);
+}
diff --git a/newlib/libc/machine/xstormy16/freer.c b/newlib/libc/machine/xstormy16/freer.c
new file mode 100644
index 000000000000..f79ef55495af
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/freer.c
@@ -0,0 +1,7 @@
+#include <malloc.h>
+
+void
+_free_r (struct _reent *r, void *x)
+{
+  free (x);
+}
diff --git a/newlib/libc/machine/xstormy16/mallocr.c b/newlib/libc/machine/xstormy16/mallocr.c
index 07be5303979d..d54df0bdf115 100644
--- a/newlib/libc/machine/xstormy16/mallocr.c
+++ b/newlib/libc/machine/xstormy16/mallocr.c
@@ -1,33 +1,7 @@
 #include <malloc.h>
 
-#ifdef DEFINE_MALLOC
 void *
 _malloc_r (struct _reent *r, size_t sz)
 {
   return malloc (sz);
 }
-#endif
-
-#ifdef DEFINE_CALLOC
-void *
-_calloc_r (struct _reent *r, size_t a, size_t b)
-{
-  return calloc (a, b);
-}
-#endif
-
-#ifdef DEFINE_FREE
-void
-_free_r (struct _reent *r, void *x)
-{
-  free (x);
-}
-#endif
-
-#ifdef DEFINE_REALLOC
-void *
-_realloc_r (struct _reent *r, void *x, size_t sz)
-{
-  return realloc (x, sz);
-}
-#endif
diff --git a/newlib/libc/machine/xstormy16/reallocr.c b/newlib/libc/machine/xstormy16/reallocr.c
new file mode 100644
index 000000000000..2bf538557b06
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/reallocr.c
@@ -0,0 +1,7 @@
+#include <malloc.h>
+
+void *
+_realloc_r (struct _reent *r, void *x, size_t sz)
+{
+  return realloc (x, sz);
+}
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 5/6] newlib: xstormy16: move malloc multiplex logic from build to source files
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
                   ` (3 preceding siblings ...)
  2022-03-02  1:36 ` [PATCH 4/6] newlib: xstormy16: break up mallocr stubs Mike Frysinger
@ 2022-03-02  1:36 ` Mike Frysinger
  2022-03-02  1:36 ` [PATCH 6/6] newlib: libc: move stdlib " Mike Frysinger
  2022-03-02  9:47 ` [PATCH 0/6] rework malloc logic from build rules " Corinna Vinschen
  6 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

Rather than define per-object rules in the Makefile, have small files
that define & include the right content.  This simplifies the build
rules, and makes understanding the source a little easier (imo) as it
makes all the subdirs behave the same: you have 1 source file and it
produces 1 object.  It's also about the same amount of boiler plate,
without having to define custom build rules that can fall out of sync.

We also realign the free & pvalloc definitions: common code puts these
in malloc.o & valloc.o respectively, not in free.o & pvalloc.o objects.

This will also be important as we merge the libc.a build into the top
dir since it relies on a single flat list of objects for overrides.
---
 newlib/libc/machine/xstormy16/Makefile.am |  50 ++---------
 newlib/libc/machine/xstormy16/Makefile.in | 101 +++++++++++++---------
 newlib/libc/machine/xstormy16/calloc.c    |   2 +
 newlib/libc/machine/xstormy16/cfree.c     |   2 +
 newlib/libc/machine/xstormy16/malign.c    |   2 +
 newlib/libc/machine/xstormy16/malloc.c    |   4 +
 newlib/libc/machine/xstormy16/msize.c     |   2 +
 newlib/libc/machine/xstormy16/realloc.c   |   2 +
 newlib/libc/machine/xstormy16/valloc.c    |   4 +
 9 files changed, 84 insertions(+), 85 deletions(-)
 create mode 100644 newlib/libc/machine/xstormy16/calloc.c
 create mode 100644 newlib/libc/machine/xstormy16/cfree.c
 create mode 100644 newlib/libc/machine/xstormy16/malign.c
 create mode 100644 newlib/libc/machine/xstormy16/malloc.c
 create mode 100644 newlib/libc/machine/xstormy16/msize.c
 create mode 100644 newlib/libc/machine/xstormy16/realloc.c
 create mode 100644 newlib/libc/machine/xstormy16/valloc.c

diff --git a/newlib/libc/machine/xstormy16/Makefile.am b/newlib/libc/machine/xstormy16/Makefile.am
index 842bab9b04ff..d3ada18d76a2 100644
--- a/newlib/libc/machine/xstormy16/Makefile.am
+++ b/newlib/libc/machine/xstormy16/Makefile.am
@@ -7,50 +7,16 @@ AM_CCASFLAGS = $(AM_CPPFLAGS)
 noinst_LIBRARIES = lib.a
 
 lib_a_SOURCES = setjmp.S \
+	calloc.c \
 	callocr.c \
+	cfree.c \
 	freer.c \
+	malign.c \
+	malloc.c \
 	mallocr.c \
+	msize.c \
 	mstats.c \
-	reallocr.c
+	realloc.c \
+	reallocr.c \
+	valloc.c
 lib_a_CFLAGS = $(AM_CFLAGS)
-
-lib_a_LIBADD = $(lpfx)malloc.o \
-	$(lpfx)free.o \
-	$(lpfx)realloc.o \
-	$(lpfx)calloc.o \
-	$(lpfx)cfree.o \
-	$(lpfx)malign.o \
-	$(lpfx)valloc.o \
-	$(lpfx)pvalloc.o \
-	$(lpfx)msize.o
-
-lib_a_DEPENDENCIES = $(lib_a_LIBADD)
-
-MALLOC_COMPILE = $(COMPILE)
-
-$(lpfx)malloc.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_MALLOC -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)free.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_FREE -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)realloc.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_REALLOC -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)calloc.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_CALLOC -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)cfree.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_CFREE -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)malign.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_MEMALIGN -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)valloc.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_VALLOC -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)pvalloc.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_PVALLOC -c $(srcdir)/tiny-malloc.c -o $@
-
-$(lpfx)msize.o: tiny-malloc.c
-	$(MALLOC_COMPILE) -DDEFINE_MALLOC_USABLE_SIZE -c $(srcdir)/tiny-malloc.c -o $@
diff --git a/newlib/libc/machine/xstormy16/calloc.c b/newlib/libc/machine/xstormy16/calloc.c
new file mode 100644
index 000000000000..46adf7fa2530
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/calloc.c
@@ -0,0 +1,2 @@
+#define DEFINE_CALLOC
+#include "tiny-malloc.c"
diff --git a/newlib/libc/machine/xstormy16/cfree.c b/newlib/libc/machine/xstormy16/cfree.c
new file mode 100644
index 000000000000..2ab5913678c9
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/cfree.c
@@ -0,0 +1,2 @@
+#define DEFINE_CFREE
+#include "tiny-malloc.c"
diff --git a/newlib/libc/machine/xstormy16/malign.c b/newlib/libc/machine/xstormy16/malign.c
new file mode 100644
index 000000000000..2daba4104f94
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/malign.c
@@ -0,0 +1,2 @@
+#define DEFINE_MEMALIGN
+#include "tiny-malloc.c"
diff --git a/newlib/libc/machine/xstormy16/malloc.c b/newlib/libc/machine/xstormy16/malloc.c
new file mode 100644
index 000000000000..f59020142e88
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/malloc.c
@@ -0,0 +1,4 @@
+/* stdlib/malloc.c defines all these symbols in this file. */
+#define DEFINE_FREE
+#define DEFINE_MALLOC
+#include "tiny-malloc.c"
diff --git a/newlib/libc/machine/xstormy16/msize.c b/newlib/libc/machine/xstormy16/msize.c
new file mode 100644
index 000000000000..90b084871a2f
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/msize.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC_USABLE_SIZE
+#include "tiny-malloc.c"
diff --git a/newlib/libc/machine/xstormy16/realloc.c b/newlib/libc/machine/xstormy16/realloc.c
new file mode 100644
index 000000000000..64a29fa2be31
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/realloc.c
@@ -0,0 +1,2 @@
+#define DEFINE_REALLOC
+#include "tiny-malloc.c"
diff --git a/newlib/libc/machine/xstormy16/valloc.c b/newlib/libc/machine/xstormy16/valloc.c
new file mode 100644
index 000000000000..d6543bc88f3e
--- /dev/null
+++ b/newlib/libc/machine/xstormy16/valloc.c
@@ -0,0 +1,4 @@
+/* stdlib/valloc.c defines all these symbols in this file. */
+#define DEFINE_PVALLOC
+#define DEFINE_VALLOC
+#include "tiny-malloc.c"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 6/6] newlib: libc: move stdlib multiplex logic from build to source files
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
                   ` (4 preceding siblings ...)
  2022-03-02  1:36 ` [PATCH 5/6] newlib: xstormy16: move malloc multiplex logic from build to source files Mike Frysinger
@ 2022-03-02  1:36 ` Mike Frysinger
  2022-03-02  9:47 ` [PATCH 0/6] rework malloc logic from build rules " Corinna Vinschen
  6 siblings, 0 replies; 12+ messages in thread
From: Mike Frysinger @ 2022-03-02  1:36 UTC (permalink / raw)
  To: newlib

Rather than define per-object rules in the Makefile, have small files
that define & include the right content.  This simplifies the build
rules, and makes understanding the source a little easier (imo) as it
makes all the subdirs behave the same: you have 1 source file and it
produces 1 object.  It's also about the same amount of boiler plate,
without having to define custom build rules that can fall out of sync.

This will also be important as we merge the libc.a build into the top
dir since it relies on a single flat list of objects for overrides.

Also take the opportunity to clean up the unnecessary header deps in
here.  Automake provides dependency generation for free now.
---
 newlib/libc/stdlib/Makefile.am  |  92 ++-----------
 newlib/libc/stdlib/Makefile.in  | 230 ++++++++++++++++----------------
 newlib/libc/stdlib/callocr.c    |   2 +
 newlib/libc/stdlib/cfreer.c     |   2 +
 newlib/libc/stdlib/freer.c      |   2 +
 newlib/libc/stdlib/malignr.c    |   2 +
 newlib/libc/stdlib/mallinfor.c  |   2 +
 newlib/libc/stdlib/mallocr.c    |   2 +
 newlib/libc/stdlib/malloptr.c   |   2 +
 newlib/libc/stdlib/mallstatsr.c |   2 +
 newlib/libc/stdlib/msizer.c     |   2 +
 newlib/libc/stdlib/pvallocr.c   |   2 +
 newlib/libc/stdlib/reallocr.c   |   2 +
 newlib/libc/stdlib/vallocr.c    |   2 +
 14 files changed, 153 insertions(+), 193 deletions(-)
 create mode 100644 newlib/libc/stdlib/callocr.c
 create mode 100644 newlib/libc/stdlib/cfreer.c
 create mode 100644 newlib/libc/stdlib/freer.c
 create mode 100644 newlib/libc/stdlib/malignr.c
 create mode 100644 newlib/libc/stdlib/mallinfor.c
 create mode 100644 newlib/libc/stdlib/mallocr.c
 create mode 100644 newlib/libc/stdlib/malloptr.c
 create mode 100644 newlib/libc/stdlib/mallstatsr.c
 create mode 100644 newlib/libc/stdlib/msizer.c
 create mode 100644 newlib/libc/stdlib/pvallocr.c
 create mode 100644 newlib/libc/stdlib/reallocr.c
 create mode 100644 newlib/libc/stdlib/vallocr.c

diff --git a/newlib/libc/stdlib/Makefile.am b/newlib/libc/stdlib/Makefile.am
index cb2fbe850b85..b06b66014b79 100644
--- a/newlib/libc/stdlib/Makefile.am
+++ b/newlib/libc/stdlib/Makefile.am
@@ -19,6 +19,8 @@ GENERAL_SOURCES = \
 	atoi.c  	\
 	atol.c		\
 	calloc.c	\
+	callocr.c	\
+	cfreer.c	\
 	div.c  		\
 	dtoa.c 		\
 	dtoastub.c 	\
@@ -26,6 +28,7 @@ GENERAL_SOURCES = \
 	envlock.c	\
 	eprintf.c	\
 	exit.c 		\
+	freer.c		\
 	gdtoa-gethex.c	\
 	gdtoa-hexnan.c	\
 	getenv.c  	\
@@ -40,7 +43,10 @@ GENERAL_SOURCES = \
 	gdtoa-gdtoa.c	\
 	gdtoa-dmisc.c	\
 	gdtoa-gmisc.c	\
+	mallinfor.c	\
 	malloc.c  	\
+	mallocr.c	\
+	mallstatsr.c	\
 	mblen.c		\
 	mblen_r.c	\
 	mbstowcs.c	\
@@ -49,6 +55,7 @@ GENERAL_SOURCES = \
 	mbtowc_r.c	\
 	mlock.c		\
 	mprec.c		\
+	msizer.c	\
 	mstats.c	\
 	on_exit_args.c	\
 	quick_exit.c	\
@@ -58,6 +65,7 @@ GENERAL_SOURCES = \
 	realloc.c	\
 	reallocarray.c	\
 	reallocf.c	\
+	reallocr.c	\
 	sb_charsets.c	\
 	strtod.c	\
 	strtoimax.c	\
@@ -121,24 +129,22 @@ ELIX_2_SOURCES = \
 	getsubopt.c	\
 	l64a.c		\
 	malign.c	\
+	malignr.c	\
+	malloptr.c	\
 	mbrlen.c	\
 	mbrtowc.c	\
 	mbsinit.c	\
 	mbsnrtowcs.c	\
 	mbsrtowcs.c	\
 	on_exit.c	\
+	pvallocr.c	\
 	valloc.c	\
+	vallocr.c	\
 	wcrtomb.c	\
 	wcsnrtombs.c	\
 	wcsrtombs.c	\
 	wctob.c
 
-ELIX_2_OBJS = \
-	$(lpfx)malignr.o	\
-	$(lpfx)malloptr.o \
-	$(lpfx)pvallocr.o	\
-	$(lpfx)vallocr.o
-
 ELIX_3_SOURCES = \
 	putenv.c	\
 	putenv_r.c	\
@@ -151,91 +157,19 @@ ELIX_4_SOURCES = \
 
 if ELIX_LEVEL_1
 ELIX_SOURCES =
-ELIX_OBJS =
 else
 if ELIX_LEVEL_2
 ELIX_SOURCES = $(ELIX_2_SOURCES)
-ELIX_OBJS = $(ELIX_2_OBJS)
 else
 if ELIX_LEVEL_3
 ELIX_SOURCES = $(ELIX_2_SOURCES) $(ELIX_3_SOURCES)
-ELIX_OBJS = $(ELIX_2_OBJS)
 else
 ELIX_SOURCES = $(ELIX_2_SOURCES) $(ELIX_3_SOURCES) $(ELIX_4_SOURCES)
-ELIX_OBJS = $(ELIX_2_OBJS)
 endif
 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
-
 noinst_LIBRARIES = lib.a
 lib_a_SOURCES = $(GENERAL_SOURCES) $(EXTENDED_SOURCES) $(ELIX_SOURCES)
-lib_a_LIBADD = $(LIBADD_OBJS) $(ELIX_OBJS)
+lib_a_LIBADD =
 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 $< -o $@
-
-$(lpfx)freer.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_FREE -c $< -o $@
-
-$(lpfx)reallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_REALLOC -c $< -o $@
-
-$(lpfx)callocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_CALLOC -c $< -o $@
-
-$(lpfx)cfreer.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_CFREE -c $< -o $@
-
-$(lpfx)malignr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MEMALIGN -c $< -o $@
-
-$(lpfx)vallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_VALLOC -c $< -o $@
-
-$(lpfx)pvallocr.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_PVALLOC -c $< -o $@
-
-$(lpfx)mallinfor.o: _mallocr.c
-	$(LIB_COMPILE) -DDEFINE_MALLINFO -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 $< -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
-$(lpfx)gdtoa-ldtoa.o: gdtoa-ldtoa.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)gdtoa-gdtoa.o: gdtoa-gdtoa.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)gdtoa-dmisc.o: gdtoa-dmisc.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)gdtoa-gmisc.o: gdtoa-gmisc.c mprec.h gdtoaimp.h gdtoa.h
-$(lpfx)ecvtbuf.o: ecvtbuf.c mprec.h
-$(lpfx)mbtowc_r.o: mbtowc_r.c mbctype.h
-$(lpfx)mprec.o: mprec.c mprec.h
-$(lpfx)strtod.o: strtod.c mprec.h
-$(lpfx)gdtoa-gethex.o: gdtoa-gethex.c mprec.h
-$(lpfx)gdtoa-hexnan.o: gdtoa-hexnan.c mprec.h
-$(lpfx)wctomb_r.o: wctomb_r.c mbctype.h
-$(lpfx)drand48.o: drand48.c rand48.h
-$(lpfx)erand48.o: erand48.c rand48.h
-$(lpfx)jrand48.o: jrand48.c rand48.h
-$(lpfx)lcong48.o: lcong48.c rand48.h
-$(lpfx)lrand48.o: lrand48.c rand48.h
-$(lpfx)mrand48.o: mrand48.c rand48.h
-$(lpfx)nrand48.o: nrand48.c rand48.h
-$(lpfx)rand48.o: rand48.c rand48.h
-$(lpfx)seed48.o: seed48.c rand48.h
-$(lpfx)srand48.o: srand48.c rand48.h
diff --git a/newlib/libc/stdlib/callocr.c b/newlib/libc/stdlib/callocr.c
new file mode 100644
index 000000000000..80fee60db585
--- /dev/null
+++ b/newlib/libc/stdlib/callocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_CALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/cfreer.c b/newlib/libc/stdlib/cfreer.c
new file mode 100644
index 000000000000..a644664ae59c
--- /dev/null
+++ b/newlib/libc/stdlib/cfreer.c
@@ -0,0 +1,2 @@
+#define DEFINE_CFREE
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/freer.c b/newlib/libc/stdlib/freer.c
new file mode 100644
index 000000000000..1418d0c8f257
--- /dev/null
+++ b/newlib/libc/stdlib/freer.c
@@ -0,0 +1,2 @@
+#define DEFINE_FREE
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/malignr.c b/newlib/libc/stdlib/malignr.c
new file mode 100644
index 000000000000..c48fbad0c4d9
--- /dev/null
+++ b/newlib/libc/stdlib/malignr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MEMALIGN
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/mallinfor.c b/newlib/libc/stdlib/mallinfor.c
new file mode 100644
index 000000000000..dc1a55d9d20a
--- /dev/null
+++ b/newlib/libc/stdlib/mallinfor.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLINFO
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
new file mode 100644
index 000000000000..c2ab1caadce1
--- /dev/null
+++ b/newlib/libc/stdlib/mallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/malloptr.c b/newlib/libc/stdlib/malloptr.c
new file mode 100644
index 000000000000..f67be247d75b
--- /dev/null
+++ b/newlib/libc/stdlib/malloptr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOPT
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/mallstatsr.c b/newlib/libc/stdlib/mallstatsr.c
new file mode 100644
index 000000000000..15cd7379de95
--- /dev/null
+++ b/newlib/libc/stdlib/mallstatsr.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC_STATS
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/msizer.c b/newlib/libc/stdlib/msizer.c
new file mode 100644
index 000000000000..1d683f485027
--- /dev/null
+++ b/newlib/libc/stdlib/msizer.c
@@ -0,0 +1,2 @@
+#define DEFINE_MALLOC_USABLE_SIZE
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/pvallocr.c b/newlib/libc/stdlib/pvallocr.c
new file mode 100644
index 000000000000..afc203860143
--- /dev/null
+++ b/newlib/libc/stdlib/pvallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_PVALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/reallocr.c b/newlib/libc/stdlib/reallocr.c
new file mode 100644
index 000000000000..45c21d2d2d7c
--- /dev/null
+++ b/newlib/libc/stdlib/reallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_REALLOC
+#include "_mallocr.c"
diff --git a/newlib/libc/stdlib/vallocr.c b/newlib/libc/stdlib/vallocr.c
new file mode 100644
index 000000000000..9f05700a4e8f
--- /dev/null
+++ b/newlib/libc/stdlib/vallocr.c
@@ -0,0 +1,2 @@
+#define DEFINE_VALLOC
+#include "_mallocr.c"
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling
  2022-03-02  1:36 ` [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling Mike Frysinger
@ 2022-03-02  9:46   ` Corinna Vinschen
  2022-03-09  9:23     ` Mike Frysinger
  2022-03-10  8:00     ` Sebastian Huber
  0 siblings, 2 replies; 12+ messages in thread
From: Corinna Vinschen @ 2022-03-02  9:46 UTC (permalink / raw)
  To: newlib

On Mar  1 20:36, Mike Frysinger wrote:
> The mallopt symbol is defined in tiny-malloc.c, not mallocr.c, but
> the Makefile in here tries to compile it out of the latter.  This
> leads to mallopt never being defined.
> 
> The build also creates mallinfo.o & mallopt.o & mallstats.o objects
> to override common ones, but the common dir doesn't use these names.
> Instead, it places these all in mstats.o.
> 
> So move the build define logic to a dedicated file and compile it
> directly to make things a bit simpler while fixing the missing func
> and aligning objects with the cmomon code.
> ---
>  newlib/libc/machine/xstormy16/Makefile.am | 15 ++--------
>  newlib/libc/machine/xstormy16/Makefile.in | 36 +++++++++++++----------
>  newlib/libc/machine/xstormy16/mstats.c    |  6 ++++
>  3 files changed, 29 insertions(+), 28 deletions(-)
>  create mode 100644 newlib/libc/machine/xstormy16/mstats.c
> [...]
> diff --git a/newlib/libc/machine/xstormy16/mstats.c b/newlib/libc/machine/xstormy16/mstats.c
> new file mode 100644
> index 000000000000..1bd24da555f1
> --- /dev/null
> +++ b/newlib/libc/machine/xstormy16/mstats.c
> @@ -0,0 +1,6 @@
> +/* stdlib/mstats.c defines all these symbols in this file.
> +   TODO: Missing mstats function.  */
> +#define DEFINE_MALLINFO
> +#define DEFINE_MALLOC_STATS
> +#define DEFINE_MALLOPT
> +#include "tiny-malloc.c"

XStormy16 is such a small target, it would be better to split these into
three files.


Corinna


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/6] rework malloc logic from build rules to source files
  2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
                   ` (5 preceding siblings ...)
  2022-03-02  1:36 ` [PATCH 6/6] newlib: libc: move stdlib " Mike Frysinger
@ 2022-03-02  9:47 ` Corinna Vinschen
  6 siblings, 0 replies; 12+ messages in thread
From: Corinna Vinschen @ 2022-03-02  9:47 UTC (permalink / raw)
  To: newlib

On Mar  1 20:36, Mike Frysinger wrote:
> I broke these out into separate changes to make it easier to review.
> The goal is to kill off all the custom build rules in stdlib/ so we
> only rely on Automake to compile so we can convert the libc build to
> a non-recursive one like we've done with libm.a.  This is the last
> series needed to unblock that.
> 
> There's also some real bugfixes in here independent of the build
> system rework, but I kept them separate for bisection purposes.

Except for splitting the malloc stats functions into three files,
the patchset looks good to me.


Thanks,
Corinna


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling
  2022-03-02  9:46   ` Corinna Vinschen
@ 2022-03-09  9:23     ` Mike Frysinger
  2022-03-10  8:12       ` Corinna Vinschen
  2022-03-10  8:00     ` Sebastian Huber
  1 sibling, 1 reply; 12+ messages in thread
From: Mike Frysinger @ 2022-03-09  9:23 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 2180 bytes --]

On 02 Mar 2022 10:46, Corinna Vinschen wrote:
> On Mar  1 20:36, Mike Frysinger wrote:
> > The mallopt symbol is defined in tiny-malloc.c, not mallocr.c, but
> > the Makefile in here tries to compile it out of the latter.  This
> > leads to mallopt never being defined.
> > 
> > The build also creates mallinfo.o & mallopt.o & mallstats.o objects
> > to override common ones, but the common dir doesn't use these names.
> > Instead, it places these all in mstats.o.
> > 
> > So move the build define logic to a dedicated file and compile it
> > directly to make things a bit simpler while fixing the missing func
> > and aligning objects with the cmomon code.
> > ---
> >  newlib/libc/machine/xstormy16/Makefile.am | 15 ++--------
> >  newlib/libc/machine/xstormy16/Makefile.in | 36 +++++++++++++----------
> >  newlib/libc/machine/xstormy16/mstats.c    |  6 ++++
> >  3 files changed, 29 insertions(+), 28 deletions(-)
> >  create mode 100644 newlib/libc/machine/xstormy16/mstats.c
> > [...]
> > diff --git a/newlib/libc/machine/xstormy16/mstats.c b/newlib/libc/machine/xstormy16/mstats.c
> > new file mode 100644
> > index 000000000000..1bd24da555f1
> > --- /dev/null
> > +++ b/newlib/libc/machine/xstormy16/mstats.c
> > @@ -0,0 +1,6 @@
> > +/* stdlib/mstats.c defines all these symbols in this file.
> > +   TODO: Missing mstats function.  */
> > +#define DEFINE_MALLINFO
> > +#define DEFINE_MALLOC_STATS
> > +#define DEFINE_MALLOPT
> > +#include "tiny-malloc.c"
> 
> XStormy16 is such a small target, it would be better to split these into
> three files.

it must be really tiny if we need to micro manage this.
    152       0       0     152      98 lib_a-mallinfo.o
    274       0       0     274     112 lib_a-mallstats.o
      4       0       0       4       4 lib_a-mallopt.o

the only way they'd get pulled in is if one func is used, so if code called
mallopt() but not mallinfo() or malloc_stats(), it would waste 426 bytes.

the point of this change is to align xstormy16 with how common code is laid
out.  are you suggesting we split the common mstats.c too ?  it wouldn't be
hard as that file is pretty small.
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling
  2022-03-02  9:46   ` Corinna Vinschen
  2022-03-09  9:23     ` Mike Frysinger
@ 2022-03-10  8:00     ` Sebastian Huber
  1 sibling, 0 replies; 12+ messages in thread
From: Sebastian Huber @ 2022-03-10  8:00 UTC (permalink / raw)
  To: newlib

On 02/03/2022 10:46, Corinna Vinschen wrote:>> diff --git 
a/newlib/libc/machine/xstormy16/mstats.c 
b/newlib/libc/machine/xstormy16/mstats.c
>> new file mode 100644
>> index 000000000000..1bd24da555f1
>> --- /dev/null
>> +++ b/newlib/libc/machine/xstormy16/mstats.c
>> @@ -0,0 +1,6 @@
>> +/* stdlib/mstats.c defines all these symbols in this file.
>> +   TODO: Missing mstats function.  */
>> +#define DEFINE_MALLINFO
>> +#define DEFINE_MALLOC_STATS
>> +#define DEFINE_MALLOPT
>> +#include "tiny-malloc.c"
> XStormy16 is such a small target, it would be better to split these into
> three files.

This target should probably use -ffunction-sections -fdata-sections anyway.

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling
  2022-03-09  9:23     ` Mike Frysinger
@ 2022-03-10  8:12       ` Corinna Vinschen
  0 siblings, 0 replies; 12+ messages in thread
From: Corinna Vinschen @ 2022-03-10  8:12 UTC (permalink / raw)
  To: newlib

On Mar  9 04:23, Mike Frysinger wrote:
> On 02 Mar 2022 10:46, Corinna Vinschen wrote:
> > On Mar  1 20:36, Mike Frysinger wrote:
> > > The mallopt symbol is defined in tiny-malloc.c, not mallocr.c, but
> > > the Makefile in here tries to compile it out of the latter.  This
> > > leads to mallopt never being defined.
> > > 
> > > The build also creates mallinfo.o & mallopt.o & mallstats.o objects
> > > to override common ones, but the common dir doesn't use these names.
> > > Instead, it places these all in mstats.o.
> > > 
> > > So move the build define logic to a dedicated file and compile it
> > > directly to make things a bit simpler while fixing the missing func
> > > and aligning objects with the cmomon code.
> > > ---
> > >  newlib/libc/machine/xstormy16/Makefile.am | 15 ++--------
> > >  newlib/libc/machine/xstormy16/Makefile.in | 36 +++++++++++++----------
> > >  newlib/libc/machine/xstormy16/mstats.c    |  6 ++++
> > >  3 files changed, 29 insertions(+), 28 deletions(-)
> > >  create mode 100644 newlib/libc/machine/xstormy16/mstats.c
> > > [...]
> > > diff --git a/newlib/libc/machine/xstormy16/mstats.c b/newlib/libc/machine/xstormy16/mstats.c
> > > new file mode 100644
> > > index 000000000000..1bd24da555f1
> > > --- /dev/null
> > > +++ b/newlib/libc/machine/xstormy16/mstats.c
> > > @@ -0,0 +1,6 @@
> > > +/* stdlib/mstats.c defines all these symbols in this file.
> > > +   TODO: Missing mstats function.  */
> > > +#define DEFINE_MALLINFO
> > > +#define DEFINE_MALLOC_STATS
> > > +#define DEFINE_MALLOPT
> > > +#include "tiny-malloc.c"
> > 
> > XStormy16 is such a small target, it would be better to split these into
> > three files.
> 
> it must be really tiny if we need to micro manage this.
>     152       0       0     152      98 lib_a-mallinfo.o
>     274       0       0     274     112 lib_a-mallstats.o
>       4       0       0       4       4 lib_a-mallopt.o
> 
> the only way they'd get pulled in is if one func is used, so if code called
> mallopt() but not mallinfo() or malloc_stats(), it would waste 426 bytes.
> 
> the point of this change is to align xstormy16 with how common code is laid
> out.  are you suggesting we split the common mstats.c too ?  it wouldn't be
> hard as that file is pretty small.
> -mike

Sebastian is right.  Just leave it as is.  GTG.


Thx,
Corinna


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-03-10  8:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02  1:36 [PATCH 0/6] rework malloc logic from build rules to source files Mike Frysinger
2022-03-02  1:36 ` [PATCH 1/6] newlib: move nano-malloc logic from build " Mike Frysinger
2022-03-02  1:36 ` [PATCH 2/6] newlib: rename mallocr.c to _mallocr.c Mike Frysinger
2022-03-02  1:36 ` [PATCH 3/6] newlib: xstormy16: fix mallopt definition & mstats handling Mike Frysinger
2022-03-02  9:46   ` Corinna Vinschen
2022-03-09  9:23     ` Mike Frysinger
2022-03-10  8:12       ` Corinna Vinschen
2022-03-10  8:00     ` Sebastian Huber
2022-03-02  1:36 ` [PATCH 4/6] newlib: xstormy16: break up mallocr stubs Mike Frysinger
2022-03-02  1:36 ` [PATCH 5/6] newlib: xstormy16: move malloc multiplex logic from build to source files Mike Frysinger
2022-03-02  1:36 ` [PATCH 6/6] newlib: libc: move stdlib " Mike Frysinger
2022-03-02  9:47 ` [PATCH 0/6] rework malloc logic from build rules " Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).