diff mbox series

Add static assert about stack alignment (PR sanitizer/82517).

Message ID fb090d21-5683-a406-0836-40386a4f1310@suse.cz
State New
Headers show
Series Add static assert about stack alignment (PR sanitizer/82517). | expand

Commit Message

Martin Liška Jan. 9, 2018, 10:41 a.m. UTC
Hi.

Folowing static assert is added as we may potentially adjust ASAN_SHADOW_GRANULARITY
(via ASAN_SHADOW_SHIFT). The assert ensures stack variables will have sufficient
alignment.

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin

gcc/ChangeLog:

2018-01-09  Martin Liska  <mliska@suse.cz>

	PR sanitizer/82517
	* asan.c (shadow_mem_size): Add static assert.
---
 gcc/asan.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Jakub Jelinek Jan. 9, 2018, 10:47 a.m. UTC | #1
On Tue, Jan 09, 2018 at 11:41:17AM +0100, Martin Liška wrote:
> Folowing static assert is added as we may potentially adjust ASAN_SHADOW_GRANULARITY
> (via ASAN_SHADOW_SHIFT). The assert ensures stack variables will have sufficient
> alignment.
> 
> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
> 
> Ready to be installed?
> Martin
> 
> gcc/ChangeLog:
> 
> 2018-01-09  Martin Liska  <mliska@suse.cz>
> 
> 	PR sanitizer/82517
> 	* asan.c (shadow_mem_size): Add static assert.

STATIC_ASSERT assumes all the 3 macros expand to constants, not sure if we
for the future can always guarantee it, e.g. MAX_SUPPORTED_STACK_ALIGNMENT
could be dependent on some command line option etc.
Use gcc_assert or gcc_checking_assert instead?

	Jakub
Martin Liška Jan. 9, 2018, 11:47 a.m. UTC | #2
On 01/09/2018 11:47 AM, Jakub Jelinek wrote:
> On Tue, Jan 09, 2018 at 11:41:17AM +0100, Martin Liška wrote:
>> Folowing static assert is added as we may potentially adjust ASAN_SHADOW_GRANULARITY
>> (via ASAN_SHADOW_SHIFT). The assert ensures stack variables will have sufficient
>> alignment.
>>
>> Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.
>>
>> Ready to be installed?
>> Martin
>>
>> gcc/ChangeLog:
>>
>> 2018-01-09  Martin Liska  <mliska@suse.cz>
>>
>> 	PR sanitizer/82517
>> 	* asan.c (shadow_mem_size): Add static assert.
> 
> STATIC_ASSERT assumes all the 3 macros expand to constants, not sure if we
> for the future can always guarantee it, e.g. MAX_SUPPORTED_STACK_ALIGNMENT
> could be dependent on some command line option etc.
> Use gcc_assert or gcc_checking_assert instead?

Agree, I've changed that to gcc_assert and installed the patch as r256378.

Martin

> 
> 	Jakub
>
diff mbox series

Patch

diff --git a/gcc/asan.c b/gcc/asan.c
index 53630088b76..0421d4282a1 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -1228,6 +1228,11 @@  asan_function_start (void)
 static unsigned HOST_WIDE_INT
 shadow_mem_size (unsigned HOST_WIDE_INT size)
 {
+  /* It must be possible to align stack variables to granularity
+     of shadow memory.  */
+  STATIC_ASSERT (BITS_PER_UNIT
+		 * ASAN_SHADOW_GRANULARITY <= MAX_SUPPORTED_STACK_ALIGNMENT);
+
   return ROUND_UP (size, ASAN_SHADOW_GRANULARITY) / ASAN_SHADOW_GRANULARITY;
 }