2015-07-25 05:03:07 +08:00
|
|
|
//===- Symbols.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Symbols.h"
|
2015-08-06 23:33:19 +08:00
|
|
|
#include "Error.h"
|
2015-07-29 06:58:25 +08:00
|
|
|
#include "InputFiles.h"
|
2016-02-02 05:00:35 +08:00
|
|
|
#include "InputSection.h"
|
|
|
|
#include "OutputSections.h"
|
|
|
|
#include "Target.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-09-05 06:28:10 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
2015-07-25 05:03:07 +08:00
|
|
|
using namespace llvm::object;
|
2015-09-02 07:12:52 +08:00
|
|
|
using namespace llvm::ELF;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
using namespace lld;
|
2016-02-28 08:25:54 +08:00
|
|
|
using namespace lld::elf;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-02-02 05:00:35 +08:00
|
|
|
template <class ELFT>
|
2016-03-15 07:16:09 +08:00
|
|
|
static typename ELFT::uint getSymVA(const SymbolBody &Body,
|
|
|
|
typename ELFT::uint &Addend) {
|
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-03-11 20:19:05 +08:00
|
|
|
|
|
|
|
switch (Body.kind()) {
|
|
|
|
case SymbolBody::DefinedSyntheticKind: {
|
|
|
|
auto &D = cast<DefinedSynthetic<ELFT>>(Body);
|
2016-05-03 09:21:08 +08:00
|
|
|
const OutputSectionBase<ELFT> *Sec = D.Section;
|
|
|
|
if (!Sec)
|
|
|
|
return D.Value;
|
2016-04-01 05:26:23 +08:00
|
|
|
if (D.Value == DefinedSynthetic<ELFT>::SectionEnd)
|
2016-05-03 09:21:08 +08:00
|
|
|
return Sec->getVA() + Sec->getSize();
|
|
|
|
return Sec->getVA() + D.Value;
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
2016-03-11 20:19:05 +08:00
|
|
|
case SymbolBody::DefinedRegularKind: {
|
|
|
|
auto &D = cast<DefinedRegular<ELFT>>(Body);
|
|
|
|
InputSectionBase<ELFT> *SC = D.Section;
|
2016-02-02 05:00:35 +08:00
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
// According to the ELF spec reference to a local symbol from outside
|
|
|
|
// the group are not allowed. Unfortunately .eh_frame breaks that rule
|
|
|
|
// and must be treated specially. For now we just replace the symbol with
|
|
|
|
// 0.
|
|
|
|
if (SC == &InputSection<ELFT>::Discarded)
|
|
|
|
return 0;
|
|
|
|
|
2016-02-02 05:00:35 +08:00
|
|
|
// This is an absolute symbol.
|
|
|
|
if (!SC)
|
2016-04-04 22:04:16 +08:00
|
|
|
return D.Value;
|
2016-02-02 05:00:35 +08:00
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
uintX_t Offset = D.Value;
|
|
|
|
if (D.isSection()) {
|
2016-03-11 22:21:37 +08:00
|
|
|
Offset += Addend;
|
|
|
|
Addend = 0;
|
|
|
|
}
|
2016-08-11 15:56:43 +08:00
|
|
|
uintX_t VA = (SC->OutSec ? SC->OutSec->getVA() : 0) + SC->getOffset(Offset);
|
2016-09-15 00:26:19 +08:00
|
|
|
if (D.isTls() && !Config->Relocatable)
|
2016-03-11 22:21:37 +08:00
|
|
|
return VA - Out<ELFT>::TlsPhdr->p_vaddr;
|
|
|
|
return VA;
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
2016-08-02 09:35:13 +08:00
|
|
|
case SymbolBody::DefinedCommonKind:
|
|
|
|
return CommonInputSection<ELFT>::X->OutSec->getVA() +
|
|
|
|
CommonInputSection<ELFT>::X->OutSecOff +
|
2016-08-31 21:28:33 +08:00
|
|
|
cast<DefinedCommon>(Body).Offset;
|
2016-03-11 20:19:05 +08:00
|
|
|
case SymbolBody::SharedKind: {
|
|
|
|
auto &SS = cast<SharedSymbol<ELFT>>(Body);
|
|
|
|
if (!SS.NeedsCopyOrPltAddr)
|
2016-02-09 23:11:01 +08:00
|
|
|
return 0;
|
2016-04-04 22:04:16 +08:00
|
|
|
if (SS.isFunc())
|
2016-03-11 20:19:05 +08:00
|
|
|
return Body.getPltVA<ELFT>();
|
2016-03-14 04:54:38 +08:00
|
|
|
return Out<ELFT>::Bss->getVA() + SS.OffsetInBss;
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
2016-04-27 08:05:06 +08:00
|
|
|
case SymbolBody::UndefinedKind:
|
2016-02-02 05:00:35 +08:00
|
|
|
return 0;
|
2016-04-08 03:24:51 +08:00
|
|
|
case SymbolBody::LazyArchiveKind:
|
|
|
|
case SymbolBody::LazyObjectKind:
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
assert(Body.symbol()->IsUsedInRegularObj && "lazy symbol reached writer");
|
2016-02-02 05:00:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2016-03-12 16:31:34 +08:00
|
|
|
llvm_unreachable("invalid symbol kind");
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
|
|
|
|
2016-04-05 03:09:08 +08:00
|
|
|
SymbolBody::SymbolBody(Kind K, uint32_t NameOffset, uint8_t StOther,
|
|
|
|
uint8_t Type)
|
2016-06-20 05:39:37 +08:00
|
|
|
: SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(true),
|
|
|
|
IsInGlobalMipsGot(false), Type(Type), StOther(StOther),
|
|
|
|
NameOffset(NameOffset) {}
|
2016-04-06 21:22:41 +08:00
|
|
|
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
SymbolBody::SymbolBody(Kind K, StringRef Name, uint8_t StOther, uint8_t Type)
|
2016-06-20 05:39:37 +08:00
|
|
|
: SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(false),
|
|
|
|
IsInGlobalMipsGot(false), Type(Type), StOther(StOther),
|
|
|
|
Name({Name.data(), Name.size()}) {}
|
2016-04-04 22:04:16 +08:00
|
|
|
|
2016-06-28 16:21:10 +08:00
|
|
|
StringRef SymbolBody::getName() const {
|
|
|
|
assert(!isLocal());
|
2016-07-18 01:23:17 +08:00
|
|
|
return StringRef(Name.S, Name.Len);
|
|
|
|
}
|
|
|
|
|
2016-03-14 03:48:18 +08:00
|
|
|
// Returns true if a symbol can be replaced at load-time by a symbol
|
|
|
|
// with the same name defined in other ELF executable or DSO.
|
|
|
|
bool SymbolBody::isPreemptible() const {
|
|
|
|
if (isLocal())
|
|
|
|
return false;
|
|
|
|
|
2016-05-06 03:41:49 +08:00
|
|
|
// Shared symbols resolve to the definition in the DSO. The exceptions are
|
|
|
|
// symbols with copy relocations (which resolve to .bss) or preempt plt
|
|
|
|
// entries (which resolve to that plt entry).
|
2016-03-14 03:48:18 +08:00
|
|
|
if (isShared())
|
2016-05-06 03:41:49 +08:00
|
|
|
return !NeedsCopyOrPltAddr;
|
2016-03-14 03:48:18 +08:00
|
|
|
|
2016-04-23 04:21:26 +08:00
|
|
|
// That's all that can be preempted in a non-DSO.
|
|
|
|
if (!Config->Shared)
|
2016-04-15 19:57:07 +08:00
|
|
|
return false;
|
|
|
|
|
2016-04-24 12:29:59 +08:00
|
|
|
// Only symbols that appear in dynsym can be preempted.
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
if (!symbol()->includeInDynsym())
|
2016-03-14 03:48:18 +08:00
|
|
|
return false;
|
2016-04-23 04:21:26 +08:00
|
|
|
|
2016-07-08 06:50:54 +08:00
|
|
|
// Only default visibility symbols can be preempted.
|
|
|
|
if (symbol()->Visibility != STV_DEFAULT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// -Bsymbolic means that definitions are not preempted.
|
2016-04-24 12:29:59 +08:00
|
|
|
if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
|
|
|
|
return !isDefined();
|
2016-07-08 06:50:54 +08:00
|
|
|
return true;
|
2016-03-14 03:48:18 +08:00
|
|
|
}
|
|
|
|
|
2016-07-09 00:10:27 +08:00
|
|
|
template <class ELFT> bool SymbolBody::hasThunk() const {
|
|
|
|
if (auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
|
|
|
|
return DR->ThunkData != nullptr;
|
|
|
|
if (auto *S = dyn_cast<SharedSymbol<ELFT>>(this))
|
|
|
|
return S->ThunkData != nullptr;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-11 20:19:05 +08:00
|
|
|
template <class ELFT>
|
2016-03-15 07:16:09 +08:00
|
|
|
typename ELFT::uint SymbolBody::getVA(typename ELFT::uint Addend) const {
|
2016-03-18 07:36:19 +08:00
|
|
|
typename ELFT::uint OutVA = getSymVA<ELFT>(*this, Addend);
|
|
|
|
return OutVA + Addend;
|
2016-03-11 20:19:05 +08:00
|
|
|
}
|
|
|
|
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getGotVA() const {
|
2016-04-07 23:20:56 +08:00
|
|
|
return Out<ELFT>::Got->getVA() + getGotOffset<ELFT>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getGotOffset() const {
|
2016-07-14 02:55:14 +08:00
|
|
|
return GotIndex * Target->GotEntrySize;
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
|
|
|
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getGotPltVA() const {
|
2016-04-07 23:20:56 +08:00
|
|
|
return Out<ELFT>::GotPlt->getVA() + getGotPltOffset<ELFT>();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getGotPltOffset() const {
|
2016-07-14 02:55:14 +08:00
|
|
|
return GotPltIndex * Target->GotPltEntrySize;
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
|
|
|
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getPltVA() const {
|
2016-06-17 00:28:50 +08:00
|
|
|
return Out<ELFT>::Plt->getVA() + Target->PltHeaderSize +
|
2016-02-02 05:00:35 +08:00
|
|
|
PltIndex * Target->PltEntrySize;
|
|
|
|
}
|
|
|
|
|
2016-04-01 05:26:23 +08:00
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getThunkVA() const {
|
2016-07-09 00:10:27 +08:00
|
|
|
if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
|
|
|
|
return DR->ThunkData->getVA();
|
|
|
|
if (const auto *S = dyn_cast<SharedSymbol<ELFT>>(this))
|
|
|
|
return S->ThunkData->getVA();
|
|
|
|
fatal("getThunkVA() not supported for Symbol class\n");
|
2016-04-01 05:26:23 +08:00
|
|
|
}
|
|
|
|
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
|
2016-08-31 21:28:33 +08:00
|
|
|
if (const auto *C = dyn_cast<DefinedCommon>(this))
|
2016-04-04 22:04:16 +08:00
|
|
|
return C->Size;
|
|
|
|
if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(this))
|
|
|
|
return DR->Size;
|
|
|
|
if (const auto *S = dyn_cast<SharedSymbol<ELFT>>(this))
|
|
|
|
return S->Sym.st_size;
|
2016-02-03 08:12:24 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
Defined::Defined(Kind K, StringRef Name, uint8_t StOther, uint8_t Type)
|
|
|
|
: SymbolBody(K, Name, StOther, Type) {}
|
2016-04-04 22:04:16 +08:00
|
|
|
|
2016-04-06 20:14:31 +08:00
|
|
|
Defined::Defined(Kind K, uint32_t NameOffset, uint8_t StOther, uint8_t Type)
|
|
|
|
: SymbolBody(K, NameOffset, StOther, Type) {}
|
2015-12-24 08:47:42 +08:00
|
|
|
|
2016-09-29 20:58:36 +08:00
|
|
|
template <class ELFT> bool DefinedRegular<ELFT>::isMipsPIC() const {
|
|
|
|
if (!Section || !isFunc())
|
|
|
|
return false;
|
|
|
|
return (this->StOther & STO_MIPS_MIPS16) == STO_MIPS_PIC ||
|
|
|
|
(Section->getFile()->getObj().getHeader()->e_flags & EF_MIPS_PIC);
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
Undefined::Undefined(StringRef Name, uint8_t StOther, uint8_t Type,
|
|
|
|
InputFile *File)
|
|
|
|
: SymbolBody(SymbolBody::UndefinedKind, Name, StOther, Type) {
|
|
|
|
this->File = File;
|
|
|
|
}
|
2016-04-06 21:22:41 +08:00
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
Undefined::Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type,
|
|
|
|
InputFile *File)
|
|
|
|
: SymbolBody(SymbolBody::UndefinedKind, NameOffset, StOther, Type) {
|
|
|
|
this->File = File;
|
|
|
|
}
|
2015-12-23 07:00:50 +08:00
|
|
|
|
2015-12-24 08:47:42 +08:00
|
|
|
template <typename ELFT>
|
|
|
|
DefinedSynthetic<ELFT>::DefinedSynthetic(StringRef N, uintX_t Value,
|
2016-05-03 09:21:08 +08:00
|
|
|
OutputSectionBase<ELFT> *Section)
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
: Defined(SymbolBody::DefinedSyntheticKind, N, STV_HIDDEN, 0 /* Type */),
|
2015-12-24 08:47:42 +08:00
|
|
|
Value(Value), Section(Section) {}
|
|
|
|
|
2016-08-31 21:28:33 +08:00
|
|
|
DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment,
|
|
|
|
uint8_t StOther, uint8_t Type, InputFile *File)
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
: Defined(SymbolBody::DefinedCommonKind, N, StOther, Type),
|
2016-07-18 01:36:22 +08:00
|
|
|
Alignment(Alignment), Size(Size) {
|
|
|
|
this->File = File;
|
|
|
|
}
|
2015-12-25 00:23:37 +08:00
|
|
|
|
2016-09-14 08:05:51 +08:00
|
|
|
InputFile *Lazy::fetch() {
|
2016-04-08 03:24:51 +08:00
|
|
|
if (auto *S = dyn_cast<LazyArchive>(this))
|
2016-07-17 11:11:46 +08:00
|
|
|
return S->fetch();
|
|
|
|
return cast<LazyObject>(this)->fetch();
|
2016-04-08 03:24:51 +08:00
|
|
|
}
|
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
LazyArchive::LazyArchive(ArchiveFile &File,
|
|
|
|
const llvm::object::Archive::Symbol S, uint8_t Type)
|
|
|
|
: Lazy(LazyArchiveKind, S.getName(), Type), Sym(S) {
|
|
|
|
this->File = &File;
|
|
|
|
}
|
|
|
|
|
|
|
|
LazyObject::LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type)
|
|
|
|
: Lazy(LazyObjectKind, Name, Type) {
|
|
|
|
this->File = &File;
|
|
|
|
}
|
|
|
|
|
2016-09-14 08:05:51 +08:00
|
|
|
InputFile *LazyArchive::fetch() {
|
2016-07-17 11:11:46 +08:00
|
|
|
MemoryBufferRef MBRef = file()->getMember(&Sym);
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
// getMember returns an empty buffer if the member was already
|
|
|
|
// read from the library.
|
|
|
|
if (MBRef.getBuffer().empty())
|
2016-09-14 08:05:51 +08:00
|
|
|
return nullptr;
|
2016-07-17 11:11:46 +08:00
|
|
|
return createObjectFile(MBRef, file()->getName());
|
2015-09-05 06:28:10 +08:00
|
|
|
}
|
|
|
|
|
2016-09-14 08:05:51 +08:00
|
|
|
InputFile *LazyObject::fetch() {
|
2016-07-17 11:11:46 +08:00
|
|
|
MemoryBufferRef MBRef = file()->getBuffer();
|
2016-06-15 05:56:36 +08:00
|
|
|
if (MBRef.getBuffer().empty())
|
2016-09-14 08:05:51 +08:00
|
|
|
return nullptr;
|
2016-04-08 03:24:51 +08:00
|
|
|
return createObjectFile(MBRef);
|
|
|
|
}
|
|
|
|
|
2016-04-23 02:42:48 +08:00
|
|
|
bool Symbol::includeInDynsym() const {
|
|
|
|
if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED)
|
2016-04-22 05:44:25 +08:00
|
|
|
return false;
|
2016-06-20 19:55:12 +08:00
|
|
|
return (ExportDynamic && VersionId != VER_NDX_LOCAL) || body()->isShared() ||
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
(body()->isUndefined() && Config->Shared);
|
2016-04-22 04:35:25 +08:00
|
|
|
}
|
2016-07-18 01:50:09 +08:00
|
|
|
|
|
|
|
// Print out a log message for --trace-symbol.
|
|
|
|
void elf::printTraceSymbol(Symbol *Sym) {
|
|
|
|
SymbolBody *B = Sym->body();
|
|
|
|
outs() << getFilename(B->File);
|
|
|
|
|
|
|
|
if (B->isUndefined())
|
|
|
|
outs() << ": reference to ";
|
|
|
|
else if (B->isCommon())
|
|
|
|
outs() << ": common definition of ";
|
|
|
|
else
|
|
|
|
outs() << ": definition of ";
|
|
|
|
outs() << B->getName() << "\n";
|
|
|
|
}
|
|
|
|
|
2016-07-09 00:10:27 +08:00
|
|
|
template bool SymbolBody::hasThunk<ELF32LE>() const;
|
|
|
|
template bool SymbolBody::hasThunk<ELF32BE>() const;
|
|
|
|
template bool SymbolBody::hasThunk<ELF64LE>() const;
|
|
|
|
template bool SymbolBody::hasThunk<ELF64BE>() const;
|
2016-04-22 04:35:25 +08:00
|
|
|
|
2016-03-11 20:19:05 +08:00
|
|
|
template uint32_t SymbolBody::template getVA<ELF32LE>(uint32_t) const;
|
|
|
|
template uint32_t SymbolBody::template getVA<ELF32BE>(uint32_t) const;
|
|
|
|
template uint64_t SymbolBody::template getVA<ELF64LE>(uint64_t) const;
|
|
|
|
template uint64_t SymbolBody::template getVA<ELF64BE>(uint64_t) const;
|
2016-02-02 05:00:35 +08:00
|
|
|
|
|
|
|
template uint32_t SymbolBody::template getGotVA<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getGotVA<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotVA<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotVA<ELF64BE>() const;
|
|
|
|
|
2016-04-07 23:20:56 +08:00
|
|
|
template uint32_t SymbolBody::template getGotOffset<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getGotOffset<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotOffset<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotOffset<ELF64BE>() const;
|
|
|
|
|
2016-02-02 05:00:35 +08:00
|
|
|
template uint32_t SymbolBody::template getGotPltVA<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getGotPltVA<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotPltVA<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotPltVA<ELF64BE>() const;
|
|
|
|
|
2016-07-09 00:10:27 +08:00
|
|
|
template uint32_t SymbolBody::template getThunkVA<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getThunkVA<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getThunkVA<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getThunkVA<ELF64BE>() const;
|
|
|
|
|
2016-04-07 23:20:56 +08:00
|
|
|
template uint32_t SymbolBody::template getGotPltOffset<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getGotPltOffset<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotPltOffset<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getGotPltOffset<ELF64BE>() const;
|
|
|
|
|
2016-02-02 05:00:35 +08:00
|
|
|
template uint32_t SymbolBody::template getPltVA<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getPltVA<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getPltVA<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getPltVA<ELF64BE>() const;
|
|
|
|
|
2016-02-03 08:12:24 +08:00
|
|
|
template uint32_t SymbolBody::template getSize<ELF32LE>() const;
|
|
|
|
template uint32_t SymbolBody::template getSize<ELF32BE>() const;
|
|
|
|
template uint64_t SymbolBody::template getSize<ELF64LE>() const;
|
|
|
|
template uint64_t SymbolBody::template getSize<ELF64BE>() const;
|
|
|
|
|
2016-09-29 20:58:36 +08:00
|
|
|
template class elf::DefinedRegular<ELF32LE>;
|
|
|
|
template class elf::DefinedRegular<ELF32BE>;
|
|
|
|
template class elf::DefinedRegular<ELF64LE>;
|
|
|
|
template class elf::DefinedRegular<ELF64BE>;
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
template class elf::DefinedSynthetic<ELF32LE>;
|
|
|
|
template class elf::DefinedSynthetic<ELF32BE>;
|
|
|
|
template class elf::DefinedSynthetic<ELF64LE>;
|
|
|
|
template class elf::DefinedSynthetic<ELF64BE>;
|