This is an archive of the discontinued LLVM Phabricator instance.

Fix weak symbols on arm and aarch64
ClosedPublic

Authored by rafael on Jun 9 2017, 11:22 AM.

Details

Reviewers
peter.smith
Summary

Given

.weak target
.global _start
_start:
b target

The intention is that the branch goes to the instruction after the branch, effectively turning it on a nop. The branch adds the runtime PC, but we were adding it statically too.

I noticed the oddity by inspection, but llvm-objdump seems to agree, since it now prints things like:

b #-4 <_start+0x4>

Diff Detail

Event Timeline

rafael created this revision.Jun 9 2017, 11:22 AM
peter.smith accepted this revision.Jun 12 2017, 4:12 AM

Looks good to me, thanks for spotting the mistake and apologies for making it in the first place. I've made a minor suggestion about making the default case unreachable but I don't think that this is that important.

ELF/InputSection.cpp
409

Might be worth making the default case unreachable.

The ABI (ARM ELF 4.5.1.1) says:
During linking, the value of an undefined weak reference is:

  • Zero if the relocation type is absolute
  • The address of the place if the relocation type is pc-relative
  • The nominal base address if the relocation type is base-relative.

The intention for just returning A was that default: would cover the absolute case. However as long as getARMUndefinedRelativeWeakVA is only called from pc-relative locations this wouldn't happen so I don't expect the default case to ever get hit.

This revision is now accepted and ready to land.Jun 12 2017, 4:12 AM
espindola closed this revision.Mar 14 2018, 4:07 PM
espindola added a subscriber: espindola.

305212