Implemented sysconf for Arm

Message ID DB8PR10MB3467FE243FBFB4B920CE0E5681AF0@DB8PR10MB3467.EURPRD10.PROD.OUTLOOK.COM
State New
Headers show
Series
  • Implemented sysconf for Arm
Related show

Commit Message

Eshan dhawan via Newlib April 27, 2020, 3:30 p.m.
The default implementation can be overridden outside newlib to allow a
different page size to improve malloc on devices with a small footprint
without needing to rebuild newlib.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

---
 newlib/libc/stdlib/mallocr.c    |  2 +-
 newlib/libc/sys/arm/Makefile.am |  2 +-
 newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--
 newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++
 4 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 newlib/libc/sys/arm/sysconf.c

-- 
2.18.0

Comments

Eshan dhawan via Newlib May 19, 2020, 4:17 p.m. | #1
Ping2!

If it's not clear to the reviewer, the use-case that we want to fulfill here is to be able to override the page size for the malloc() call for the project and not require a new build of newlib.
With this approach, simply re-implementing the function sysconf(int) in the application to return the appropriate page size for the application and have the linker will select the local implementation over the newlib provided one is enough to reserve a smaller memory block for malloc.

I also need assistance to push the patch since I've not got commit access.

Thanks.

Torbjörn

-----Original Message-----
From: Torbjorn SVENSSON 

Sent: den 7 maj 2020 10:29
To: Newlib <newlib-bounces@sourceware.org>
Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>
Subject: RE: [PATCH] Implemented sysconf for Arm

Ping

-----Original Message-----
From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Torbjorn SVENSSON via Newlib

Sent: den 27 april 2020 17:31
To: newlib@sourceware.org
Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>
Subject: [PATCH] Implemented sysconf for Arm

The default implementation can be overridden outside newlib to allow a
different page size to improve malloc on devices with a small footprint
without needing to rebuild newlib.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

---
 newlib/libc/stdlib/mallocr.c    |  2 +-
 newlib/libc/sys/arm/Makefile.am |  2 +-
 newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--
 newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++
 4 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 newlib/libc/sys/arm/sysconf.c

diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
index 26d1c89cc..28d278f51 100644
--- a/newlib/libc/stdlib/mallocr.c
+++ b/newlib/libc/stdlib/mallocr.c
@@ -316,7 +316,7 @@ extern "C" {
 # undef WIN32
 #endif
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ARM_EABI__)
 #ifdef SMALL_MEMORY
 #define malloc_getpagesize (128)
 #else
diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am
index 711872de3..9111f3647 100644
--- a/newlib/libc/sys/arm/Makefile.am
+++ b/newlib/libc/sys/arm/Makefile.am
@@ -14,7 +14,7 @@ else
 extra_objs =
 endif
 
-lib_a_SOURCES = access.c aeabi_atexit.c
+lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c
 lib_a_LIBADD = $(extra_objs)
 EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c
 lib_a_DEPENDENCIES = $(extra_objs)
diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in
index c01e4e2ed..67fb695f5 100644
--- a/newlib/libc/sys/arm/Makefile.in
+++ b/newlib/libc/sys/arm/Makefile.in
@@ -70,7 +70,8 @@ ARFLAGS = cru
 lib_a_AR = $(AR) $(ARFLAGS)
 @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \
 @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o
-am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)
+am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \
+	lib_a-sysconf.$(OBJEXT)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp =
@@ -183,6 +184,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -198,7 +200,7 @@ AM_CCASFLAGS = $(INCLUDES)
 noinst_LIBRARIES = lib.a
 @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 
 @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o
-lib_a_SOURCES = access.c aeabi_atexit.c
+lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c
 lib_a_LIBADD = $(extra_objs)
 EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c
 lib_a_DEPENDENCIES = $(extra_objs)
@@ -288,6 +290,12 @@ lib_a-aeabi_atexit.o: aeabi_atexit.c
 lib_a-aeabi_atexit.obj: aeabi_atexit.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`
 
+lib_a-sysconf.o: sysconf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c
+
+lib_a-sysconf.obj: sysconf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`
+
 lib_a-syscalls.o: syscalls.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c
 
diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c
new file mode 100644
index 000000000..86a324fa4
--- /dev/null
+++ b/newlib/libc/sys/arm/sysconf.c
@@ -0,0 +1,20 @@
+/* libc/sys/arm/sysconf.c - The sysconf function */
+
+/* Copyright 2020, STMicroelectronics */
+
+#include <unistd.h>
+#include <errno.h>
+
+long sysconf(int name)
+{
+  switch (name)
+  {
+  case _SC_PAGESIZE:
+    return 4096;
+
+  default:
+    errno = EINVAL;
+    return -1;
+  }
+  return -1; /* Can't get here */
+}
-- 
2.18.0
Eshan dhawan via Newlib May 20, 2020, 8:13 a.m. | #2
Adding Richard to this thread

On May 19 16:17, Torbjorn SVENSSON via Newlib wrote:
> Ping2!

> 

