aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/s390
diff options
context:
space:
mode:
authorAndreas Krebbel <krebbel@linux.ibm.com>2024-03-14 09:54:31 +0100
committerAndreas Krebbel <krebbel@linux.ibm.com>2024-03-14 10:51:57 +0100
commit90a7da695284da49182446ba45fbcddb9eb7fc91 (patch)
tree6ba55dd468343a688561e0af94262a465f73ff08 /gcc/config/s390
parent8f6e0814b4bfd0a399055e9214562aebfcd902ad (diff)
downloadgcc-90a7da695284da49182446ba45fbcddb9eb7fc91.zip
gcc-90a7da695284da49182446ba45fbcddb9eb7fc91.tar.gz
gcc-90a7da695284da49182446ba45fbcddb9eb7fc91.tar.bz2
IBM Z: Fix -munaligned-symbols
With this fix we make sure that only symbols with a natural alignment smaller than 2 are considered misaligned with -munaligned-symbols. Background is that -munaligned-symbols is only supposed to affect symbols whose natural alignment wouldn't be enough to fulfill our ABI requirement of having all symbols at even addresses. Because only these are the cases where we differ from other architectures. gcc/ChangeLog: * config/s390/s390.cc (s390_encode_section_info): Adjust the check for misaligned symbols. * config/s390/s390.opt: Improve documentation. gcc/testsuite/ChangeLog: * gcc.target/s390/aligned-1.c: Add weak and void variables incorporating the cases from unaligned-2.c. * gcc.target/s390/unaligned-1.c: Likewise. * gcc.target/s390/unaligned-2.c: Removed.
Diffstat (limited to 'gcc/config/s390')
-rw-r--r--gcc/config/s390/s390.cc15
-rw-r--r--gcc/config/s390/s390.opt7
2 files changed, 16 insertions, 6 deletions
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index e639655..372a232 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -13802,10 +13802,19 @@ s390_encode_section_info (tree decl, rtx rtl, int first)
that can go wrong (i.e. no FUNC_DECLs).
All symbols without an explicit alignment are assumed to be 2
byte aligned as mandated by our ABI. This behavior can be
- overridden for external symbols with the -munaligned-symbols
- switch. */
+ overridden for external and weak symbols with the
+ -munaligned-symbols switch.
+ For all external symbols without explicit alignment
+ DECL_ALIGN is already trimmed down to 8, however for weak
+ symbols this does not happen. These cases are catched by the
+ type size check. */
+ const_tree size = TYPE_SIZE (TREE_TYPE (decl));
+ unsigned HOST_WIDE_INT size_num = (tree_fits_uhwi_p (size)
+ ? tree_to_uhwi (size) : 0);
if ((DECL_USER_ALIGN (decl) && DECL_ALIGN (decl) % 16)
- || (s390_unaligned_symbols_p && !decl_binds_to_current_def_p (decl)))
+ || (s390_unaligned_symbols_p
+ && !decl_binds_to_current_def_p (decl)
+ && (DECL_USER_ALIGN (decl) ? DECL_ALIGN (decl) % 16 : size_num < 16)))
SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl, 0));
else if (DECL_ALIGN (decl) % 32)
SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl, 0));
diff --git a/gcc/config/s390/s390.opt b/gcc/config/s390/s390.opt
index 901ae4b..a5b5aa9 100644
--- a/gcc/config/s390/s390.opt
+++ b/gcc/config/s390/s390.opt
@@ -332,7 +332,8 @@ Store all argument registers on the stack.
munaligned-symbols
Target Var(s390_unaligned_symbols_p) Init(0)
-Assume external symbols to be potentially unaligned. By default all
-symbols without explicit alignment are assumed to reside on a 2 byte
-boundary as mandated by the IBM Z ABI.
+Assume external symbols, whose natural alignment would be 1, to be
+potentially unaligned. By default all symbols without explicit
+alignment are assumed to reside on a 2 byte boundary as mandated by
+the IBM Z ABI.