This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC PATCH, binutils, ARM 1/9] Refactor Cortex-A8 erratum workaround in preparation


[Posting patch series as RFC]

This patch is part of a patch series to add support for ARMv8-M security extension[1] to GNU ld. This specific patch refactors Cortex-A8 erratum workaround code to handle Thumb code relocation in stubs in the same as other relocations in stubs, as needed by subsequent patches.

Contrary to other types of veneers, the ones for Cortex-A8 erratum workaround are generated for branches without relocations against them (see comment below "if (found && found->non_a8_stub)" in cortex_a8_erratum_scan () function). Because of that, the related code needs to patch the source of the branch itself rather than rely on elf32_arm_final_link_relocate to be called to relocate it.

Currently, this is done by storing the offset of the source of the branch from the beginning of its section in struct elf32_arm_stub_hash_entry's target_value field rather than the offset of the target of the branch. arm_build_one_stub () then compute the target offset from the source offset and the distance between the source and target of the branch stored in a new target_addend field of struct elf32_arm_stub_hash_entry. That offset is taken from the branch immediate and thus includes the addend. Because of that, the relocation addend for the veneer must not be used when computing the target offset which which led to the creation of the if in arm_build_one_stub () function (see the difference in computation of points_to).

While all this works, this special casing makes the code less maintainable and more difficult to understand (especially target_value having a different meaning). This patch aims at improving this.

[1] Software requirements for ARMv8-M security extension are described in document ARM-ECM-0359818 [2]
[2] Available on in Developer guides and articles > Software development > ARMÂv8-M Security Extensions: Requirements on Development Tools

ChangeLog entry is as follows:

*** bfd/ChangeLog ***

2015-08-07  Thomas Preud'homme  <>

        * elf32-arm.c (struct elf32_arm_stub_hash_entry): Delete target_addend
        field and add source_value.
        (struct a8_erratum_fix): Delete addend field and add target_offset.
        (stub_hash_newfunc): Initialize source_value field amd remove
        initialization for target_addend.
        (arm_build_one_stub): Stop special casing Thumb relocations: promote
        the else to being always executed, moving the
        arm_stub_a8_veneer_b_cond specific code in it.  Remove
        stub_entry->target_addend from points_to computation.
        (cortex_a8_erratum_scan): Store in a8_erratum_fix structure the offset
        to target symbol from start of section rather than the offset from the
        stub address.
        (elf32_arm_size_stubs): Set stub_entry's source_value and target_value
        fields from struct a8_erratum_fix's offset and target_offset
        (make_branch_to_a8_stub): Rename target variable to loc.  Compute
        veneered_insn_loc and loc using stub_entry's source_value.

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

Any comments?

Best regards,


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]