This is an archive of the discontinued LLVM Phabricator instance.

Fix PLT and GOTPLT entries for x86 PIC.
ClosedPublic

Authored by ruiu on Apr 4 2017, 3:21 PM.

Details

Summary

Previously, the code we set to our .got.plt entries expected that
.got and .got.plt are consecutive in the virtual address space.
Since %ebx points to the last entry of .got for position-independent
code, it assumed that .got is accessible with small negative
displacements and .got.plt are accessible with small positive
displacements.

That assumption was simply wrong. We don't impose any restrictions on
relative layout of .got and .got.plt. As a result, the control is
transferred to a bogus address from .plt at runtime, which resulted in
segfaults.

This patch removes that wrong assumption. We still assume that .got.plt
has a fixed relative address to .got, but we no longer assume that they
are consecutive in memory.

With this change, a "hello world" program compiled with -fPIC works.

Fixes https://bugs.llvm.org/show_bug.cgi?id=31332.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.Apr 4 2017, 3:21 PM
smeenai added a subscriber: smeenai.Apr 4 2017, 3:43 PM

This fixes the issues I was seeing as well. Thanks @ruiu!

peter.smith accepted this revision.Apr 5 2017, 2:05 AM

That looks good to me. I agree that it is the better solution to not assume anything about the relative locations of .got and .got.plt

This revision is now accepted and ready to land.Apr 5 2017, 2:05 AM
This revision was automatically updated to reflect the committed changes.