2015-07-25 05:03:07 +08:00
|
|
|
//===- SymbolTable.cpp ----------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-10-14 03:51:57 +08:00
|
|
|
//
|
|
|
|
// Symbol table is a bag of all known symbols. We put all symbols of
|
2016-01-06 04:47:37 +08:00
|
|
|
// all input files to the symbol table. The symbol table is basically
|
2015-10-14 03:51:57 +08:00
|
|
|
// a hash table with the logic to resolve symbol name conflicts using
|
|
|
|
// the symbol types.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
#include "SymbolTable.h"
|
2015-09-12 06:42:45 +08:00
|
|
|
#include "Config.h"
|
2015-08-06 23:08:23 +08:00
|
|
|
#include "Error.h"
|
2016-06-29 10:46:51 +08:00
|
|
|
#include "LinkerScript.h"
|
2016-09-09 22:16:00 +08:00
|
|
|
#include "Strings.h"
|
2016-07-12 15:44:40 +08:00
|
|
|
#include "SymbolListFile.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "Symbols.h"
|
2016-02-13 04:54:57 +08:00
|
|
|
#include "llvm/Bitcode/ReaderWriter.h"
|
2016-01-08 01:20:07 +08:00
|
|
|
#include "llvm/Support/StringSaver.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
2015-08-31 09:16:19 +08:00
|
|
|
using namespace llvm::object;
|
2015-09-23 02:19:46 +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-01-06 04:47:37 +08:00
|
|
|
// All input object files must be for the same architecture
|
|
|
|
// (e.g. it does not make sense to link x86 object files with
|
|
|
|
// MIPS object files.) This function checks for that error.
|
2016-06-29 17:46:00 +08:00
|
|
|
template <class ELFT> static bool isCompatible(InputFile *F) {
|
|
|
|
if (!isa<ELFFileBase<ELFT>>(F) && !isa<BitcodeFile>(F))
|
2016-01-30 03:41:13 +08:00
|
|
|
return true;
|
2016-06-29 09:30:50 +08:00
|
|
|
if (F->EKind == Config->EKind && F->EMachine == Config->EMachine)
|
2016-01-30 03:41:13 +08:00
|
|
|
return true;
|
2015-12-17 07:31:22 +08:00
|
|
|
StringRef A = F->getName();
|
|
|
|
StringRef B = Config->Emulation;
|
|
|
|
if (B.empty())
|
|
|
|
B = Config->FirstElf->getName();
|
2016-01-30 03:41:13 +08:00
|
|
|
error(A + " is incompatible with " + B);
|
|
|
|
return false;
|
2015-12-17 07:31:22 +08:00
|
|
|
}
|
|
|
|
|
2016-01-06 04:47:37 +08:00
|
|
|
// Add symbols in File to the symbol table.
|
2015-10-10 05:07:25 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void SymbolTable<ELFT>::addFile(std::unique_ptr<InputFile> File) {
|
2015-12-23 22:35:51 +08:00
|
|
|
InputFile *FileP = File.get();
|
2016-01-30 03:41:13 +08:00
|
|
|
if (!isCompatible<ELFT>(FileP))
|
|
|
|
return;
|
2015-10-11 11:36:49 +08:00
|
|
|
|
2015-12-17 06:59:13 +08:00
|
|
|
// .a file
|
|
|
|
if (auto *F = dyn_cast<ArchiveFile>(FileP)) {
|
2015-12-23 22:35:51 +08:00
|
|
|
ArchiveFiles.emplace_back(cast<ArchiveFile>(File.release()));
|
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
|
|
|
F->parse<ELFT>();
|
2015-09-05 06:28:10 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-10-13 02:03:21 +08:00
|
|
|
|
2016-04-14 02:07:57 +08:00
|
|
|
// Lazy object file
|
|
|
|
if (auto *F = dyn_cast<LazyObjectFile>(FileP)) {
|
|
|
|
LazyObjectFiles.emplace_back(cast<LazyObjectFile>(File.release()));
|
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
|
|
|
F->parse<ELFT>();
|
2016-04-14 02:07:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Config->Trace)
|
2016-07-17 02:55:47 +08:00
|
|
|
outs() << getFilename(FileP) << "\n";
|
2016-04-14 02:07:57 +08:00
|
|
|
|
2015-12-17 06:59:13 +08:00
|
|
|
// .so file
|
|
|
|
if (auto *F = dyn_cast<SharedFile<ELFT>>(FileP)) {
|
|
|
|
// DSOs are uniquified not by filename but by soname.
|
|
|
|
F->parseSoName();
|
2016-01-09 06:17:42 +08:00
|
|
|
if (!SoNames.insert(F->getSoName()).second)
|
2015-10-02 03:52:48 +08:00
|
|
|
return;
|
2015-12-17 06:59:13 +08:00
|
|
|
|
2015-12-23 22:35:51 +08:00
|
|
|
SharedFiles.emplace_back(cast<SharedFile<ELFT>>(File.release()));
|
2016-01-06 09:56:36 +08:00
|
|
|
F->parseRest();
|
2015-12-17 06:59:13 +08:00
|
|
|
return;
|
2015-10-02 03:52:48 +08:00
|
|
|
}
|
2015-12-17 06:59:13 +08:00
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
// LLVM bitcode file
|
2016-02-13 04:54:57 +08:00
|
|
|
if (auto *F = dyn_cast<BitcodeFile>(FileP)) {
|
|
|
|
BitcodeFiles.emplace_back(cast<BitcodeFile>(File.release()));
|
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
|
|
|
F->parse<ELFT>(ComdatGroups);
|
2016-02-13 04:54:57 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
// Regular object file
|
2015-12-17 06:59:13 +08:00
|
|
|
auto *F = cast<ObjectFile<ELFT>>(FileP);
|
2015-12-23 22:35:51 +08:00
|
|
|
ObjectFiles.emplace_back(cast<ObjectFile<ELFT>>(File.release()));
|
2016-01-06 10:06:33 +08:00
|
|
|
F->parse(ComdatGroups);
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
|
2016-04-23 08:26:32 +08:00
|
|
|
// This function is where all the optimizations of link-time
|
|
|
|
// optimization happens. When LTO is in use, some input files are
|
|
|
|
// not in native object file format but in the LLVM bitcode format.
|
|
|
|
// This function compiles bitcode files into a few big native files
|
|
|
|
// using LLVM functions and replaces bitcode symbols with the results.
|
|
|
|
// Because all bitcode files that consist of a program are passed
|
|
|
|
// to the compiler at once, it can do whole-program optimization.
|
2016-02-13 04:54:57 +08:00
|
|
|
template <class ELFT> void SymbolTable<ELFT>::addCombinedLtoObject() {
|
|
|
|
if (BitcodeFiles.empty())
|
|
|
|
return;
|
2016-03-23 04:52:10 +08:00
|
|
|
|
|
|
|
// Compile bitcode files.
|
|
|
|
Lto.reset(new BitcodeCompiler);
|
|
|
|
for (const std::unique_ptr<BitcodeFile> &F : BitcodeFiles)
|
|
|
|
Lto->add(*F);
|
2016-04-16 06:38:10 +08:00
|
|
|
std::vector<std::unique_ptr<InputFile>> IFs = Lto->compile();
|
2016-03-23 04:52:10 +08:00
|
|
|
|
|
|
|
// Replace bitcode symbols.
|
2016-04-16 06:38:10 +08:00
|
|
|
for (auto &IF : IFs) {
|
|
|
|
ObjectFile<ELFT> *Obj = cast<ObjectFile<ELFT>>(IF.release());
|
|
|
|
|
2016-07-17 02:55:47 +08:00
|
|
|
DenseSet<StringRef> DummyGroups;
|
2016-04-16 06:38:10 +08:00
|
|
|
Obj->parse(DummyGroups);
|
|
|
|
ObjectFiles.emplace_back(Obj);
|
2016-02-13 04:54:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-06 15:43:03 +08:00
|
|
|
template <class ELFT>
|
2016-04-04 22:04:16 +08:00
|
|
|
DefinedRegular<ELFT> *SymbolTable<ELFT>::addAbsolute(StringRef Name,
|
|
|
|
uint8_t Visibility) {
|
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 cast<DefinedRegular<ELFT>>(
|
|
|
|
addRegular(Name, STB_GLOBAL, Visibility)->body());
|
2015-09-26 02:56:53 +08:00
|
|
|
}
|
|
|
|
|
2016-01-06 04:47:37 +08:00
|
|
|
// Add Name as an "ignored" symbol. An ignored symbol is a regular
|
2016-04-04 22:04:16 +08:00
|
|
|
// linker-synthesized defined symbol, but is only defined if needed.
|
2015-12-16 22:45:09 +08:00
|
|
|
template <class ELFT>
|
2016-04-04 22:04:16 +08:00
|
|
|
DefinedRegular<ELFT> *SymbolTable<ELFT>::addIgnored(StringRef Name,
|
|
|
|
uint8_t Visibility) {
|
|
|
|
if (!find(Name))
|
|
|
|
return nullptr;
|
|
|
|
return addAbsolute(Name, Visibility);
|
2015-10-02 05:22:26 +08:00
|
|
|
}
|
|
|
|
|
2016-07-18 01:50:09 +08:00
|
|
|
// Set a flag for --trace-symbol so that we can print out a log message
|
|
|
|
// if a new symbol with the same name is inserted into the symbol table.
|
|
|
|
template <class ELFT> void SymbolTable<ELFT>::trace(StringRef Name) {
|
2016-07-18 09:35:00 +08:00
|
|
|
Symtab.insert({Name, {-1, true}});
|
2016-07-18 01:50:09 +08:00
|
|
|
}
|
|
|
|
|
2016-01-08 01:20:07 +08:00
|
|
|
// Rename SYM as __wrap_SYM. The original symbol is preserved as __real_SYM.
|
|
|
|
// Used to implement --wrap.
|
|
|
|
template <class ELFT> void SymbolTable<ELFT>::wrap(StringRef Name) {
|
2016-04-28 08:03:38 +08:00
|
|
|
SymbolBody *B = find(Name);
|
|
|
|
if (!B)
|
2016-01-08 01:20:07 +08:00
|
|
|
return;
|
|
|
|
StringSaver Saver(Alloc);
|
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
|
|
|
Symbol *Sym = B->symbol();
|
|
|
|
Symbol *Real = addUndefined(Saver.save("__real_" + Name));
|
|
|
|
Symbol *Wrap = addUndefined(Saver.save("__wrap_" + Name));
|
|
|
|
// We rename symbols by replacing the old symbol's SymbolBody with the new
|
|
|
|
// symbol's SymbolBody. This causes all SymbolBody pointers referring to the
|
|
|
|
// old symbol to instead refer to the new symbol.
|
|
|
|
memcpy(Real->Body.buffer, Sym->Body.buffer, sizeof(Sym->Body));
|
|
|
|
memcpy(Sym->Body.buffer, Wrap->Body.buffer, sizeof(Wrap->Body));
|
2016-01-08 01:20:07 +08:00
|
|
|
}
|
|
|
|
|
2016-04-23 02:42:48 +08:00
|
|
|
static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
|
|
|
|
if (VA == STV_DEFAULT)
|
|
|
|
return VB;
|
|
|
|
if (VB == STV_DEFAULT)
|
|
|
|
return VA;
|
|
|
|
return std::min(VA, VB);
|
|
|
|
}
|
|
|
|
|
2016-07-21 21:13:21 +08:00
|
|
|
// Parses a symbol in the form of <name>@<version> or <name>@@<version>.
|
|
|
|
static std::pair<StringRef, uint16_t> getSymbolVersion(StringRef S) {
|
|
|
|
if (Config->VersionDefinitions.empty())
|
|
|
|
return {S, Config->DefaultSymbolVersion};
|
|
|
|
|
|
|
|
size_t Pos = S.find('@');
|
|
|
|
if (Pos == 0 || Pos == StringRef::npos)
|
|
|
|
return {S, Config->DefaultSymbolVersion};
|
|
|
|
|
|
|
|
StringRef Name = S.substr(0, Pos);
|
|
|
|
StringRef Verstr = S.substr(Pos + 1);
|
|
|
|
if (Verstr.empty())
|
|
|
|
return {S, Config->DefaultSymbolVersion};
|
|
|
|
|
|
|
|
// '@@' in a symbol name means the default version.
|
|
|
|
// It is usually the most recent one.
|
|
|
|
bool IsDefault = (Verstr[0] == '@');
|
|
|
|
if (IsDefault)
|
|
|
|
Verstr = Verstr.substr(1);
|
|
|
|
|
|
|
|
for (VersionDefinition &V : Config->VersionDefinitions) {
|
|
|
|
if (V.Name == Verstr)
|
|
|
|
return {Name, IsDefault ? V.Id : (V.Id | VERSYM_HIDDEN)};
|
|
|
|
}
|
|
|
|
|
|
|
|
// It is an error if the specified version was not defined.
|
|
|
|
error("symbol " + S + " has undefined version " + Verstr);
|
|
|
|
return {S, Config->DefaultSymbolVersion};
|
|
|
|
}
|
|
|
|
|
2016-01-09 06:01:33 +08:00
|
|
|
// Find an existing symbol or create and insert a new one.
|
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
|
|
|
template <class ELFT>
|
2016-07-21 21:13:21 +08:00
|
|
|
std::pair<Symbol *, bool> SymbolTable<ELFT>::insert(StringRef &Name) {
|
2016-07-20 22:26:48 +08:00
|
|
|
auto P = Symtab.insert({Name, SymIndex((int)SymVector.size(), false)});
|
2016-07-18 09:35:00 +08:00
|
|
|
SymIndex &V = P.first->second;
|
2016-07-18 01:50:09 +08:00
|
|
|
bool IsNew = P.second;
|
|
|
|
|
2016-07-18 09:35:00 +08:00
|
|
|
if (V.Idx == -1) {
|
|
|
|
IsNew = true;
|
2016-07-20 22:26:48 +08:00
|
|
|
V = SymIndex((int)SymVector.size(), true);
|
2016-07-18 09:35:00 +08:00
|
|
|
}
|
|
|
|
|
2016-04-15 04:42:43 +08:00
|
|
|
Symbol *Sym;
|
2016-07-18 01:50:09 +08:00
|
|
|
if (IsNew) {
|
2016-04-23 04:21:26 +08:00
|
|
|
Sym = new (Alloc) Symbol;
|
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
|
|
|
Sym->Binding = STB_WEAK;
|
2016-04-23 04:21:26 +08:00
|
|
|
Sym->Visibility = STV_DEFAULT;
|
|
|
|
Sym->IsUsedInRegularObj = false;
|
2016-08-31 04:15:03 +08:00
|
|
|
Sym->HasUnnamedAddr = true;
|
2016-04-23 04:21:26 +08:00
|
|
|
Sym->ExportDynamic = false;
|
2016-07-18 09:35:00 +08:00
|
|
|
Sym->Traced = V.Traced;
|
2016-07-21 21:13:21 +08:00
|
|
|
std::tie(Name, Sym->VersionId) = getSymbolVersion(Name);
|
2016-04-15 04:42:43 +08:00
|
|
|
SymVector.push_back(Sym);
|
|
|
|
} else {
|
2016-07-18 09:35:00 +08:00
|
|
|
Sym = SymVector[V.Idx];
|
2016-04-15 04:42:43 +08:00
|
|
|
}
|
2016-07-18 01:50:09 +08:00
|
|
|
return {Sym, IsNew};
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Find an existing symbol or create and insert a new one, then apply the given
|
|
|
|
// attributes.
|
|
|
|
template <class ELFT>
|
|
|
|
std::pair<Symbol *, bool>
|
2016-07-21 21:13:21 +08:00
|
|
|
SymbolTable<ELFT>::insert(StringRef &Name, uint8_t Type, uint8_t Visibility,
|
2016-08-31 04:15:03 +08:00
|
|
|
bool CanOmitFromDynSym, bool HasUnnamedAddr,
|
2016-08-31 21:49:23 +08:00
|
|
|
InputFile *File) {
|
|
|
|
bool IsUsedInRegularObj = !File || File->kind() == InputFile::ObjectKind;
|
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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
|
|
|
std::tie(S, WasInserted) = insert(Name);
|
|
|
|
|
2016-08-31 04:15:03 +08:00
|
|
|
// Merge in the new unnamed_addr attribute.
|
|
|
|
S->HasUnnamedAddr &= HasUnnamedAddr;
|
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
|
|
|
// Merge in the new symbol's visibility.
|
|
|
|
S->Visibility = getMinVisibility(S->Visibility, Visibility);
|
|
|
|
if (!CanOmitFromDynSym && (Config->Shared || Config->ExportDynamic))
|
|
|
|
S->ExportDynamic = true;
|
|
|
|
if (IsUsedInRegularObj)
|
|
|
|
S->IsUsedInRegularObj = true;
|
2016-05-04 02:03:47 +08:00
|
|
|
if (!WasInserted && S->body()->Type != SymbolBody::UnknownType &&
|
|
|
|
((Type == STT_TLS) != S->body()->isTls()))
|
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
|
|
|
error("TLS attribute mismatch for symbol: " +
|
|
|
|
conflictMsg(S->body(), File));
|
|
|
|
|
|
|
|
return {S, WasInserted};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct a string in the form of "Sym in File1 and File2".
|
|
|
|
// Used to construct an error message.
|
|
|
|
template <typename ELFT>
|
|
|
|
std::string SymbolTable<ELFT>::conflictMsg(SymbolBody *Existing,
|
|
|
|
InputFile *NewFile) {
|
2016-07-08 07:04:15 +08:00
|
|
|
std::string Sym = Existing->getName();
|
|
|
|
if (Config->Demangle)
|
|
|
|
Sym = demangle(Sym);
|
2016-07-17 11:11:46 +08:00
|
|
|
return Sym + " in " + getFilename(Existing->File) + " and " +
|
2016-07-08 07:04:15 +08:00
|
|
|
getFilename(NewFile);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT> Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name) {
|
|
|
|
return addUndefined(Name, STB_GLOBAL, STV_DEFAULT, /*Type*/ 0,
|
2016-08-31 04:15:03 +08:00
|
|
|
/*CanOmitFromDynSym*/ false, /*HasUnnamedAddr*/ false,
|
|
|
|
/*File*/ nullptr);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
Symbol *SymbolTable<ELFT>::addUndefined(StringRef Name, uint8_t Binding,
|
|
|
|
uint8_t StOther, uint8_t Type,
|
2016-06-16 01:56:10 +08:00
|
|
|
bool CanOmitFromDynSym,
|
2016-08-31 04:15:03 +08:00
|
|
|
bool HasUnnamedAddr, 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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
|
|
|
std::tie(S, WasInserted) =
|
2016-08-31 21:49:23 +08:00
|
|
|
insert(Name, Type, StOther & 3, CanOmitFromDynSym, HasUnnamedAddr, 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
|
|
|
if (WasInserted) {
|
|
|
|
S->Binding = Binding;
|
2016-07-17 11:11:46 +08:00
|
|
|
replaceBody<Undefined>(S, Name, StOther, Type, 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
|
|
|
return S;
|
|
|
|
}
|
2016-06-10 02:01:35 +08:00
|
|
|
if (Binding != STB_WEAK) {
|
|
|
|
if (S->body()->isShared() || S->body()->isLazy())
|
|
|
|
S->Binding = Binding;
|
|
|
|
if (auto *SS = dyn_cast<SharedSymbol<ELFT>>(S->body()))
|
2016-07-17 11:11:46 +08:00
|
|
|
SS->file()->IsUsed = true;
|
2016-06-10 02:01:35 +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
|
|
|
if (auto *L = dyn_cast<Lazy>(S->body())) {
|
|
|
|
// An undefined weak will not fetch archive members, but we have to remember
|
|
|
|
// its type. See also comment in addLazyArchive.
|
|
|
|
if (S->isWeak())
|
|
|
|
L->Type = Type;
|
2016-07-17 11:11:46 +08:00
|
|
|
else if (auto F = L->fetch())
|
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
|
|
|
addFile(std::move(F));
|
|
|
|
}
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a new defined symbol with the specified binding. Return 1 if the new
|
|
|
|
// symbol should win, -1 if the new symbol should lose, or 0 if both symbols are
|
|
|
|
// strong defined symbols.
|
|
|
|
static int compareDefined(Symbol *S, bool WasInserted, uint8_t Binding) {
|
|
|
|
if (WasInserted)
|
|
|
|
return 1;
|
|
|
|
SymbolBody *Body = S->body();
|
|
|
|
if (Body->isLazy() || Body->isUndefined() || Body->isShared())
|
|
|
|
return 1;
|
|
|
|
if (Binding == STB_WEAK)
|
|
|
|
return -1;
|
|
|
|
if (S->isWeak())
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have a new non-common defined symbol with the specified binding. Return 1
|
|
|
|
// if the new symbol should win, -1 if the new symbol should lose, or 0 if there
|
|
|
|
// is a conflict. If the new symbol wins, also update the binding.
|
2016-07-29 03:24:13 +08:00
|
|
|
static int compareDefinedNonCommon(Symbol *S, bool WasInserted,
|
|
|
|
uint8_t Binding) {
|
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 (int Cmp = compareDefined(S, WasInserted, Binding)) {
|
|
|
|
if (Cmp > 0)
|
|
|
|
S->Binding = Binding;
|
|
|
|
return Cmp;
|
|
|
|
}
|
2016-08-31 21:28:33 +08:00
|
|
|
if (isa<DefinedCommon>(S->body())) {
|
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
|
|
|
// Non-common symbols take precedence over common symbols.
|
|
|
|
if (Config->WarnCommon)
|
|
|
|
warning("common " + S->body()->getName() + " is overridden");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
Symbol *SymbolTable<ELFT>::addCommon(StringRef N, uint64_t Size,
|
|
|
|
uint64_t Alignment, uint8_t Binding,
|
|
|
|
uint8_t StOther, uint8_t Type,
|
2016-08-31 04:15:03 +08:00
|
|
|
bool HasUnnamedAddr, 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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
2016-08-31 21:49:23 +08:00
|
|
|
std::tie(S, WasInserted) = insert(
|
|
|
|
N, Type, StOther & 3, /*CanOmitFromDynSym*/ false, HasUnnamedAddr, 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
|
|
|
int Cmp = compareDefined(S, WasInserted, Binding);
|
|
|
|
if (Cmp > 0) {
|
|
|
|
S->Binding = Binding;
|
2016-08-31 21:28:33 +08:00
|
|
|
replaceBody<DefinedCommon>(S, N, Size, Alignment, StOther, Type, 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
|
|
|
} else if (Cmp == 0) {
|
2016-08-31 21:28:33 +08:00
|
|
|
auto *C = dyn_cast<DefinedCommon>(S->body());
|
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 (!C) {
|
|
|
|
// Non-common symbols take precedence over common symbols.
|
|
|
|
if (Config->WarnCommon)
|
|
|
|
warning("common " + S->body()->getName() + " is overridden");
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Config->WarnCommon)
|
|
|
|
warning("multiple common of " + S->body()->getName());
|
|
|
|
|
2016-08-31 21:42:08 +08:00
|
|
|
Alignment = C->Alignment = std::max(C->Alignment, Alignment);
|
|
|
|
if (Size > C->Size)
|
|
|
|
replaceBody<DefinedCommon>(S, N, Size, Alignment, StOther, Type, 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
|
|
|
}
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
void SymbolTable<ELFT>::reportDuplicate(SymbolBody *Existing,
|
|
|
|
InputFile *NewFile) {
|
|
|
|
std::string Msg = "duplicate symbol: " + conflictMsg(Existing, NewFile);
|
|
|
|
if (Config->AllowMultipleDefinition)
|
|
|
|
warning(Msg);
|
|
|
|
else
|
|
|
|
error(Msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, const Elf_Sym &Sym,
|
|
|
|
InputSectionBase<ELFT> *Section) {
|
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
2016-08-31 21:49:23 +08:00
|
|
|
std::tie(S, WasInserted) =
|
|
|
|
insert(Name, Sym.getType(), Sym.getVisibility(),
|
|
|
|
/*CanOmitFromDynSym*/ false, /*HasUnnamedAddr*/ false,
|
|
|
|
Section ? Section->getFile() : nullptr);
|
2016-08-31 21:28:33 +08:00
|
|
|
int Cmp = compareDefinedNonCommon(S, WasInserted, Sym.getBinding());
|
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 (Cmp > 0)
|
|
|
|
replaceBody<DefinedRegular<ELFT>>(S, Name, Sym, Section);
|
|
|
|
else if (Cmp == 0)
|
|
|
|
reportDuplicate(S->body(), Section->getFile());
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
Symbol *SymbolTable<ELFT>::addRegular(StringRef Name, uint8_t Binding,
|
|
|
|
uint8_t StOther) {
|
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
|
|
|
std::tie(S, WasInserted) =
|
|
|
|
insert(Name, STT_NOTYPE, StOther & 3, /*CanOmitFromDynSym*/ false,
|
2016-08-31 21:49:23 +08:00
|
|
|
/*HasUnnamedAddr*/ false, nullptr);
|
2016-08-31 21:28:33 +08:00
|
|
|
int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
|
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 (Cmp > 0)
|
|
|
|
replaceBody<DefinedRegular<ELFT>>(S, Name, StOther);
|
|
|
|
else if (Cmp == 0)
|
|
|
|
reportDuplicate(S->body(), nullptr);
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
Symbol *SymbolTable<ELFT>::addSynthetic(StringRef N,
|
2016-05-03 09:21:08 +08:00
|
|
|
OutputSectionBase<ELFT> *Section,
|
2016-08-19 23:36:32 +08:00
|
|
|
uintX_t Value, uint8_t StOther) {
|
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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
2016-08-19 23:36:32 +08:00
|
|
|
std::tie(S, WasInserted) = insert(N, STT_NOTYPE, /*Visibility*/ StOther & 0x3,
|
|
|
|
/*CanOmitFromDynSym*/ false,
|
2016-08-31 21:49:23 +08:00
|
|
|
/*HasUnnamedAddr*/ false, nullptr);
|
2016-08-31 21:28:33 +08:00
|
|
|
int Cmp = compareDefinedNonCommon(S, WasInserted, STB_GLOBAL);
|
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 (Cmp > 0)
|
|
|
|
replaceBody<DefinedSynthetic<ELFT>>(S, N, Value, Section);
|
|
|
|
else if (Cmp == 0)
|
|
|
|
reportDuplicate(S->body(), nullptr);
|
|
|
|
return S;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename ELFT>
|
|
|
|
void SymbolTable<ELFT>::addShared(SharedFile<ELFT> *F, StringRef Name,
|
|
|
|
const Elf_Sym &Sym,
|
|
|
|
const typename ELFT::Verdef *Verdef) {
|
|
|
|
// DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
|
|
|
|
// as the visibility, which will leave the visibility in the symbol table
|
|
|
|
// unchanged.
|
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
|
|
|
std::tie(S, WasInserted) =
|
|
|
|
insert(Name, Sym.getType(), STV_DEFAULT, /*CanOmitFromDynSym*/ true,
|
2016-08-31 21:49:23 +08:00
|
|
|
/*HasUnnamedAddr*/ false, F);
|
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
|
|
|
// Make sure we preempt DSO symbols with default visibility.
|
|
|
|
if (Sym.getVisibility() == STV_DEFAULT)
|
|
|
|
S->ExportDynamic = true;
|
2016-06-10 02:01:35 +08:00
|
|
|
if (WasInserted || isa<Undefined>(S->body())) {
|
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
|
|
|
replaceBody<SharedSymbol<ELFT>>(S, F, Name, Sym, Verdef);
|
2016-06-10 02:01:35 +08:00
|
|
|
if (!S->isWeak())
|
|
|
|
F->IsUsed = true;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
2016-08-31 04:53:26 +08:00
|
|
|
Symbol *SymbolTable<ELFT>::addBitcode(StringRef Name, uint8_t Binding,
|
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,
|
2016-08-31 04:15:03 +08:00
|
|
|
bool CanOmitFromDynSym,
|
|
|
|
bool HasUnnamedAddr, BitcodeFile *F) {
|
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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
2016-08-31 04:15:03 +08:00
|
|
|
std::tie(S, WasInserted) =
|
2016-08-31 21:49:23 +08:00
|
|
|
insert(Name, Type, StOther & 3, CanOmitFromDynSym, HasUnnamedAddr, F);
|
2016-08-31 21:28:33 +08:00
|
|
|
int Cmp = compareDefinedNonCommon(S, WasInserted, Binding);
|
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 (Cmp > 0)
|
2016-08-31 20:30:34 +08:00
|
|
|
replaceBody<DefinedRegular<ELFT>>(S, Name, StOther, Type, F);
|
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
|
|
|
else if (Cmp == 0)
|
|
|
|
reportDuplicate(S->body(), F);
|
|
|
|
return S;
|
2015-09-05 06:28:10 +08:00
|
|
|
}
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-10-14 00:34:14 +08:00
|
|
|
template <class ELFT> SymbolBody *SymbolTable<ELFT>::find(StringRef Name) {
|
|
|
|
auto It = Symtab.find(Name);
|
|
|
|
if (It == Symtab.end())
|
|
|
|
return nullptr;
|
2016-07-18 09:35:00 +08:00
|
|
|
SymIndex V = It->second;
|
|
|
|
if (V.Idx == -1)
|
|
|
|
return nullptr;
|
|
|
|
return SymVector[V.Idx]->body();
|
2015-10-14 00:34:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-03 05:17:20 +08:00
|
|
|
// Returns a list of defined symbols that match with a given regex.
|
2016-06-29 10:46:51 +08:00
|
|
|
template <class ELFT>
|
2016-09-03 05:17:20 +08:00
|
|
|
std::vector<SymbolBody *> SymbolTable<ELFT>::findAll(const Regex &Re) {
|
2016-06-29 12:47:39 +08:00
|
|
|
std::vector<SymbolBody *> Res;
|
2016-07-18 09:34:57 +08:00
|
|
|
for (Symbol *Sym : SymVector) {
|
|
|
|
SymbolBody *B = Sym->body();
|
2016-09-03 05:17:20 +08:00
|
|
|
StringRef Name = B->getName();
|
|
|
|
if (!B->isUndefined() && const_cast<Regex &>(Re).match(Name))
|
2016-06-29 12:47:39 +08:00
|
|
|
Res.push_back(B);
|
|
|
|
}
|
|
|
|
return Res;
|
2016-06-29 10:46:51 +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
|
|
|
template <class ELFT>
|
2016-07-17 02:55:47 +08:00
|
|
|
void SymbolTable<ELFT>::addLazyArchive(ArchiveFile *F,
|
|
|
|
const object::Archive::Symbol Sym) {
|
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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
2016-07-21 21:13:21 +08:00
|
|
|
StringRef Name = Sym.getName();
|
|
|
|
std::tie(S, WasInserted) = insert(Name);
|
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 (WasInserted) {
|
2016-06-15 05:40:23 +08:00
|
|
|
replaceBody<LazyArchive>(S, *F, Sym, SymbolBody::UnknownType);
|
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;
|
|
|
|
}
|
|
|
|
if (!S->body()->isUndefined())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Weak undefined symbols should not fetch members from archives. If we were
|
|
|
|
// to keep old symbol we would not know that an archive member was available
|
|
|
|
// if a strong undefined symbol shows up afterwards in the link. If a strong
|
|
|
|
// undefined symbol never shows up, this lazy symbol will get to the end of
|
|
|
|
// the link and must be treated as the weak undefined one. We already marked
|
|
|
|
// this symbol as used when we added it to the symbol table, but we also need
|
|
|
|
// to preserve its type. FIXME: Move the Type field to Symbol.
|
|
|
|
if (S->isWeak()) {
|
2016-06-15 05:40:23 +08:00
|
|
|
replaceBody<LazyArchive>(S, *F, Sym, S->body()->Type);
|
2015-10-06 22:33:58 +08:00
|
|
|
return;
|
|
|
|
}
|
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
|
|
|
MemoryBufferRef MBRef = F->getMember(&Sym);
|
|
|
|
if (!MBRef.getBuffer().empty())
|
|
|
|
addFile(createObjectFile(MBRef, F->getName()));
|
2015-09-05 06:28:10 +08:00
|
|
|
}
|
|
|
|
|
2015-12-17 07:23:14 +08:00
|
|
|
template <class ELFT>
|
2016-06-15 05:56:36 +08:00
|
|
|
void SymbolTable<ELFT>::addLazyObject(StringRef Name, LazyObjectFile &Obj) {
|
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
|
|
|
Symbol *S;
|
|
|
|
bool WasInserted;
|
|
|
|
std::tie(S, WasInserted) = insert(Name);
|
|
|
|
if (WasInserted) {
|
2016-06-15 05:56:36 +08:00
|
|
|
replaceBody<LazyObject>(S, Name, Obj, SymbolBody::UnknownType);
|
2015-12-17 07:23:14 +08:00
|
|
|
return;
|
|
|
|
}
|
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 (!S->body()->isUndefined())
|
|
|
|
return;
|
2015-12-17 07:23:14 +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
|
|
|
// See comment for addLazyArchive above.
|
2016-06-15 05:56:36 +08:00
|
|
|
if (S->isWeak()) {
|
|
|
|
replaceBody<LazyObject>(S, Name, Obj, S->body()->Type);
|
|
|
|
} else {
|
|
|
|
MemoryBufferRef MBRef = Obj.getBuffer();
|
|
|
|
if (!MBRef.getBuffer().empty())
|
|
|
|
addFile(createObjectFile(MBRef));
|
|
|
|
}
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
2015-09-26 02:56:53 +08:00
|
|
|
|
2016-04-27 08:05:03 +08:00
|
|
|
// Process undefined (-u) flags by loading lazy symbols named by those flags.
|
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
|
|
|
template <class ELFT> void SymbolTable<ELFT>::scanUndefinedFlags() {
|
2016-04-27 08:05:03 +08:00
|
|
|
for (StringRef S : Config->Undefined)
|
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 (auto *L = dyn_cast_or_null<Lazy>(find(S)))
|
2016-07-17 11:11:46 +08:00
|
|
|
if (std::unique_ptr<InputFile> File = L->fetch())
|
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
|
|
|
addFile(std::move(File));
|
2016-04-27 08:05:03 +08:00
|
|
|
}
|
|
|
|
|
2015-10-14 02:10:33 +08:00
|
|
|
// This function takes care of the case in which shared libraries depend on
|
|
|
|
// the user program (not the other way, which is usual). Shared libraries
|
|
|
|
// may have undefined symbols, expecting that the user program provides
|
|
|
|
// the definitions for them. An example is BSD's __progname symbol.
|
|
|
|
// We need to put such symbols to the main program's .dynsym so that
|
|
|
|
// shared libraries can find them.
|
|
|
|
// Except this, we ignore undefined symbols in DSOs.
|
|
|
|
template <class ELFT> void SymbolTable<ELFT>::scanShlibUndefined() {
|
2015-10-14 00:34:14 +08:00
|
|
|
for (std::unique_ptr<SharedFile<ELFT>> &File : SharedFiles)
|
|
|
|
for (StringRef U : File->getUndefinedSymbols())
|
|
|
|
if (SymbolBody *Sym = find(U))
|
|
|
|
if (Sym->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
|
|
|
Sym->symbol()->ExportDynamic = true;
|
2015-10-14 00:34:14 +08:00
|
|
|
}
|
|
|
|
|
2016-09-03 06:15:08 +08:00
|
|
|
// This function processes --export-dynamic-symbol and --dynamic-list.
|
2016-04-14 02:51:11 +08:00
|
|
|
template <class ELFT> void SymbolTable<ELFT>::scanDynamicList() {
|
|
|
|
for (StringRef S : Config->DynamicList)
|
|
|
|
if (SymbolBody *B = find(S))
|
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
|
|
|
B->symbol()->ExportDynamic = true;
|
2016-04-14 02:51:11 +08:00
|
|
|
}
|
|
|
|
|
2016-07-16 20:26:39 +08:00
|
|
|
static void setVersionId(SymbolBody *Body, StringRef VersionName,
|
|
|
|
StringRef Name, uint16_t Version) {
|
|
|
|
if (!Body || Body->isUndefined()) {
|
|
|
|
if (Config->NoUndefinedVersion)
|
|
|
|
error("version script assignment of " + VersionName + " to symbol " +
|
|
|
|
Name + " failed: symbol not defined");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol *Sym = Body->symbol();
|
2016-07-17 02:45:25 +08:00
|
|
|
if (Sym->VersionId != Config->DefaultSymbolVersion)
|
2016-07-16 20:26:39 +08:00
|
|
|
warning("duplicate symbol " + Name + " in version script");
|
|
|
|
Sym->VersionId = Version;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class ELFT>
|
|
|
|
std::map<std::string, SymbolBody *> SymbolTable<ELFT>::getDemangledSyms() {
|
|
|
|
std::map<std::string, SymbolBody *> Result;
|
2016-07-18 09:34:57 +08:00
|
|
|
for (Symbol *Sym : SymVector) {
|
|
|
|
SymbolBody *B = Sym->body();
|
|
|
|
Result[demangle(B->getName())] = B;
|
|
|
|
}
|
2016-07-16 20:26:39 +08:00
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool hasExternCpp() {
|
|
|
|
for (VersionDefinition &V : Config->VersionDefinitions)
|
|
|
|
for (SymbolVersion Sym : V.Globals)
|
|
|
|
if (Sym.IsExternCpp)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-30 17:29:37 +08:00
|
|
|
static SymbolBody *findDemangled(const std::map<std::string, SymbolBody *> &D,
|
|
|
|
StringRef Name) {
|
|
|
|
auto I = D.find(Name);
|
|
|
|
if (I != D.end())
|
|
|
|
return I->second;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-30 17:35:03 +08:00
|
|
|
static std::vector<SymbolBody *>
|
|
|
|
findAllDemangled(const std::map<std::string, SymbolBody *> &D,
|
2016-09-03 05:17:20 +08:00
|
|
|
const Regex &Re) {
|
2016-08-30 17:35:03 +08:00
|
|
|
std::vector<SymbolBody *> Res;
|
|
|
|
for (auto &P : D) {
|
|
|
|
SymbolBody *Body = P.second;
|
2016-09-03 05:17:20 +08:00
|
|
|
if (!Body->isUndefined() && const_cast<Regex &>(Re).match(P.first))
|
2016-08-30 17:35:03 +08:00
|
|
|
Res.push_back(Body);
|
|
|
|
}
|
|
|
|
return Res;
|
|
|
|
}
|
|
|
|
|
2016-09-03 06:15:08 +08:00
|
|
|
// This function processes version scripts by updating VersionId
|
|
|
|
// member of symbols.
|
2016-04-23 04:21:26 +08:00
|
|
|
template <class ELFT> void SymbolTable<ELFT>::scanVersionScript() {
|
2016-09-03 06:15:08 +08:00
|
|
|
// If there's only one anonymous version definition in a version
|
|
|
|
// script file, the script does not actullay define any symbol version,
|
|
|
|
// but just specifies symbols visibilities. We assume that the script was
|
|
|
|
// in the form of { global: foo; bar; local *; }. So, local is default.
|
|
|
|
// Here, we make specified symbols global.
|
2016-06-20 19:55:12 +08:00
|
|
|
if (!Config->VersionScriptGlobals.empty()) {
|
2016-09-08 22:50:55 +08:00
|
|
|
std::vector<StringRef> Globs;
|
|
|
|
for (SymbolVersion &Sym : Config->VersionScriptGlobals) {
|
|
|
|
if (hasWildcard(Sym.Name)) {
|
|
|
|
Globs.push_back(Sym.Name);
|
|
|
|
continue;
|
|
|
|
}
|
2016-07-16 20:26:39 +08:00
|
|
|
if (SymbolBody *B = find(Sym.Name))
|
2016-06-20 19:55:12 +08:00
|
|
|
B->symbol()->VersionId = VER_NDX_GLOBAL;
|
2016-09-08 22:50:55 +08:00
|
|
|
}
|
|
|
|
if (Globs.empty())
|
|
|
|
return;
|
|
|
|
Regex Re = compileGlobPatterns(Globs);
|
|
|
|
std::vector<SymbolBody *> Syms = findAll(Re);
|
|
|
|
for (SymbolBody *B : Syms)
|
|
|
|
B->symbol()->VersionId = VER_NDX_GLOBAL;
|
2016-06-20 19:55:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-16 12:09:27 +08:00
|
|
|
if (Config->VersionDefinitions.empty())
|
[ELF] - Fixed incorrect logic of version assignments when mixing wildcards with values matching.
Previously we had incorrect logic here. Imagine we would have the next script:
LIBSAMPLE_1.0
{
global:
a_2;
local:
*;
};
LIBSAMPLE_2.0
{
global:
a*;
};
According to previous logic it would assign version 1 to a_2 and then
would try to reassign it to version 2 because of applying wildcard a*.
And show a warning about that.
Generally Ian Lance Tailor wrote about next rules that should be applied:
(http://www.airs.com/blog/archives/300)
Here are the current rules for gold:
"If there is an exact match for the mangled name, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look for an extern C++ or an extern Java exact match. If we find an exact match, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look through the wildcard patterns, ignoring “*” patterns. We look through the version tags in reverse order. For each version tag, we look through the global patterns and then the local patterns. We use the first match we find (i.e., the last matching version tag in the file).
Otherwise, we use the “*” pattern if there is one. We give a warning if there are multiple “*” patterns."
Patch makes wildcard matching to be in revered order and to follow after the regular naming matching.
Differential revision: http://reviews.llvm.org/D21894
llvm-svn: 274739
2016-07-07 15:45:27 +08:00
|
|
|
return;
|
|
|
|
|
2016-09-03 06:15:08 +08:00
|
|
|
// Now we have version definitions, so we need to set version ids to symbols.
|
|
|
|
// Each version definition has a glob pattern, and all symbols that match
|
|
|
|
// with the pattern get that version.
|
|
|
|
|
|
|
|
// Users can use "extern C++ {}" directive to match against demangled
|
|
|
|
// C++ symbols. For example, you can write a pattern such as
|
|
|
|
// "llvm::*::foo(int, ?)". Obviously, there's no way to handle this
|
|
|
|
// other than trying to match a regexp against all demangled symbols.
|
|
|
|
// So, if "extern C++" feature is used, we demangle all known symbols.
|
2016-07-16 20:26:39 +08:00
|
|
|
std::map<std::string, SymbolBody *> Demangled;
|
|
|
|
if (hasExternCpp())
|
|
|
|
Demangled = getDemangledSyms();
|
|
|
|
|
2016-09-03 06:15:08 +08:00
|
|
|
// First, we assign versions to exact matching symbols,
|
|
|
|
// i.e. version definitions not containing any glob meta-characters.
|
2016-07-16 20:26:39 +08:00
|
|
|
for (VersionDefinition &V : Config->VersionDefinitions) {
|
|
|
|
for (SymbolVersion Sym : V.Globals) {
|
2016-09-09 22:16:00 +08:00
|
|
|
if (hasWildcard(Sym.Name))
|
2016-07-13 15:46:00 +08:00
|
|
|
continue;
|
2016-08-30 17:29:37 +08:00
|
|
|
StringRef N = Sym.Name;
|
|
|
|
SymbolBody *B = Sym.IsExternCpp ? findDemangled(Demangled, N) : find(N);
|
|
|
|
setVersionId(B, V.Name, N, V.Id);
|
[ELF] - Fixed incorrect logic of version assignments when mixing wildcards with values matching.
Previously we had incorrect logic here. Imagine we would have the next script:
LIBSAMPLE_1.0
{
global:
a_2;
local:
*;
};
LIBSAMPLE_2.0
{
global:
a*;
};
According to previous logic it would assign version 1 to a_2 and then
would try to reassign it to version 2 because of applying wildcard a*.
And show a warning about that.
Generally Ian Lance Tailor wrote about next rules that should be applied:
(http://www.airs.com/blog/archives/300)
Here are the current rules for gold:
"If there is an exact match for the mangled name, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look for an extern C++ or an extern Java exact match. If we find an exact match, we use it. If there is more than one exact match, we give a warning, and we use the first tag in the script which matches. If a symbol has an exact match as both global and local for the same version tag, we give an error.
Otherwise, we look through the wildcard patterns, ignoring “*” patterns. We look through the version tags in reverse order. For each version tag, we look through the global patterns and then the local patterns. We use the first match we find (i.e., the last matching version tag in the file).
Otherwise, we use the “*” pattern if there is one. We give a warning if there are multiple “*” patterns."
Patch makes wildcard matching to be in revered order and to follow after the regular naming matching.
Differential revision: http://reviews.llvm.org/D21894
llvm-svn: 274739
2016-07-07 15:45:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-03 06:15:08 +08:00
|
|
|
// Next, we assign versions to fuzzy matching symbols,
|
|
|
|
// i.e. version definitions containing glob meta-characters.
|
|
|
|
// Note that because the last match takes precedence over previous matches,
|
|
|
|
// we iterate over the definitions in the reverse order.
|
2016-07-16 12:09:27 +08:00
|
|
|
for (size_t I = Config->VersionDefinitions.size() - 1; I != (size_t)-1; --I) {
|
|
|
|
VersionDefinition &V = Config->VersionDefinitions[I];
|
2016-08-30 17:39:36 +08:00
|
|
|
for (SymbolVersion &Sym : V.Globals) {
|
2016-09-09 22:16:00 +08:00
|
|
|
if (!hasWildcard(Sym.Name))
|
2016-08-30 17:39:36 +08:00
|
|
|
continue;
|
2016-09-03 06:15:08 +08:00
|
|
|
Regex Re = compileGlobPatterns({Sym.Name});
|
|
|
|
std::vector<SymbolBody *> Syms =
|
|
|
|
Sym.IsExternCpp ? findAllDemangled(Demangled, Re) : findAll(Re);
|
|
|
|
|
|
|
|
// Exact matching takes precendence over fuzzy matching,
|
|
|
|
// so we set a version to a symbol only if no version has been assigned
|
|
|
|
// to the symbol. This behavior is compatible with GNU.
|
|
|
|
for (SymbolBody *B : Syms)
|
2016-08-30 17:39:36 +08:00
|
|
|
if (B->symbol()->VersionId == Config->DefaultSymbolVersion)
|
|
|
|
B->symbol()->VersionId = V.Id;
|
|
|
|
}
|
2016-06-20 19:55:12 +08:00
|
|
|
}
|
2016-04-23 04:21:26 +08:00
|
|
|
}
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
template class elf::SymbolTable<ELF32LE>;
|
|
|
|
template class elf::SymbolTable<ELF32BE>;
|
|
|
|
template class elf::SymbolTable<ELF64LE>;
|
|
|
|
template class elf::SymbolTable<ELF64BE>;
|