On Thu, Jun 11, 2020 at 10:12:14AM +0200, Martin Liška wrote:
> gcc/ChangeLog:
> 
>       PR sanitizer/95634
>       * asan.c (asan_emit_stack_protection): Fix emission for ilp32
>       by using Pmode instead of ptr_mode.
> ---
>  gcc/asan.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/asan.c b/gcc/asan.c
> index e015fa3ec9b..5d123a3e8a6 100644
> --- a/gcc/asan.c
> +++ b/gcc/asan.c
> @@ -1610,8 +1610,8 @@ asan_emit_stack_protection (rtx base, rtx pbase, 
> unsigned int alignb,
>           = (1 << (use_after_return_class + 6));
>         offset -= GET_MODE_SIZE (ptr_mode);
>         mem = gen_rtx_MEM (ptr_mode, base);
> -       mem = adjust_address (mem, ptr_mode, offset);
> -       rtx addr = gen_reg_rtx (ptr_mode);
> +       mem = adjust_address (mem, Pmode, offset);
> +       rtx addr = gen_reg_rtx (Pmode);

That is not correct.  On the architectures where ptr_mode != Pmode,
when you are reading a pointer from memory, you want to use ptr_mode,
because that is how the pointer is represented in memory.
So, it needs to stay:
          mem = gen_rtx_MEM (ptr_mode, base);
          mem = adjust_address (mem, ptr_mode, offset);
          rtx addr = gen_reg_rtx (ptr_mode);
          emit_move_insn (addr, mem);
But, at this point addr is ptr_mode, but you need to convert it into Pmode.
          addr = convert_memory_address (Pmode, addr);
This one will do nothing at all on normal arches where ptr_mode == Pmode,
and perform some extension (zero/sign/whatever else the arch needs)
otherwise.

>         mem = gen_rtx_MEM (QImode, addr);
>         emit_move_insn (mem, const0_rtx);
> -- 
> 2.26.2

        Jakub

Reply via email to