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"
|
2016-01-14 02:55:39 +08:00
|
|
|
#include "llvm/Config/config.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_CXXABI_H
|
|
|
|
#include <cxxabi.h>
|
|
|
|
#endif
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
uintX_t VA = SC->OutSec->getVA() + SC->getOffset(Offset);
|
2016-04-04 22:04:16 +08:00
|
|
|
if (D.isTls())
|
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-03-11 20:19:05 +08:00
|
|
|
case SymbolBody::DefinedCommonKind:
|
|
|
|
return Out<ELFT>::Bss->getVA() + cast<DefinedCommon>(Body).OffsetInBss;
|
|
|
|
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-11 20:19:05 +08:00
|
|
|
case SymbolBody::DefinedBitcodeKind:
|
2016-03-29 10:20:10 +08:00
|
|
|
llvm_unreachable("should have been replaced");
|
2016-02-02 05:00:35 +08:00
|
|
|
}
|
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-05-24 12:51:49 +08:00
|
|
|
: SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(true), 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-05-24 12:51:49 +08:00
|
|
|
: SymbolKind(K), NeedsCopyOrPltAddr(false), IsLocal(false), Type(Type),
|
|
|
|
StOther(StOther), Name({Name.data(), Name.size()}) {}
|
2016-04-04 22:04:16 +08:00
|
|
|
|
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-04-24 12:29:59 +08:00
|
|
|
// Normally only default visibility symbols can be preempted, but -Bsymbolic
|
|
|
|
// means that not even they can be preempted.
|
|
|
|
if (Config->Bsymbolic || (Config->BsymbolicFunctions && isFunc()))
|
|
|
|
return !isDefined();
|
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
|
|
|
return symbol()->Visibility == STV_DEFAULT;
|
2016-03-14 03:48:18 +08:00
|
|
|
}
|
|
|
|
|
2016-05-03 05:30:42 +08:00
|
|
|
template <class ELFT> InputFile *SymbolBody::getSourceFile() {
|
|
|
|
if (auto *S = dyn_cast<DefinedRegular<ELFT>>(this))
|
|
|
|
return S->Section ? S->Section->getFile() : nullptr;
|
|
|
|
if (auto *S = dyn_cast<SharedSymbol<ELFT>>(this))
|
|
|
|
return S->File;
|
|
|
|
if (auto *S = dyn_cast<DefinedBitcode>(this))
|
|
|
|
return S->File;
|
|
|
|
if (auto *S = dyn_cast<Undefined>(this))
|
|
|
|
return S->File;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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 {
|
|
|
|
return (Out<ELFT>::Got->getMipsLocalEntriesNum() + GotIndex) *
|
|
|
|
sizeof(typename ELFT::uint);
|
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 {
|
|
|
|
return GotPltIndex * sizeof(typename ELFT::uint);
|
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 {
|
|
|
|
auto *D = cast<DefinedRegular<ELFT>>(this);
|
|
|
|
auto *S = cast<InputSection<ELFT>>(D->Section);
|
|
|
|
return S->OutSec->getVA() + S->OutSecOff + S->getThunkOff() +
|
|
|
|
ThunkIndex * Target->ThunkSize;
|
|
|
|
}
|
|
|
|
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint SymbolBody::getSize() const {
|
2016-04-04 22:04:16 +08:00
|
|
|
if (const auto *C = dyn_cast<DefinedCommon>(this))
|
|
|
|
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
|
|
|
|
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
|
|
|
DefinedBitcode::DefinedBitcode(StringRef Name, uint8_t StOther, uint8_t Type,
|
|
|
|
BitcodeFile *F)
|
|
|
|
: Defined(DefinedBitcodeKind, Name, StOther, Type), File(F) {}
|
2016-02-13 04:54:57 +08:00
|
|
|
|
|
|
|
bool DefinedBitcode::classof(const SymbolBody *S) {
|
|
|
|
return S->kind() == DefinedBitcodeKind;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
Undefined::Undefined(StringRef Name, uint8_t StOther, uint8_t Type)
|
|
|
|
: SymbolBody(SymbolBody::UndefinedKind, Name, StOther, Type) {}
|
2016-04-06 21:22:41 +08:00
|
|
|
|
2016-04-28 08:26:54 +08:00
|
|
|
Undefined::Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type)
|
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::UndefinedKind, NameOffset, StOther, Type) {}
|
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) {}
|
|
|
|
|
2015-12-25 00:23:37 +08:00
|
|
|
DefinedCommon::DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment,
|
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
|
|
|
uint8_t StOther, uint8_t Type)
|
|
|
|
: Defined(SymbolBody::DefinedCommonKind, N, StOther, Type),
|
2016-03-11 02:58:53 +08:00
|
|
|
Alignment(Alignment), Size(Size) {}
|
2015-12-25 00:23:37 +08:00
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
std::unique_ptr<InputFile> Lazy::getFile() {
|
|
|
|
if (auto *S = dyn_cast<LazyArchive>(this))
|
|
|
|
return S->getFile();
|
|
|
|
return cast<LazyObject>(this)->getFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<InputFile> LazyArchive::getFile() {
|
2016-06-15 05:40:23 +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())
|
|
|
|
return std::unique_ptr<InputFile>(nullptr);
|
2016-06-15 05:40:23 +08:00
|
|
|
return createObjectFile(MBRef, File.getName());
|
2015-09-05 06:28:10 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
std::unique_ptr<InputFile> LazyObject::getFile() {
|
2016-06-15 05:56:36 +08:00
|
|
|
MemoryBufferRef MBRef = File.getBuffer();
|
|
|
|
if (MBRef.getBuffer().empty())
|
|
|
|
return std::unique_ptr<InputFile>(nullptr);
|
2016-04-08 03:24:51 +08:00
|
|
|
return createObjectFile(MBRef);
|
|
|
|
}
|
|
|
|
|
2016-01-14 02:55:39 +08:00
|
|
|
// Returns the demangled C++ symbol name for Name.
|
2016-02-28 08:25:54 +08:00
|
|
|
std::string elf::demangle(StringRef Name) {
|
2016-01-14 02:55:39 +08:00
|
|
|
#if !defined(HAVE_CXXABI_H)
|
|
|
|
return Name;
|
|
|
|
#else
|
|
|
|
if (!Config->Demangle)
|
|
|
|
return Name;
|
2016-01-14 03:40:13 +08:00
|
|
|
|
2016-01-14 06:09:09 +08:00
|
|
|
// __cxa_demangle can be used to demangle strings other than symbol
|
|
|
|
// names which do not necessarily start with "_Z". Name can be
|
|
|
|
// either a C or C++ symbol. Don't call __cxa_demangle if the name
|
|
|
|
// does not look like a C++ symbol name to avoid getting unexpected
|
|
|
|
// result for a C symbol that happens to match a mangled type name.
|
2016-01-14 03:40:13 +08:00
|
|
|
if (!Name.startswith("_Z"))
|
|
|
|
return Name;
|
|
|
|
|
2016-01-14 02:55:39 +08:00
|
|
|
char *Buf =
|
|
|
|
abi::__cxa_demangle(Name.str().c_str(), nullptr, nullptr, nullptr);
|
|
|
|
if (!Buf)
|
|
|
|
return Name;
|
|
|
|
std::string S(Buf);
|
|
|
|
free(Buf);
|
|
|
|
return S;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
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;
|
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
|
|
|
return (ExportDynamic && VersionScriptGlobal) || body()->isShared() ||
|
|
|
|
(body()->isUndefined() && Config->Shared);
|
2016-04-22 04:35:25 +08:00
|
|
|
}
|
|
|
|
|
2016-05-03 05:30:42 +08:00
|
|
|
template InputFile *SymbolBody::template getSourceFile<ELF32LE>();
|
|
|
|
template InputFile *SymbolBody::template getSourceFile<ELF32BE>();
|
|
|
|
template InputFile *SymbolBody::template getSourceFile<ELF64LE>();
|
|
|
|
template InputFile *SymbolBody::template getSourceFile<ELF64BE>();
|
|
|
|
|
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-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-04-01 05:26:23 +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-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>;
|