The plain non-size-optimized C-version of memset is broken when compiled with -O3.
Unfortunately both is true when newlib will be compiled for ARM. The default there is -O3 and no optimized assembler version of memset will be used.
I've already notified upstream: http://sourceware.org/ml/newlib/2013/msg01059.html
I'm attaching a quick patch wich works only with gcc, to make it usuable with other compilers, someone will have to play with autofoo like here: http://sourceware.org/ml/libc-alpha/2013-06/msg00734.html
I wanted to do it myself, but eautorecof doesn't work for newlib.
Created attachment 364926 [details, diff]
gcc-only patch to fix the problem.
Created attachment 365044 [details, diff]
Updated patch (including configure stuff) which should work with any compiler.
Tested on ARM Cortex-Mn.
I've just checked newlib 2.1.0 which was released at 23-12-2013 and it contains the necessary patch for the memset problem (I've reported upstream too).
So just upgrading the version to 2.1.0 would fix this bug.
Up to now I haven't tested 2.1.0 myself, but I assume it will now work too with -O3 as the source looks like the attached patch.
I'm still not sure where newlib got the -O3 from (maybe it has taken it from my host CFLAGS, which indeed contains -O3), but I don't care much.
It might be a good idea to add a useflag to add --enable-target-optspace to the configure flags (or even enable that by default), as that option enables -Os. But I'm not sure about that, because I don't know where newlib is used besides my use case (ARM Cortex-Mn).
(In reply to Alexander Holler from comment #3)
2.1.0 is in the tree already
we don't create USE flags that just control optimization flags. testing 2.1.0, i don't see -O3 being used.
Very unusual but newlib uses the optimization level as found in the CFLAGS of the build machine (e.g. in /etc/portage/make.conf) to (cross-)compile the target libraries.
Therefor a useflag might make sense here.
Anyway, since it now works even if CFLAGS contains -O3 (just tested), it's ok.
Thanks for the version bump.
(In reply to Alexander Holler from comment #5)
this is a known TODO in crossdev (bug 420089). a USE flag doesn't make sense.