> If it's not clear to the reviewer, the use-case that we want to fulfill here is to be able to override the page size for the malloc() call for the project and not require a new build of newlib.

> With this approach, simply re-implementing the function sysconf(int) in the application to return the appropriate page size for the application and have the linker will select the local implementation over the newlib provided one is enough to reserve a smaller memory block for malloc.

> 

> I also need assistance to push the patch since I've not got commit access.

> 

> Thanks.

> 

> Torbjörn

> 

> -----Original Message-----

> From: Torbjorn SVENSSON 

> Sent: den 7 maj 2020 10:29

> To: Newlib <newlib-bounces@sourceware.org>

> Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> Subject: RE: [PATCH] Implemented sysconf for Arm

> 

> Ping

> 

> -----Original Message-----

> From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Torbjorn SVENSSON via Newlib

> Sent: den 27 april 2020 17:31

> To: newlib@sourceware.org

> Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> Subject: [PATCH] Implemented sysconf for Arm

> 

> The default implementation can be overridden outside newlib to allow a

> different page size to improve malloc on devices with a small footprint

> without needing to rebuild newlib.

> 

> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

> Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> ---

>  newlib/libc/stdlib/mallocr.c    |  2 +-

>  newlib/libc/sys/arm/Makefile.am |  2 +-

>  newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--

>  newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++

>  4 files changed, 32 insertions(+), 4 deletions(-)

>  create mode 100644 newlib/libc/sys/arm/sysconf.c

> 

> diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c

> index 26d1c89cc..28d278f51 100644

> --- a/newlib/libc/stdlib/mallocr.c

> +++ b/newlib/libc/stdlib/mallocr.c

> @@ -316,7 +316,7 @@ extern "C" {

>  # undef WIN32

>  #endif

>  

> -#ifndef _WIN32

> +#if !defined(_WIN32) && !defined(__ARM_EABI__)

>  #ifdef SMALL_MEMORY

>  #define malloc_getpagesize (128)

>  #else

> diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am

> index 711872de3..9111f3647 100644

> --- a/newlib/libc/sys/arm/Makefile.am

> +++ b/newlib/libc/sys/arm/Makefile.am

> @@ -14,7 +14,7 @@ else

>  extra_objs =

>  endif

>  

> -lib_a_SOURCES = access.c aeabi_atexit.c

> +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

>  lib_a_LIBADD = $(extra_objs)

>  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

>  lib_a_DEPENDENCIES = $(extra_objs)

> diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in

> index c01e4e2ed..67fb695f5 100644

> --- a/newlib/libc/sys/arm/Makefile.in

> +++ b/newlib/libc/sys/arm/Makefile.in

> @@ -70,7 +70,8 @@ ARFLAGS = cru

>  lib_a_AR = $(AR) $(ARFLAGS)

>  @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \

>  @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o

> -am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)

> +am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \

> +	lib_a-sysconf.$(OBJEXT)

>  lib_a_OBJECTS = $(am_lib_a_OBJECTS)

>  DEFAULT_INCLUDES = -I.@am__isrc@

>  depcomp =

> @@ -183,6 +184,7 @@ pdfdir = @pdfdir@

>  prefix = @prefix@

>  program_transform_name = @program_transform_name@

>  psdir = @psdir@

> +runstatedir = @runstatedir@

>  sbindir = @sbindir@

>  sharedstatedir = @sharedstatedir@

>  srcdir = @srcdir@

> @@ -198,7 +200,7 @@ AM_CCASFLAGS = $(INCLUDES)

>  noinst_LIBRARIES = lib.a

>  @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 

>  @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o

> -lib_a_SOURCES = access.c aeabi_atexit.c

> +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

>  lib_a_LIBADD = $(extra_objs)

>  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

>  lib_a_DEPENDENCIES = $(extra_objs)

> @@ -288,6 +290,12 @@ lib_a-aeabi_atexit.o: aeabi_atexit.c

>  lib_a-aeabi_atexit.obj: aeabi_atexit.c

>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`

>  

> +lib_a-sysconf.o: sysconf.c

> +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c

> +

> +lib_a-sysconf.obj: sysconf.c

> +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`

> +

>  lib_a-syscalls.o: syscalls.c

>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c

>  

> diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c

> new file mode 100644

> index 000000000..86a324fa4

> --- /dev/null

> +++ b/newlib/libc/sys/arm/sysconf.c

> @@ -0,0 +1,20 @@

> +/* libc/sys/arm/sysconf.c - The sysconf function */

> +

> +/* Copyright 2020, STMicroelectronics */

> +

> +#include <unistd.h>

> +#include <errno.h>

> +

> +long sysconf(int name)

> +{

> +  switch (name)

> +  {

> +  case _SC_PAGESIZE:

> +    return 4096;

> +

> +  default:

> +    errno = EINVAL;

> +    return -1;

> +  }

> +  return -1; /* Can't get here */

> +}

> -- 

> 2.18.0


-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
Eshan dhawan via Newlib July 29, 2020, 3:26 p.m. | #3
Ping3

-----Original Message-----
From: Torbjorn SVENSSON 

