diff options
author | Martin Liska <mliska@suse.cz> | 2021-02-23 09:01:53 +0100 |
---|---|---|
committer | Martin Liska <mliska@suse.cz> | 2021-02-23 16:03:09 +0100 |
commit | 3f8384545784696fbd66aaec24a998a819e912c5 (patch) | |
tree | 58147e9a0e45c847d92ba489a54b5a973ecdb31f /gcc | |
parent | 5bd7afb71fca3a5a6e9f8586d86903bae1849193 (diff) | |
download | gcc-3f8384545784696fbd66aaec24a998a819e912c5.zip gcc-3f8384545784696fbd66aaec24a998a819e912c5.tar.gz gcc-3f8384545784696fbd66aaec24a998a819e912c5.tar.bz2 |
IPA ICF + ASAN: do not merge vars with different alignment
gcc/ChangeLog:
PR sanitizer/99168
* ipa-icf.c (sem_variable::merge): Do not merge 2 variables
with different alignment. That leads to an invalid red zone
size allocated in runtime.
gcc/testsuite/ChangeLog:
PR sanitizer/99168
* c-c++-common/asan/pr99168.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ipa-icf.c | 13 | ||||
-rw-r--r-- | gcc/testsuite/c-c++-common/asan/pr99168.c | 26 |
2 files changed, 39 insertions, 0 deletions
diff --git a/gcc/ipa-icf.c b/gcc/ipa-icf.c index 687ad8d..5dd33a7 100644 --- a/gcc/ipa-icf.c +++ b/gcc/ipa-icf.c @@ -88,6 +88,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-vector-builder.h" #include "symtab-thunks.h" #include "alias.h" +#include "asan.h" using namespace ipa_icf_gimple; @@ -2022,6 +2023,18 @@ sem_variable::merge (sem_item *alias_item) return false; } + if (DECL_ALIGN (original->decl) != DECL_ALIGN (alias->decl) + && (sanitize_flags_p (SANITIZE_ADDRESS, original->decl) + || sanitize_flags_p (SANITIZE_ADDRESS, alias->decl))) + { + if (dump_enabled_p ()) + dump_printf (MSG_MISSED_OPTIMIZATION, + "Not unifying; " + "ASAN requires equal alignments for original and alias\n"); + + return false; + } + if (DECL_ALIGN (original->decl) < DECL_ALIGN (alias->decl)) { if (dump_enabled_p ()) diff --git a/gcc/testsuite/c-c++-common/asan/pr99168.c b/gcc/testsuite/c-c++-common/asan/pr99168.c new file mode 100644 index 0000000..ed59ffb --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr99168.c @@ -0,0 +1,26 @@ +/* PR sanitizer/99168 */ +/* { dg-do run } */ + +struct my_struct +{ + unsigned long volatile x; +} __attribute__((aligned(128))); + +static int variablek[5][6] = {}; +static struct my_struct variables1 = {0UL}; +static struct my_struct variables2 __attribute__((aligned(32))) = {0UL}; + +int main() { + int i, j; + for (i = 0; i < 5; i++) { + for (j = 0; j < 6; j++) { + __builtin_printf("%d ", variablek[i][j]); + } + } + __builtin_printf("\n"); + + __builtin_printf("%lu\n", variables1.x); + __builtin_printf("%lu\n", variables2.x); + + return 0; +} |