public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Use relro section for capabilty relocations
@ 2021-09-21  9:13 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2021-09-21  9:13 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:d15d06b798a812989a840fcb4ec23a96b78a5ca6

commit d15d06b798a812989a840fcb4ec23a96b78a5ca6
Author: Alex Coplan <alex.coplan@arm.com>
Date:   Wed Jul 21 12:38:08 2021 +0100

    Use relro section for capabilty relocations
    
    Capabilities that point to objects in the current TU need to be
    relocated dynamically. Hence, these can't be in the .rodata section.
    Instead, they must be in the .rel.ro section.
    
    gcc/ChangeLog:
    
            * output.h (RELOC_CAPABILITY): New.
            * targhooks.c (default_reloc_rw_mask): Set RELOC_CAPABILITY bit.
            * varasm.c (compute_reloc_for_constant): Set RELOC_CAPABILITY
            appropriately.
            (compute_reloc_for_rtx): Likewise.
            (categorize_decl_for_section): Adjust check for local bit.
            (default_elf_select_rtx_section): Adjust check for local bit.

Diff:
---
 gcc/output.h    |  3 +++
 gcc/targhooks.c |  2 +-
 gcc/varasm.c    | 22 ++++++++++++++++------
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/gcc/output.h b/gcc/output.h
index 6503a02486f..378fd196b2f 100644
--- a/gcc/output.h
+++ b/gcc/output.h
@@ -349,6 +349,9 @@ extern tree last_assemble_variable_decl;
 
 extern bool first_function_block_is_cold;
 
+/* RELOC flags as for SELECT_SECTION.  */
+#define RELOC_CAPABILITY 4
+
 /* Decide whether DECL needs to be in a writable section.
    RELOC is the same as for SELECT_SECTION.  */
 extern bool decl_readonly_section (const_tree, int);
diff --git a/gcc/targhooks.c b/gcc/targhooks.c
index e7da0b67625..6315bcba8f2 100644
--- a/gcc/targhooks.c
+++ b/gcc/targhooks.c
@@ -1178,7 +1178,7 @@ default_secondary_memory_needed_mode (machine_mode mode)
 int
 default_reloc_rw_mask (void)
 {
-  return flag_pic ? 3 : 0;
+  return (flag_pic ? 3 : 0) | RELOC_CAPABILITY;
 }
 
 /* By default, address diff vectors are generated
diff --git a/gcc/varasm.c b/gcc/varasm.c
index 96fa820c3c7..b31ec5b632a 100644
--- a/gcc/varasm.c
+++ b/gcc/varasm.c
@@ -4319,6 +4319,9 @@ compute_reloc_for_constant (tree exp)
 	  break;
 	}
 
+      if (capability_type_p (TREE_TYPE (exp)))
+	reloc |= RELOC_CAPABILITY;
+
       if (!targetm.binds_local_p (tem))
 	reloc |= 2;
       else
@@ -6792,12 +6795,12 @@ categorize_decl_for_section (const_tree decl, int reloc)
 	     do something.  If so, we wish to segregate the data in order to
 	     minimize cache misses inside the dynamic linker.  */
 	  if (reloc & targetm.asm_out.reloc_rw_mask ())
-	    ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
+	    ret = reloc & 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
 	  else
 	    ret = SECCAT_DATA;
 	}
       else if (reloc & targetm.asm_out.reloc_rw_mask ())
-	ret = reloc == 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
+	ret = reloc & 1 ? SECCAT_DATA_REL_RO_LOCAL : SECCAT_DATA_REL_RO;
       else if (reloc || flag_merge_constants < 2
 	       || ((flag_sanitize & SANITIZE_ADDRESS)
 		   /* PR 81697: for architectures that use section anchors we
@@ -7049,24 +7052,31 @@ compute_reloc_for_rtx_1 (const_rtx x)
 static int
 compute_reloc_for_rtx (const_rtx x)
 {
+  int reloc = 0;
+
   switch (GET_CODE (x))
     {
     case SYMBOL_REF:
     case LABEL_REF:
-      return compute_reloc_for_rtx_1 (x);
+      reloc = compute_reloc_for_rtx_1 (x);
+      break;
 
     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 *
@@ -7090,7 +7100,7 @@ default_elf_select_rtx_section (machine_mode mode, rtx x,
 
   if (reloc & targetm.asm_out.reloc_rw_mask ())
     {
-      if (reloc == 1)
+      if (reloc & 1)
 	return get_named_section (NULL, ".data.rel.ro.local", 1);
       else
 	return get_named_section (NULL, ".data.rel.ro", 3);


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

only message in thread, other threads:[~2021-09-21  9:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-21  9:13 [gcc(refs/vendors/ARM/heads/morello)] Use relro section for capabilty relocations 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).