Sent: den 19 maj 2020 18:17
To: newlib@sourceware.org
Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>
Subject: RE: [PATCH] Implemented sysconf for Arm

Ping2!

If it's not clear to the reviewer, the use-case that we want to fulfill here is to be able to override the page size for the malloc() call for the project and not require a new build of newlib.
With this approach, simply re-implementing the function sysconf(int) in the application to return the appropriate page size for the application and have the linker will select the local implementation over the newlib provided one is enough to reserve a smaller memory block for malloc.

I also need assistance to push the patch since I've not got commit access.

Thanks.

Torbjörn

-----Original Message-----
From: Torbjorn SVENSSON 

Sent: den 7 maj 2020 10:29
To: Newlib <newlib-bounces@sourceware.org>
Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>
Subject: RE: [PATCH] Implemented sysconf for Arm

Ping

-----Original Message-----
From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Torbjorn SVENSSON via Newlib

Sent: den 27 april 2020 17:31
To: newlib@sourceware.org
Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>
Subject: [PATCH] Implemented sysconf for Arm

The default implementation can be overridden outside newlib to allow a
different page size to improve malloc on devices with a small footprint
without needing to rebuild newlib.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

---
 newlib/libc/stdlib/mallocr.c    |  2 +-
 newlib/libc/sys/arm/Makefile.am |  2 +-
 newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--
 newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++
 4 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 newlib/libc/sys/arm/sysconf.c

diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
index 26d1c89cc..28d278f51 100644
--- a/newlib/libc/stdlib/mallocr.c
+++ b/newlib/libc/stdlib/mallocr.c
@@ -316,7 +316,7 @@ extern "C" {
 # undef WIN32
 #endif
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ARM_EABI__)
 #ifdef SMALL_MEMORY
 #define malloc_getpagesize (128)
 #else
diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am
index 711872de3..9111f3647 100644
--- a/newlib/libc/sys/arm/Makefile.am
+++ b/newlib/libc/sys/arm/Makefile.am
@@ -14,7 +14,7 @@ else
 extra_objs =
 endif
 
-lib_a_SOURCES = access.c aeabi_atexit.c
+lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c
 lib_a_LIBADD = $(extra_objs)
 EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c
 lib_a_DEPENDENCIES = $(extra_objs)
diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in
index c01e4e2ed..67fb695f5 100644
--- a/newlib/libc/sys/arm/Makefile.in
+++ b/newlib/libc/sys/arm/Makefile.in
@@ -70,7 +70,8 @@ ARFLAGS = cru
 lib_a_AR = $(AR) $(ARFLAGS)
 @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \
 @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o
-am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)
+am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \
+	lib_a-sysconf.$(OBJEXT)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp =
@@ -183,6 +184,7 @@ pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -198,7 +200,7 @@ AM_CCASFLAGS = $(INCLUDES)
 noinst_LIBRARIES = lib.a
 @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 
 @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o
-lib_a_SOURCES = access.c aeabi_atexit.c
+lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c
 lib_a_LIBADD = $(extra_objs)
 EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c
 lib_a_DEPENDENCIES = $(extra_objs)
@@ -288,6 +290,12 @@ lib_a-aeabi_atexit.o: aeabi_atexit.c
 lib_a-aeabi_atexit.obj: aeabi_atexit.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`
 
+lib_a-sysconf.o: sysconf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c
+
+lib_a-sysconf.obj: sysconf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`
+
 lib_a-syscalls.o: syscalls.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c
 
diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c
new file mode 100644
index 000000000..86a324fa4
--- /dev/null
+++ b/newlib/libc/sys/arm/sysconf.c
@@ -0,0 +1,20 @@
+/* libc/sys/arm/sysconf.c - The sysconf function */
+
+/* Copyright 2020, STMicroelectronics */
+
+#include <unistd.h>
+#include <errno.h>
+
+long sysconf(int name)
+{
+  switch (name)
+  {
+  case _SC_PAGESIZE:
+    return 4096;
+
+  default:
+    errno = EINVAL;
+    return -1;
+  }
+  return -1; /* Can't get here */
+}
-- 
2.18.0
Eshan dhawan via Newlib July 29, 2020, 3:43 p.m. | #4
And again adding Richard.

Richard, is nobody from ARM looking into this stuff, at least once in a
while?


Corinna


On Jul 29 15:26, Torbjorn SVENSSON via Newlib wrote:
> Ping3

> 

> -----Original Message-----

> From: Torbjorn SVENSSON 

> Sent: den 19 maj 2020 18:17

> To: newlib@sourceware.org

> Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> Subject: RE: [PATCH] Implemented sysconf for Arm

> 

> Ping2!

> 

> If it's not clear to the reviewer, the use-case that we want to fulfill here is to be able to override the page size for the malloc() call for the project and not require a new build of newlib.

> With this approach, simply re-implementing the function sysconf(int) in the application to return the appropriate page size for the application and have the linker will select the local implementation over the newlib provided one is enough to reserve a smaller memory block for malloc.

> 

> I also need assistance to push the patch since I've not got commit access.

> 

> Thanks.

> 

