[PATCH 1/2] x86_64: Use __seg_fs qualifiers in {STACK,POINTER}_CHK_GUARD macros

H.J. Lu hjl.tools@gmail.com
Wed Sep 10 12:28:41 GMT 2025


On Tue, Sep 9, 2025 at 9:43 AM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Use the __seg_fs named address space qualifiers to cast reads of
> the guard values in the TCB as %fs: prefixed addresses.
>
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: H.J.Lu <hjl.tools@gmail.com>
> Cc: Florian Weimer <fweimer@redhat.com>
> Cc: Carlos O'Donell <carlos@redhat.com>
> ---
>  sysdeps/x86_64/stackguard-macros.h | 8 ++------
>  1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/sysdeps/x86_64/stackguard-macros.h b/sysdeps/x86_64/stackguard-macros.h
> index 1948800cd0..1d4c620ff1 100644
> --- a/sysdeps/x86_64/stackguard-macros.h
> +++ b/sysdeps/x86_64/stackguard-macros.h
> @@ -1,11 +1,7 @@
>  #include <stdint.h>
>
>  #define STACK_CHK_GUARD \
> -  ({ uintptr_t x;                                              \
> -     asm ("mov %%fs:%c1, %0" : "=r" (x)                                \
> -         : "i" (offsetof (tcbhead_t, stack_guard))); x; })
> +  (*(uintptr_t __seg_fs *) offsetof (tcbhead_t, stack_guard))
>
>  #define POINTER_CHK_GUARD \
> -  ({ uintptr_t x;                                              \
> -     asm ("mov %%fs:%c1, %0" : "=r" (x)                                \
> -         : "i" (offsetof (tcbhead_t, pointer_guard))); x; })
> +  (*(uintptr_t __seg_fs *) offsetof (tcbhead_t, pointer_guard))
> --
> 2.51.0
>

LGTM.

Reviewed-by: H.J. Lu <hjl.tools@gmail.com>

Thanks.

-- 
H.J.


More information about the Libc-alpha mailing list