This is an archive of the discontinued LLVM Phabricator instance.

PR34148: Do not assume we can use a copy relocation for an `external_weak` global
ClosedPublic

Authored by rsmith on Aug 10 2017, 8:03 PM.

Details

Summary

An external_weak global may be intended to resolve as a null pointer if it's not defined, so it doesn't make sense to use a copy relocation for it.

See also https://reviews.llvm.org/D36280 (which fixes an overlapping issue for X86).

Diff Detail

Repository
rL LLVM

Event Timeline

rsmith created this revision.Aug 10 2017, 8:03 PM
rafael accepted this revision.Aug 11 2017, 2:28 PM

LGTM as this fixes a bug, but even this I think is incomplete.

Thinking a bit more about it I see that I was wrong. Even if we have a hidden weak_external we should not be using lea. For example, the normal sequence for accessing a hidden variable when linked with bfd becomes

00000150 <_start>:
150: e8 00 00 00 00 call 155 <_start+0x5>
155: 58 pop %eax
156: 81 c0 ab 1e 00 00 add $0x1eab,%eax
15c: 8d 80 00 e0 ff ff lea -0x2000(%eax),%eax
162: c3 ret

The problem is that there are no relocations. This is resolving the undefined weak symbol to the load address, not to 0.

This revision is now accepted and ready to land.Aug 11 2017, 2:28 PM