2015-08-14 22:12:54 +08:00
|
|
|
//===- Symbols.h ------------------------------------------------*- C++ -*-===//
|
2015-07-25 05:03:07 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
//
|
|
|
|
// All symbols are handled as SymbolBodies regardless of their types.
|
|
|
|
// This file defines various types of SymbolBodies.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
#ifndef LLD_ELF_SYMBOLS_H
|
|
|
|
#define LLD_ELF_SYMBOLS_H
|
|
|
|
|
2015-09-22 08:01:39 +08:00
|
|
|
#include "InputSection.h"
|
2015-08-25 04:06:32 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
2015-09-05 06:28:10 +08:00
|
|
|
#include "llvm/Object/Archive.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "llvm/Object/ELF.h"
|
|
|
|
|
|
|
|
namespace lld {
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-09-05 06:28:10 +08:00
|
|
|
class ArchiveFile;
|
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
|
|
|
class BitcodeFile;
|
2015-07-25 05:03:07 +08:00
|
|
|
class InputFile;
|
2016-06-15 05:56:36 +08:00
|
|
|
class LazyObjectFile;
|
2015-07-25 05:03:07 +08:00
|
|
|
class SymbolBody;
|
2015-07-29 06:58:25 +08:00
|
|
|
template <class ELFT> class ObjectFile;
|
2015-09-19 06:13:25 +08:00
|
|
|
template <class ELFT> class OutputSection;
|
2015-10-16 06:27:29 +08:00
|
|
|
template <class ELFT> class OutputSectionBase;
|
2015-10-12 04:59:12 +08:00
|
|
|
template <class ELFT> class SharedFile;
|
2015-07-25 05:03:07 +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
|
|
|
struct Symbol;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
// The base class for real symbol classes.
|
|
|
|
class SymbolBody {
|
|
|
|
public:
|
|
|
|
enum Kind {
|
2015-09-26 05:20:23 +08:00
|
|
|
DefinedFirst,
|
|
|
|
DefinedRegularKind = DefinedFirst,
|
|
|
|
SharedKind,
|
2015-12-25 00:23:37 +08:00
|
|
|
DefinedCommonKind,
|
2015-12-24 08:47:42 +08:00
|
|
|
DefinedSyntheticKind,
|
|
|
|
DefinedLast = DefinedSyntheticKind,
|
2016-04-27 08:05:06 +08:00
|
|
|
UndefinedKind,
|
2016-04-08 03:24:51 +08:00
|
|
|
LazyArchiveKind,
|
|
|
|
LazyObjectKind,
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2016-07-18 01:50:09 +08:00
|
|
|
SymbolBody(Kind K) : SymbolKind(K) {}
|
|
|
|
|
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 *symbol();
|
|
|
|
const Symbol *symbol() const {
|
|
|
|
return const_cast<SymbolBody *>(this)->symbol();
|
|
|
|
}
|
|
|
|
|
2015-07-29 06:58:25 +08:00
|
|
|
Kind kind() const { return static_cast<Kind>(SymbolKind); }
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-04-27 08:05:06 +08:00
|
|
|
bool isUndefined() const { return SymbolKind == UndefinedKind; }
|
2015-09-05 06:28:10 +08:00
|
|
|
bool isDefined() const { return SymbolKind <= DefinedLast; }
|
2015-08-31 07:17:30 +08:00
|
|
|
bool isCommon() const { return SymbolKind == DefinedCommonKind; }
|
2016-04-08 03:24:51 +08:00
|
|
|
bool isLazy() const {
|
|
|
|
return SymbolKind == LazyArchiveKind || SymbolKind == LazyObjectKind;
|
|
|
|
}
|
2015-09-08 23:50:05 +08:00
|
|
|
bool isShared() const { return SymbolKind == SharedKind; }
|
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
|
|
|
bool isLocal() const { return IsLocal; }
|
2016-03-14 03:48:18 +08:00
|
|
|
bool isPreemptible() const;
|
2016-03-13 12:40:14 +08:00
|
|
|
|
2016-06-28 16:21:10 +08:00
|
|
|
StringRef getName() const;
|
2016-07-18 01:23:17 +08:00
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
uint32_t getNameOffset() const {
|
|
|
|
assert(isLocal());
|
|
|
|
return NameOffset;
|
|
|
|
}
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-04-05 03:09:08 +08:00
|
|
|
uint8_t getVisibility() const { return StOther & 0x3; }
|
2015-09-02 07:12:52 +08:00
|
|
|
|
2016-01-29 09:49:33 +08:00
|
|
|
unsigned DynsymIndex = 0;
|
2015-10-09 08:42:06 +08:00
|
|
|
uint32_t GotIndex = -1;
|
2015-10-20 16:54:27 +08:00
|
|
|
uint32_t GotPltIndex = -1;
|
2015-10-09 08:42:06 +08:00
|
|
|
uint32_t PltIndex = -1;
|
2016-06-06 03:03:28 +08:00
|
|
|
uint32_t GlobalDynIndex = -1;
|
2015-09-18 22:40:19 +08:00
|
|
|
bool isInGot() const { return GotIndex != -1U; }
|
2015-09-21 23:11:29 +08:00
|
|
|
bool isInPlt() const { return PltIndex != -1U; }
|
2016-07-09 00:10:27 +08:00
|
|
|
template <class ELFT> bool hasThunk() const;
|
2015-09-21 23:11:29 +08:00
|
|
|
|
2016-03-15 03:37:58 +08:00
|
|
|
template <class ELFT>
|
2016-03-15 07:16:09 +08:00
|
|
|
typename ELFT::uint getVA(typename ELFT::uint Addend = 0) const;
|
|
|
|
|
2016-04-07 23:20:56 +08:00
|
|
|
template <class ELFT> typename ELFT::uint getGotOffset() const;
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint getGotVA() const;
|
2016-04-07 23:20:56 +08:00
|
|
|
template <class ELFT> typename ELFT::uint getGotPltOffset() const;
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint getGotPltVA() const;
|
|
|
|
template <class ELFT> typename ELFT::uint getPltVA() const;
|
2016-04-01 05:26:23 +08:00
|
|
|
template <class ELFT> typename ELFT::uint getThunkVA() const;
|
2016-03-15 07:16:09 +08:00
|
|
|
template <class ELFT> typename ELFT::uint getSize() const;
|
2016-02-02 05:00:35 +08:00
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
// The file from which this symbol was created.
|
|
|
|
InputFile *File = nullptr;
|
2016-05-03 05:30:42 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
protected:
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
SymbolBody(Kind K, StringRef Name, uint8_t StOther, uint8_t Type);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-04-05 03:09:08 +08:00
|
|
|
SymbolBody(Kind K, uint32_t NameOffset, uint8_t StOther, uint8_t Type);
|
2016-04-04 22:04:16 +08:00
|
|
|
|
2015-07-29 06:58:25 +08:00
|
|
|
const unsigned SymbolKind : 8;
|
2015-12-25 14:55:39 +08:00
|
|
|
|
2016-02-05 23:27:15 +08:00
|
|
|
public:
|
2016-02-09 23:11:01 +08:00
|
|
|
// True if the linker has to generate a copy relocation for this shared
|
|
|
|
// symbol or if the symbol should point to its plt entry.
|
|
|
|
unsigned NeedsCopyOrPltAddr : 1;
|
|
|
|
|
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
|
|
|
// True if this is a local symbol.
|
|
|
|
unsigned IsLocal : 1;
|
2016-04-27 08:05:06 +08:00
|
|
|
|
2016-06-20 05:39:37 +08:00
|
|
|
// True if this symbol has an entry in the global part of MIPS GOT.
|
|
|
|
unsigned IsInGlobalMipsGot : 1;
|
|
|
|
|
2016-10-21 15:22:30 +08:00
|
|
|
// True if this symbol is referenced by 32-bit GOT relocations.
|
|
|
|
unsigned Is32BitMipsGot : 1;
|
|
|
|
|
2016-04-05 02:15:38 +08:00
|
|
|
// The following fields have the same meaning as the ELF symbol attributes.
|
|
|
|
uint8_t Type; // symbol type
|
2016-04-05 03:09:08 +08:00
|
|
|
uint8_t StOther; // st_other field value
|
2016-04-05 02:15:38 +08:00
|
|
|
|
2016-05-04 02:03:47 +08:00
|
|
|
// The Type field may also have this value. It means that we have not yet seen
|
|
|
|
// a non-Lazy symbol with this name, so we don't know what its type is. The
|
|
|
|
// Type field is normally set to this value for Lazy symbols unless we saw a
|
|
|
|
// weak undefined symbol first, in which case we need to remember the original
|
|
|
|
// symbol's type in order to check for TLS mismatches.
|
|
|
|
enum { UnknownType = 255 };
|
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
bool isSection() const { return Type == llvm::ELF::STT_SECTION; }
|
|
|
|
bool isTls() const { return Type == llvm::ELF::STT_TLS; }
|
|
|
|
bool isFunc() const { return Type == llvm::ELF::STT_FUNC; }
|
|
|
|
bool isGnuIFunc() const { return Type == llvm::ELF::STT_GNU_IFUNC; }
|
|
|
|
bool isObject() const { return Type == llvm::ELF::STT_OBJECT; }
|
|
|
|
bool isFile() const { return Type == llvm::ELF::STT_FILE; }
|
2016-04-23 02:42:48 +08:00
|
|
|
|
2016-03-06 14:26:18 +08:00
|
|
|
protected:
|
2016-04-04 22:31:20 +08:00
|
|
|
struct Str {
|
|
|
|
const char *S;
|
|
|
|
size_t Len;
|
|
|
|
};
|
2016-04-04 22:04:16 +08:00
|
|
|
union {
|
2016-04-04 22:31:20 +08:00
|
|
|
Str Name;
|
2016-04-04 22:04:16 +08:00
|
|
|
uint32_t NameOffset;
|
|
|
|
};
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2015-12-24 22:22:24 +08:00
|
|
|
// The base class for any defined symbols.
|
2015-12-24 08:47:42 +08:00
|
|
|
class Defined : public SymbolBody {
|
|
|
|
public:
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
Defined(Kind K, StringRef Name, uint8_t StOther, uint8_t Type);
|
2016-04-05 03:09:08 +08:00
|
|
|
Defined(Kind K, uint32_t NameOffset, uint8_t StOther, uint8_t Type);
|
2015-12-24 08:47:42 +08:00
|
|
|
static bool classof(const SymbolBody *S) { return S->isDefined(); }
|
|
|
|
};
|
|
|
|
|
2016-08-31 21:28:33 +08:00
|
|
|
class DefinedCommon : public Defined {
|
2015-08-29 05:26:51 +08:00
|
|
|
public:
|
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
|
|
|
DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, uint8_t StOther,
|
2016-07-18 01:36:22 +08:00
|
|
|
uint8_t Type, InputFile *File);
|
2015-08-29 05:26:51 +08:00
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) {
|
2015-12-22 04:47:33 +08:00
|
|
|
return S->kind() == SymbolBody::DefinedCommonKind;
|
2015-08-29 05:26:51 +08:00
|
|
|
}
|
2015-09-01 06:55:21 +08:00
|
|
|
|
|
|
|
// The output offset of this common symbol in the output bss. Computed by the
|
|
|
|
// writer.
|
2016-07-29 03:24:13 +08:00
|
|
|
uint64_t Offset;
|
2015-09-01 09:19:12 +08:00
|
|
|
|
|
|
|
// The maximum alignment we have seen for this symbol.
|
2016-03-11 02:58:53 +08:00
|
|
|
uint64_t Alignment;
|
2015-12-25 00:23:37 +08:00
|
|
|
|
|
|
|
uint64_t Size;
|
2015-08-29 05:26:51 +08:00
|
|
|
};
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// Regular defined symbols read from object file symbol tables.
|
2016-04-03 02:06:18 +08:00
|
|
|
template <class ELFT> class DefinedRegular : public Defined {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
2016-04-04 22:04:16 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-08-14 23:10:49 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
public:
|
2016-04-03 02:06:18 +08:00
|
|
|
DefinedRegular(StringRef Name, const Elf_Sym &Sym,
|
2015-12-24 22:22:24 +08:00
|
|
|
InputSectionBase<ELFT> *Section)
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
: Defined(SymbolBody::DefinedRegularKind, Name, Sym.st_other,
|
|
|
|
Sym.getType()),
|
2016-04-04 22:04:16 +08:00
|
|
|
Value(Sym.st_value), Size(Sym.st_size),
|
2016-07-17 11:11:46 +08:00
|
|
|
Section(Section ? Section->Repl : NullInputSection) {
|
|
|
|
if (Section)
|
|
|
|
this->File = Section->getFile();
|
|
|
|
}
|
2016-04-04 22:04:16 +08:00
|
|
|
|
2016-04-05 19:47:46 +08:00
|
|
|
DefinedRegular(const Elf_Sym &Sym, InputSectionBase<ELFT> *Section)
|
|
|
|
: Defined(SymbolBody::DefinedRegularKind, Sym.st_name, Sym.st_other,
|
2016-04-04 22:04:16 +08:00
|
|
|
Sym.getType()),
|
|
|
|
Value(Sym.st_value), Size(Sym.st_size),
|
|
|
|
Section(Section ? Section->Repl : NullInputSection) {
|
|
|
|
assert(isLocal());
|
2016-07-17 11:11:46 +08:00
|
|
|
if (Section)
|
|
|
|
this->File = Section->getFile();
|
2016-04-04 22:04:16 +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
|
|
|
DefinedRegular(StringRef Name, uint8_t StOther)
|
|
|
|
: Defined(SymbolBody::DefinedRegularKind, Name, StOther,
|
2016-04-04 22:04:16 +08:00
|
|
|
llvm::ELF::STT_NOTYPE),
|
|
|
|
Value(0), Size(0), Section(NullInputSection) {}
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-08-31 20:30:34 +08:00
|
|
|
DefinedRegular(StringRef Name, uint8_t StOther, uint8_t Type, BitcodeFile *F)
|
|
|
|
: Defined(SymbolBody::DefinedRegularKind, Name, StOther, Type), Value(0),
|
|
|
|
Size(0), Section(NullInputSection) {
|
|
|
|
this->File = F;
|
|
|
|
}
|
|
|
|
|
2016-09-29 20:58:36 +08:00
|
|
|
// Return true if the symbol is a PIC function.
|
|
|
|
bool isMipsPIC() const;
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
static bool classof(const SymbolBody *S) {
|
2015-12-22 04:47:33 +08:00
|
|
|
return S->kind() == SymbolBody::DefinedRegularKind;
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
|
|
|
|
2016-04-04 22:04:16 +08:00
|
|
|
uintX_t Value;
|
|
|
|
uintX_t Size;
|
2016-04-03 02:06:18 +08:00
|
|
|
|
2016-02-26 02:43:51 +08:00
|
|
|
// The input section this symbol belongs to. Notice that this is
|
|
|
|
// a reference to a pointer. We are using two levels of indirections
|
|
|
|
// because of ICF. If ICF decides two sections need to be merged, it
|
|
|
|
// manipulates this Section pointers so that they point to the same
|
|
|
|
// section. This is a bit tricky, so be careful to not be confused.
|
|
|
|
// If this is null, the symbol is an absolute symbol.
|
|
|
|
InputSectionBase<ELFT> *&Section;
|
|
|
|
|
2016-07-09 00:10:27 +08:00
|
|
|
// If non-null the symbol has a Thunk that may be used as an alternative
|
|
|
|
// destination for callers of this Symbol.
|
2016-07-09 03:28:55 +08:00
|
|
|
Thunk<ELFT> *ThunkData = nullptr;
|
2016-07-09 00:10:27 +08:00
|
|
|
|
2016-02-26 02:43:51 +08:00
|
|
|
private:
|
|
|
|
static InputSectionBase<ELFT> *NullInputSection;
|
2015-08-12 01:33:02 +08:00
|
|
|
};
|
|
|
|
|
2016-02-26 02:43:51 +08:00
|
|
|
template <class ELFT>
|
|
|
|
InputSectionBase<ELFT> *DefinedRegular<ELFT>::NullInputSection;
|
|
|
|
|
2015-12-17 08:48:16 +08:00
|
|
|
// DefinedSynthetic is a class to represent linker-generated ELF symbols.
|
|
|
|
// The difference from the regular symbol is that DefinedSynthetic symbols
|
|
|
|
// don't belong to any input files or sections. Thus, its constructor
|
|
|
|
// takes an output section to calculate output VA, etc.
|
2016-05-03 09:21:08 +08:00
|
|
|
// If Section is null, this symbol is relative to the image base.
|
2015-12-24 08:47:42 +08:00
|
|
|
template <class ELFT> class DefinedSynthetic : public Defined {
|
2015-09-26 02:56:53 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-04-14 00:57:28 +08:00
|
|
|
DefinedSynthetic(StringRef N, uintX_t Value,
|
2016-05-03 09:21:08 +08:00
|
|
|
OutputSectionBase<ELFT> *Section);
|
2015-09-26 02:56:53 +08:00
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) {
|
2015-12-22 04:47:33 +08:00
|
|
|
return S->kind() == SymbolBody::DefinedSyntheticKind;
|
2015-09-26 02:56:53 +08:00
|
|
|
}
|
|
|
|
|
2016-04-01 05:26:23 +08:00
|
|
|
// Special value designates that the symbol 'points'
|
|
|
|
// to the end of the section.
|
|
|
|
static const uintX_t SectionEnd = uintX_t(-1);
|
|
|
|
|
2015-12-24 08:47:42 +08:00
|
|
|
uintX_t Value;
|
2016-05-03 09:21:08 +08:00
|
|
|
const OutputSectionBase<ELFT> *Section;
|
2015-09-26 02:56:53 +08:00
|
|
|
};
|
|
|
|
|
2016-04-27 08:05:06 +08:00
|
|
|
class Undefined : public SymbolBody {
|
2015-12-23 07:00:50 +08:00
|
|
|
public:
|
2016-07-17 11:11:46 +08:00
|
|
|
Undefined(StringRef Name, uint8_t StOther, uint8_t Type, InputFile *F);
|
|
|
|
Undefined(uint32_t NameOffset, uint8_t StOther, uint8_t Type, InputFile *F);
|
2015-12-23 09:06:39 +08:00
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) {
|
2016-04-27 08:05:06 +08:00
|
|
|
return S->kind() == UndefinedKind;
|
2015-12-23 09:06:39 +08:00
|
|
|
}
|
2016-05-03 05:30:42 +08:00
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
InputFile *file() { return this->File; }
|
2015-12-23 07:00:50 +08:00
|
|
|
};
|
2015-08-31 09:46:20 +08:00
|
|
|
|
2016-04-03 02:06:18 +08:00
|
|
|
template <class ELFT> class SharedSymbol : public Defined {
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
2016-04-28 04:22:31 +08:00
|
|
|
typedef typename ELFT::Verdef Elf_Verdef;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2015-09-08 23:50:05 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static bool classof(const SymbolBody *S) {
|
2015-12-22 04:47:33 +08:00
|
|
|
return S->kind() == SymbolBody::SharedKind;
|
2015-09-08 23:50:05 +08:00
|
|
|
}
|
|
|
|
|
2016-04-28 04:22:31 +08:00
|
|
|
SharedSymbol(SharedFile<ELFT> *F, StringRef Name, const Elf_Sym &Sym,
|
|
|
|
const Elf_Verdef *Verdef)
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
: Defined(SymbolBody::SharedKind, Name, Sym.st_other, Sym.getType()),
|
2016-07-17 11:11:46 +08:00
|
|
|
Sym(Sym), Verdef(Verdef) {
|
2016-04-27 00:22:51 +08:00
|
|
|
// IFuncs defined in DSOs are treated as functions by the static linker.
|
|
|
|
if (isGnuIFunc())
|
|
|
|
Type = llvm::ELF::STT_FUNC;
|
2016-07-17 11:11:46 +08:00
|
|
|
this->File = F;
|
2016-04-27 00:22:51 +08:00
|
|
|
}
|
2015-10-12 04:59:12 +08:00
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
SharedFile<ELFT> *file() { return (SharedFile<ELFT> *)this->File; }
|
|
|
|
|
2016-04-03 02:06:18 +08:00
|
|
|
const Elf_Sym &Sym;
|
2015-10-29 00:48:58 +08:00
|
|
|
|
2016-06-20 19:55:12 +08:00
|
|
|
// This field is a pointer to the symbol's version definition.
|
|
|
|
const Elf_Verdef *Verdef;
|
2016-04-28 04:22:31 +08:00
|
|
|
|
2016-02-09 23:11:01 +08:00
|
|
|
// OffsetInBss is significant only when needsCopy() is true.
|
2016-01-06 00:35:43 +08:00
|
|
|
uintX_t OffsetInBss = 0;
|
2016-02-09 23:11:01 +08:00
|
|
|
|
2016-07-09 00:10:27 +08:00
|
|
|
// If non-null the symbol has a Thunk that may be used as an alternative
|
|
|
|
// destination for callers of this Symbol.
|
2016-07-09 03:59:11 +08:00
|
|
|
Thunk<ELFT> *ThunkData = nullptr;
|
2016-04-04 22:04:16 +08:00
|
|
|
bool needsCopy() const { return this->NeedsCopyOrPltAddr && !this->isFunc(); }
|
2015-09-08 23:50:05 +08:00
|
|
|
};
|
|
|
|
|
2015-09-05 06:28:10 +08:00
|
|
|
// This class represents a symbol defined in an archive file. It is
|
|
|
|
// created from an archive file header, and it knows how to load an
|
|
|
|
// object file from an archive to replace itself with a defined
|
|
|
|
// symbol. If the resolver finds both Undefined and Lazy for
|
|
|
|
// the same name, it will ask the Lazy to load a file.
|
|
|
|
class Lazy : public SymbolBody {
|
|
|
|
public:
|
2016-04-08 03:24:51 +08:00
|
|
|
static bool classof(const SymbolBody *S) { return S->isLazy(); }
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
// Returns an object file for this symbol, or a nullptr if the file
|
|
|
|
// was already returned.
|
2016-09-14 08:05:51 +08:00
|
|
|
InputFile *fetch();
|
2016-07-18 01:44:41 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Lazy(SymbolBody::Kind K, StringRef Name, uint8_t Type)
|
|
|
|
: SymbolBody(K, Name, llvm::ELF::STV_DEFAULT, Type) {}
|
2016-04-08 03:24:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// LazyArchive symbols represents symbols in archive files.
|
|
|
|
class LazyArchive : public Lazy {
|
|
|
|
public:
|
2016-06-15 05:40:23 +08:00
|
|
|
LazyArchive(ArchiveFile &File, const llvm::object::Archive::Symbol S,
|
2016-07-17 11:11:46 +08:00
|
|
|
uint8_t Type);
|
2016-04-08 03:24:51 +08:00
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) {
|
|
|
|
return S->kind() == LazyArchiveKind;
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
ArchiveFile *file() { return (ArchiveFile *)this->File; }
|
2016-09-14 08:05:51 +08:00
|
|
|
InputFile *fetch();
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
const llvm::object::Archive::Symbol Sym;
|
|
|
|
};
|
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
// LazyObject symbols represents symbols in object files between
|
|
|
|
// --start-lib and --end-lib options.
|
|
|
|
class LazyObject : public Lazy {
|
|
|
|
public:
|
2016-07-17 11:11:46 +08:00
|
|
|
LazyObject(StringRef Name, LazyObjectFile &File, uint8_t Type);
|
2016-04-08 03:24:51 +08:00
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) {
|
|
|
|
return S->kind() == LazyObjectKind;
|
|
|
|
}
|
|
|
|
|
2016-07-17 11:11:46 +08:00
|
|
|
LazyObjectFile *file() { return (LazyObjectFile *)this->File; }
|
2016-09-14 08:05:51 +08:00
|
|
|
InputFile *fetch();
|
2016-04-08 03:24:51 +08:00
|
|
|
};
|
|
|
|
|
2015-12-25 14:12:18 +08:00
|
|
|
// Some linker-generated symbols need to be created as
|
2016-04-04 22:04:16 +08:00
|
|
|
// DefinedRegular symbols.
|
2015-12-25 14:12:18 +08:00
|
|
|
template <class ELFT> struct ElfSym {
|
2016-08-23 02:44:04 +08:00
|
|
|
// The content for __ehdr_start symbol.
|
|
|
|
static DefinedRegular<ELFT> *EhdrStart;
|
|
|
|
|
2016-02-26 22:36:36 +08:00
|
|
|
// The content for _etext and etext symbols.
|
2016-04-22 04:50:15 +08:00
|
|
|
static DefinedRegular<ELFT> *Etext;
|
|
|
|
static DefinedRegular<ELFT> *Etext2;
|
2016-02-26 22:36:36 +08:00
|
|
|
|
|
|
|
// The content for _edata and edata symbols.
|
2016-04-22 04:50:15 +08:00
|
|
|
static DefinedRegular<ELFT> *Edata;
|
|
|
|
static DefinedRegular<ELFT> *Edata2;
|
2016-02-26 22:36:36 +08:00
|
|
|
|
2015-12-25 14:12:18 +08:00
|
|
|
// The content for _end and end symbols.
|
2016-04-22 04:50:15 +08:00
|
|
|
static DefinedRegular<ELFT> *End;
|
|
|
|
static DefinedRegular<ELFT> *End2;
|
2015-12-25 14:12:18 +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
|
|
|
// The content for _gp_disp symbol for MIPS target.
|
2016-04-12 21:26:51 +08:00
|
|
|
static SymbolBody *MipsGpDisp;
|
2015-12-25 14:12:18 +08:00
|
|
|
};
|
|
|
|
|
2016-08-23 02:44:04 +08:00
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::EhdrStart;
|
2016-04-22 04:50:15 +08:00
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext2;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata2;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End2;
|
2016-04-12 21:26:51 +08:00
|
|
|
template <class ELFT> SymbolBody *ElfSym<ELFT>::MipsGpDisp;
|
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
|
|
|
|
|
|
|
// A real symbol object, SymbolBody, is usually stored within a Symbol. There's
|
|
|
|
// always one Symbol for each symbol name. The resolver updates the SymbolBody
|
|
|
|
// stored in the Body field of this object as it resolves symbols. Symbol also
|
|
|
|
// holds computed properties of symbol names.
|
|
|
|
struct Symbol {
|
|
|
|
// Symbol binding. This is on the Symbol to track changes during resolution.
|
|
|
|
// In particular:
|
|
|
|
// An undefined weak is still weak when it resolves to a shared library.
|
|
|
|
// An undefined weak will not fetch archive members, but we have to remember
|
|
|
|
// it is weak.
|
|
|
|
uint8_t Binding;
|
|
|
|
|
2016-06-20 19:55:12 +08:00
|
|
|
// Version definition index.
|
|
|
|
uint16_t VersionId;
|
|
|
|
|
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 visibility. This is the computed minimum visibility of all
|
|
|
|
// observed non-DSO symbols.
|
|
|
|
unsigned Visibility : 2;
|
|
|
|
|
|
|
|
// True if the symbol was used for linking and thus need to be added to the
|
|
|
|
// output file's symbol table. This is true for all symbols except for
|
|
|
|
// unreferenced DSO symbols and bitcode symbols that are unreferenced except
|
|
|
|
// by other bitcode objects.
|
|
|
|
unsigned IsUsedInRegularObj : 1;
|
|
|
|
|
|
|
|
// If this flag is true and the symbol has protected or default visibility, it
|
|
|
|
// will appear in .dynsym. This flag is set by interposable DSO symbols in
|
|
|
|
// executables, by most symbols in DSOs and executables built with
|
|
|
|
// --export-dynamic, and by dynamic lists.
|
|
|
|
unsigned ExportDynamic : 1;
|
|
|
|
|
2016-07-18 01:50:09 +08:00
|
|
|
// True if this symbol is specified by --trace-symbol option.
|
|
|
|
unsigned Traced : 1;
|
|
|
|
|
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
|
|
|
bool includeInDynsym() const;
|
|
|
|
bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
|
|
|
|
|
|
|
|
// This field is used to store the Symbol's SymbolBody. This instantiation of
|
|
|
|
// AlignedCharArrayUnion gives us a struct with a char array field that is
|
|
|
|
// large and aligned enough to store any derived class of SymbolBody. We
|
|
|
|
// assume that the size and alignment of ELF64LE symbols is sufficient for any
|
|
|
|
// ELFT, and we verify this with the static_asserts in replaceBody.
|
2016-08-31 21:28:33 +08:00
|
|
|
llvm::AlignedCharArrayUnion<
|
|
|
|
DefinedCommon, DefinedRegular<llvm::object::ELF64LE>,
|
|
|
|
DefinedSynthetic<llvm::object::ELF64LE>, Undefined,
|
2016-10-20 16:36:42 +08:00
|
|
|
SharedSymbol<llvm::object::ELF64LE>, LazyArchive, LazyObject> 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
|
|
|
|
|
|
|
SymbolBody *body() { return reinterpret_cast<SymbolBody *>(Body.buffer); }
|
|
|
|
const SymbolBody *body() const { return const_cast<Symbol *>(this)->body(); }
|
|
|
|
};
|
|
|
|
|
2016-07-18 01:50:09 +08:00
|
|
|
void printTraceSymbol(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
|
|
|
template <typename T, typename... ArgT>
|
|
|
|
void replaceBody(Symbol *S, ArgT &&... Arg) {
|
|
|
|
static_assert(sizeof(T) <= sizeof(S->Body), "Body too small");
|
2016-10-20 23:55:41 +08:00
|
|
|
static_assert(alignof(T) <= alignof(decltype(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
|
|
|
"Body not aligned enough");
|
2016-05-01 13:39:02 +08:00
|
|
|
assert(static_cast<SymbolBody *>(static_cast<T *>(nullptr)) == nullptr &&
|
|
|
|
"Not a SymbolBody");
|
2016-07-18 01:50:09 +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
|
|
|
new (S->Body.buffer) T(std::forward<ArgT>(Arg)...);
|
2016-07-18 01:50:09 +08:00
|
|
|
|
|
|
|
// Print out a log message if --trace-symbol was specified.
|
|
|
|
// This is for debugging.
|
|
|
|
if (S->Traced)
|
|
|
|
printTraceSymbol(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
|
|
|
}
|
|
|
|
|
|
|
|
inline Symbol *SymbolBody::symbol() {
|
|
|
|
assert(!isLocal());
|
|
|
|
return reinterpret_cast<Symbol *>(reinterpret_cast<char *>(this) -
|
|
|
|
offsetof(Symbol, Body));
|
|
|
|
}
|
2015-12-25 14:12:18 +08:00
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|