[PATCH] Add missing store in emission of asan_stack_free.

Jakub Jelinek jakub@redhat.com
Wed Jun 10 10:08:31 GMT 2020


On Wed, Jun 10, 2020 at 11:49:01AM +0200, Martin Liška wrote:
> -	store_by_pieces (shadow_mem, sz, builtin_memset_read_str, &c,
> -			 BITS_PER_UNIT, true, RETURN_BEGIN);
> +	{
> +	  /* Emit:
> +	       memset(ShadowBase, kAsanStackAfterReturnMagic, ShadowSize);
> +	       **SavedFlagPtr(FakeStack) = 0

SavedFlagPtr has two arguments, doesn't it?

> +	  */
> +	  store_by_pieces (shadow_mem, sz, builtin_memset_read_str, &c,
> +			   BITS_PER_UNIT, true, RETURN_BEGIN);
> +
> +	  unsigned HOST_WIDE_INT offset
> +	    = (1 << (use_after_return_class + 6));
> +	  offset -= GET_MODE_SIZE (ptr_mode);

So, mem here is a MEM into which we stored ASAN_STACK_RETIRED_MAGIC.

> +	  mem = adjust_address (mem, ptr_mode, offset);

This adds offset to it and changes mode to ptr_mode.  So,
mem is now *(ptr_mode)(&old_mem + offset)

> +	  rtx addr = gen_reg_rtx (ptr_mode);
> +	  emit_move_insn (addr, mem);

We load that value.

> +	  mem = gen_rtx_MEM (ptr_mode, addr);
> +	  mem = adjust_address (mem, QImode, 0);

And here I'm lost why you do that.  If you want to store a single
byte into what it points to, then why don't you just
	mem = gen_rtx_MEM (QImode, addr);
instead of the above two lines?
adjust_address will return a MEM like the above, with offset not adjusted
(as the addition is 0) and mode changed to QImode, but there is no reason
not to create it already in QImode.

> +	  emit_move_insn (mem, const0_rtx);
> +	}
>        else if (use_after_return_class >= 5
>  	       || !set_storage_via_setmem (shadow_mem,
>  					   GEN_INT (sz),
> -- 
> 2.26.2
> 


	Jakub



More information about the Gcc-patches mailing list