]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Prevent SG veneers from being collected by --gc-section
authorThomas Preud'homme <thomas.preudhomme@arm.com>
Mon, 20 Jun 2016 11:06:31 +0000 (12:06 +0100)
committerThomas Preud'homme <thomas.preudhomme@arm.com>
Mon, 20 Jun 2016 11:09:31 +0000 (12:09 +0100)
2016-06-20  Thomas Preud'homme  <thomas.preudhomme@arm.com>

bfd/
* elf32-arm.c (elf32_arm_gc_mark_extra_sections): Mark sections holding
ARMv8-M secure entry functions.

ld/testsuite/
* ld-arm/arm-elf.exp (Secure gateway veneers (ARMv8-M Baseline)): Also
pass --gc-sections to ld.
(Secure gateway veneers (ARMv8-M Mainline)): Likewise.

bfd/ChangeLog.arm
bfd/elf32-arm.c
ld/testsuite/ChangeLog.arm
ld/testsuite/ld-arm/arm-elf.exp

index 0c7dbc37866e845346084734af7b761d3adcb12a..0e613565b4653f19364e541a8d1a81591e30741c 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-20  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       * elf32-arm.c (elf32_arm_gc_mark_extra_sections): Mark sections holding
+       ARMv8-M secure entry functions.
+
 2016-05-20  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * elf32-arm.c (enum elf32_arm_stub_type): Remove
index 417b76ccc733401247a364515711fcb85ee38088..588f832cce261032b7a1bb0d217bad8f8e2ae0dd 100644 (file)
@@ -14620,7 +14620,11 @@ elf32_arm_check_relocs (bfd *abfd, struct bfd_link_info *info,
 }
 
 /* Unwinding tables are not referenced directly.  This pass marks them as
-   required if the corresponding code section is marked.  */
+   required if the corresponding code section is marked.  Similarly, ARMv8-M
+   secure entry functions can only be referenced by SG veneers which are
+   created after the GC process. They need to be marked in case they reside in
+   their own section (as would be the case if code was compiled with
+   -ffunction-sections).  */
 
 static bfd_boolean
 elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
@@ -14628,10 +14632,21 @@ elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
 {
   bfd *sub;
   Elf_Internal_Shdr **elf_shdrp;
-  bfd_boolean again;
+  asection *cmse_sec;
+  obj_attribute *out_attr;
+  Elf_Internal_Shdr *symtab_hdr;
+  unsigned i, sym_count, ext_start;
+  const struct elf_backend_data *bed;
+  struct elf_link_hash_entry **sym_hashes;
+  struct elf32_arm_link_hash_entry *cmse_hash;
+  bfd_boolean again, is_v8m, first_bfd_browse = TRUE;
 
   _bfd_elf_gc_mark_extra_sections (info, gc_mark_hook);
 
+  out_attr = elf_known_obj_attributes_proc (info->output_bfd);
+  is_v8m = out_attr[Tag_CPU_arch].i >= TAG_CPU_ARCH_V8M_BASE
+          && out_attr[Tag_CPU_arch_profile].i == 'M';
+
   /* Marking EH data may cause additional code sections to be marked,
      requiring multiple passes.  */
   again = TRUE;
@@ -14662,7 +14677,34 @@ elf32_arm_gc_mark_extra_sections (struct bfd_link_info *info,
                    return FALSE;
                }
            }
+
+         /* Mark section holding ARMv8-M secure entry functions.  We mark all
+            of them so no need for a second browsing.  */
+         if (is_v8m && first_bfd_browse)
+           {
+             sym_hashes = elf_sym_hashes (sub);
+             bed = get_elf_backend_data (sub);
+             symtab_hdr = &elf_tdata (sub)->symtab_hdr;
+             sym_count = symtab_hdr->sh_size / bed->s->sizeof_sym;
+             ext_start = symtab_hdr->sh_info;
+
+             /* Scan symbols.  */
+             for (i = ext_start; i < sym_count; i++)
+               {
+                 cmse_hash = elf32_arm_hash_entry (sym_hashes[i - ext_start]);
+
+                 /* Assume it is a special symbol.  If not, cmse_scan will
+                    warn about it and user can do something about it.  */
+                 if (ARM_GET_SYM_CMSE_SPCL (cmse_hash->root.target_internal))
+                   {
+                     cmse_sec = cmse_hash->root.root.u.def.section;
+                     if (!_bfd_elf_gc_mark (info, cmse_sec, gc_mark_hook))
+                       return FALSE;
+                   }
+               }
+           }
        }
