[PATCH] D26240: [LLD][ARM][AArch64] ARM and AArch64 undefined weak reference values for relative relocations

Peter Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 2 05:16:52 PDT 2016


peter.smith created this revision.
peter.smith added reviewers: ruiu, rafael.
peter.smith added a subscriber: llvm-commits.
Herald added subscribers: rengolin, aemerson.

The ARM 32 and 64-bit ABI does not use 0 for undefined weak references that are used in PC relative relocations. In particular:

- A branch relocation to an undefined weak resolves to the next instruction.
- In all other cases the symbol resolves to the place so that S + A - P resolves to A.

The branch relocation resolving to the next instruction is the most important as it is a common idiom in statically linked ARM and AArch64 code to use branches to weak references to initialization functions of optional parts of the program. More importantly it can also cause spurious relocation out of range errors as the (S + A) - P of the branch relocation evaluates to (0 + A) - P which is often a large negative number.

References:

- ARM: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf
  - Section 4.5.1.1 Weak references and 4.6.1.4 Static ARM Relocations, search for Call and Jump Relocations
- AArch64: http://infocenter.arm.com/help/topic/com.arm.doc.ihi0056c/IHI0056C_beta_aaelf64.pdf
  - Section 4.5.1.1 Weak references and Section 4.6.7 Call and Jump Relocations


https://reviews.llvm.org/D26240

Files:
  ELF/InputSection.cpp
  test/ELF/aarch64-undefined-weak.s
  test/ELF/arm-thumb-no-undefined-thunk.s
  test/ELF/arm-thumb-undefined-weak.s
  test/ELF/arm-undefined-weak.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26240.76692.patch
Type: text/x-patch
Size: 7479 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161102/d07824a7/attachment.bin>


More information about the llvm-commits mailing list