2015-08-14 22:12:54 +08:00
|
|
|
//===- InputFiles.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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLD_ELF_INPUT_FILES_H
|
|
|
|
#define LLD_ELF_INPUT_FILES_H
|
|
|
|
|
2015-10-07 17:13:03 +08:00
|
|
|
#include "Config.h"
|
2015-09-05 06:28:10 +08:00
|
|
|
#include "Error.h"
|
2017-07-18 19:55:35 +08:00
|
|
|
#include "InputSection.h"
|
2015-08-28 10:40:04 +08:00
|
|
|
#include "Symbols.h"
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
#include "lld/Core/LLVM.h"
|
2016-07-26 10:00:42 +08:00
|
|
|
#include "lld/Core/Reproduce.h"
|
2017-05-26 05:53:02 +08:00
|
|
|
#include "llvm/ADT/CachedHashString.h"
|
2015-09-05 06:28:10 +08:00
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2016-03-12 02:46:51 +08:00
|
|
|
#include "llvm/IR/Comdat.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"
|
2016-03-12 02:46:51 +08:00
|
|
|
#include "llvm/Object/IRObjectFile.h"
|
2017-07-21 19:26:08 +08:00
|
|
|
#include "llvm/Support/Threading.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-04-28 04:22:31 +08:00
|
|
|
#include <map>
|
|
|
|
|
2016-09-29 08:40:08 +08:00
|
|
|
namespace llvm {
|
2016-10-26 19:07:09 +08:00
|
|
|
class DWARFDebugLine;
|
2017-01-09 09:42:02 +08:00
|
|
|
class TarWriter;
|
2017-03-31 03:13:47 +08:00
|
|
|
struct DILineInfo;
|
2016-09-29 08:40:08 +08:00
|
|
|
namespace lto {
|
|
|
|
class InputFile;
|
|
|
|
}
|
2017-07-18 19:55:35 +08:00
|
|
|
} // namespace llvm
|
2016-09-29 08:40:08 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
namespace lld {
|
2017-01-06 18:04:08 +08:00
|
|
|
namespace elf {
|
|
|
|
class InputFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns "(internal)", "foo.a(bar.o)" or "baz.o".
|
|
|
|
std::string toString(const elf::InputFile *F);
|
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
namespace elf {
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
using llvm::object::Archive;
|
|
|
|
|
|
|
|
class Lazy;
|
2015-07-25 05:03:07 +08:00
|
|
|
class SymbolBody;
|
|
|
|
|
2017-01-09 09:42:02 +08:00
|
|
|
// If -reproduce option is given, all input files are written
|
|
|
|
// to this tar archive.
|
|
|
|
extern llvm::TarWriter *Tar;
|
|
|
|
|
|
|
|
// Opens a given file.
|
|
|
|
llvm::Optional<MemoryBufferRef> readFile(StringRef Path);
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// The root class of input files.
|
|
|
|
class InputFile {
|
|
|
|
public:
|
2016-04-08 03:24:51 +08:00
|
|
|
enum Kind {
|
|
|
|
ObjectKind,
|
|
|
|
SharedKind,
|
|
|
|
LazyObjectKind,
|
|
|
|
ArchiveKind,
|
|
|
|
BitcodeKind,
|
2016-09-10 06:08:04 +08:00
|
|
|
BinaryKind,
|
2016-04-08 03:24:51 +08:00
|
|
|
};
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
Kind kind() const { return FileKind; }
|
|
|
|
|
2015-08-05 20:03:34 +08:00
|
|
|
StringRef getName() const { return MB.getBufferIdentifier(); }
|
2016-02-13 04:54:57 +08:00
|
|
|
MemoryBufferRef MB;
|
2015-08-05 20:03:34 +08:00
|
|
|
|
2017-03-22 01:22:13 +08:00
|
|
|
// Returns sections. It is a runtime error to call this function
|
|
|
|
// on files that don't have the notion of sections.
|
2017-03-21 16:19:34 +08:00
|
|
|
ArrayRef<InputSectionBase *> getSections() const {
|
|
|
|
assert(FileKind == ObjectKind || FileKind == BinaryKind);
|
|
|
|
return Sections;
|
|
|
|
}
|
|
|
|
|
2016-02-02 16:22:41 +08:00
|
|
|
// Filename of .a which contained this file. If this file was
|
|
|
|
// not in an archive file, it is the empty string. We use this
|
|
|
|
// string for creating error messages.
|
2016-02-03 04:24:31 +08:00
|
|
|
StringRef ArchiveName;
|
2016-02-02 16:22:41 +08:00
|
|
|
|
2016-06-29 09:30:50 +08:00
|
|
|
// If this is an architecture-specific file, the following members
|
|
|
|
// have ELF type (i.e. ELF{32,64}{LE,BE}) and target machine type.
|
|
|
|
ELFKind EKind = ELFNoneKind;
|
|
|
|
uint16_t EMachine = llvm::ELF::EM_NONE;
|
2016-10-27 22:00:51 +08:00
|
|
|
uint8_t OSABI = 0;
|
2016-06-29 09:30:50 +08:00
|
|
|
|
2017-04-04 03:11:23 +08:00
|
|
|
// Cache for toString(). Only toString() should use this member.
|
|
|
|
mutable std::string ToStringCache;
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
protected:
|
2017-03-31 05:13:00 +08:00
|
|
|
InputFile(Kind K, MemoryBufferRef M);
|
2017-03-21 16:19:34 +08:00
|
|
|
std::vector<InputSectionBase *> Sections;
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
private:
|
|
|
|
const Kind FileKind;
|
|
|
|
};
|
|
|
|
|
2015-10-12 09:55:32 +08:00
|
|
|
template <typename ELFT> class ELFFileBase : public InputFile {
|
2015-09-04 04:03:54 +08:00
|
|
|
public:
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::Word Elf_Word;
|
|
|
|
typedef typename ELFT::SymRange Elf_Sym_Range;
|
2015-10-12 09:55:32 +08:00
|
|
|
|
2015-10-13 09:17:02 +08:00
|
|
|
ELFFileBase(Kind K, MemoryBufferRef M);
|
2015-09-04 04:03:54 +08:00
|
|
|
static bool classof(const InputFile *F) {
|
|
|
|
Kind K = F->kind();
|
|
|
|
return K == ObjectKind || K == SharedKind;
|
|
|
|
}
|
|
|
|
|
2016-11-04 04:44:50 +08:00
|
|
|
llvm::object::ELFFile<ELFT> getObj() const {
|
|
|
|
return llvm::object::ELFFile<ELFT>(MB.getBuffer());
|
|
|
|
}
|
2015-10-12 09:55:32 +08:00
|
|
|
|
|
|
|
StringRef getStringTable() const { return StringTable; }
|
2015-09-23 00:53:55 +08:00
|
|
|
|
2015-11-03 22:13:40 +08:00
|
|
|
uint32_t getSectionIndex(const Elf_Sym &Sym) const;
|
|
|
|
|
2016-11-04 04:48:57 +08:00
|
|
|
Elf_Sym_Range getGlobalSymbols();
|
2017-07-20 06:27:35 +08:00
|
|
|
Elf_Sym_Range getELFSymbols() const { return Symbols; }
|
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
|
|
|
|
2015-09-04 04:03:54 +08:00
|
|
|
protected:
|
2016-11-04 00:55:44 +08:00
|
|
|
ArrayRef<Elf_Sym> Symbols;
|
|
|
|
uint32_t FirstNonLocal = 0;
|
2015-11-03 22:13:40 +08:00
|
|
|
ArrayRef<Elf_Word> SymtabSHNDX;
|
2015-10-12 23:15:45 +08:00
|
|
|
StringRef StringTable;
|
2016-11-03 23:43:47 +08:00
|
|
|
void initSymtab(ArrayRef<Elf_Shdr> Sections, const Elf_Shdr *Symtab);
|
2015-10-12 20:14:30 +08:00
|
|
|
};
|
|
|
|
|
2015-10-12 10:22:58 +08:00
|
|
|
// .o file.
|
|
|
|
template <class ELFT> class ObjectFile : public ELFFileBase<ELFT> {
|
|
|
|
typedef ELFFileBase<ELFT> Base;
|
2016-11-10 22:53:24 +08:00
|
|
|
typedef typename ELFT::Rel Elf_Rel;
|
|
|
|
typedef typename ELFT::Rela Elf_Rela;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Word Elf_Word;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-11-03 10:28:13 +08:00
|
|
|
StringRef getShtGroupSignature(ArrayRef<Elf_Shdr> Sections,
|
|
|
|
const Elf_Shdr &Sec);
|
2016-03-14 06:02:04 +08:00
|
|
|
ArrayRef<Elf_Word> getShtGroupEntries(const Elf_Shdr &Sec);
|
2015-10-10 03:25:07 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
public:
|
2015-09-03 04:43:43 +08:00
|
|
|
static bool classof(const InputFile *F) {
|
2015-10-13 09:17:02 +08:00
|
|
|
return F->kind() == Base::ObjectKind;
|
2015-09-03 04:43:43 +08:00
|
|
|
}
|
2015-08-05 20:03:34 +08:00
|
|
|
|
2016-03-11 20:06:30 +08:00
|
|
|
ArrayRef<SymbolBody *> getSymbols();
|
|
|
|
ArrayRef<SymbolBody *> getLocalSymbols();
|
2015-10-12 10:22:58 +08:00
|
|
|
|
2017-04-27 06:51:51 +08:00
|
|
|
ObjectFile(MemoryBufferRef M, StringRef ArchiveName);
|
2017-05-26 05:53:02 +08:00
|
|
|
void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2017-02-23 10:28:28 +08:00
|
|
|
InputSectionBase *getSection(const Elf_Sym &Sym) const;
|
2015-08-05 21:55:34 +08:00
|
|
|
|
2016-03-11 20:06:30 +08:00
|
|
|
SymbolBody &getSymbolBody(uint32_t SymbolIndex) const {
|
2016-10-04 17:02:42 +08:00
|
|
|
if (SymbolIndex >= SymbolBodies.size())
|
2016-11-24 02:07:33 +08:00
|
|
|
fatal(toString(this) + ": invalid symbol index");
|
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 *SymbolBodies[SymbolIndex];
|
2015-08-28 07:15:56 +08:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:36:42 +08:00
|
|
|
template <typename RelT>
|
|
|
|
SymbolBody &getRelocTargetSym(const RelT &Rel) const {
|
2017-03-18 07:29:01 +08:00
|
|
|
uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
|
2016-04-27 07:52:44 +08:00
|
|
|
return getSymbolBody(SymIndex);
|
|
|
|
}
|
|
|
|
|
2016-11-03 02:42:13 +08:00
|
|
|
// Returns source line information for a given offset.
|
|
|
|
// If no information is available, returns "".
|
2017-02-25 03:52:52 +08:00
|
|
|
std::string getLineInfo(InputSectionBase *S, uint64_t Offset);
|
2017-03-31 03:13:47 +08:00
|
|
|
llvm::Optional<llvm::DILineInfo> getDILineInfo(InputSectionBase *, uint64_t);
|
2016-10-26 19:07:09 +08:00
|
|
|
|
2016-11-10 05:36:56 +08:00
|
|
|
// MIPS GP0 value defined by this file. This value represents the gp value
|
2015-12-25 21:02:13 +08:00
|
|
|
// used to create the relocatable object and required to support
|
|
|
|
// R_MIPS_GPREL16 / R_MIPS_GPREL32 relocations.
|
2016-11-10 05:36:56 +08:00
|
|
|
uint32_t MipsGp0 = 0;
|
2015-12-25 21:02:13 +08:00
|
|
|
|
2016-10-26 19:07:09 +08:00
|
|
|
// Name of source file obtained from STT_FILE symbol value,
|
|
|
|
// or empty string if there is no such symbol in object file
|
|
|
|
// symbol table.
|
|
|
|
StringRef SourceFile;
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
private:
|
2017-05-26 05:53:02 +08:00
|
|
|
void
|
|
|
|
initializeSections(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
|
2016-11-08 23:51:00 +08:00
|
|
|
void initializeSymbols();
|
2016-11-03 02:42:13 +08:00
|
|
|
void initializeDwarfLine();
|
2017-02-23 10:28:28 +08:00
|
|
|
InputSectionBase *getRelocTarget(const Elf_Shdr &Sec);
|
2017-06-13 02:46:33 +08:00
|
|
|
InputSectionBase *createInputSection(const Elf_Shdr &Sec);
|
|
|
|
StringRef getSectionName(const Elf_Shdr &Sec);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2016-07-16 04:38:28 +08:00
|
|
|
bool shouldMerge(const Elf_Shdr &Sec);
|
2016-01-21 10:10:12 +08:00
|
|
|
SymbolBody *createSymbolBody(const Elf_Sym *Sym);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-10-12 10:22:58 +08:00
|
|
|
// List of all symbols referenced or defined by this file.
|
|
|
|
std::vector<SymbolBody *> SymbolBodies;
|
|
|
|
|
2017-06-13 02:46:33 +08:00
|
|
|
// .shstrtab contents.
|
|
|
|
StringRef SectionStringTable;
|
|
|
|
|
2016-11-03 02:42:13 +08:00
|
|
|
// Debugging information to retrieve source file and line for error
|
|
|
|
// reporting. Linker may find reasonable number of errors in a
|
|
|
|
// single object file, so we cache debugging information in order to
|
|
|
|
// parse it only once for each object file we link.
|
|
|
|
std::unique_ptr<llvm::DWARFDebugLine> DwarfLine;
|
2017-07-21 19:26:08 +08:00
|
|
|
llvm::once_flag InitDwarfLine;
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
2016-04-08 03:24:51 +08:00
|
|
|
// LazyObjectFile is analogous to ArchiveFile in the sense that
|
|
|
|
// the file contains lazy symbols. The difference is that
|
|
|
|
// LazyObjectFile wraps a single file instead of multiple files.
|
|
|
|
//
|
|
|
|
// This class is used for --start-lib and --end-lib options which
|
|
|
|
// instruct the linker to link object files between them with the
|
|
|
|
// archive file semantics.
|
|
|
|
class LazyObjectFile : public InputFile {
|
|
|
|
public:
|
2017-05-06 03:24:58 +08:00
|
|
|
LazyObjectFile(MemoryBufferRef M, StringRef ArchiveName,
|
|
|
|
uint64_t OffsetInArchive)
|
2017-05-05 23:17:07 +08:00
|
|
|
: InputFile(LazyObjectKind, M), OffsetInArchive(OffsetInArchive) {
|
2017-05-05 21:55:51 +08:00
|
|
|
this->ArchiveName = ArchiveName;
|
|
|
|
}
|
2016-04-08 03:24:51 +08:00
|
|
|
|
|
|
|
static bool classof(const InputFile *F) {
|
|
|
|
return F->kind() == LazyObjectKind;
|
|
|
|
}
|
|
|
|
|
ELF: New symbol table design.
This patch implements a new design for the symbol table that stores
SymbolBodies within a memory region of the Symbol object. Symbols are mutated
by constructing SymbolBodies in place over existing SymbolBodies, rather
than by mutating pointers. As mentioned in the initial proposal [1], this
memory layout helps reduce the cache miss rate by improving memory locality.
Performance numbers:
old(s) new(s)
Without debug info:
chrome 7.178 6.432 (-11.5%)
LLVMgold.so 0.505 0.502 (-0.5%)
clang 0.954 0.827 (-15.4%)
llvm-as 0.052 0.045 (-15.5%)
With debug info:
scylla 5.695 5.613 (-1.5%)
clang 14.396 14.143 (-1.8%)
Performance counter results show that the fewer required indirections is
indeed the cause of the improved performance. For example, when linking
chrome, stalled cycles decreases from 14,556,444,002 to 12,959,238,310, and
instructions per cycle increases from 0.78 to 0.83. We are also executing
many fewer instructions (15,516,401,933 down to 15,002,434,310), probably
because we spend less time allocating SymbolBodies.
The new mechanism by which symbols are added to the symbol table is by calling
add* functions on the SymbolTable.
In this patch, I handle local symbols by storing them inside "unparented"
SymbolBodies. This is suboptimal, but if we do want to try to avoid allocating
these SymbolBodies, we can probably do that separately.
I also removed a few members from the SymbolBody class that were only being
used to pass information from the input file to the symbol table.
This patch implements the new design for the ELF linker only. I intend to
prepare a similar patch for the COFF linker.
[1] http://lists.llvm.org/pipermail/llvm-dev/2016-April/098832.html
Differential Revision: http://reviews.llvm.org/D19752
llvm-svn: 268178
2016-05-01 12:55:03 +08:00
|
|
|
template <class ELFT> void parse();
|
2016-06-15 05:56:36 +08:00
|
|
|
MemoryBufferRef getBuffer();
|
2017-05-04 22:54:48 +08:00
|
|
|
InputFile *fetch();
|
2016-04-08 03:24:51 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::vector<StringRef> getSymbols();
|
|
|
|
template <class ELFT> std::vector<StringRef> getElfSymbols();
|
|
|
|
std::vector<StringRef> getBitcodeSymbols();
|
|
|
|
|
2016-06-15 05:56:36 +08:00
|
|
|
bool Seen = false;
|
2017-05-05 23:17:07 +08:00
|
|
|
uint64_t OffsetInArchive;
|
2016-04-08 03:24:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// An ArchiveFile object represents a .a file.
|
2015-09-05 06:28:10 +08:00
|
|
|
class ArchiveFile : public InputFile {
|
|
|
|
public:
|
2017-05-04 05:03:08 +08:00
|
|
|
explicit ArchiveFile(std::unique_ptr<Archive> &&File);
|
2015-09-05 06:28:10 +08:00
|
|
|
static bool classof(const InputFile *F) { return F->kind() == ArchiveKind; }
|
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 parse();
|
2017-06-21 23:36:24 +08:00
|
|
|
ArrayRef<Symbol *> getSymbols() { return Symbols; }
|
2015-09-05 06:28:10 +08:00
|
|
|
|
2016-10-13 03:35:54 +08:00
|
|
|
// Returns a memory buffer for a given symbol and the offset in the archive
|
|
|
|
// for the member. An empty memory buffer and an offset of zero
|
2015-09-05 06:28:10 +08:00
|
|
|
// is returned if we have already returned the same memory buffer.
|
|
|
|
// (So that we don't instantiate same members more than once.)
|
2016-10-13 03:35:54 +08:00
|
|
|
std::pair<MemoryBufferRef, uint64_t> getMember(const Archive::Symbol *Sym);
|
2015-09-05 06:28:10 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
std::unique_ptr<Archive> File;
|
|
|
|
llvm::DenseSet<uint64_t> Seen;
|
2017-06-21 23:36:24 +08:00
|
|
|
std::vector<Symbol *> Symbols;
|
2015-09-05 06:28:10 +08:00
|
|
|
};
|
|
|
|
|
2016-02-13 04:54:57 +08:00
|
|
|
class BitcodeFile : public InputFile {
|
|
|
|
public:
|
2017-04-14 10:55:06 +08:00
|
|
|
BitcodeFile(MemoryBufferRef M, StringRef ArchiveName,
|
|
|
|
uint64_t OffsetInArchive);
|
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
|
|
|
static bool classof(const InputFile *F) { return F->kind() == BitcodeKind; }
|
2017-05-26 05:53:02 +08:00
|
|
|
template <class ELFT>
|
|
|
|
void parse(llvm::DenseSet<llvm::CachedHashStringRef> &ComdatGroups);
|
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
|
|
|
ArrayRef<Symbol *> getSymbols() { return Symbols; }
|
2016-09-29 08:40:08 +08:00
|
|
|
std::unique_ptr<llvm::lto::InputFile> Obj;
|
2016-02-13 04:54:57 +08:00
|
|
|
|
|
|
|
private:
|
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
|
|
|
std::vector<Symbol *> Symbols;
|
2016-02-13 04:54:57 +08:00
|
|
|
};
|
|
|
|
|
2015-09-04 04:03:54 +08:00
|
|
|
// .so file.
|
2015-10-12 10:22:58 +08:00
|
|
|
template <class ELFT> class SharedFile : public ELFFileBase<ELFT> {
|
2015-10-12 09:55:32 +08:00
|
|
|
typedef ELFFileBase<ELFT> Base;
|
2016-11-26 02:51:56 +08:00
|
|
|
typedef typename ELFT::Dyn Elf_Dyn;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Shdr Elf_Shdr;
|
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
|
|
|
typedef typename ELFT::SymRange Elf_Sym_Range;
|
2016-04-28 04:22:31 +08:00
|
|
|
typedef typename ELFT::Verdef Elf_Verdef;
|
2016-11-26 02:51:56 +08:00
|
|
|
typedef typename ELFT::Versym Elf_Versym;
|
2015-09-08 23:50:05 +08:00
|
|
|
|
2015-10-14 00:34:14 +08:00
|
|
|
std::vector<StringRef> Undefs;
|
2016-04-28 04:22:31 +08:00
|
|
|
const Elf_Shdr *VersymSec = nullptr;
|
|
|
|
const Elf_Shdr *VerdefSec = nullptr;
|
2015-09-08 23:50:05 +08:00
|
|
|
|
2015-09-04 04:03:54 +08:00
|
|
|
public:
|
2017-04-25 05:44:20 +08:00
|
|
|
std::string SoName;
|
|
|
|
|
2015-11-03 22:13:40 +08:00
|
|
|
const Elf_Shdr *getSection(const Elf_Sym &Sym) const;
|
2015-10-14 00:34:14 +08:00
|
|
|
llvm::ArrayRef<StringRef> getUndefinedSymbols() { return Undefs; }
|
|
|
|
|
2015-09-04 04:03:54 +08:00
|
|
|
static bool classof(const InputFile *F) {
|
2015-10-13 09:17:02 +08:00
|
|
|
return F->kind() == Base::SharedKind;
|
2015-09-04 04:03:54 +08:00
|
|
|
}
|
|
|
|
|
2017-04-25 05:44:20 +08:00
|
|
|
SharedFile(MemoryBufferRef M, StringRef DefaultSoName);
|
2015-09-04 04:03:54 +08:00
|
|
|
|
2015-10-12 10:22:58 +08:00
|
|
|
void parseSoName();
|
2016-01-06 09:56:36 +08:00
|
|
|
void parseRest();
|
2016-04-28 04:22:31 +08:00
|
|
|
std::vector<const Elf_Verdef *> parseVerdefs(const Elf_Versym *&Versym);
|
|
|
|
|
|
|
|
struct NeededVer {
|
|
|
|
// The string table offset of the version name in the output file.
|
|
|
|
size_t StrTab;
|
|
|
|
|
|
|
|
// The version identifier for this version name.
|
|
|
|
uint16_t Index;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Mapping from Elf_Verdef data structures to information about Elf_Vernaux
|
|
|
|
// data structures in the output file.
|
|
|
|
std::map<const Elf_Verdef *, NeededVer> VerdefMap;
|
2015-10-12 10:22:58 +08:00
|
|
|
|
|
|
|
// Used for --as-needed
|
|
|
|
bool AsNeeded = false;
|
|
|
|
bool IsUsed = false;
|
|
|
|
bool isNeeded() const { return !AsNeeded || IsUsed; }
|
2015-09-04 04:03:54 +08:00
|
|
|
};
|
|
|
|
|
2016-09-10 06:08:04 +08:00
|
|
|
class BinaryFile : public InputFile {
|
|
|
|
public:
|
|
|
|
explicit BinaryFile(MemoryBufferRef M) : InputFile(BinaryKind, M) {}
|
|
|
|
static bool classof(const InputFile *F) { return F->kind() == BinaryKind; }
|
2016-10-28 01:45:40 +08:00
|
|
|
template <class ELFT> void parse();
|
2016-09-10 06:08:04 +08:00
|
|
|
};
|
|
|
|
|
2016-10-29 04:57:25 +08:00
|
|
|
InputFile *createObjectFile(MemoryBufferRef MB, StringRef ArchiveName = "",
|
2016-10-13 03:35:54 +08:00
|
|
|
uint64_t OffsetInArchive = 0);
|
2017-04-25 05:44:20 +08:00
|
|
|
InputFile *createSharedFile(MemoryBufferRef MB, StringRef DefaultSoName);
|
2015-09-05 06:28:10 +08:00
|
|
|
|
2016-02-28 08:25:54 +08:00
|
|
|
} // namespace elf
|
2015-07-25 05:03:07 +08:00
|
|
|
} // namespace lld
|
|
|
|
|
|
|
|
#endif
|