From 04a99db8c73cb8804fa56a7487d6aa1bf26ee752 Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Tue, 8 Mar 2022 17:31:08 -0300 Subject: [PATCH] nptl: x86_64: Use same code for CURRENT_STACK_FRAME and stackinfo_get_sp Cherry-picked by scw@google.com from 8cd559cf5afe3894f92c2be6f972e1a4e38c56ca with local modifications (different file path and not use macros introduced in 01bd62517cc242ae503aaa7002e9e94551803e4d). This fixes UB and code removal when building with clang. 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); The resulting code is similar to CURRENT_STACK_FRAME. Checked on x86_64-linux-gnu. --- sysdeps/x86_64/nptl/pthreaddef.h | 4 +++- sysdeps/x86_64/stackinfo.h | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sysdeps/x86_64/nptl/pthreaddef.h b/sysdeps/x86_64/nptl/pthreaddef.h index 036deb57723..7cf6677114a 100644 --- a/sysdeps/x86_64/nptl/pthreaddef.h +++ b/sysdeps/x86_64/nptl/pthreaddef.h @@ -41,4 +41,6 @@ /* Location of current stack frame. The frame pointer is not usable. */ #define CURRENT_STACK_FRAME \ - ({ register char *frame __asm__("rsp"); frame; }) + ({ register void * p__ __asm__("rsp"); \ + asm volatile("" : "=r" (p__)); \ + p__; }) diff --git a/sysdeps/x86_64/stackinfo.h b/sysdeps/x86_64/stackinfo.h index f7a5672f275..1301c5e197d 100644 --- a/sysdeps/x86_64/stackinfo.h +++ b/sysdeps/x86_64/stackinfo.h @@ -34,7 +34,9 @@ for which they need to act as barriers as well, hence the additional (unnecessary) parameters. */ #define stackinfo_get_sp() \ - ({ void *p__; asm volatile ("mov %%" RSP_LP ", %0" : "=r" (p__)); p__; }) + ({ register void * p__ __asm__(RSP_LP); \ + asm volatile("" : "=r" (p__)); \ + p__; }) #define stackinfo_sub_sp(ptr) \ ({ ptrdiff_t d__; \ asm volatile ("sub %%" RSP_LP " , %0" : "=r" (d__) : "0" (ptr)); \ -- 2.47.3