public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] nptl: x86_64: Use stackinfo.h definition for CURRENT_STACK_FRAME
@ 2022-08-29 19:00 Adhemerval Zanella
  2022-08-29 19:24 ` Noah Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Adhemerval Zanella @ 2022-08-29 19:00 UTC (permalink / raw)
  To: libc-alpha

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__; })
 #else
 # define CURRENT_STACK_FRAME	__builtin_frame_address (0)
 #endif
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nptl: x86_64: Use stackinfo.h definition for CURRENT_STACK_FRAME
  2022-08-29 19:00 [PATCH] nptl: x86_64: Use stackinfo.h definition for CURRENT_STACK_FRAME Adhemerval Zanella
@ 2022-08-29 19:24 ` Noah Goldstein
  2022-08-29 20:20   ` Adhemerval Zanella Netto
  0 siblings, 1 reply; 3+ messages in thread
From: Noah Goldstein @ 2022-08-29 19:24 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: GNU C Library

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?
>  #else
>  # define CURRENT_STACK_FRAME   __builtin_frame_address (0)
>  #endif
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] nptl: x86_64: Use stackinfo.h definition for CURRENT_STACK_FRAME
  2022-08-29 19:24 ` Noah Goldstein
@ 2022-08-29 20:20   ` Adhemerval Zanella Netto
  0 siblings, 0 replies; 3+ messages in thread
From: Adhemerval Zanella Netto @ 2022-08-29 20:20 UTC (permalink / raw)
  To: Noah Goldstein; +Cc: GNU C Library



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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-29 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-29 19:00 [PATCH] nptl: x86_64: Use stackinfo.h definition for CURRENT_STACK_FRAME Adhemerval Zanella
2022-08-29 19:24 ` Noah Goldstein
2022-08-29 20:20   ` Adhemerval Zanella Netto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).