asan: fix RTX emission for ilp32

Message ID dc8e753a-a797-ab17-c386-382e588e28d6@suse.cz
State New
Headers show
Series
  • asan: fix RTX emission for ilp32
Related show

Commit Message

Martin Liška June 11, 2020, 8:12 a.m.
Hello.

There's a patch for ilp32 where we should use Pmode instead of ptr_mode.

Patch can bootstrap on x86_64-linux-gnu and survives regression tests.

Ready to be installed?
Thanks,
Martin

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(-)

-- 
2.26.2

Comments

Marek Polacek via Gcc-patches June 11, 2020, 8:50 a.m. | #1
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
Martin Liška June 11, 2020, 9 a.m. | #2
On 6/11/20 10:50 AM, Jakub Jelinek wrote:
> 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.


Thank you for help, I'm going to push the patch.

Martin

> 

>>   	  mem = gen_rtx_MEM (QImode, addr);

>>   	  emit_move_insn (mem, const0_rtx);

>> -- 

>> 2.26.2

> 

> 	Jakub

>

Patch

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);
  	  emit_move_insn (addr, mem);
  	  mem = gen_rtx_MEM (QImode, addr);
  	  emit_move_insn (mem, const0_rtx);