[PATCH] nptl: x86_64: Use stackinfo.h definition for CURRENT_STACK_FRAME

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Mon Aug 29 20:20:25 GMT 2022



On 29/08/22 16:24, Noah Goldstein wrote:
> On Mon, Aug 29, 2022 at 12:00 PM Adhemerval Zanella via Libc-alpha
> <libc-alpha@sourceware.org> wrote:
>>
>> It avoids the possible warning of uninitialized 'frame' variable when
>> building with clang:
>>
>>   ../sysdeps/nptl/jmp-unwind.c:27:42: error: variable 'frame' is
>>   uninitialized when used here [-Werror,-Wuninitialized]
>>     __pthread_cleanup_upto (env->__jmpbuf, CURRENT_STACK_FRAME);
>>
>> It increases the generated code by one instruction:
>>
>> --- master
>> +++ patch
>> @@ -25068,11 +25068,11 @@ Disassembly of section .text:
>>     3db1b:      00 00
>>     3db1d:      48 89 44 24 08          mov    %rax,0x8(%rsp)
>>     3db22:      31 c0                   xor    %eax,%eax
>> -   3db24:      48 8b 44 24 08          mov    0x8(%rsp),%rax
>> -   3db29:      64 48 2b 04 25 28 00    sub    %fs:0x28,%rax
>> -   3db30:      00 00
>> -   3db32:      75 0c                   jne    3db40
>>     <_longjmp_unwind+0x30>
>> -   3db34:      48 89 e6                mov    %rsp,%rsi
>> +   3db24:      48 89 e6                mov    %rsp,%rsi
>> +   3db27:      48 8b 44 24 08          mov    0x8(%rsp),%rax
>> +   3db2c:      64 48 2b 04 25 28 00    sub    %fs:0x28,%rax
>> +   3db33:      00 00
>> +   3db35:      75 09                   jne    3db40
>>     <_longjmp_unwind+0x30>
>>     3db37:      48 83 c4 18             add    $0x18,%rsp
>>     3db3b:      e9 60 31 05 00          jmp    90ca0
>> <__GI___pthread_cleanup_upto>
>>     3db40:      e8 4b ec 0e 00          call   12c790 <__stack_chk_fail>
>>
>> Checked on x86_64-linux-gnu.
>> ---
>>  sysdeps/x86/nptl/pthreaddef.h | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/sysdeps/x86/nptl/pthreaddef.h b/sysdeps/x86/nptl/pthreaddef.h
>> index 63fdbcb27c..3ff95efee6 100644
>> --- a/sysdeps/x86/nptl/pthreaddef.h
>> +++ b/sysdeps/x86/nptl/pthreaddef.h
>> @@ -42,7 +42,7 @@
>>  #ifdef __x86_64__
>>  /* The frame pointer is not usable.  */
>>  # define CURRENT_STACK_FRAME \
>> -  ({ register char *frame __asm__("rsp"); frame; })
>> +  ({ void *p__; asm volatile ("mov %%" RSP_REG ", %0" : "=r" (p__)); p__; })
> 
> Is the mov instruction needed at all?
> 
> Would:
> ```
> ({ register void * p__ __asm__("rsp"); asm volatile("" : "=r"(p__)); p__; });
> ```
> work?

This works, thanks. I will send an update version.


More information about the Libc-alpha mailing list