> Torbjörn

> 

> -----Original Message-----

> From: Torbjorn SVENSSON 

> Sent: den 7 maj 2020 10:29

> To: Newlib <newlib-bounces@sourceware.org>

> Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> Subject: RE: [PATCH] Implemented sysconf for Arm

> 

> Ping

> 

> -----Original Message-----

> From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Torbjorn SVENSSON via Newlib

> Sent: den 27 april 2020 17:31

> To: newlib@sourceware.org

> Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> Subject: [PATCH] Implemented sysconf for Arm

> 

> The default implementation can be overridden outside newlib to allow a

> different page size to improve malloc on devices with a small footprint

> without needing to rebuild newlib.

> 

> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

> Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> ---

>  newlib/libc/stdlib/mallocr.c    |  2 +-

>  newlib/libc/sys/arm/Makefile.am |  2 +-

>  newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--

>  newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++

>  4 files changed, 32 insertions(+), 4 deletions(-)

>  create mode 100644 newlib/libc/sys/arm/sysconf.c

> 

> diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c

> index 26d1c89cc..28d278f51 100644

> --- a/newlib/libc/stdlib/mallocr.c

> +++ b/newlib/libc/stdlib/mallocr.c

> @@ -316,7 +316,7 @@ extern "C" {

>  # undef WIN32

>  #endif

>  

> -#ifndef _WIN32

> +#if !defined(_WIN32) && !defined(__ARM_EABI__)

>  #ifdef SMALL_MEMORY

>  #define malloc_getpagesize (128)

>  #else

> diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am

> index 711872de3..9111f3647 100644

> --- a/newlib/libc/sys/arm/Makefile.am

> +++ b/newlib/libc/sys/arm/Makefile.am

> @@ -14,7 +14,7 @@ else

>  extra_objs =

>  endif

>  

> -lib_a_SOURCES = access.c aeabi_atexit.c

> +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

>  lib_a_LIBADD = $(extra_objs)

>  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

>  lib_a_DEPENDENCIES = $(extra_objs)

> diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in

> index c01e4e2ed..67fb695f5 100644

> --- a/newlib/libc/sys/arm/Makefile.in

> +++ b/newlib/libc/sys/arm/Makefile.in

> @@ -70,7 +70,8 @@ ARFLAGS = cru

>  lib_a_AR = $(AR) $(ARFLAGS)

>  @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \

>  @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o

> -am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)

> +am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \

> +	lib_a-sysconf.$(OBJEXT)

>  lib_a_OBJECTS = $(am_lib_a_OBJECTS)

>  DEFAULT_INCLUDES = -I.@am__isrc@

>  depcomp =

> @@ -183,6 +184,7 @@ pdfdir = @pdfdir@

>  prefix = @prefix@

>  program_transform_name = @program_transform_name@

>  psdir = @psdir@

> +runstatedir = @runstatedir@

>  sbindir = @sbindir@

>  sharedstatedir = @sharedstatedir@

>  srcdir = @srcdir@

> @@ -198,7 +200,7 @@ AM_CCASFLAGS = $(INCLUDES)

>  noinst_LIBRARIES = lib.a

>  @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 

>  @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o

> -lib_a_SOURCES = access.c aeabi_atexit.c

> +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

>  lib_a_LIBADD = $(extra_objs)

>  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

>  lib_a_DEPENDENCIES = $(extra_objs)

> @@ -288,6 +290,12 @@ lib_a-aeabi_atexit.o: aeabi_atexit.c

>  lib_a-aeabi_atexit.obj: aeabi_atexit.c

>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`

>  

> +lib_a-sysconf.o: sysconf.c

> +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c

> +

> +lib_a-sysconf.obj: sysconf.c

> +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`

> +

>  lib_a-syscalls.o: syscalls.c

>  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c

>  

> diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c

> new file mode 100644

> index 000000000..86a324fa4

> --- /dev/null

> +++ b/newlib/libc/sys/arm/sysconf.c

> @@ -0,0 +1,20 @@

> +/* libc/sys/arm/sysconf.c - The sysconf function */

> +

> +/* Copyright 2020, STMicroelectronics */

> +

> +#include <unistd.h>

> +#include <errno.h>

> +

> +long sysconf(int name)

> +{

> +  switch (name)

> +  {

> +  case _SC_PAGESIZE:

> +    return 4096;

> +

> +  default:

> +    errno = EINVAL;

> +    return -1;

> +  }

> +  return -1; /* Can't get here */

> +}

> -- 

> 2.18.0


-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat
Szabolcs Nagy July 30, 2020, 3:27 p.m. | #5
The 07/29/2020 17:43, Corinna Vinschen via Newlib wrote:
> And again adding Richard.

> 

> Richard, is nobody from ARM looking into this stuff, at least once in a

> while?


i don't know what's the best way to do
link-time or run-time configuration of
newlib internals.

it seems to me that malloc allocation
granule does not have to use page size
as defined in the arm architecture nor
page size as defined in posix nor
page size as defined in the elf abi.

