Fix PLT and GOTPLT entries for 32-bit x86 PIC.
authorRui Ueyama <ruiu@google.com>
Wed, 5 Apr 2017 16:01:33 +0000 (16:01 +0000)
committerRui Ueyama <ruiu@google.com>
Wed, 5 Apr 2017 16:01:33 +0000 (16:01 +0000)
commit9c766d7a397b652b5a04c6acff16b1473a3c8838
treeeb343629064f782053d9dcc5eaf5057e28fe721b
parentaa65a2beb875e2bbe2c1b71ea3bf648d35101469
Fix PLT and GOTPLT entries for 32-bit x86 PIC.

Previously, the code we set to our .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.

Differential Revision: https://reviews.llvm.org/D31682

llvm-svn: 299553
lld/ELF/Target.cpp
lld/test/ELF/plt-i686.s