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;
|
2015-07-25 05:03:07 +08:00
|
|
|
class InputFile;
|
|
|
|
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
|
|
|
|
2016-01-14 02:55:39 +08:00
|
|
|
// Returns a demangled C++ symbol name. If Name is not a mangled
|
|
|
|
// name or the system does not provide __cxa_demangle function,
|
|
|
|
// it returns the unmodified string.
|
|
|
|
std::string demangle(StringRef Name);
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// A real symbol object, SymbolBody, is usually accessed indirectly
|
|
|
|
// through a Symbol. There's always one Symbol for each symbol name.
|
|
|
|
// The resolver updates SymbolBody pointers as it resolves symbols.
|
|
|
|
struct Symbol {
|
|
|
|
SymbolBody *Body;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The base class for real symbol classes.
|
|
|
|
class SymbolBody {
|
2016-04-06 21:22:41 +08:00
|
|
|
void init();
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
public:
|
|
|
|
enum Kind {
|
2015-09-26 05:20:23 +08:00
|
|
|
DefinedFirst,
|
|
|
|
DefinedRegularKind = DefinedFirst,
|
|
|
|
SharedKind,
|
2015-12-25 00:23:37 +08:00
|
|
|
DefinedCommonKind,
|
2016-02-13 04:54:57 +08:00
|
|
|
DefinedBitcodeKind,
|
2015-12-24 08:47:42 +08:00
|
|
|
DefinedSyntheticKind,
|
|
|
|
DefinedLast = DefinedSyntheticKind,
|
2015-12-23 07:00:50 +08:00
|
|
|
UndefinedElfKind,
|
2016-04-06 21:22:41 +08:00
|
|
|
UndefinedBitcodeKind,
|
2015-09-26 05:20:23 +08:00
|
|
|
LazyKind
|
2015-07-25 05:03:07 +08:00
|
|
|
};
|
|
|
|
|
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-04 22:04:16 +08:00
|
|
|
bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; }
|
2015-12-23 07:00:50 +08:00
|
|
|
bool isUndefined() const {
|
2016-04-06 21:22:41 +08:00
|
|
|
return SymbolKind == UndefinedBitcodeKind || SymbolKind == UndefinedElfKind;
|
2015-12-23 07:00:50 +08:00
|
|
|
}
|
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; }
|
2015-09-05 06:28:10 +08:00
|
|
|
bool isLazy() const { return SymbolKind == LazyKind; }
|
2015-09-08 23:50:05 +08:00
|
|
|
bool isShared() const { return SymbolKind == SharedKind; }
|
2016-04-04 22:04:16 +08:00
|
|
|
bool isLocal() const { return Binding == llvm::ELF::STB_LOCAL; }
|
2015-09-08 23:50:05 +08:00
|
|
|
bool isUsedInRegularObj() const { return IsUsedInRegularObj; }
|
2016-03-14 03:48:18 +08:00
|
|
|
bool isPreemptible() const;
|
2016-03-13 12:40:14 +08:00
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// Returns the symbol name.
|
2016-04-04 22:04:16 +08:00
|
|
|
StringRef getName() const {
|
|
|
|
assert(!isLocal());
|
2016-04-04 22:31:20 +08:00
|
|
|
return StringRef(Name.S, Name.Len);
|
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-12-02 03:20:26 +08:00
|
|
|
uint32_t GlobalDynIndex = -1;
|
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-04-01 05:26:23 +08:00
|
|
|
uint32_t ThunkIndex = -1;
|
2015-12-02 03:20:26 +08:00
|
|
|
bool hasGlobalDynIndex() { return GlobalDynIndex != uint32_t(-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-04-01 05:26:23 +08:00
|
|
|
bool hasThunk() const { return ThunkIndex != -1U; }
|
2015-09-21 23:11:29 +08:00
|
|
|
|
2016-03-29 08:15:52 +08:00
|
|
|
void setUsedInRegularObj() { IsUsedInRegularObj = true; }
|
|
|
|
|
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
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// A SymbolBody has a backreference to a Symbol. Originally they are
|
|
|
|
// doubly-linked. A backreference will never change. But the pointer
|
|
|
|
// in the Symbol may be mutated by the resolver. If you have a
|
|
|
|
// pointer P to a SymbolBody and are not sure whether the resolver
|
|
|
|
// has chosen the object among other objects having the same name,
|
|
|
|
// you can access P->Backref->Body to get the resolver's result.
|
|
|
|
void setBackref(Symbol *P) { Backref = P; }
|
2016-03-11 20:06:30 +08:00
|
|
|
SymbolBody &repl() { return Backref ? *Backref->Body : *this; }
|
2016-03-23 05:04:03 +08:00
|
|
|
Symbol *getSymbol() const { return Backref; }
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
// Decides which symbol should "win" in the symbol table, this or
|
|
|
|
// the Other. Returns 1 if this wins, -1 if the Other wins, or 0 if
|
|
|
|
// they are duplicate (conflicting) symbols.
|
2016-04-05 08:47:58 +08:00
|
|
|
int compare(SymbolBody *Other);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
protected:
|
2016-04-05 03:09:08 +08:00
|
|
|
SymbolBody(Kind K, StringRef Name, uint8_t Binding, uint8_t StOther,
|
2016-04-06 21:22:41 +08:00
|
|
|
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
|
|
|
|
|
|
|
// True if the symbol was used for linking and thus need to be
|
|
|
|
// added to the output file's symbol table. It is usually true,
|
|
|
|
// but if it is a shared symbol that were not referenced by anyone,
|
|
|
|
// it can be false.
|
2015-09-08 23:50:05 +08:00
|
|
|
unsigned IsUsedInRegularObj : 1;
|
2015-12-25 14:55:39 +08:00
|
|
|
|
2016-02-05 23:27:15 +08:00
|
|
|
public:
|
2015-12-25 14:55:39 +08:00
|
|
|
// If true, the symbol is added to .dynsym symbol table.
|
2016-02-05 23:27:15 +08:00
|
|
|
unsigned MustBeInDynSym : 1;
|
2015-12-25 14:55:39 +08:00
|
|
|
|
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;
|
|
|
|
|
2016-04-06 22:31:03 +08:00
|
|
|
unsigned CanKeepUndefined : 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
|
|
|
|
uint8_t Binding; // symbol binding
|
2016-04-05 03:09:08 +08:00
|
|
|
uint8_t StOther; // st_other field value
|
2016-04-05 02:15:38 +08:00
|
|
|
|
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-05 03:09:08 +08:00
|
|
|
void setVisibility(uint8_t V) { StOther = (StOther & ~0x3) | V; }
|
2016-02-09 23:11:01 +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
|
|
|
Symbol *Backref = nullptr;
|
|
|
|
};
|
|
|
|
|
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:
|
2016-04-05 03:09:08 +08:00
|
|
|
Defined(Kind K, StringRef Name, uint8_t Binding, uint8_t StOther,
|
|
|
|
uint8_t Type);
|
|
|
|
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-04-03 02:06:18 +08:00
|
|
|
// The defined symbol in LLVM bitcode files.
|
2016-02-13 04:54:57 +08:00
|
|
|
class DefinedBitcode : public Defined {
|
|
|
|
public:
|
2016-04-05 03:09:08 +08:00
|
|
|
DefinedBitcode(StringRef Name, bool IsWeak, uint8_t StOther);
|
2016-02-13 04:54:57 +08:00
|
|
|
static bool classof(const SymbolBody *S);
|
|
|
|
};
|
|
|
|
|
2015-12-25 00:23:37 +08:00
|
|
|
class DefinedCommon : public Defined {
|
2015-08-29 05:26:51 +08:00
|
|
|
public:
|
2016-04-04 22:04:16 +08:00
|
|
|
DefinedCommon(StringRef N, uint64_t Size, uint64_t Alignment, uint8_t Binding,
|
2016-04-05 03:09:08 +08:00
|
|
|
uint8_t StOther, uint8_t Type);
|
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-01-06 00:35:43 +08:00
|
|
|
uint64_t OffsetInBss;
|
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)
|
2016-04-04 22:04:16 +08:00
|
|
|
: Defined(SymbolBody::DefinedRegularKind, Name, Sym.getBinding(),
|
|
|
|
Sym.st_other, Sym.getType()),
|
|
|
|
Value(Sym.st_value), Size(Sym.st_size),
|
|
|
|
Section(Section ? Section->Repl : NullInputSection) {}
|
|
|
|
|
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-04-05 03:09:08 +08:00
|
|
|
DefinedRegular(StringRef Name, uint8_t Binding, uint8_t StOther)
|
|
|
|
: Defined(SymbolBody::DefinedRegularKind, Name, Binding, 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
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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.
|
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-03-02 00:23:13 +08:00
|
|
|
DefinedSynthetic(StringRef N, uintX_t Value, OutputSectionBase<ELFT> &Section,
|
2016-04-05 03:09:08 +08:00
|
|
|
uint8_t StOther);
|
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;
|
2015-10-16 06:27:29 +08:00
|
|
|
const OutputSectionBase<ELFT> &Section;
|
2015-09-26 02:56:53 +08:00
|
|
|
};
|
|
|
|
|
2016-04-06 21:22:41 +08:00
|
|
|
class UndefinedBitcode : public SymbolBody {
|
2015-12-23 07:00:50 +08:00
|
|
|
public:
|
2016-04-06 21:22:41 +08:00
|
|
|
UndefinedBitcode(StringRef N, bool IsWeak, uint8_t StOther);
|
2015-08-15 00:46:28 +08:00
|
|
|
|
2016-04-06 21:22:41 +08:00
|
|
|
static bool classof(const SymbolBody *S) {
|
|
|
|
return S->kind() == UndefinedBitcodeKind;
|
|
|
|
}
|
2015-08-15 00:46:28 +08:00
|
|
|
};
|
|
|
|
|
2016-04-06 21:22:41 +08:00
|
|
|
template <class ELFT> class UndefinedElf : public SymbolBody {
|
2016-04-04 22:04:16 +08:00
|
|
|
typedef typename ELFT::uint uintX_t;
|
2016-03-15 07:16:09 +08:00
|
|
|
typedef typename ELFT::Sym Elf_Sym;
|
2015-12-23 07:00:50 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
UndefinedElf(StringRef N, const Elf_Sym &Sym);
|
2016-04-05 19:47:46 +08:00
|
|
|
UndefinedElf(const Elf_Sym &Sym);
|
2016-04-06 21:22:41 +08:00
|
|
|
UndefinedElf(StringRef Name, uint8_t Binding, uint8_t StOther, uint8_t Type,
|
|
|
|
bool CanKeepUndefined);
|
|
|
|
|
|
|
|
bool canKeepUndefined() const { return CanKeepUndefined; }
|
2016-04-04 22:04:16 +08:00
|
|
|
|
|
|
|
uintX_t Size;
|
2015-12-23 09:06:39 +08:00
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) {
|
|
|
|
return S->kind() == SymbolBody::UndefinedElfKind;
|
|
|
|
}
|
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;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-10-12 04:59:12 +08:00
|
|
|
SharedSymbol(SharedFile<ELFT> *F, StringRef Name, const Elf_Sym &Sym)
|
2016-04-04 22:04:16 +08:00
|
|
|
: Defined(SymbolBody::SharedKind, Name, Sym.getBinding(), Sym.st_other,
|
|
|
|
Sym.getType()),
|
2016-04-03 02:06:18 +08:00
|
|
|
File(F), Sym(Sym) {}
|
2015-10-12 04:59:12 +08:00
|
|
|
|
|
|
|
SharedFile<ELFT> *File;
|
2016-04-03 02:06:18 +08:00
|
|
|
const Elf_Sym &Sym;
|
2015-10-29 00:48:58 +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-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:
|
|
|
|
Lazy(ArchiveFile *F, const llvm::object::Archive::Symbol S)
|
2016-04-04 22:04:16 +08:00
|
|
|
: SymbolBody(LazyKind, S.getName(), llvm::ELF::STB_GLOBAL,
|
|
|
|
llvm::ELF::STV_DEFAULT, /* Type */ 0),
|
2015-09-05 06:28:10 +08:00
|
|
|
File(F), Sym(S) {}
|
|
|
|
|
|
|
|
static bool classof(const SymbolBody *S) { return S->kind() == LazyKind; }
|
|
|
|
|
|
|
|
// Returns an object file for this symbol, or a nullptr if the file
|
|
|
|
// was already returned.
|
|
|
|
std::unique_ptr<InputFile> getMember();
|
|
|
|
|
|
|
|
private:
|
|
|
|
ArchiveFile *File;
|
|
|
|
const llvm::object::Archive::Symbol Sym;
|
|
|
|
};
|
|
|
|
|
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-02-26 22:36:36 +08:00
|
|
|
// The content for _etext and etext symbols.
|
2016-04-04 22:04:16 +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-04 22:04:16 +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-04 22:04:16 +08:00
|
|
|
static DefinedRegular<ELFT> *End;
|
|
|
|
static DefinedRegular<ELFT> *End2;
|
2015-12-25 14:12:18 +08:00
|
|
|
|
|
|
|
// The content for _gp symbol for MIPS target.
|
2016-04-04 22:04:16 +08:00
|
|
|
static DefinedRegular<ELFT> *MipsGp;
|
2015-12-25 14:12:18 +08:00
|
|
|
|
|
|
|
// __rel_iplt_start/__rel_iplt_end for signaling
|
|
|
|
// where R_[*]_IRELATIVE relocations do live.
|
2016-04-04 22:04:16 +08:00
|
|
|
static DefinedRegular<ELFT> *RelaIpltStart;
|
|
|
|
static DefinedRegular<ELFT> *RelaIpltEnd;
|
2015-12-25 14:12:18 +08:00
|
|
|
};
|
|
|
|
|
2016-04-04 22:04:16 +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;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGp;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::RelaIpltStart;
|
|
|
|
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::RelaIpltEnd;
|
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
|