so ideally there would be a hook with
different name that users can link-time
override. (so there is no danger of
something trying to use _SC_PAGESIZE
or sysconf in general for something else
that conflicts with the malloc usage)

but if currently sysconf is only used by
malloc in newlib then i guess the patch
works (i'd add a comment though that it
is the malloc block size and not a
property of the memory system).


> 

> 

> Corinna

> 

> 

> On Jul 29 15:26, Torbjorn SVENSSON via Newlib wrote:

> > Ping3

> > 

> > -----Original Message-----

> > From: Torbjorn SVENSSON 

> > Sent: den 19 maj 2020 18:17

> > To: newlib@sourceware.org

> > Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > Subject: RE: [PATCH] Implemented sysconf for Arm

> > 

> > Ping2!

> > 

> > If it's not clear to the reviewer, the use-case that we want to fulfill here is to be able to override the page size for the malloc() call for the project and not require a new build of newlib.

> > With this approach, simply re-implementing the function sysconf(int) in the application to return the appropriate page size for the application and have the linker will select the local implementation over the newlib provided one is enough to reserve a smaller memory block for malloc.

> > 

> > I also need assistance to push the patch since I've not got commit access.

> > 

> > Thanks.

> > 

> > Torbjörn

> > 

> > -----Original Message-----

> > From: Torbjorn SVENSSON 

> > Sent: den 7 maj 2020 10:29

> > To: Newlib <newlib-bounces@sourceware.org>

> > Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > Subject: RE: [PATCH] Implemented sysconf for Arm

> > 

> > Ping

> > 

> > -----Original Message-----

> > From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Torbjorn SVENSSON via Newlib

> > Sent: den 27 april 2020 17:31

> > To: newlib@sourceware.org

> > Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > Subject: [PATCH] Implemented sysconf for Arm

> > 

> > The default implementation can be overridden outside newlib to allow a

> > different page size to improve malloc on devices with a small footprint

> > without needing to rebuild newlib.

> > 

> > Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

> > Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > ---

> >  newlib/libc/stdlib/mallocr.c    |  2 +-

> >  newlib/libc/sys/arm/Makefile.am |  2 +-

> >  newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--

> >  newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++

> >  4 files changed, 32 insertions(+), 4 deletions(-)

> >  create mode 100644 newlib/libc/sys/arm/sysconf.c

> > 

> > diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c

> > index 26d1c89cc..28d278f51 100644

> > --- a/newlib/libc/stdlib/mallocr.c

> > +++ b/newlib/libc/stdlib/mallocr.c

> > @@ -316,7 +316,7 @@ extern "C" {

> >  # undef WIN32

> >  #endif

> >  

> > -#ifndef _WIN32

> > +#if !defined(_WIN32) && !defined(__ARM_EABI__)

> >  #ifdef SMALL_MEMORY

> >  #define malloc_getpagesize (128)

> >  #else

> > diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am

> > index 711872de3..9111f3647 100644

> > --- a/newlib/libc/sys/arm/Makefile.am

> > +++ b/newlib/libc/sys/arm/Makefile.am

> > @@ -14,7 +14,7 @@ else

> >  extra_objs =

> >  endif

> >  

> > -lib_a_SOURCES = access.c aeabi_atexit.c

> > +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

> >  lib_a_LIBADD = $(extra_objs)

> >  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

> >  lib_a_DEPENDENCIES = $(extra_objs)

> > diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in

> > index c01e4e2ed..67fb695f5 100644

> > --- a/newlib/libc/sys/arm/Makefile.in

> > +++ b/newlib/libc/sys/arm/Makefile.in

> > @@ -70,7 +70,8 @@ ARFLAGS = cru

> >  lib_a_AR = $(AR) $(ARFLAGS)

> >  @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \

> >  @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o

> > -am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)

> > +am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \

> > +	lib_a-sysconf.$(OBJEXT)

> >  lib_a_OBJECTS = $(am_lib_a_OBJECTS)

> >  DEFAULT_INCLUDES = -I.@am__isrc@

> >  depcomp =

> > @@ -183,6 +184,7 @@ pdfdir = @pdfdir@

> >  prefix = @prefix@

> >  program_transform_name = @program_transform_name@

> >  psdir = @psdir@

> > +runstatedir = @runstatedir@

> >  sbindir = @sbindir@

> >  sharedstatedir = @sharedstatedir@

> >  srcdir = @srcdir@

> > @@ -198,7 +200,7 @@ AM_CCASFLAGS = $(INCLUDES)

> >  noinst_LIBRARIES = lib.a

> >  @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 

> >  @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o

> > -lib_a_SOURCES = access.c aeabi_atexit.c

> > +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

> >  lib_a_LIBADD = $(extra_objs)

> >  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

> >  lib_a_DEPENDENCIES = $(extra_objs)

> > @@ -288,6 +290,12 @@ lib_a-aeabi_atexit.o: aeabi_atexit.c

> >  lib_a-aeabi_atexit.obj: aeabi_atexit.c

> >  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`

> >  

> > +lib_a-sysconf.o: sysconf.c

> > +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c

> > +

> > +lib_a-sysconf.obj: sysconf.c

> > +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`

