public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH, binutils, ARM 7/11] Support for dedicated stub section with padding
@ 2016-03-29 14:40 Thomas Preudhomme
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Preudhomme @ 2016-03-29 14:40 UTC (permalink / raw)
  To: binutils

Hi,

This patch is part of a patch series to add support for ARMv8-M security 
extension[1] to GNU ld. This specific patch adds support for padding the 
dedicated section of a given veneer type.

ARM v8-M security extensions require [3] secure gateway veneers to be 
generated for (secure) entry function in order for code to transition from 
non-secure state to secure state when calling these entry function. One 
requirement for these veneers [4] is that a consecutive sequence of them must 
be padded to 32 bytes to make sure that no bit pattern of the SG instruction 
is found in non secure callable memory. This patch adds support for padding a 
dedicated section used for a given type of veneers, thus respecting this 
requirement.


[1] Software requirements for ARMv8-M security extension are described in 
document ARM-ECM-0359818 [2]
[2] Available on http://infocenter.arm.com in Developer guides and articles > 
Software development > ARM®v8-M Security Extensions: Requirements on 
Development Tools
[3] See section 3.4.3 and requirement 44 of ARM-ECM-0359818 [2]
[4] requirement 12 and 13 and following comment of ARM-ECM-0359818 [2]

ChangeLog entry is as follows:


*** bfd/ChangeLog ***

2016-02-17  Thomas Preud'homme  <thomas.preudhomme@arm.com>

        * elf32-arm.c (arm_dedicated_stub_section_padding): New function.
        (elf32_arm_size_stubs): Declare stub_type in a more outer scope and
        account for padding for stub section requiring one.
        (elf32_arm_build_stubs): Add comment to stress the importance of
        zeroing veneer section content.


diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 
94a3d197cae5fbf173da11dd4a50350e5ac68bb3..8b3dc8fc2dce2a4dbb1b5dbea6e94ee287111286 
100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -4464,6 +4464,24 @@ arm_stub_sym_claimed (enum elf32_arm_stub_type 
stub_type)
   abort ();  /* Should be unreachable.  */
 }
 
+/* Returns the padding needed for the dedicated section used stubs of type
+   STUB_TYPE.  */
+
+static int
+arm_dedicated_stub_section_padding (enum elf32_arm_stub_type stub_type)
+{
+  if (stub_type >= max_stub_type)
+    abort ();  /* Should be unreachable.  */
+
+  switch (stub_type)
+    {
+    default:
+      return 0;
+    }
+
+  abort ();  /* Should be unreachable.  */
+}
+
 static bfd_boolean
 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
 		    void * in_arg)
@@ -5440,6 +5458,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
       bfd *input_bfd;
       unsigned int bfd_indx;
       asection *stub_sec;
+      enum elf32_arm_stub_type stub_type;
       bfd_boolean stub_changed = FALSE;
       unsigned prev_num_a8_fixes = num_a8_fixes;
 
@@ -5495,7 +5514,6 @@ elf32_arm_size_stubs (bfd *output_bfd,
 	      for (; irela < irelaend; irela++)
 		{
 		  unsigned int r_type, r_indx;
-		  enum elf32_arm_stub_type stub_type;
 		  asection *sym_sec;
 		  bfd_vma sym_value;
 		  bfd_vma destination;
@@ -5795,7 +5813,27 @@ elf32_arm_size_stubs (bfd *output_bfd,
 	  stub_sec->size = 0;
 	}
 
+      /* Compute stub section size, considering padding.  */
       bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
+      for (stub_type = arm_stub_none + 1; stub_type < max_stub_type;
+	   stub_type++)
+	{
+	  int size, padding;
+	  asection **stub_sec_p;
+
+	  padding = arm_dedicated_stub_section_padding (stub_type);
+	  stub_sec_p = arm_dedicated_stub_input_section_ptr (htab, stub_type);
+	  /* Skip if no stub input section or no stub section padding
+	     required.  */
+	  if ((stub_sec_p != NULL && *stub_sec_p == NULL) || padding == 0)
+	    continue;
+	  /* Stub section padding required but no dedicated section.  */
+	  BFD_ASSERT (stub_sec_p);
+
+	  size = (*stub_sec_p)->size;
+	  size = (size + padding - 1) & ~(padding - 1);
+	  (*stub_sec_p)->size = size;
+	}
 
       /* Add Cortex-A8 erratum veneers to stub section sizes too.  */
       if (htab->fix_cortex_a8)
@@ -5903,7 +5941,8 @@ elf32_arm_build_stubs (struct bfd_link_info *info)
       if (!strstr (stub_sec->name, STUB_SUFFIX))
 	continue;
 
-      /* Allocate memory to hold the linker stubs.  */
+      /* Allocate memory to hold the linker stubs.  Zeroing the stub sections
+	 must at least be done for stub section requiring padding.  */
       size = stub_sec->size;
       stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, 
size);
       if (stub_sec->contents == NULL && size != 0)



The patch doesn't show any regression when running the binutils-gdb testsuite 
for the arm-none-eabi target.

Best regards,

Thomas

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH, binutils, ARM 7/11] Support for dedicated stub section with padding
       [not found] <6199794.MLGQcacbfr@e108577-lin>
