zcfh commented on PR #2156:
URL: https://github.com/apache/brpc/pull/2156#issuecomment-1976430923

   目前从clang11 切换 到clang16 遇到了一些新的问题。和 #1776  
提到的问题应该是一样的,不过我看**1776对应的代码并没有合入**, 是有做了其他修复吗。
   
   对比了汇编,这样差异在于326-331 行这段代码(version 0.96)
   ```c++
           // Clean tls variables, must be done before changing version_butex
           // otherwise another thread just joined this thread may not see side
           // effects of destructing tls variables.
           KeyTable* kt = tls_bls.keytable;
           if (kt != NULL) {
               return_keytable(m->attr.keytable_pool, kt);
               // After deletion: tls may be set during deletion.
               tls_bls.keytable = NULL;
               m->local_storage.keytable = NULL; // optional
           }
   ```
   
   clang11 对于 tls_bls 成员变量的读写,每次都会经过一次call。而clang16会在`do`循环外缓存`tls_bls`的地址。
   具体汇编差异如下
   clang11
   ``` as
   ;third_party/brpc-0.9.6/src/bthread/task_group.cpp:325 
   # KeyTable* kt = tls_bls.keytable;
        a9e:    66 48 8d 3d 00 00 00    data16 lea 0x0(%rip),%rdi        # aa6 
<bthread::TaskGroup::task_runner(long)+0x196>
        aa5:    00
        aa6:    66 66 48 e8 00 00 00    data16 data16 callq aae 
<bthread::TaskGroup::task_runner(long)+0x19e>
        aad:    00
        aae:    48 8b 30                mov    (%rax),%rsi
   third_party/brpc-0.9.6/src/bthread/task_group.cpp:326
        ab1:    48 85 f6                test   %rsi,%rsi
        ab4:    74 28                   je     ade 
<bthread::TaskGroup::task_runner(long)+0x1ce>
   ...
   third_party/brpc-0.9.6/src/bthread/task_group.cpp:329
   # tls_bls.keytable = NULL;
        abf:    66 48 8d 3d 00 00 00    data16 lea 0x0(%rip),%rdi        # ac7 
<bthread::TaskGroup::task_runner(long)+0x1b7>
        ac6:    00
        ac7:    66 66 48 e8 00 00 00    data16 data16 callq acf 
<bthread::TaskGroup::task_runner(long)+0x1bf>
        ace:    00
        acf:    48 c7 00 00 00 00 00    movq   $0x0,(%rax)
   ```
   clang16
   
   ```
   ;third_party/brpc-0.9.6/src/bthread/task_group.cpp:265
        838:    48 8b 40 30             mov    0x30(%rax),%rax
        83c:    48 85 c0                test   %rax,%rax
        83f:    75 df                   jne    820 
<bthread::TaskGroup::task_runner(long)+0x30>
        841:    4c 89 65 d0             mov    %r12,-0x30(%rbp)
        845:    66 48 8d 3d 00 00 00    data16 lea 0x0(%rip),%rdi        # 84d 
<bthread::TaskGroup::task_runner(long)+0x5d>
        84c:    00
        84d:    66 66 48 e8 00 00 00    data16 data16 callq 855 
<bthread::TaskGroup::task_runner(long)+0x65>
        854:    00
        855:    48 89 c3                mov    %rax,%rbx  # do 循环外保存 tls_bls 
的地址到rbx
   ...
   ;third_party/brpc-0.9.6/src/bthread/task_group.cpp:325
   # KeyTable* kt = tls_bls.keytable;
        96e:    48 8b 33                mov    (%rbx),%rsi
   ;third_party/brpc-0.9.6/src/bthread/task_group.cpp:326
        971:    48 85 f6                test   %rsi,%rsi
        974:    74 18                   je     98e 
<bthread::TaskGroup::task_runner(long)+0x19e>
   ...
   ;third_party/brpc-0.9.6/src/bthread/task_group.cpp:329
   # tls_bls.keytable = NULL;
        97f:    48 c7 03 00 00 00 00    movq   $0x0,(%rbx)
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@brpc.apache.org
For additional commands, e-mail: dev-h...@brpc.apache.org

Reply via email to