> > +

> >  lib_a-syscalls.o: syscalls.c

> >  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c

> >  

> > diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c

> > new file mode 100644

> > index 000000000..86a324fa4

> > --- /dev/null

> > +++ b/newlib/libc/sys/arm/sysconf.c

> > @@ -0,0 +1,20 @@

> > +/* libc/sys/arm/sysconf.c - The sysconf function */

> > +

> > +/* Copyright 2020, STMicroelectronics */

> > +

> > +#include <unistd.h>

> > +#include <errno.h>

> > +

> > +long sysconf(int name)

> > +{

> > +  switch (name)

> > +  {

> > +  case _SC_PAGESIZE:

> > +    return 4096;

> > +

> > +  default:

> > +    errno = EINVAL;

> > +    return -1;

> > +  }

> > +  return -1; /* Can't get here */

> > +}

> > -- 

> > 2.18.0

> 

> -- 

> Corinna Vinschen

> Cygwin Maintainer

> Red Hat

> 


--
Eshan dhawan via Newlib Aug. 19, 2020, 9:09 a.m. | #6
Hello,

Thanks for the comments and sorry for the late reply (vacation period).

From our point of view, we do not have any strong opinion that this needs to be implemented using the sysconf() function, but that's how existing code, in mallocr.c, defines the malloc_getpagesize symbol if not hard coded. The important part for us is that the value cannot be fixed during the compilation of newlib. During the compilation or runtime of the application, the value must be possible to change to work with devices that has limited RAM while still allow for "normal" page-size on devices with larger RAM.
If you think it's better to create a separate function for this, it would mean a bigger patch with the danger that other targets might be affected too.

The important block of code in mallocr.c (line 654-691 in 8a7ec55c535cddd74d45a2f6fb644ecded114de8) is this:
#ifndef malloc_getpagesize
#  ifdef _SC_PAGESIZE         /* some SVR4 systems omit an underscore */
#    ifndef _SC_PAGE_SIZE
#      define _SC_PAGE_SIZE _SC_PAGESIZE
#    endif
#  endif
#  ifdef _SC_PAGE_SIZE
#    define malloc_getpagesize sysconf(_SC_PAGE_SIZE)
#  else
#    if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE)
       extern size_t getpagesize();
#      define malloc_getpagesize getpagesize()
#    else
#      include <sys/param.h>
#      ifdef EXEC_PAGESIZE
#        define malloc_getpagesize EXEC_PAGESIZE
#      else
#        ifdef NBPG
#          ifndef CLSIZE
#            define malloc_getpagesize NBPG
#          else
#            define malloc_getpagesize (NBPG * CLSIZE)
#          endif
#        else 
#          ifdef NBPC
#            define malloc_getpagesize NBPC
#          else
#            ifdef PAGESIZE
#              define malloc_getpagesize PAGESIZE
#            else
#              define malloc_getpagesize (4096) /* just guess */
#            endif
#          endif
#        endif 
#      endif
#    endif 
#  endif
#endif


Kind regards,
Torbjörn

-----Original Message-----
From: Szabolcs Nagy <szabolcs.nagy@arm.com> 

Sent: den 30 juli 2020 17:28
To: Richard.Earnshaw@arm.com; newlib@sourceware.org; Niklas DAHLQUIST <niklas.dahlquist@st.com>; Torbjorn SVENSSON <torbjorn.svensson@st.com>
Subject: Re: [PATCH] Implemented sysconf for Arm

The 07/29/2020 17:43, Corinna Vinschen via Newlib wrote:
> And again adding Richard.

> 

> Richard, is nobody from ARM looking into this stuff, at least once in a

> while?


i don't know what's the best way to do
link-time or run-time configuration of
newlib internals.

it seems to me that malloc allocation
granule does not have to use page size
as defined in the arm architecture nor
page size as defined in posix nor
page size as defined in the elf abi.

so ideally there would be a hook with
different name that users can link-time
override. (so there is no danger of
something trying to use _SC_PAGESIZE
or sysconf in general for something else
that conflicts with the malloc usage)

but if currently sysconf is only used by
malloc in newlib then i guess the patch
works (i'd add a comment though that it
is the malloc block size and not a
property of the memory system).


> 

> 

> Corinna

> 

> 

> On Jul 29 15:26, Torbjorn SVENSSON via Newlib wrote:

> > Ping3

> > 

> > -----Original Message-----

> > From: Torbjorn SVENSSON 

> > Sent: den 19 maj 2020 18:17

> > To: newlib@sourceware.org

> > Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > Subject: RE: [PATCH] Implemented sysconf for Arm

> > 

> > Ping2!

> > 

> > If it's not clear to the reviewer, the use-case that we want to fulfill here is to be able to override the page size for the malloc() call for the project and not require a new build of newlib.

> > With this approach, simply re-implementing the function sysconf(int) in the application to return the appropriate page size for the application and have the linker will select the local implementation over the newlib provided one is enough to reserve a smaller memory block for malloc.

> > 

> > I also need assistance to push the patch since I've not got commit access.