+      first_bfd_browse = FALSE;
     }
 
   return TRUE;
index 1ad82f502d2a5087f2f2403471e83c002452ea64..f8327172f5e39fd3775bee030132b00770cad675 100644 (file)
@@ -1,22 +1,28 @@
+2016-06-20  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+       * ld-arm/arm-elf.exp (Secure gateway veneers (ARMv8-M Baseline)): Also
+       pass --gc-sections to ld.
+       (Secure gateway veneers (ARMv8-M Mainline)): Likewise.
+
 2016-03-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
-       * testsuite/ld-arm/cmse-implib.s: Add input import library testing.
-       * testsuite/ld-arm/cmse-implib.rd: Update accordingly.
-       * testsuite/ld-arm/cmse-new-implib.out: New file.
-       * testsuite/ld-arm/cmse-new-implib.rd: Likewise.
-       * testsuite/ld-arm/cmse-new-implib-no-output.out: Likewise.
-       * testsuite/ld-arm/cmse-new-earlier-later-implib.out: Likewise.
-       * testsuite/ld-arm/cmse-new-comeback-implib.rd: Likewise.
-       * testsuite/ld-arm/cmse-new-wrong-implib.out: Likewise.
+       * ld-arm/cmse-implib.s: Add input import library testing.
+       * ld-arm/cmse-implib.rd: Update accordingly.
+       * ld-arm/cmse-new-implib.out: New file.
+       * ld-arm/cmse-new-implib.rd: Likewise.
+       * ld-arm/cmse-new-implib-no-output.out: Likewise.
+       * ld-arm/cmse-new-earlier-later-implib.out: Likewise.
+       * ld-arm/cmse-new-comeback-implib.rd: Likewise.
+       * ld-arm/cmse-new-wrong-implib.out: Likewise.
 
 2016-03-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
-       * testsuite/ld-arm/arm-elf.exp
-       (Secure gateway import library generation): New test.
+       * ld-arm/arm-elf.exp (Secure gateway import library generation): New
+       test.
        (Secure gateway import library generation: errors): Likewise.
-       * testsuite/ld-arm/cmse-implib.s: New file.
-       * testsuite/ld-arm/cmse-implib-errors.out: Likewise.
-       * testsuite/ld-arm/cmse-implib.rd: Likewise.
+       * ld-arm/cmse-implib.s: New file.
+       * ld-arm/cmse-implib-errors.out: Likewise.
+       * ld-arm/cmse-implib.rd: Likewise.
 
 2016-03-29  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
index 38f69b49d615cd766062fed6f0c1efef4a1bd4c8..384b56d99973ab8e98c19c9c3a931201b9dc6765 100644 (file)
@@ -612,7 +612,7 @@ set armeabitests_nonacl {
      {{ld cmse-veneers-wrong-entryfct.out}}
      "cmse-veneers-wrong-entryfct"}
     {"Secure gateway veneers (ARMv8-M Baseline)"
-     "-Ttext=0x8000 --section-start .gnu.sgstubs=0x20000" ""
+     "-Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --gc-sections" ""
      "-march=armv8-m.base -mthumb"
      {cmse-veneers.s}
      {{objdump {-d -j .gnu.sgstubs} cmse-veneers.d}
@@ -620,7 +620,7 @@ set armeabitests_nonacl {
       {nm {} cmse-veneers.rd}}
      "cmse-veneers-baseline"}
     {"Secure gateway veneers (ARMv8-M Mainline)"
-     "-Ttext=0x8000 --section-start .gnu.sgstubs=0x20000" ""
+     "-Ttext=0x8000 --section-start .gnu.sgstubs=0x20000 --gc-sections" ""
      "-march=armv8-m.main -mthumb"
      {cmse-veneers.s}
      {{objdump {-d -j .gnu.sgstubs} cmse-veneers.d}