Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 14 Mar 2024 14:45:29 +0800
From: lixing <lixing@...ngson.cn>
To: musl@...ts.openwall.com
Subject: Re: loongarch64 atomics not working?


在 2024/3/14 下午1:44, Waldemar Brodkorb 写道:
> Hi,
> Rich Felker wrote,
>
>>> Yes I do. I found the reason why my mksh didn't worked.
>>> I compiled everything with -Os and then I get the deadlock.
>>> When I compile everything with -O2 musl mksh is working.
>>>
>>> So it seems some gcc problem code compiled with -Os.
>> Let's look at the generated asm for the function using a_cas_p and see
>> if this is a gcc bug or if the asm argument constraints as written
>> allowed a transformation that's not actually valid.
> Broken mksh with -Os:
>   
> 000000012003b970 <cgt_init>:
>     12003b970:   02ff8063        addi.d          $sp, $sp, -32
>     12003b974:   29c02077        st.d            $s0, $sp, 8
>     12003b978:   27000078        stptr.d         $s1, $sp, 0
>     12003b97c:   00150097        move            $s0, $a0
>     12003b980:   001500b8        move            $s1, $a1
>     12003b984:   1a000084        pcalau12i       $a0, 4
>     12003b988:   1a000085        pcalau12i       $a1, 4
>     12003b98c:   29c04076        st.d            $fp, $sp, 16
>     12003b990:   29c06061        st.d            $ra, $sp, 24
>     12003b994:   02c08076        addi.d          $fp, $sp, 32
>     12003b998:   02c060a5        addi.d          $a1, $a1, 24
>     12003b99c:   02c0c084        addi.d          $a0, $a0, 48
>     12003b9a0:   54021400        bl              532     # 12003bbb4 <__vdsosym>
>     12003b9a4:   0015008e        move            $t2, $a0
>     12003b9a8:   38720000        dbar            0x0
>     12003b9ac:   1a00002d        pcalau12i       $t1, 1
>     12003b9b0:   1a00032f        pcalau12i       $t3, 25
>     12003b9b4:   02e5c1ad        addi.d          $t1, $t1, -1680
>     12003b9b8:   02ca21ec        addi.d          $t0, $t3, 648
>     12003b9bc:   2200018c        ll.d            $t0, $t0, 0
>     12003b9c0:   5c00198d        bne             $t0, $t1, 24    # 12003b9d8 <cgt_init+0x68>
>     12003b9c4:   001501cc        move            $t0, $t2
>     12003b9c8:   02ca21f0        addi.d          $t4, $t3, 648
>     12003b9cc:   2300020c        sc.d            $t0, $t4, 0
>     12003b9d0:   0040818c        slli.w          $t0, $t0, 0x0
>     12003b9d4:   43ffe59f        beqz            $t0, -28        # 12003b9b8 <cgt_init+0x48>
>     12003b9d8:   38720000        dbar            0x0
>     12003b9dc:   400025c0        beqz            $t2, 36 # 12003ba00 <cgt_init+0x90>
>     12003b9e0:   28c04076        ld.d            $fp, $sp, 16
>     12003b9e4:   28c06061        ld.d            $ra, $sp, 24
>     12003b9e8:   00150305        move            $a1, $s1
>     12003b9ec:   001502e4        move            $a0, $s0
>     12003b9f0:   26000078        ldptr.d         $s1, $sp, 0
>     12003b9f4:   28c02077        ld.d            $s0, $sp, 8
>     12003b9f8:   02c08063        addi.d          $sp, $sp, 32
>     12003b9fc:   4c0001c0        jr              $t2
>     12003ba00:   28c06061        ld.d            $ra, $sp, 24
>     12003ba04:   28c04076        ld.d            $fp, $sp, 16
>     12003ba08:   28c02077        ld.d            $s0, $sp, 8
>     12003ba0c:   26000078        ldptr.d         $s1, $sp, 0
>     12003ba10:   02bf6804        li.w            $a0, -38
>     12003ba14:   02c08063        addi.d          $sp, $sp, 32
>     12003ba18:   4c000020        ret
>
> Working mksh with -O2:
> 0000000120045f50 <cgt_init>:
>     120045f50:   02ff8063        addi.d          $sp, $sp, -32
>     120045f54:   29c02077        st.d            $s0, $sp, 8
>     120045f58:   27000078        stptr.d         $s1, $sp, 0
>     120045f5c:   00150097        move            $s0, $a0
>     120045f60:   001500b8        move            $s1, $a1
>     120045f64:   1a000084        pcalau12i       $a0, 4
>     120045f68:   1a000085        pcalau12i       $a1, 4
>     120045f6c:   29c04076        st.d            $fp, $sp, 16
>     120045f70:   29c06061        st.d            $ra, $sp, 24
>     120045f74:   02c08076        addi.d          $fp, $sp, 32
>     120045f78:   02dbc0a5        addi.d          $a1, $a1, 1776
>     120045f7c:   02dc2084        addi.d          $a0, $a0, 1800
>     120045f80:   54024c00        bl              588     # 1200461cc <__vdsosym>
>     120045f84:   0015008f        move            $t3, $a0
>     120045f88:   38720000        dbar            0x0
>     120045f8c:   1a000030        pcalau12i       $t4, 1
>     120045f90:   1a00036d        pcalau12i       $t1, 27
>     120045f94:   02fd4210        addi.d          $t4, $t4, -176
>     120045f98:   50001400        b               20      # 120045fac <cgt_init+0x5c>
>     120045f9c:   02ca21ae        addi.d          $t2, $t1, 648
>     120045fa0:   230001cc        sc.d            $t0, $t2, 0
>     120045fa4:   0040818c        slli.w          $t0, $t0, 0x0
>     120045fa8:   44001580        bnez            $t0, 20 # 120045fbc <cgt_init+0x6c>
>     120045fac:   02ca21ac        addi.d          $t0, $t1, 648
>     120045fb0:   2200018e        ll.d            $t2, $t0, 0
>     120045fb4:   001501ec        move            $t0, $t3
>     120045fb8:   5bffe60e        beq             $t4, $t2, -28   # 120045f9c <cgt_init+0x4c>
>     120045fbc:   38720000        dbar            0x0
>     120045fc0:   400025e0        beqz            $t3, 36 # 120045fe4 <cgt_init+0x94>
>     120045fc4:   28c04076        ld.d            $fp, $sp, 16
>     120045fc8:   28c06061        ld.d            $ra, $sp, 24
>     120045fcc:   00150305        move            $a1, $s1
>     120045fd0:   001502e4        move            $a0, $s0
>     120045fd4:   26000078        ldptr.d         $s1, $sp, 0
>     120045fd8:   28c02077        ld.d            $s0, $sp, 8
>     120045fdc:   02c08063        addi.d          $sp, $sp, 32
>     120045fe0:   4c0001e0        jr              $t3
>     120045fe4:   28c06061        ld.d            $ra, $sp, 24
>     120045fe8:   28c04076        ld.d            $fp, $sp, 16
>     120045fec:   28c02077        ld.d            $s0, $sp, 8
>     120045ff0:   26000078        ldptr.d         $s1, $sp, 0
>     120045ff4:   02bf6804        li.w            $a0, -38
>     120045ff8:   02c08063        addi.d          $sp, $sp, 32
>     120045ffc:   4c000020        ret
>
> Does that help? Both binaries can be found on https://debug.openadk.org.
>
> best regards
>   Waldemar

we checked the objdump binaries for -Os and -O2, the a_cas_p implement 
looks ok for both.

Also, we cross build the musl and mksh with -Os, the binary hang with 
qemu user mode emulation , but not hang in the real hardware.

so, maybe this is a qemu problem, we will let our qemu guys to check 
this problem.

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.