This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: Bug compiling the C version of memset with gcc -O3
- From: Alexander Holler <holler at ahsoftware dot de>
- To: newlib at sourceware dot org
- Date: Sun, 08 Dec 2013 06:06:19 +0100
- Subject: Re: Bug compiling the C version of memset with gcc -O3
- Authentication-results: sourceware.org; auth=none
- References: <52A3DC07 dot 8030803 at ahsoftware dot de>
Am 08.12.2013 03:40, schrieb Alexander Holler:
> I've stumbled over bug compiling newlib 2.0 for ARM with gcc and -O3.
I've attached a quickly done patch which fixed the issue here. Please
not that this patch still needs some love from someone (see the line
containing "hack" in the patch) as I haven't changed configure and
possible existing tests.
It's unlikely that I will post another (better) version of this patch,
but maybe someone else wants to do that. An example how it could look
like can be found here:
http://sourceware.org/ml/libc-alpha/2013-06/msg00734.html
Regards,
Alexander Holler
diff -Naur newlib-2.0.0.orig/newlib/libc/string/memmove.c newlib-2.0.0/newlib/libc/string/memmove.c
--- newlib-2.0.0.orig/newlib/libc/string/memmove.c 2010-09-22 05:15:07.000000000 +0200
+++ newlib-2.0.0/newlib/libc/string/memmove.c 2013-12-08 05:17:00.450248311 +0100
@@ -40,6 +40,22 @@
#include <stddef.h>
#include <limits.h>
+/* hack because currently I don't want to fiddle with autoconf */
+#define HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
+
+/*
+ Taken from glibc:
+ Add the compiler optimization to inhibit loop transformation to library
+ calls. This is used to avoid recursive calls in memset and memmove
+ default implementations.
+*/
+#ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
+# define inhibit_loop_to_libcall \
+ __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
+#else
+# define inhibit_loop_to_libcall
+#endif
+
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
#define UNALIGNED(X, Y) \
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
@@ -55,6 +71,7 @@
/*SUPPRESS 20*/
_PTR
+inhibit_loop_to_libcall
_DEFUN (memmove, (dst_void, src_void, length),
_PTR dst_void _AND
_CONST _PTR src_void _AND
diff -Naur newlib-2.0.0.orig/newlib/libc/string/memset.c newlib-2.0.0/newlib/libc/string/memset.c
--- newlib-2.0.0.orig/newlib/libc/string/memset.c 2008-05-27 20:44:40.000000000 +0200
+++ newlib-2.0.0/newlib/libc/string/memset.c 2013-12-08 05:16:27.830247253 +0100
@@ -35,11 +35,28 @@
#include <string.h>
+/* hack because currently I don't want to fiddle with autoconf */
+#define HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
+
+/*
+ Taken from glibc:
+ Add the compiler optimization to inhibit loop transformation to library
+ calls. This is used to avoid recursive calls in memset and memmove
+ default implementations.
+*/
+#ifdef HAVE_CC_INHIBIT_LOOP_TO_LIBCALL
+# define inhibit_loop_to_libcall \
+ __attribute__ ((__optimize__ ("-fno-tree-loop-distribute-patterns")))
+#else
+# define inhibit_loop_to_libcall
+#endif
+
#define LBLOCKSIZE (sizeof(long))
#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
_PTR
+inhibit_loop_to_libcall
_DEFUN (memset, (m, c, n),
_PTR m _AND
int c _AND