Relocation for R_ARM_THM_ALU_PREL_11_0 is not calculated correctly
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
I am using the gcc-arm-none-eabi version 6-2017-q1-update, which uses LD version 2.26.
I am attempting to link in some vendor libraries along with my own source code. The libraries were compiled with a different toolchain (IAR), but contain ARM ELF Relocatable object files. Using arm-none-
For the must part I am able to link correctly, however I get a single link error:
relocation truncated to fit: R_ARM_THM_
This relocation is used by the ADR instruction to provide an offset from the PC. Based on where the symbol ends up in relation to the relocation, the ADR may be either an ADD or SUB immediate instruction from PC. The link appears only to work correctly in the case of an ADD.
I traced the error down to the elf32_arm_
Here the addend and relocation value are calculated correctly:
relocation -= Pa (input_
+ input_section-
+ rel->r_offset);
However then the value is assigned incorrectly:
value = relocation;
This should be:
value = abs(relocation);
It was originally written this way but changed for some reason. The commit that changed it was:
I am not sure why the abs() was considered useless in this case. The commit message mentions warnings from clang.
Regardless, the assignment without the abs() call will cause the linker to think an overflow has occurred when one has not. If the resulting relocation is negative, and no abs() is performed, the following overflow check will trigger a false error for negative values:
if (value >= 0x1000)
return bfd_reloc_overflow;
Not only that, but the following check performed later will never evaluate to true:
if (relocation < 0)
insn |= 0xa00000;
Proposed solution would be to change back to:
value = abs(relocation);
Please let me know if anymore information is needed. I can try to generate a simple example which demonstrates the problem if needed.
Thanks
Binutils Bug report: https:/ /sourceware. org/bugzilla/ show_bug. cgi?id= 21523