> > 

> > Thanks.

> > 

> > Torbjörn

> > 

> > -----Original Message-----

> > From: Torbjorn SVENSSON 

> > Sent: den 7 maj 2020 10:29

> > To: Newlib <newlib-bounces@sourceware.org>

> > Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > Subject: RE: [PATCH] Implemented sysconf for Arm

> > 

> > Ping

> > 

> > -----Original Message-----

> > From: Newlib <newlib-bounces@sourceware.org> On Behalf Of Torbjorn SVENSSON via Newlib

> > Sent: den 27 april 2020 17:31

> > To: newlib@sourceware.org

> > Cc: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > Subject: [PATCH] Implemented sysconf for Arm

> > 

> > The default implementation can be overridden outside newlib to allow a

> > different page size to improve malloc on devices with a small footprint

> > without needing to rebuild newlib.

> > 

> > Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@st.com>

> > Signed-off-by: Niklas DAHLQUIST <niklas.dahlquist@st.com>

> > ---

> >  newlib/libc/stdlib/mallocr.c    |  2 +-

> >  newlib/libc/sys/arm/Makefile.am |  2 +-

> >  newlib/libc/sys/arm/Makefile.in | 12 ++++++++++--

> >  newlib/libc/sys/arm/sysconf.c   | 20 ++++++++++++++++++++

> >  4 files changed, 32 insertions(+), 4 deletions(-)

> >  create mode 100644 newlib/libc/sys/arm/sysconf.c

> > 

> > diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c

> > index 26d1c89cc..28d278f51 100644

> > --- a/newlib/libc/stdlib/mallocr.c

> > +++ b/newlib/libc/stdlib/mallocr.c

> > @@ -316,7 +316,7 @@ extern "C" {

> >  # undef WIN32

> >  #endif

> >  

> > -#ifndef _WIN32

> > +#if !defined(_WIN32) && !defined(__ARM_EABI__)

> >  #ifdef SMALL_MEMORY

> >  #define malloc_getpagesize (128)

> >  #else

> > diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am

> > index 711872de3..9111f3647 100644

> > --- a/newlib/libc/sys/arm/Makefile.am

> > +++ b/newlib/libc/sys/arm/Makefile.am

> > @@ -14,7 +14,7 @@ else

> >  extra_objs =

> >  endif

> >  

> > -lib_a_SOURCES = access.c aeabi_atexit.c

> > +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

> >  lib_a_LIBADD = $(extra_objs)

> >  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

> >  lib_a_DEPENDENCIES = $(extra_objs)

> > diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in

> > index c01e4e2ed..67fb695f5 100644

> > --- a/newlib/libc/sys/arm/Makefile.in

> > +++ b/newlib/libc/sys/arm/Makefile.in

> > @@ -70,7 +70,8 @@ ARFLAGS = cru

> >  lib_a_AR = $(AR) $(ARFLAGS)

> >  @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \

> >  @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o

> > -am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)

> > +am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \

> > +	lib_a-sysconf.$(OBJEXT)

> >  lib_a_OBJECTS = $(am_lib_a_OBJECTS)

> >  DEFAULT_INCLUDES = -I.@am__isrc@

> >  depcomp =

> > @@ -183,6 +184,7 @@ pdfdir = @pdfdir@

> >  prefix = @prefix@

> >  program_transform_name = @program_transform_name@

> >  psdir = @psdir@

> > +runstatedir = @runstatedir@

> >  sbindir = @sbindir@

> >  sharedstatedir = @sharedstatedir@

> >  srcdir = @srcdir@

> > @@ -198,7 +200,7 @@ AM_CCASFLAGS = $(INCLUDES)

> >  noinst_LIBRARIES = lib.a

> >  @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 

> >  @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o

> > -lib_a_SOURCES = access.c aeabi_atexit.c

> > +lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c

> >  lib_a_LIBADD = $(extra_objs)

> >  EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c

> >  lib_a_DEPENDENCIES = $(extra_objs)

> > @@ -288,6 +290,12 @@ lib_a-aeabi_atexit.o: aeabi_atexit.c

> >  lib_a-aeabi_atexit.obj: aeabi_atexit.c

> >  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`

> >  

> > +lib_a-sysconf.o: sysconf.c

> > +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c

> > +

> > +lib_a-sysconf.obj: sysconf.c

> > +	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`

> > +

> >  lib_a-syscalls.o: syscalls.c

> >  	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c

> >  

> > diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c

> > new file mode 100644

> > index 000000000..86a324fa4

> > --- /dev/null

> > +++ b/newlib/libc/sys/arm/sysconf.c

> > @@ -0,0 +1,20 @@

> > +/* libc/sys/arm/sysconf.c - The sysconf function */

> > +

> > +/* Copyright 2020, STMicroelectronics */

> > +

> > +#include <unistd.h>

> > +#include <errno.h>

> > +

> > +long sysconf(int name)

> > +{

> > +  switch (name)

> > +  {

> > +  case _SC_PAGESIZE:

> > +    return 4096;

> > +

> > +  default:

> > +    errno = EINVAL;

> > +    return -1;

> > +  }

> > +  return -1; /* Can't get here */

> > +}

