On 2022/12/16 19:28, Geert Uytterhoeven wrote:
Hi Zhen,
On Fri, Dec 16, 2022 at 10:43 AM Leizhen (ThunderTown)
<thunder.leizhen@xxxxxxxxxx> wrote:
On 2022/12/16 15:42, Leizhen (ThunderTown) wrote:
On 2022/12/15 22:51, Geert Uytterhoeven wrote:
On 30f3bb09778de64 with your debug patch v2:
I've set up the qemu environment, and I'll try to solve it by tomorrow at the latest.
It seems that the problem is still strcmp(). After I commented strcmp() in
arch/m68k/include/asm/string.h, and force it to use the one in lib/string.c,
it works well.
I can confirm that.
One difference is that the one in lib/string.c always return -1/0/1,
while the m68k version can return other negative or positive numbers.
However, adding:
if (res < 0) return -1;
if (res > 0) return 1;
to the m68k version doesn't make a difference.
Renaming the m68k version (changed to -1/0/1) to m68k_strcmp(), and
the generic version to lib_strcmp(), and adding a wrapper that calls
and compares both, shows that both functions do return the same value,
and the test succeeds.
Moving the m68k version inside lib/string.c makes the test pass, too.
So it must be related to the function being inline, and gcc making
(incorrect) assumptions...
Yes, it's the compiler's fault. I just replied David Laight:
I added 'volatile' to prevent compiler optimizations, and it's OK now.
diff --git a/arch/m68k/include/asm/string.h b/arch/m68k/include/asm/string.h
index f759d944c449940..3db81e5a783c72a 100644
--- a/arch/m68k/include/asm/string.h
+++ b/arch/m68k/include/asm/string.h
@@ -42,9 +42,9 @@ static inline char *strncpy(char *dest, const char *src, size_t n)
#define __HAVE_ARCH_STRCMP
static inline int strcmp(const char *cs, const char *ct)
{
- char res;
+ signed char res;
- asm ("\n"
+ asm volatile ("\n"
"1: move.b (%0)+,%2\n" /* get *cs */
" cmp.b (%1)+,%2\n" /* compare a byte */
" jne 2f\n" /* not equal, break out */
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
.
--
Regards,
Zhen Lei