[PATCH] D54782: [ELF] Take IPLT header size in account when -z retpolineplt is specified
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 20 23:19:44 PST 2018
MaskRay created this revision.
Herald added subscribers: llvm-commits, krytarowski, arichardson, emaste.
Herald added a reviewer: espindola.
This fixes PR39711: -z now -z retpolineplt has broken IPLT
Statically linked executable does not have PLT, but may have IPLT with zero header size. When -z retpolineplt is specified, however, the repoline header size should be taken into account.
I've checked that this fixes the FreeBSD reproduce in PR39711 and a Linux program linked against glibc.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D54782
Files:
ELF/Symbols.cpp
ELF/SyntheticSections.cpp
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2280,7 +2280,8 @@
PltSection::PltSection(bool IsIplt)
: SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 16,
Config->EMachine == EM_PPC64 ? ".glink" : ".plt"),
- HeaderSize(IsIplt ? 0 : Target->PltHeaderSize), IsIplt(IsIplt) {
+ HeaderSize(IsIplt && !Config->ZRetpolineplt ? 0 : Target->PltHeaderSize),
+ IsIplt(IsIplt) {
// The PLT needs to be writable on SPARC as the dynamic linker will
// modify the instructions in the PLT entries.
if (Config->EMachine == EM_SPARCV9)
@@ -2290,7 +2291,7 @@
void PltSection::writeTo(uint8_t *Buf) {
// At beginning of PLT but not the IPLT, we have code to call the dynamic
// linker to resolve dynsyms at runtime. Write such code.
- if (!IsIplt)
+ if (!IsIplt || Config->ZRetpolineplt)
Target->writePltHeader(Buf);
size_t Off = HeaderSize;
// The IPlt is immediately after the Plt, account for this in RelOff
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -144,8 +144,11 @@
}
uint64_t Symbol::getPltVA() const {
- if (this->IsInIplt)
+ if (this->IsInIplt) {
+ if (Config->ZRetpolineplt)
+ return In.Plt->getVA() + Target->getPltEntryOffset(PltIndex);
return In.Iplt->getVA() + PltIndex * Target->PltEntrySize;
+ }
return In.Plt->getVA() + Target->getPltEntryOffset(PltIndex);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54782.174871.patch
Type: text/x-patch
Size: 1576 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181121/b7e87e7d/attachment.bin>
More information about the llvm-commits
mailing list