> > -- 

> > 2.18.0

> 

> -- 

> Corinna Vinschen

> Cygwin Maintainer

> Red Hat

> 


--

Patch

diff --git a/newlib/libc/stdlib/mallocr.c b/newlib/libc/stdlib/mallocr.c
index 26d1c89cc..28d278f51 100644
--- a/newlib/libc/stdlib/mallocr.c
+++ b/newlib/libc/stdlib/mallocr.c
@@ -316,7 +316,7 @@  extern "C" {
 # undef WIN32
 #endif
 
-#ifndef _WIN32
+#if !defined(_WIN32) && !defined(__ARM_EABI__)
 #ifdef SMALL_MEMORY
 #define malloc_getpagesize (128)
 #else
diff --git a/newlib/libc/sys/arm/Makefile.am b/newlib/libc/sys/arm/Makefile.am
index 711872de3..9111f3647 100644
--- a/newlib/libc/sys/arm/Makefile.am
+++ b/newlib/libc/sys/arm/Makefile.am
@@ -14,7 +14,7 @@  else
 extra_objs =
 endif
 
-lib_a_SOURCES = access.c aeabi_atexit.c
+lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c
 lib_a_LIBADD = $(extra_objs)
 EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c
 lib_a_DEPENDENCIES = $(extra_objs)
diff --git a/newlib/libc/sys/arm/Makefile.in b/newlib/libc/sys/arm/Makefile.in
index c01e4e2ed..67fb695f5 100644
--- a/newlib/libc/sys/arm/Makefile.in
+++ b/newlib/libc/sys/arm/Makefile.in
@@ -70,7 +70,8 @@  ARFLAGS = cru
 lib_a_AR = $(AR) $(ARFLAGS)
 @MAY_SUPPLY_SYSCALLS_TRUE@am__DEPENDENCIES_1 = $(lpfx)libcfunc.o \
 @MAY_SUPPLY_SYSCALLS_TRUE@	$(lpfx)trap.o $(lpfx)syscalls.o
-am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT)
+am_lib_a_OBJECTS = lib_a-access.$(OBJEXT) lib_a-aeabi_atexit.$(OBJEXT) \
+	lib_a-sysconf.$(OBJEXT)
 lib_a_OBJECTS = $(am_lib_a_OBJECTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
 depcomp =
@@ -183,6 +184,7 @@  pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
+runstatedir = @runstatedir@
 sbindir = @sbindir@
 sharedstatedir = @sharedstatedir@
 srcdir = @srcdir@
@@ -198,7 +200,7 @@  AM_CCASFLAGS = $(INCLUDES)
 noinst_LIBRARIES = lib.a
 @MAY_SUPPLY_SYSCALLS_FALSE@extra_objs = 
 @MAY_SUPPLY_SYSCALLS_TRUE@extra_objs = $(lpfx)libcfunc.o $(lpfx)trap.o $(lpfx)syscalls.o
-lib_a_SOURCES = access.c aeabi_atexit.c
+lib_a_SOURCES = access.c aeabi_atexit.c sysconf.c
 lib_a_LIBADD = $(extra_objs)
 EXTRA_lib_a_SOURCES = trap.S syscalls.c libcfunc.c
 lib_a_DEPENDENCIES = $(extra_objs)
@@ -288,6 +290,12 @@  lib_a-aeabi_atexit.o: aeabi_atexit.c
 lib_a-aeabi_atexit.obj: aeabi_atexit.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-aeabi_atexit.obj `if test -f 'aeabi_atexit.c'; then $(CYGPATH_W) 'aeabi_atexit.c'; else $(CYGPATH_W) '$(srcdir)/aeabi_atexit.c'; fi`
 
+lib_a-sysconf.o: sysconf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.o `test -f 'sysconf.c' || echo '$(srcdir)/'`sysconf.c
+
+lib_a-sysconf.obj: sysconf.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-sysconf.obj `if test -f 'sysconf.c'; then $(CYGPATH_W) 'sysconf.c'; else $(CYGPATH_W) '$(srcdir)/sysconf.c'; fi`
+
 lib_a-syscalls.o: syscalls.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-syscalls.o `test -f 'syscalls.c' || echo '$(srcdir)/'`syscalls.c
 
diff --git a/newlib/libc/sys/arm/sysconf.c b/newlib/libc/sys/arm/sysconf.c
new file mode 100644
index 000000000..86a324fa4
--- /dev/null
+++ b/newlib/libc/sys/arm/sysconf.c
@@ -0,0 +1,20 @@ 
+/* libc/sys/arm/sysconf.c - The sysconf function */
+
+/* Copyright 2020, STMicroelectronics */
+
+#include <unistd.h>
+#include <errno.h>
+
+long sysconf(int name)
+{
+  switch (name)
+  {
+  case _SC_PAGESIZE:
+    return 4096;
+
+  default:
+    errno = EINVAL;
+    return -1;
+  }
+  return -1; /* Can't get here */
+}