This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] Add alignment checks for the LDST<N>_ABS_LO12_NC relocations
ClosedPublic

Authored by peter.smith on Sep 4 2017, 10:29 AM.

Details

Summary

The R_AARCH64_LDST<N>_ABS LO12_NC relocations where N is 8, 16, 32, 64 or 128 have a scaled immediate. For example R_AARCH64_LDST32_ABS_LO12_NC shifts the calculated value right by 4. If the target symbol + relocation addend is not aligned properly then bits of the answer will be lost.

This change adds an alignment check to the relocations to make sure the target of the relocation is aligned properly. This matches the behavior of GNU ld. The motivation is to catch ODR violations such as a declaration of extern int foo, but a definition of bool foo as the compiler may use R_AARCH64_LDST32_ABS_LO12_NC for the former, but not align the destination.

This was discovered while investigating a BuildBot failure where GNU ld caught the ODR violations but lld did not https://bugs.llvm.org/show_bug.cgi?id=34453

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith created this revision.Sep 4 2017, 10:29 AM
ruiu accepted this revision.Sep 5 2017, 11:31 AM

LGTM

This revision is now accepted and ready to land.Sep 5 2017, 11:31 AM
This revision was automatically updated to reflect the committed changes.