This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH bfd arm] Fix mismatch to EABI in misaligned R_ARM_THM_PC8
- From: "Joey Ye" <joey dot ye at arm dot com>
- To: <binutils at sourceware dot org>
- Date: Fri, 19 Oct 2012 22:58:33 +0800
- Subject: [PATCH bfd arm] Fix mismatch to EABI in misaligned R_ARM_THM_PC8
This patch implement relocation operation according to ARM EABI section
4.7.1.1
and 4.7.1.2. Trunk binutils malfunctions when linking objection files
relocating
non-4-byte aligned location with R_ARM_THM_PC8 type.
Original bfd missed following two EABI updates, as extracted from aaelf
2.08:
***
4.7.1.1 Addends and PC-bias compensation
For R_ARM_THM_PC8 the initial addend is formed by the formula (((imm + 4) &
0x3ff) - 4), where imm is the normal interpretation of the immediate field
in a Thumb LDR(3)/LDR(lliteral) instruction.
4.7.1.2
Pa is the adjusted address of the place being relocated, defined as (P &
0xFFFFFFFC).
R_ARM_THM_PC8: S + A - Pa
R_ARM_THM_ALU_PREL_11_0: ((S + A) | T) - Pa
R_ARM_THM_PC12: S + A - Pa
***
Test case not available since GAS doesn't generate these types of
relocation.
OK to trunk and 2.21/2.22?
ChangeLog:
2012-10-19 Joey Ye <joey.ye@arm.com>
* elf32-arm.c (elf32_arm_final_link_relocate,
case R_ARM_THM_ALU_PREL_11_0, case R_ARM_THM_PC12): Align address of
the place being relocated.
(elf32_arm_final_link_relocate, case R_ARM_THM_PC8): Align address
of the place being relocated and truncate addend.
(Pa): New macro.
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index c57a4f9..dc14c93 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -63,6 +63,9 @@
#define ARM_ELF_ABI_VERSION 0
#define ARM_ELF_OS_ABI_VERSION ELFOSABI_ARM
+/* The Adjusted Place, as defined by AAELF. */
+#define Pa(X) ((X) & 0xfffffffc)
+
static bfd_boolean elf32_arm_write_section (bfd *output_bfd,
struct bfd_link_info *link_info,
asection *sec,
@@ -8619,9 +8622,9 @@ elf32_arm_final_link_relocate (reloc_howto_type *
howto,
}
relocation = value + signed_addend;
- relocation -= (input_section->output_section->vma
- + input_section->output_offset
- + rel->r_offset) & 0xfffffffc;
+ relocation -= Pa (input_section->output_section->vma
+ + input_section->output_offset
+ + rel->r_offset);
value = abs (relocation);
@@ -8654,9 +8657,9 @@ elf32_arm_final_link_relocate (reloc_howto_type *
howto,
addend = ((((insn & 0x00ff) << 2) + 4) & 0x3ff) -4;
relocation = value + addend;
- relocation -= (input_section->output_section->vma
- + input_section->output_offset
- + rel->r_offset) & 0xfffffffc;
+ relocation -= Pa (input_section->output_section->vma
+ + input_section->output_offset
+ + rel->r_offset);
value = abs (relocation);
@@ -8691,9 +8694,9 @@ elf32_arm_final_link_relocate (reloc_howto_type *
howto,
}
relocation = value + signed_addend;
- relocation -= (input_section->output_section->vma
- + input_section->output_offset
- + rel->r_offset) & 0xfffffffc;
+ relocation -= Pa (input_section->output_section->vma
+ + input_section->output_offset
+ + rel->r_offset);
value = abs (relocation);