Bug 30773 - [m68k] busybox awk is broken (lshift.S related)
Summary: [m68k] busybox awk is broken (lshift.S related)
Status: RESOLVED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: math (show other bugs)
Version: 2.38
: P2 normal
Target Milestone: 2.39
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-17 06:17 UTC by wbx
Modified: 2023-08-18 07:04 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-08-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description wbx 2023-08-17 06:17:58 UTC
Hi,

Running glibc 2.38 system in qemu-system-m68k (machine virt, cpu m68040).
Patch from here is applied https://sourceware.org/bugzilla/show_bug.cgi?id=30740.

There is one issue, this oneliner does not work, I use it to show the ip address of the system:
ipaddr=$(ip addr show $(ip route show|awk '/default/ { print $5 }')|awk '/inet / { print $2 }'|tail -1)

With strace I get:
Fatal glibc error: printf_fp.c:501 (__printf_fp_buffer_1): assertion failed: cy == 1 || (p.frac[p.fracsize - 2] == 0 && p.frac[0] == 0)
Aborted

Removing sysdeps/m68k/m680x0/lshift.S fixes the issue.

best regards
 Waldemar
Comment 1 Andreas Schwab 2023-08-17 07:22:32 UTC
Please provide a self-contained test case.  What exactly does gawk pass to printf?
Comment 2 wbx 2023-08-17 09:36:45 UTC
root@openadk:~ # ip route show                                             
default via 10.0.2.2 dev eth0 
10.0.2.0/24 dev eth0 scope link  src 10.0.2.15 
root@openadk:~ # ip route show|awk '/default/ { print $5 }'                                     
dev

This normally should give eth0 instead of dev. It is not gawk, it is busybox awk, which is failing here. But I now checked with gawk, and it has the same problem.

Does that help?

best regards
 Waldemar
Comment 3 Andreas Schwab 2023-08-17 10:39:50 UTC
Worksforme.  Most probably an emulation bug.
Comment 4 Adhemerval Zanella 2023-08-17 12:29:36 UTC
Waldemar forgot to said his build was done with -mcpu=68040. And this option gcc  does not define __mc68020__, which makes sysdeps/m68k/m680x0/lshift.S and sysdeps/m68k/m680x0/rshift.S use a code path for not m68000 (which does seem wrong).

This following fix does make the m68040 build prints the expected value:

diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S
index 2aee10348e..bfb6d5580a 100644
--- a/sysdeps/m68k/m680x0/lshift.S
+++ b/sysdeps/m68k/m680x0/lshift.S
@@ -57,7 +57,7 @@ ENTRY(__mpn_lshift)
        bne     L(Lnormal)
        cmpl    R(s_ptr),R(res_ptr)
        bls     L(Lspecial)             /* jump if s_ptr >= res_ptr */
-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
+#if defined (__mc68020__) || defined (__mc68040__)
        lea     MEM_INDX1(s_ptr,s_size,l,4),R(a2)
 #else /* not mc68020 */
        movel   R(s_size),R(d0)
@@ -71,7 +71,7 @@ L(Lnormal:)
        moveql  #32,R(d5)
        subl    R(cnt),R(d5)

-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
+#if defined (__mc68020__) || defined (__mc68040__)
        lea     MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr)
        lea     MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr)
 #else /* not mc68000 */
diff --git a/sysdeps/m68k/m680x0/rshift.S b/sysdeps/m68k/m680x0/rshift.S
index d16bca9307..c8735c3bf1 100644
--- a/sysdeps/m68k/m680x0/rshift.S
+++ b/sysdeps/m68k/m680x0/rshift.S
@@ -56,7 +56,7 @@ ENTRY(__mpn_rshift)
        bne     L(Lnormal)
        cmpl    R(res_ptr),R(s_ptr)
        bls     L(Lspecial)             /* jump if res_ptr >= s_ptr */
-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
+#if defined (__mc68020__) || defined (__mc68040__)
        lea     MEM_INDX1(res_ptr,s_size,l,4),R(a2)
 #else /* not mc68020 */
        movel   R(s_size),R(d0)
@@ -121,7 +121,7 @@ L(Lend:)

        cfi_restore_state
 L(Lspecial:)
-#if (defined (__mc68020__) || defined (__NeXT__) || defined(mc68020))
+#if defined (__mc68020__) || defined (__mc68040__)
        lea     MEM_INDX1(s_ptr,s_size,l,4),R(s_ptr)
        lea     MEM_INDX1(res_ptr,s_size,l,4),R(res_ptr)
 #else /* not mc68000 */
Comment 5 Andreas Schwab 2023-08-17 14:03:05 UTC
diff --git a/sysdeps/m68k/m680x0/lshift.S b/sysdeps/m68k/m680x0/lshift.S
index 2aee10348e..4240738959 100644
--- a/sysdeps/m68k/m680x0/lshift.S
+++ b/sysdeps/m68k/m680x0/lshift.S
@@ -77,8 +77,8 @@ L(Lnormal:)
 #else /* not mc68000 */
 	movel	R(s_size),R(d0)
 	asll	#2,R(d0)
-	addl	R(s_size),R(s_ptr)
-	addl	R(s_size),R(res_ptr)
+	addl	R(d0),R(s_ptr)
+	addl	R(d0),R(res_ptr)
 #endif
 	movel	MEM_PREDEC(s_ptr),R(d2)
 	movel	R(d2),R(d0)
Comment 6 Adhemerval Zanella 2023-08-17 14:09:15 UTC
Ok, but this is a different issue I think.  Since this code is originally copied from gmplib, mpn/m68k/m68k-defs.m4 has:

define(scale_available_p,
`m4_ifdef_anyof_p(
`HAVE_HOST_CPU_m68360'
`HAVE_HOST_CPU_m68020'
`HAVE_HOST_CPU_m68030'
`HAVE_HOST_CPU_m68040'
`HAVE_HOST_CPU_m68060')')

So glibc should also checks for __mc68030__, __mc68040__, __mc68060__, instead of just __mc68020__.
Comment 7 Andreas Schwab 2023-08-17 14:35:58 UTC
It was correct when it was copied verbatim from gmp.  The problem is that gcc has changed in the mean time.
Comment 8 Sam James 2023-08-18 05:01:47 UTC
ftr: andreas fixed that part in https://sourceware.org/git/?p=glibc.git;a=commit;h=464fd8249e8b791248cab7b0e0cd91757435fa9e.
Comment 9 wbx 2023-08-18 06:19:48 UTC
thanks. That is working!