aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorAndreas Krebbel <krebbel@linux.ibm.com>2023-12-18 17:54:42 +0100
committerAndreas Krebbel <krebbel@linux.ibm.com>2023-12-18 19:42:37 +0100
commitf85fdf59c91fe4aa56633347268d144d3e075844 (patch)
tree6a1a6648b4c4d60b08e0c5f1d583f55120a60abd /gcc
parent4554a151d0ec62332c332175ec1017f853006b60 (diff)
downloadgcc-f85fdf59c91fe4aa56633347268d144d3e075844.zip
gcc-f85fdf59c91fe4aa56633347268d144d3e075844.tar.gz
gcc-f85fdf59c91fe4aa56633347268d144d3e075844.tar.bz2
IBM Z: Cover weak symbols with -munaligned-symbols
With the recently introduced -munaligned-symbols option byte-sized variables which are resolved externally are considered to be potentially misaligned. However, this should rather also be applied to symbols which resolve locally if they are weak. Done with this patch. gcc/ChangeLog: * config/s390/s390.cc (s390_encode_section_info): Replace SYMBOL_REF_LOCAL_P with decl_binds_to_current_def_p. gcc/testsuite/ChangeLog: * gcc.target/s390/unaligned-2.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/config/s390/s390.cc6
-rw-r--r--gcc/testsuite/gcc.target/s390/unaligned-2.c16
2 files changed, 18 insertions, 4 deletions
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 044de87..a5c36b4 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -13802,10 +13802,8 @@ s390_encode_section_info (tree decl, rtx rtl, int first)
byte aligned as mandated by our ABI. This behavior can be
overridden for external symbols with the -munaligned-symbols
switch. */
- if (DECL_ALIGN (decl) % 16
- && (DECL_USER_ALIGN (decl)
- || (!SYMBOL_REF_LOCAL_P (XEXP (rtl, 0))
- && s390_unaligned_symbols_p)))
+ if ((DECL_USER_ALIGN (decl) && DECL_ALIGN (decl) % 16)
+ || (s390_unaligned_symbols_p && !decl_binds_to_current_def_p (decl)))
SYMBOL_FLAG_SET_NOTALIGN2 (XEXP (rtl, 0));
else if (DECL_ALIGN (decl) % 32)
SYMBOL_FLAG_SET_NOTALIGN4 (XEXP (rtl, 0));
diff --git a/gcc/testsuite/gcc.target/s390/unaligned-2.c b/gcc/testsuite/gcc.target/s390/unaligned-2.c
new file mode 100644
index 0000000..c1ece6d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/s390/unaligned-2.c
@@ -0,0 +1,16 @@
+/* weak symbols might get overridden in another module by symbols
+ which are not aligned on a 2-byte boundary. Although this violates
+ the zABI we try to handle this gracefully by not using larl on
+ these symbols if -munaligned-symbols has been specified. */
+
+/* { dg-do compile } */
+/* { dg-options "-O3 -march=z900 -fno-section-anchors -munaligned-symbols" } */
+unsigned char __attribute__((weak)) weaksym = 0;
+
+unsigned char
+foo ()
+{
+ return weaksym;
+}
+
+/* { dg-final { scan-assembler-times "larl\t%r\[0-9\]*,weaksym\n" 0 } } */