From: Thomas Preud'homme Date: Mon, 20 Jun 2016 11:06:31 +0000 (+0100) Subject: Prevent SG veneers from being collected by --gc-section X-Git-Tag: users/ARM/embedded-gdb-2_26-branch-2016q1~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7e62612a6e1158902555f9e769b5751873bc945b;p=thirdparty%2Fbinutils-gdb.git Prevent SG veneers from being collected by --gc-section 2016-06-20 Thomas Preud'homme 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. --- diff --git a/bfd/ChangeLog.arm b/bfd/ChangeLog.arm index 0c7dbc37866..0e613565b46 100644 --- a/bfd/ChangeLog.arm +++ b/bfd/ChangeLog.arm @@ -1,3 +1,8 @@ +2016-06-20 Thomas Preud'homme + + * elf32-arm.c (elf32_arm_gc_mark_extra_sections): Mark sections holding + ARMv8-M secure entry functions. + 2016-05-20 Thomas Preud'homme * elf32-arm.c (enum elf32_arm_stub_type): Remove diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 417b76ccc73..588f832cce2 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -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; diff --git a/ld/testsuite/ChangeLog.arm b/ld/testsuite/ChangeLog.arm index 1ad82f502d2..f8327172f5e 100644 --- a/ld/testsuite/ChangeLog.arm +++ b/ld/testsuite/ChangeLog.arm @@ -1,22 +1,28 @@ +2016-06-20 Thomas Preud'homme + + * 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 - * 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 - * 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 diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp index 38f69b49d61..384b56d9997 100644 --- a/ld/testsuite/ld-arm/arm-elf.exp +++ b/ld/testsuite/ld-arm/arm-elf.exp @@ -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}