public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andreas Krebbel <krebbel@linux.ibm.com>
To: gcc-patches@gcc.gnu.org
Subject: [Committed] IBM Z: Cover weak symbols with -munaligned-symbols
Date: Mon, 18 Dec 2023 19:52:51 +0100	[thread overview]
Message-ID: <20231218185251.57671-1-krebbel@linux.ibm.com> (raw)

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.

Committed to mainline.

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.
---
 gcc/config/s390/s390.cc                     |  6 ++----
 gcc/testsuite/gcc.target/s390/unaligned-2.c | 16 ++++++++++++++++
 2 files changed, 18 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/s390/unaligned-2.c

diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 044de874590..a5c36b43972 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 00000000000..c1ece6d5935
--- /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 } } */
-- 
2.43.0


                 reply	other threads:[~2023-12-18 18:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231218185251.57671-1-krebbel@linux.ibm.com \
    --to=krebbel@linux.ibm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).