public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Don't put compile-time CADI constants in .data.rel.ro
@ 2022-05-06 14:45 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:45 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:538b00262bd311dfed679093ef1411002ababa72

commit 538b00262bd311dfed679093ef1411002ababa72
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Tue May 3 10:46:58 2022 +0100

    Don't put compile-time CADI constants in .data.rel.ro
    
    We were putting compile-time CADI constants in .data.rel.ro even
    though they don't need relocation.  This isn't wrong in a dynamic
    object, just perhaps a little redundant.  However, the linux
    kernel (rightly) doesn't expect to have to deal with runtime
    relocations, so its linker script checks that .data.rel.ro is empty.
    
    The patch moves the RELOC_CAPABILITY handling from compute_reloc_for_rtx
    to compute_reloc_for_rtx_1 and makes it conditional on seeing an (inner)
    LABEL_REF or SYMBOL_REF.  CONST_NULL-based constants are explicitly
    not included.
    
    This means that we can go back to the trunk version of
    compute_reloc_for_rtx.  That version isn't inherently better than
    the branch-local one, but I thought it might reduce surprises when
    doing a rebase onto a later release.

Diff:
---
 gcc/config/aarch64/aarch64.c                       |  4 +++-
 gcc/output.h                                       |  2 ++
 .../gcc.target/aarch64/morello/const-pool-2.c      |  3 +++
 gcc/varasm.c                                       | 26 +++++++++++-----------
 4 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 2ddfb819899..0879583288f 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -9733,7 +9733,9 @@ aarch64_can_use_per_function_literal_pools_p (const_rtx x)
 {
   /* Real capabilities aren't link-time constants, so putting one in the
      text section would require the text segment to be load-time writable.  */
-  if (!TARGET_CAPABILITY_FAKE && x && CAPABILITY_MODE_P (GET_MODE (x)))
+  if (!TARGET_CAPABILITY_FAKE
+      && x
+      && (compute_reloc_for_rtx (x) & RELOC_CAPABILITY))
     return false;
 
   return (aarch64_pcrelative_literal_loads
diff --git a/gcc/output.h b/gcc/output.h
index f7335da8f17..7fe50f3163a 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -365,6 +365,8 @@ extern bool decl_readonly_section (const_tree, int);
    given a constant expression.  */
 extern int compute_reloc_for_constant (tree);
 
+extern int compute_reloc_for_rtx (const_rtx);
+
 /* User label prefix in effect for this compilation.  */
 extern const char *user_label_prefix;
 
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/const-pool-2.c b/gcc/testsuite/gcc.target/aarch64/morello/const-pool-2.c
new file mode 100644
index 00000000000..987fda71c99
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/const-pool-2.c
@@ -0,0 +1,3 @@
+__intcap_t foo() { return 0x12345678abcdefLL; }
+
+/* { dg-final { scan-assembler-not {\.data\.rel} } } */
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 6dbb478e93e..4ec8ca79205 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -7170,12 +7170,19 @@ default_unique_section (tree decl, int reloc)
 static int
 compute_reloc_for_rtx_1 (const_rtx x)
 {
+  int reloc = 0;
   switch (GET_CODE (x))
     {
     case SYMBOL_REF:
-      return SYMBOL_REF_LOCAL_P (x) ? 1 : 2;
     case LABEL_REF:
-      return 1;
+      if (CAPABILITY_MODE_P (GET_MODE (x)))
+	reloc |= RELOC_CAPABILITY;
+      if (SYMBOL_REF_P (x) && !SYMBOL_REF_LOCAL_P (x))
+	reloc |= 2;
+      else
+	reloc |= 1;
+      return reloc;
+
     default:
       return 0;
     }
@@ -7185,34 +7192,27 @@ compute_reloc_for_rtx_1 (const_rtx x)
    is a mask for which bit 1 indicates a global relocation, and bit 0
    indicates a local relocation.  */
 
-static int
+int
 compute_reloc_for_rtx (const_rtx x)
 {
-  int reloc = 0;
-
   switch (GET_CODE (x))
     {
     case SYMBOL_REF:
     case LABEL_REF:
-      reloc = compute_reloc_for_rtx_1 (x);
-      break;
+      return compute_reloc_for_rtx_1 (x);
 
     case CONST:
       {
+	int reloc = 0;
 	subrtx_iterator::array_type array;
 	FOR_EACH_SUBRTX (iter, array, x, ALL)
 	  reloc |= compute_reloc_for_rtx_1 (*iter);
+	return reloc;
       }
-      break;
 
     default:
       return 0;
     }
-
-  if (CAPABILITY_MODE_P (GET_MODE (x)))
-    reloc |= RELOC_CAPABILITY;
-
-  return reloc;
 }
 
 section *


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-06 14:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:45 [gcc(refs/vendors/ARM/heads/morello)] Don't put compile-time CADI constants in .data.rel.ro Matthew Malcomson

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).