Hi Alex, Alex Potapenko wrote,
On Thu, Apr 21, 2016 at 4:30 PM, Rene Nielsen rene.nielsen@microsemi.com wrote:
I have found a bug in .../libc/string/generic/memmove.c, which is the one that MIPS uses, since there's no specialized, optimized version for MIPS.
We're currently using uClibc v. 1.0.12, but I suspect the bug to be present in earlier releases too.
Here's a snippet from memmove.c#memmove(): ---------------------oOo--------------------- /* This test makes the forward copying code be used whenever possible. Reduces the working set. */ if (dstp - srcp >= len) /* *Unsigned* compare! */ { #ifndef __ARCH_HAS_BWD_MEMCPY__ /* Backward memcpy implementation cannot be used */ memcpy(dest, src, len); #else /* Copy from the beginning to the end. */ ---------------------oOo---------------------
Given the name of the define (__ARCH_HAS_BWD_MEMCPY__) it sounds as when this is defined, the architecture indeed has backward memcpy() support. But how come the line is preceded by #ifndef and not #ifdef, when the code inside calls memcpy()?
Also, the first comment inside the #ifndef seems odd, since memcpy() indeed is called: /* Backward memcpy implementation cannot be used */
Our SDK does not define __ARCH_HAS_BWD_MEMCPY__, so when memmove() resorts to a simple memcpy() that does the wrong thing for overlapping regions, our application fails with disastrous side-effects.
I have attached a patch that fixes this.
Hi Rene!
I am Optware-ng project maintainer. I have tried your patch to see if it fixes memset/memcpy related issue we were having on mipsel (e.g., see transmission issue https://github.com/Optware/Optware-ng/issues/53). Unfortunately, even though your test passes fine with 'memmove() succeeded', transmission still crashes after a while when a torrent is added, so I had to restore the old patch that reverted memcpy.S/memset.S to pre-2636b17616 (e3c3bf2b580), which fixed the issue. Probably, even with your patch, there's still something wrong with memcpy.S/memset.S.
Can you please try uClibc-ng 1.0.15 and disable UCLIBC_USE_MIPS_PREFETCH in your build?
We identified prefetch as the problematic instructions on the combination of MIPS CPU, kernel and uClibc-ng.
It is not perfect, but a valid workaround, until we find the reason for the problems.
Thanks in advance, Waldemar