@ 2016-05-05 10:27 ` Thomas Preudhomme
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Preudhomme @ 2016-05-05 10:27 UTC (permalink / raw)
  To: binutils

On Tuesday 29 March 2016 15:40:17 Thomas Preudhomme wrote:
> Hi,
> 
> This patch is part of a patch series to add support for ARMv8-M Security
> Extensions[1] to GNU ld. This specific patch adds support for padding the
> dedicated section of a given veneer type.
> 
> ARM v8-M Security Extensions require [3] secure gateway veneers to be
> generated for (secure) entry function in order for code to transition from
> non-secure state to secure state when calling these entry function. One
> requirement for these veneers [4] is that a consecutive sequence of them
> must be padded to 32 bytes to make sure that no bit pattern of the SG
> instruction is found in non secure callable memory. This patch adds support
> for padding a dedicated section used for a given type of veneers, thus
> respecting this requirement.
> 
> 
> [1] Software requirements for ARMv8-M security extension are described in
> document ARM-ECM-0359818 [2]
> [2] Available on http://infocenter.arm.com in Developer guides and articles
> > Software development > ARM®v8-M Security Extensions: Requirements on
> Development Tools
> [3] See section 3.4.3 and requirement 44 of ARM-ECM-0359818 [2]
> [4] requirement 12 and 13 and following comment of ARM-ECM-0359818 [2]
> 

Please find an updated version without the switch case for the 
arm_dedicated_stub_* functions.

ChangeLog entry is unchanged:

*** bfd/ChangeLog ***

2016-02-17  Thomas Preud'homme  <thomas.preudhomme@arm.com>

        * elf32-arm.c (arm_dedicated_stub_section_padding): New function.
        (elf32_arm_size_stubs): Declare stub_type in a more outer scope and
        account for padding for stub section requiring one.
        (elf32_arm_build_stubs): Add comment to stress the importance of
        zeroing veneer section content.


diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 
ab878b20905c907b3496317c7ed1c9c698d850c9..f2b50667ef50572488e4d868ce40e67580356343 
100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -4435,6 +4435,18 @@ arm_stub_sym_claimed (enum elf32_arm_stub_type 
stub_type)
   return FALSE;
 }
 
+/* Returns the padding needed for the dedicated section used stubs of type
+   STUB_TYPE.  */
+
+static int
+arm_dedicated_stub_section_padding (enum elf32_arm_stub_type stub_type)
+{
+  if (stub_type >= max_stub_type)
+    abort ();  /* Should be unreachable.  */
+
+  return 0;
+}
+
 static bfd_boolean
 arm_build_one_stub (struct bfd_hash_entry *gen_entry,
 		    void * in_arg)
@@ -5411,6 +5423,7 @@ elf32_arm_size_stubs (bfd *output_bfd,
       bfd *input_bfd;
       unsigned int bfd_indx;
       asection *stub_sec;
+      enum elf32_arm_stub_type stub_type;
       bfd_boolean stub_changed = FALSE;
       unsigned prev_num_a8_fixes = num_a8_fixes;
 
@@ -5466,7 +5479,6 @@ elf32_arm_size_stubs (bfd *output_bfd,
 	      for (; irela < irelaend; irela++)
 		{
 		  unsigned int r_type, r_indx;
-		  enum elf32_arm_stub_type stub_type;
 		  asection *sym_sec;
 		  bfd_vma sym_value;
 		  bfd_vma destination;
@@ -5765,7 +5777,27 @@ elf32_arm_size_stubs (bfd *output_bfd,
 	  stub_sec->size = 0;
 	}
 
+      /* Compute stub section size, considering padding.  */
       bfd_hash_traverse (&htab->stub_hash_table, arm_size_one_stub, htab);
+      for (stub_type = arm_stub_none + 1; stub_type < max_stub_type;
+	   stub_type++)
+	{
+	  int size, padding;
+	  asection **stub_sec_p;
+
+	  padding = arm_dedicated_stub_section_padding (stub_type);
+	  stub_sec_p = arm_dedicated_stub_input_section_ptr (htab, stub_type);
+	  /* Skip if no stub input section or no stub section padding
+	     required.  */
+	  if ((stub_sec_p != NULL && *stub_sec_p == NULL) || padding == 0)
+	    continue;
+	  /* Stub section padding required but no dedicated section.  */
+	  BFD_ASSERT (stub_sec_p);
+
+	  size = (*stub_sec_p)->size;
+	  size = (size + padding - 1) & ~(padding - 1);
+	  (*stub_sec_p)->size = size;
+	}
 
       /* Add Cortex-A8 erratum veneers to stub section sizes too.  */
       if (htab->fix_cortex_a8)
@@ -5873,7 +5905,8 @@ elf32_arm_build_stubs (struct bfd_link_info *info)
       if (!strstr (stub_sec->name, STUB_SUFFIX))
 	continue;
 
-      /* Allocate memory to hold the linker stubs.  */
+      /* Allocate memory to hold the linker stubs.  Zeroing the stub sections
+	 must at least be done for stub section requiring padding.  */
       size = stub_sec->size;
       stub_sec->contents = (unsigned char *) bfd_zalloc (htab->stub_bfd, 
size);
       if (stub_sec->contents == NULL && size != 0)


Best regards,

Thomas

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-05 10:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-29 14:40 [PATCH, binutils, ARM 7/11] Support for dedicated stub section with padding Thomas Preudhomme
     [not found] <6199794.MLGQcacbfr@e108577-lin>
2016-05-05 10:27 ` Thomas Preudhomme

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