aboutsummaryrefslogtreecommitdiff
path: root/gcc/varasm.c
diff options
context:
space:
mode:
authorMaxim Ostapenko <m.ostapenko@samsung.com>2017-11-30 21:38:16 +0000
committerMaxim Ostapenko <chefmax@gcc.gnu.org>2017-11-30 23:38:16 +0200
commit1069dc251bd97f187ff42b543ca90e08203465ae (patch)
tree3885b39c1cc27358616aae7eb80eaf44a07faa7d /gcc/varasm.c
parent75ad35b5c4a40ff92ead1ea49aebf68cafe2fa12 (diff)
downloadgcc-1069dc251bd97f187ff42b543ca90e08203465ae.zip
gcc-1069dc251bd97f187ff42b543ca90e08203465ae.tar.gz
gcc-1069dc251bd97f187ff42b543ca90e08203465ae.tar.bz2
re PR sanitizer/81697 (Incorrect ASan global variables alignment on arm)
gcc/ 2017-11-30 Maxim Ostapenko <m.ostapenko@samsung.com> PR sanitizer/81697 * asan.c (asan_protect_global): Add new ignore_decl_rtl_set_p parameter. Return true if ignore_decl_rtl_set_p is true and other conditions are satisfied. * asan.h (asan_protect_global): Add new parameter. * varasm.c (categorize_decl_for_section): Pass true as second parameter to asan_protect_global calls. gcc/testsuite/ 2017-11-30 Maxim Ostapenko <m.ostapenko@samsung.com> PR sanitizer/81697 * c-c++-common/asan/pr81697.c: New test. From-SVN: r255283
Diffstat (limited to 'gcc/varasm.c')
-rw-r--r--gcc/varasm.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 0c7b26e..392ac44 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -6530,6 +6530,7 @@ categorize_decl_for_section (const_tree decl, int reloc)
}
else if (VAR_P (decl))
{
+ tree d = CONST_CAST_TREE (decl);
if (bss_initializer_p (decl))
ret = SECCAT_BSS;
else if (! TREE_READONLY (decl)
@@ -6550,7 +6551,17 @@ categorize_decl_for_section (const_tree decl, int reloc)
ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
else if (reloc || flag_merge_constants < 2
|| ((flag_sanitize & SANITIZE_ADDRESS)
- && asan_protect_global (CONST_CAST_TREE (decl))))
+ /* PR 81697: for architectures that use section anchors we
+ need to ignore DECL_RTL_SET_P (decl) for string constants
+ inside this asan_protect_global call because otherwise
+ we'll wrongly put them into SECCAT_RODATA_MERGE_CONST
+ section, set DECL_RTL (decl) later on and add DECL to
+ protected globals via successive asan_protect_global
+ calls. In this scenario we'll end up with wrong
+ alignment of these strings at runtime and possible ASan
+ false positives. */
+ && asan_protect_global (d, use_object_blocks_p ()
+ && use_blocks_for_decl_p (d))))
/* C and C++ don't allow different variables to share the same
location. -fmerge-all-constants allows even that (at the
expense of not conforming). */